ParameterBuilder

프로시저 클래스에 여러 행(Row)의 값을 하나의 문자열로 파싱하여 전달할때 사용하는 클래스

Methods

Append

  • Parameters

    • DataRow dataRow : 값을 참조할 DataRow 객체

    • string fieldName : DataRow의 ColumnName (이면서 GetParameter 메서드에서 참조할 Key Field)

    • string value : 값

  • Returns

    • ParameterBuilder : 메서드를 호출했던 자신 객체 반환

public ParameterBuilder Append(DataRow dataRow, string fieldName);

public ParameterBuilder Append(DataRow dataRow, string fieldName, char symbol);

public ParameterBuilder Append(string fieldName, string value);

public ParameterBuilder Append(string fieldName, string value, char symbol);

GetParameter

  • Parameters

    • string fieldName : Append 메서드에서 등록했던 Key Field

  • Returns

    • string : 파싱된 문자열 값

public string GetParameter(string fieldName);

GetCount

  • Parameters

    • string fieldName : Append 메서드에서 등록했던 Key Field

  • Returns

    • int : 등록된 파라미터의 개수

public int GetCount(string fieldName);

예시

private bool ExecuteSave(string workType)
{
    ParameterBuilder paramBuilder = new ParameterBuilder();
    
    DataTable source = BindingData(grdDefault);
    if (source == null)
				return false;
				
		foreach (DataRow row in source.Rows)
		{
				// DataRow로부터 값을 자동으로 처리
				paramBuilder.Append(row, "row_status");
				paramBuilder.Append(row, "type");
				paramBuilder.Append(row, "date");
				paramBuilder.Append(row, "apply_date");
				paramBuilder.Append(row, "descriptions");
				
				// DataRow의 값을 직접 가공하여 처리
				DateTime.TryParse(row.GetValue("start_time")?.ToString(), out DateTime startTime);
				DateTime.TryParse(row.GetValue("end_time")?.ToString(), out DateTime endTime);
				paramBuilder.Append("start_time", startTime.ToString("HH:mm:ss"));
				paramBuilder.Append("end_time", startTime.ToString("HH:mm:ss"));
		}

		try
		{
				sav_work_calender procInfo = new sav_work_calender();
				procInfo.AddParamData(
				workType,
				resourceType.ToString().ToLower(),
				paramBuilder.GetParameter("row_status"),
				paramBuilder.GetParameter("type"),
				paramBuilder.GetParameter("date"),
				paramBuilder.GetParameter("apply_date"),
				paramBuilder.GetParameter("start_time"),
				paramBuilder.GetParameter("end_time"),
				paramBuilder.GetParameter("descriptions"),
				SessionInfo.UserId,
				$"{GetClientPCName()}/{GetIPAddress()}");
				
				ResultSet result = ExecuteProcedure(procInfo);
				
				bool isSuccess = result?.IsSuccess ?? false;
				
				return isSuccess;
		}
		catch (Exception ex)
		{
				ShowErrorMessageBox(ex);
				return false;
		}
}

적용 사례

  • 저장용 프로시저 호출 메서드의 코드를 좀 더 간결하게 작성 가능

  • 아래 두 코드는 같은 동작을 하며, ParameterBuilder의 사용 여부에만 차이가 있음

private bool ExecuteSave(string workType)
{
    if (!ValidateControls(grpMaster))
        return false;

    // 기본 정보
    string groupCode = txtGroup_code1.Text;
    string groupName = txtGroup_name1.Text;
    int codeLength = Convert.ToInt32(numCode_length.Value);
    string category = cboGroup_category1.EditValue?.ToString() ?? string.Empty;

    string fieldCaption1 = txtField_caption1.Text;
    string fieldCaption2 = txtField_caption2.Text;
    string numCaption1 = txtNumref_caption1.Text;
    string numCaption2 = txtNumref_caption2.Text;

    string useYN = chkUse_yn.EditValue?.ToString() ?? string.Empty;
    string memo = memoMemo.Text;

    // 상세 정보
    string rowStatus = string.Empty;
    string subCodes = string.Empty;
    string codeNames = string.Empty;
    string systemYNs = string.Empty;
    string extraFields1 = string.Empty;
    string extraFields2 = string.Empty;
    string numrefs1 = string.Empty;
    string numrefs2 = string.Empty;
    string sortSeqs = string.Empty;
    string useYNs = string.Empty;

    if (!workType.Equals("D"))
    {
        int i = 0;
        DataTable datas = BindingData(grdDetail);

        if (datas != null)
        {
            foreach (DataRow row in datas.Rows)
            {
                if (i++ > 0)
                {
                    rowStatus += "|";
                    subCodes += "|";
                    codeNames += "|";
                    systemYNs += "|";
                    extraFields1 += "|";
                    extraFields2 += "|";
                    numrefs1 += "|";
                    numrefs2 += "|";
                    sortSeqs += "|";
                    useYNs += "|";
                }
                

                rowStatus += row.GetValue("row_status")?.ToString() ?? string.Empty;
                subCodes += row.GetValue("sub_code")?.ToString() ?? string.Empty;
                codeNames += row.GetValue("code_name")?.ToString() ?? string.Empty;
                systemYNs += row.GetValue("system_yn")?.ToString() ?? string.Empty;
                extraFields2 += row.GetValue("extra_field1")?.ToString() ?? string.Empty;
                extraFields1 += row.GetValue("extra_field2")?.ToString() ?? string.Empty;
                numrefs1 += row.GetValue("numref1")?.ToString() ?? string.Empty;
                numrefs2 += row.GetValue("numref2")?.ToString() ?? string.Empty;
                sortSeqs += row.GetValue("sort_seq")?.ToString() ?? string.Empty;
                useYNs += row.GetValue("use_yn")?.ToString() ?? string.Empty;
            }
        }
    }

    try
    {
        P_DEV002_xxx_S procInfo = new P_DEV002_xxx_S();

        procInfo.AddParamData(
            workType,
            groupCode,
            groupName,
            codeLength,
            category,
            fieldCaption1,
            fieldCaption2,
            numCaption1,
            numCaption2,
            useYN,
            memo,
            SessionInfo.UserId,
            $"{GetClientPCName()}/{GetIPAddress()}",
            rowStatus,
            subCodes,
            codeNames,
            systemYNs,
            extraFields1,
            extraFields2,
            numrefs1,
            numrefs2,
            sortSeqs,
            useYNs);

        ResultSet result = ExecuteProcedure(procInfo);

        if (!workType.Equals("D"))
        {
            _FindRowValue = result?.ReturnString;
        }

        return result?.IsSuccess ?? false;
    }
    catch (Exception ex)
    {
        ShowErrorMessageBox(ex);
        return false;
    }
}

Last updated

Was this helpful?