# Util

## Extension Methods

### ChangeImageOpacity

* `Image image` 의 불투명한 정도가 변경된 새 인스턴스를 반환
* `float opacity` : 1F (= 100%)

```csharp
public static Image ChangeImageOpacity(this Image image, float opacity);
```

### ConvertByteArrayToImage

* 이진 이미지 데이터를 Image 타입 인스턴스로 변환

```csharp
public static Image ConvertByteArrayToImage(this byte[] byteArray);
```

### ConvertImageToByteArray

* Image 타입 인스턴스를 이진 이미지 데이터로 변환

```csharp
public static byte[] ConvertImageToByteArray(this Image image);
```

### FindNodeIdByFieldValue

* TreeList의 fieldName에 해당하는 컬럼에서 value와 동일한 값의 첫번째로 찾은 Node의 Id를 반환

```csharp
public static int FindNodeIdByFieldValue(this TreeList tree, string fieldName, object value);
```

### FindRowHandleByDataRow

* GridControl에 바인딩된 DataTable의 DataRow를 참조하여 GridView의 RowHandle을 반환

```csharp
public static int FindRowHandleByDataRow(this GridView gridView, DataRow row);
```

### GetSelectedDataRows

* 각 TreeList, GridView 에서 선택된 행(또는 노드)의 DataRow 들을 반환

```csharp
public static DataRow[] GetSelectedDataRows(this TreeList treeList);

public static DataRow[] GetSelectedDataRows(this GridView gridView);
```

###

### IsFloat

* 값(`value`)이 소수 타입(Single, Double, Decimal)인지 여부를 반환

{% tabs %}
{% tab title="C#" %}

```csharp
public static bool IsFloat(this ValueType value);
```

{% endtab %}

{% tab title="Example" %}

```csharp
int intValue = 12;
float floatValue = 12.345F;
double doubleValue = 12.345D;
decimal decimalValue = 12.345M;

intValue.IsFloat(); // false
floatValue.IsFloat(); // true
doubleValue.IsFloat(); // true
decimalValue.IsFloat(); // true
```

{% endtab %}
{% endtabs %}

### IsInteger

* 값(`value`)이 정수 타입(Byte, SByte, Int16, Int32, Int64, UInt16, UInt32, UInt64)인지 여부를 반환

{% tabs %}
{% tab title="C#" %}

```csharp
public static bool IsInteger(this ValueType value);
```

{% endtab %}

{% tab title="Example" %}

```csharp
int intValue = 12;
float floatValue = 12.345F;
double doubleValue = 12.345D;
decimal decimalValue = 12.345M;

intValue.IsInteger(); // true
floatValue.IsInteger(); // false
doubleValue.IsInteger(); // false
decimalValue.IsInteger(); // false
```

{% endtab %}
{% endtabs %}

### IsNumeric

* 값(`value`)이 숫자 타입(Single, Double, Decimal, Byte, SByte, Int16, Int32, Int64, UInt16, UInt32, UInt64)인지 여부를 반환

{% tabs %}
{% tab title="C#" %}

```csharp
public static bool IsNumeric(this ValueType value);
```

{% endtab %}

{% tab title="Example" %}

```csharp
int intValue = 12;
float floatValue = 12.345F;
double doubleValue = 12.345D;
decimal decimalValue = 12.345M;

intValue.IsNumeric(); // true
floatValue.IsNumeric(); // true
doubleValue.IsNumeric(); // true
decimalValue.IsNumeric(); // true
```

{% endtab %}
{% endtabs %}

### IsNumericType

* 타입(`type`)이 숫자 타입(Single, Double, Decimal, Byte, SByte, Int16, Int32, Int64, UInt16, UInt32, UInt64)인지 여부를 반환

{% tabs %}
{% tab title="C#" %}

```csharp
public static bool IsNumericType(this Type type);
```

{% endtab %}

{% tab title="Example" %}

```csharp
string stringValue = "ABC";
int intValue = 12;
float floatValue = 12.345F;
double doubleValue = 12.345D;
decimal decimalValue = 12.345M;

stringValue.GetType().IsNumericType(); // false
intValue.GetType().IsNumericType(); // true
floatValue.GetType().IsNumericType(); // true
doubleValue.GetType().IsNumericType(); // true
decimalValue.GetType().IsNumericType(); // true
```

{% endtab %}
{% endtabs %}

### KeyCodeToUnicode

```csharp
public static string KeyCodeToUnicode(this Keys key);
```

### Left

```csharp
public static string Left(this string target, int length);
```

### Right

```csharp
public static string Right(this string target, int length);
```

### LoadDocument

```csharp
public static void LoadDocument(this SpreadsheetControl spreadsheetControl, IWorkbook document);
```

### MoveDownRow

```csharp
public static void MoveDownRow(this GridView gridView);
```

### MoveUpRow

```csharp
public static void MoveUpRow(this GridView gridView);
```

### ToClrType

```csharp
public static Type ToClrType(this SqlDbType sqlType);
```

### ToSqlDbType

```csharp
public static SqlDbType ToSqlDbType(this Type clrType);
```

### ExpandToFirstNode

```csharp
public static void ExpandToFirstNode(this TreeListNode node);
```

### GetTempDirectory

* 현재 응용 프로그램이 실행된 디렉토리에 하위 디렉토리(temp)를 생성하고 그 경로를 반환

```csharp
public static string GetTempDirectory();
```

###

### ClearTempDirectory

* 현재 응용 프로그램이 실행된 디렉토리에 하위 디렉토리(temp) 내 모든 파일을 제거

```csharp
public static void ClearTempDirectory();
```

###

### GetNextFileName

* 중복 되지 않은 파일명을 반환
* ex) Parameter Value( "**C:\A.txt**" ) → Return Value ( "**C:\A (1).txt**" )

```csharp
public static string GetNextFileName(string fileName);
```

### ValidateUri

```csharp
public static bool ValidateUri(this string uriString);
```

### GetValue

* DataRow의 특정 컬럼의 값을 반환
* string columnName 에 해당하는 컬럼이 존재하지 않을 경우 null 을 반환

```csharp
public static object GetValue(this DataRow dataRow, string columnName);
```

### SetValue

* DataRow의 특정 컬럼에 값을 할당
* `string columnName` 에 해당하는 컬럼이 존재하지 않을 경우 false 반환

```csharp
public static bool SetValue(this DataRow dataRow, string columnName, object value);
```

###

### MoveToLastPosition

* MemoEdit 의 마지막에 입력된 텍스트로 커서를 이동

```csharp
public static void MoveToLastPosition(this MemoEdit memoEdit);
```

### AppendUri

```csharp
public static Uri AppendUri(this Uri uri, params string[] paths);
```

### GetGroupRowCount

```csharp
public static int GetGroupRowCount(this GridView view);
```

### GetPivotData

* PivotGridControl 의 화면에 보이는 표를 DataTable로 반환

```csharp
public static DataTable GetPivotData(this PivotGridControl pivotGridControl);
```

### FindByTag

* 열거형 개체의 요소가 Tag 속성을 지닌 타입일 경우 해당 속성의 값과 파라미터(`object tag`)의 값을 비교하여 첫 번째로 일치하는 개체를 반환
* GroupControl.CustomHeaderButtons, RepositoryItemButtonEdit.Buttons 등 (예시 참고)

{% tabs %}
{% tab title="C#" %}

```csharp
public static T FindByTag<T>(this IEnumerable<T> collection, object tag);
```

{% endtab %}

{% tab title="Example" %}

```csharp
// GroupControl의 버튼 중 Tag 속성에 값이 "upload"인 버튼을 비활성화
IBaseButton button = grpList.CustomHeaderButtons.FindByTag("upload");
if (button != null)
{
    button.Properties.Enabled = false;
}

// RepositoryItemButtonEdit의 버튼 중 Tag 속성에 값이 "popup"인 버튼을 비활성화
EditorButton button = repositoryButtonEdit.Buttons.FindByTag("popup");
if (button != null)
{
    button.Enabled = false;
}
```

{% endtab %}
{% endtabs %}

## General Static Methods

### AddEnterKeyDownAction

```csharp
public static void AddEnterKeyDownAction(object targetControl, Action action);
```

### ConvertColorToInt

```csharp
public static uint ConvertColorToInt(Color colorValue);
```

### ConvertIntToColor

```csharp
public static Color ConvertIntToColor(uint colorValue);
```

### ConvertExcelToDataTable

* Spreadsheet 파일을 읽고 DataTable 자료형으로 결과를 반환
* Parameters
  * `string path` : Spreadsheet 파일의 경로
  * `int rowIndexOfColumns` : DataTable의 DataColumn을 정의할 엑셀 파일의 행 순서 (0 이면 엑셀 파일의 첫번째 행)

```csharp
public static DataTable ConvertExcelToDataTable(IWorkbook document, int rowIndexOfColumns, uint worksheetIndex = 0);

public static DataTable ConvertExcelToDataTable(string path, int rowIndexOfColumns, uint worksheetIndex = 0);

public static DataTable ConvertExcelToDataTable(byte[] buffer, DocumentFormat format, int rowIndexOfColumns, uint worksheetIndex = 0);

public static DataTable ConvertExcelToDataTable(Stream stream, DocumentFormat format, int rowIndexOfColumns, uint worksheetIndex = 0);
```

###

### FindControlAtCursor

```csharp
public static Control FindControlAtCursor(Form form);
```

###

### FindControlAtPoint

```csharp
public static Control FindControlAtPoint(Control container, Point pos);
```

### GetClientPCName

```csharp
public static string GetClientPCName();
```

### GetIPAddress

```csharp
public static string GetIPAddress();
```

### GetMacAddress

```csharp
public static string GetMacAddress();
```

### GetPublicIPAddress

```csharp
public static string GetPublicIPAddress();
```

### GetDistanceFromColors

```csharp
public static int GetDistanceFromColors(Color current, Color match);
```

### InitDataSource

```csharp
public static DataTable InitDataSource(object control);
```

### IsDirectory

```csharp
public static bool IsDirectory(string path);
```

### IsRecognisedImageFile

```csharp
public static bool IsRecognisedImageFile(string fileName);
```

### GetValue

```csharp
public static object GetValue(object component, string propertyName);
```

### ResolveValue

```csharp
public static object ResolveValue(object component, string path, object replacementValue);
```

### SetPropertyValue

```csharp
public static bool SetPropertyValue(object component, string path, object value);
```

### LoadImage

```csharp
public static Image LoadImage(string path);
```

### GetSalt

```csharp
public static byte[] GetSalt(int maximumSaltLength);
```

### Tree\_KeyDown

```csharp
public static void Tree_KeyDown(object sender, KeyEventArgs e);
```

###

### ConvertDataTableToExcel

```csharp
public static IWorkbook ConvertDataTableToExcel(DataTable dataTable);
```

### GetBestFontSize

* Control 개체 사이즈에 맞는 문자열의 크기를 반환

```csharp
public static float GetBestFontSize(Control control, string text, int margin, float minSize, float maxSize);
```

### CopyGridRows

* 원본 GridContrl(`sourceGrid`)의 시작, 끝 행 위치에 해당하는 행을 참조하여 대상 GridControl(`destGrid`)의 복사 위치(`destIndex`)에 새로운 행을 추가

```csharp
public static void CopyGridRows(GridControl sourceGrid, int startIndex, int endIndex, GridControl destGrid, int destIndex);
```

### GetDefaultPrinter

* 시스템에 설정된 기본 프린터 이름을 반환

```csharp
public static string GetDefaultPrinter();
```

### GetPrinters

* 시스템에 등록된 모든 프린터 이름을 문자열 배열로 반환

```csharp
public static string[] GetPrinters();
```

### SetDefaultPrinter

* 파라미터의 프린터 이름으로 기본 프린터 설정

```csharp
public static bool SetDefaultPrinter(string name);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://youngtae.gitbook.io/gst_platform/library/util.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
