using ClientLib; using ClientLib.CommonService2; using DevExpress.XtraEditors; using DevExpress.XtraTreeList; using DevExpress.XtraTreeList.Nodes; using PublicLib; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Windows.Forms; namespace HANMI_STD { public partial class CodeManager : CommonMDI { DataView m_Group_View; DataView m_Code_View; public CodeManager() { InitializeComponent(); this.Shown += (sender, e) => { try { SerializedSqlParam[] aParam = new SerializedSqlParam[] { ClientClass.CreateSqlParameter("COMP_CD", SqlDbType.NVarChar, ConstClass._COMP_CD) }; ResultData result = ClientClass.GetData("GetRoutingManager", aParam); if (result.isError) { throw new Exception(result.ResultValue); } UtilClass.SetLookup(repositoryItemLookUpEdit_ROUT_CD, result.TableData, "ROUT_CD", "ROUT_NM", false, false); } catch (Exception ex) { MessageBox.Show(ex.Message); } searchProc(); }; simpleButton_AddMain.Click += (sender, e) => { InsertCateForm from = new InsertCateForm(); if (from.ShowDialog() != System.Windows.Forms.DialogResult.Yes) { return; } searchProc(); }; gridControl_Main.DoubleClick += (sender, e) => { DataRow row = bandedGridView_Main.GetFocusedDataRow(); if (row != null) { InsertCateForm form = new InsertCateForm(); form.setData(row); if (form.ShowDialog() == System.Windows.Forms.DialogResult.Yes) { searchProc(); } } }; simpleButton_DeleteMain.Click += (sender, e) => { bandedGridView_Main.PostEditor(); bandedGridView_Main.UpdateCurrentRow(); Application.DoEvents(); DataTable data = gridControl_Main.DataSource as DataTable; DataRow[] rows = data.Select("SEL_YN = 'Y'"); if (rows == null || rows.Length < 1) { MessageBox.Show("삭제할 항목을 선택하십시오."); return; } foreach (DataRow row in rows) { row.Delete(); } }; gridControl_Group.DoubleClick += (sender, e) => { DataRow row = bandedGridView_Group.GetFocusedDataRow(); if (row != null) { DataRow mrow = bandedGridView_Main.GetFocusedDataRow(); InsertGroupForm form = new InsertGroupForm(UtilClass.toStr(mrow["CATE_CD"])); form.setData(row); if (form.ShowDialog() == System.Windows.Forms.DialogResult.Yes) { searchProc(); } } }; simpleButton_AddGroup.Click += (sender, e) => { DataRow mrow = bandedGridView_Main.GetFocusedDataRow(); InsertGroupForm from = new InsertGroupForm(UtilClass.toStr(mrow["CATE_CD"])); if (from.ShowDialog() != System.Windows.Forms.DialogResult.Yes) { return; } searchProc(); }; simpleButton_DeleteGroup.Click += (sender, e) => { bandedGridView_Group.PostEditor(); bandedGridView_Group.UpdateCurrentRow(); Application.DoEvents(); DataTable data = m_Group_View.Table; DataRow[] rows = data.Select("SEL_YN = 'Y'"); if (rows == null || rows.Length < 1) { MessageBox.Show("삭제할 항목을 선택하십시오."); return; } foreach (DataRow row in rows) { row.Delete(); } }; bandedGridView_Main.FocusedRowChanged += (sender, e) => { DataRow row = bandedGridView_Main.GetFocusedDataRow(); if (row != null) { if (m_Group_View != null) { m_Group_View.RowFilter = " CATE_CD = '" + UtilClass.toStr(row["CATE_CD"]) + "'"; DataRow grow = bandedGridView_Group.GetFocusedDataRow(); if (grow != null) { if (m_Code_View != null) { m_Code_View.RowFilter = " CATE_CD = '" + UtilClass.toStr(grow["CATE_CD"]) + "'" + " AND GRP_CD = '" + UtilClass.toStr(grow["GRP_CD"]) + "'"; } } else { if (m_Code_View != null) { m_Code_View.RowFilter = " CATE_CD = ''" + " AND GRP_CD = ''"; } } } } }; bandedGridView_Group.FocusedRowChanged += (sender, e) => { DataRow row = bandedGridView_Group.GetFocusedDataRow(); if (row != null) { if (m_Code_View != null) { m_Code_View.RowFilter = " GRP_CD = '" + UtilClass.toStr(row["GRP_CD"]) + "'"; } } }; bandedGridView_Main.FocusedRowChanged += (sender, e) => { DataRow row = bandedGridView_Main.GetFocusedDataRow(); bandedGridView_Main.Columns["CATE_CD"].OptionsColumn.AllowEdit = row != null && (row.RowState == DataRowState.Added || row.RowState == DataRowState.Detached); }; bandedGridView_Group.FocusedRowChanged += (sender, e) => { DataRow row = bandedGridView_Group.GetFocusedDataRow(); bandedGridView_Group.Columns["GRP_CD"].OptionsColumn.AllowEdit = row != null && (row.RowState == DataRowState.Added || row.RowState == DataRowState.Detached); }; bandedGridView_Code.FocusedRowChanged += (sender, e) => { DataRow row = bandedGridView_Code.GetFocusedDataRow(); bandedGridView_Code.Columns["NO_CD"].OptionsColumn.AllowEdit = row != null && (row.RowState == DataRowState.Added || row.RowState == DataRowState.Detached); }; } public override void searchProc() { try { this.Cursor = Cursors.WaitCursor; ResultData result = ClientClass.GetData("GetCodeManager", null); if (result.isError) { throw new Exception(result.ResultValue); } gridControl_Main.DataSource = result.DataList.Tables[0]; m_Group_View = new DataView(result.DataList.Tables[1]); m_Code_View = new DataView(result.DataList.Tables[2]); if (result.DataList.Tables[0].Rows.Count > 0) { DataRow row = result.DataList.Tables[0].Rows[0]; m_Group_View.RowFilter = " CATE_CD = '" + UtilClass.toStr(row["CATE_CD"]) + "'"; } if (m_Group_View != null && m_Group_View.Count > 0) { DataRow row = m_Group_View.Table.Rows[0]; m_Code_View.RowFilter = " CATE_CD = '" + UtilClass.toStr(row["CATE_CD"]) + "'" + " AND GRP_CD = '" + UtilClass.toStr(row["GRP_CD"]) + "'"; } else { m_Code_View.RowFilter = " CATE_CD = ''" + " AND GRP_CD = ''"; } gridControl_Group.DataSource = m_Group_View; gridControl_Code.DataSource = m_Code_View; this.Cursor = Cursors.Arrow; } catch (Exception ex) { this.Cursor = Cursors.Arrow; MessageBox.Show(ex.Message); } } public override void newProc() { DataRow row = bandedGridView_Group.GetFocusedDataRow(); bandedGridView_Code.AddNewRow(); bandedGridView_Code.GetFocusedDataRow()["CATE_CD"] = UtilClass.toStr(row["CATE_CD"]); bandedGridView_Code.GetFocusedDataRow()["GRP_CD"] = UtilClass.toStr(row["GRP_CD"]); bandedGridView_Code.GetFocusedDataRow()["DEL_YN"] = "N"; } public override void deleteProc() { bandedGridView_Code.PostEditor(); bandedGridView_Code.UpdateCurrentRow(); Application.DoEvents(); DataTable data = m_Code_View.Table; DataRow[] rows = data.Select("SEL_YN = 'Y'"); if (rows == null || rows.Length < 1) { MessageBox.Show("삭제할 항목을 선택하십시오."); return; } foreach (DataRow row in rows) { row.Delete(); } } public override void saveProc() { try { this.Cursor = Cursors.WaitCursor; bandedGridView_Main.PostEditor(); bandedGridView_Main.UpdateCurrentRow(); bandedGridView_Group.PostEditor(); bandedGridView_Group.UpdateCurrentRow(); bandedGridView_Code.PostEditor(); bandedGridView_Code.UpdateCurrentRow(); Application.DoEvents(); DataTable aData = gridControl_Main.DataSource as DataTable; DataTable bData = m_Group_View.Table; // gridControl_Group.DataSource as DataTable; DataTable cData = m_Code_View.Table; //gridControl_Code.DataSource as DataTable; ResultData[] dataList = null; ResultData data1 = new ResultData(); DataTable dtData1 = UtilClass.GetDataTable(aData, true, "CATE_CD", "CATE_CD_NM", "PRNNO" ); dtData1.TableName = "ADATA"; data1.TableData = dtData1; ResultData data2 = new ResultData(); DataTable dtData2 = UtilClass.GetDataTable(bData, true, "CATE_CD", "GRP_CD", "GRP_CD_NM", "PRNNO" ); dtData2.TableName = "BDATA"; data2.TableData = dtData2; ResultData data3 = new ResultData(); DataTable dtData3 = UtilClass.GetDataTable(cData, true, "CATE_CD", "GRP_CD", "NO_CD", "NO_CD_NM", "DEL_YN", "NO_RMK", "PRNNO", "WORK_ROUT_CD" ); dtData3.TableName = "CDATA"; data3.TableData = dtData3; for (int i = 0; i < dtData3.Rows.Count; i++) { if (UtilClass.isNull(dtData3.Rows[i]["NO_CD"])) { throw new Exception("코드가 입력되지 않은 데이터가 있습니다."); } if (UtilClass.isNull(dtData3.Rows[i]["NO_CD_NM"])) { throw new Exception(UtilClass.toStr(dtData3.Rows[i]["NO_CD"]) + "코드의 코드명이 입력되지 않았습니다."); } } dataList = new ResultData[] { data1, data2, data3 }; ResultData result = ClientClass.SetTableData("SaveCodeManager", dataList, null); if (result.isError) { throw new Exception(result.ResultValue); } MessageBox.Show("정상적으로 저장하였습니다."); aData.AcceptChanges(); bData.AcceptChanges(); cData.AcceptChanges(); this.Cursor = Cursors.Arrow; } catch (Exception ex) { this.Cursor = Cursors.Arrow; MessageBox.Show(ex.Message); } } } }