using ClientLib; using ClientLib.CommonService2; using DevExpress.XtraGrid.Views.Grid; using DevExpress.XtraGrid.Columns; using DevExpress.XtraGrid.Views.Grid.ViewInfo; using DevExpress.XtraGrid.Views.Base; using DevExpress.XtraEditors; using PublicLib; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using DevExpress.XtraEditors.DXErrorProvider; namespace HANMI_MACH { //public static class MyExtenstions //{ // public static Control FindControl(this Control root, string text) // { // if (root == null) throw new ArgumentNullException("root"); // foreach (Control child in root.Controls) // { // if (child.Text == text) return child; // Control found = FindControl(child, text); // if (found != null) return found; // } // return null; // } //} public partial class MachineManager : PublicLib.CommonMDI { private DataView m_MATView; public MachineManager() { InitializeComponent(); textEdit_Search.KeyPress += (sender, e) => { if (e.KeyChar == '\r') { searchProc(); } }; //gridView_Main.EditFormPrepared += (sender, e) => //{ // Control ctrl = MyExtenstions.FindControl(e.Panel, "Update"); // if (ctrl != null) // ctrl.Text = "OK"; // ctrl = MyExtenstions.FindControl(e.Panel, "Cancel"); // if (ctrl != null) // ctrl.Text = "NO"; //}; ////상태 구분 DataView fab_kind_cd = new DataView(ConstClass._DATA); fab_kind_cd.RowFilter = "CATE_CD = 'E' and GRP_CD = 'E01'"; UtilClass.SetLookup(repositoryItemLookUpEdit_FAB_KIND, fab_kind_cd, "NO_CD", "NO_CD_NM", true); gridView_Main.FocusedRowChanged += (sender, e) => { DataRow row = gridView_Main.GetFocusedDataRow(); gridView_Main.Columns["MACH_CD"].OptionsColumn.AllowEdit = row != null && (row.RowState == DataRowState.Added || row.RowState == DataRowState.Detached); if (row != null) { if (m_MATView != null) { m_MATView.RowFilter = " COMP_CD = '" + UtilClass.toStr(row["COMP_CD"]) + "' and " + " MACH_CD = '" + UtilClass.toStr(row["MACH_CD"]) + "'"; } } }; //gridView_MAT.ShownEditor += (sender, e) => //{ // DataRow row = gridView_MAT.GetFocusedDataRow(); // gridView_MAT.Columns["MAT_CD"].OptionsColumn.AllowEdit = row != null && (row.RowState == DataRowState.Added || row.RowState == DataRowState.Detached); //}; gridView_MAT.FocusedRowChanged += (sender, e) => { DataRow row = gridView_MAT.GetFocusedDataRow(); gridView_MAT.Columns["MAT_CD"].OptionsColumn.AllowEdit = row != null && (row.RowState == DataRowState.Added || row.RowState == DataRowState.Detached); }; //처리 해야함.. gridView_Main.ValidatingEditor += (sender, e) => { GridView view = sender as GridView; if (view.FocusedColumn.FieldName == "MACH_NO") { if (UtilClass.toStr(e.Value) == "" ) { e.Valid = false; e.ErrorText = "필수값입니다.."; } } }; gridView_Main.ValidateRow += (sender, e) => { GridView view = sender as GridView; DataRow row = view.GetFocusedDataRow(); if (UtilClass.toStr(row["MACH_NO"]) == "") { e.Valid = false; e.ErrorText = "설비 번호는 필수값입니다"; view.FocusedColumn = view.Columns["MACH_NO"]; return; } ; if (UtilClass.toStr(row["MACH_NM"]) == "") { e.Valid = false; e.ErrorText = "설비이름은 필수값입니다"; view.FocusedColumn = view.Columns["MACH_NM"]; return; } }; this.Shown += (sender, e) => { try { SerializedSqlParam[] aParam1 = new SerializedSqlParam[] { ClientClass.CreateSqlParameter("COMP_CD", SqlDbType.NVarChar, ConstClass._COMP_CD) }; ResultData resultROUT = ClientClass.GetData("GetRoutingManager", aParam1); if (resultROUT.isError) { throw new Exception(resultROUT.ResultValue); } UtilClass.SetLookup(repLOOKUPEDIT_ROUT_CD, resultROUT.TableData, "ROUT_CD", "ROUT_NM", true); this.Cursor = Cursors.Arrow; searchProc(); } catch (Exception ex) { MessageBox.Show(ex.Message); this.Close(); } }; } public override void searchProc() { try { this.Cursor = Cursors.WaitCursor; gridControl_Main.DataSource = null; gridControl_MAT.DataSource = null; SerializedSqlParam[] aParam = new SerializedSqlParam[] { ClientClass.CreateSqlParameter("COMP_CD", SqlDbType.NVarChar, ConstClass._COMP_CD), ClientClass.CreateSqlParameter("SEARCH", SqlDbType.NVarChar, textEdit_Search.Text) }; ResultData resultData = ClientClass.GetData("GetMachineManager", aParam); if (resultData.isError) { throw new Exception(resultData.ResultValue); } gridControl_Main.DataSource = resultData.DataList.Tables[0]; m_MATView = new DataView(resultData.DataList.Tables[1]); if (resultData.DataList.Tables[0].Rows.Count > 0) { DataRow row = resultData.DataList.Tables[0].Rows[0]; m_MATView.RowFilter = " COMP_CD = '" + UtilClass.toStr(row["COMP_CD"]) + "' and " + " MACH_CD = '" + UtilClass.toStr(row["MACH_CD"]) + "'"; } gridControl_MAT.DataSource = m_MATView; this.Cursor = Cursors.Arrow; } catch (Exception ex) { this.Cursor = Cursors.Arrow; MessageBox.Show(ex.Message); } } public override void newProc() { gridView_Main.PostEditor(); gridView_Main.UpdateCurrentRow(); gridView_Main.AddNewRow(); string AUTO_MACH_CD; AUTO_MACH_CD = "A" + UtilClass.toStr(gridView_Main.RowCount) + ConstClass._USR_ID ; gridView_Main.GetFocusedDataRow()["COMP_CD"] = ConstClass._COMP_CD; gridView_Main.GetFocusedDataRow()["MACH_CD"] = AUTO_MACH_CD.Substring(0, AUTO_MACH_CD.Length<10?AUTO_MACH_CD.Length:10); gridView_Main.GetFocusedDataRow()["MACH_STATE_CD"] = "01"; // gridView_Main.PostEditor(); // gridView_Main.UpdateCurrentRow(); //gridView_Main.ShowEditForm(); gridView_Main.Focus(); gridView_Main.FocusedColumn = gridView_Main.Columns["MACH_NO"]; } public override void updateProc() { } public override void deleteProc() { gridView_Main.PostEditor(); gridView_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(); } } public override void saveProc() { try { this.Cursor = Cursors.WaitCursor; gridView_Main.PostEditor(); gridView_Main.UpdateCurrentRow(); Application.DoEvents(); DataRow row = gridView_Main.GetFocusedDataRow(); string MACH_CD = ""; if (row != null) { MACH_CD = UtilClass.toStr(row["MACH_CD"]); } DataTable aData = gridControl_Main.DataSource as DataTable; DataTable bData = m_MATView.Table; ResultData[] dataList = null; ResultData data1 = new ResultData(); DataTable dtData1 = UtilClass.GetDataTable(aData, true, "COMP_CD", "MACH_CD", "MACH_NO", "MACH_NM", "ROUT_CD", "MODEL_NM", "MACH_STATE_CD", "MAIN_USR_ID", "SUB_USR_ID", "DEL_YN", "MACH_RMK" ); dtData1.TableName = "ADATA"; data1.TableData = dtData1; dataList = new ResultData[] { data1 }; SerializedSqlParam[] aParam = new SerializedSqlParam[] { ClientClass.CreateSqlParameter("REG_ID", SqlDbType.NVarChar, ConstClass._USR_ID), ClientClass.CreateSqlParameter("RESULT_STR", SqlDbType.NVarChar, "", ParameterDirection.Output, 1000) }; ResultData result = ClientClass.SetTableData("SaveMachineManager", dataList, aParam); if (result.isError || !UtilClass.isNull(result.ResultValue)) { throw new Exception(result.ResultValue); } this.Cursor = Cursors.Arrow; MessageBox.Show("정상적으로 저장하였습니다."); searchProc(); //if (!UtilClass.isNull(item_cd)) //{ // for (int i = 0; i < gridView_Main.RowCount; i++) // { // if (UtilClass.isEqual(item_cd, gridView_Main.GetDataRow(i)["ITEM_CD"])) // { // gridView_Main.FocusedRowHandle = i; // break; // } // } //} } catch (Exception ex) { this.Cursor = Cursors.Arrow; MessageBox.Show(ex.Message); } } public override void excelProc() { this.ExportExcelGrid(gridControl_Main); } private void repLOOKUP_FACT_Popup(object sender, EventArgs e) { } } }