using ClientLib; using ClientLib.CommonService2; using PublicLib; using DevExpress.XtraEditors; using DevExpress.XtraGrid.Views.Grid.ViewInfo; using Microsoft.Win32; using System; using System.Data; using System.IO; using System.Reflection; using System.Drawing; using System.Windows.Forms; using System.Diagnostics; using DevExpress.XtraGrid.Views.Grid; using DevExpress.XtraExport; namespace HM_WORK { public partial class WorkManager : XtraForm { private bool m_LoginCancel; //private bool m_Loading; Timer m_Timer; public WorkManager() { InitializeComponent(); textEdit_CUST_NM.ImeMode = System.Windows.Forms.ImeMode.Hangul; m_LoginCancel = false; //m_Loading = true; this.ClientSize = new Size(1800, 980); if (ConstClass._DEBUG_MODE) { this.WindowState = FormWindowState.Normal; } else { this.WindowState = Screen.PrimaryScreen.WorkingArea.Width > 1920 ? FormWindowState.Normal : FormWindowState.Maximized; } if (File.Exists(ConstClass._RUN_PATH + "app.ico")) { this.Icon = Icon.ExtractAssociatedIcon(ConstClass._RUN_PATH + "app.ico"); } else { this.Icon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location); } // Registry ConstClass._REG = Registry.CurrentUser; ConstClass._REG = ConstClass._REG.OpenSubKey(ConstClass._REGISTRY_PATH, true); if (ConstClass._REG == null) { ConstClass._REG = Registry.CurrentUser.CreateSubKey(ConstClass._REGISTRY_PATH); } ConstClass._MD5 = new FileHashCalc(); UtilClass.SetLocalIPAddress(); ConstClass._PC_NM = SystemInformation.ComputerName; ConstClass._USER = Properties.Settings.Default.USER; ConstClass._DEFAULT_URL = Properties.Settings.Default.DEFAULT_URL; ConstClass._SERVICE_URL = ConstClass._DEFAULT_URL + Properties.Settings.Default.SERVICE_URL; ConstClass._UPDATE_SERVICE = ConstClass._DEFAULT_URL + Properties.Settings.Default.UPDATE_SERVICE; ClientClass.initClient(); ConstClass._USR_ID = ""; LoginForm loginForm = new LoginForm(); if (loginForm.ShowDialog() != DialogResult.Yes) { m_LoginCancel = true; } m_Timer = new Timer(); m_Timer.Enabled = false; dateEdit_SDATE.DateTime = DateTime.Now; dateEdit_FDATE.DateTime = DateTime.Now; labelControl_SDATE_YO.Text = GetDay(DateTime.Now) + "부터"; labelControl_FDATE_YO.Text = GetDay(DateTime.Now) + "까지"; simpleButton_OUT.Click += (sender, e) => { OutBarCodeForm form = new OutBarCodeForm(); if (form.ShowDialog() == System.Windows.Forms.DialogResult.Yes) { searchProc(); } }; comboBoxEdit_ORDER_BY.EditValueChanged += (sender, e) => { searchProc(); }; dateEdit_SDATE.EditValueChanged += (sender, e) => { labelControl_SDATE_YO.Text = GetDay(dateEdit_SDATE.DateTime) + "부터"; }; dateEdit_FDATE.EditValueChanged += (sender, e) => { labelControl_FDATE_YO.Text = GetDay(dateEdit_FDATE.DateTime) + "까지"; }; simpleButton_Cust_Search.Click += (sender, e) => { selectCustProc(); }; textEdit_CUST_NM.KeyPress += (sender, e) => { if (e.KeyChar == '\r') { selectCustProc(); } }; gridView_Main.CustomDrawCell += (sender, e) => { DataRow row = gridView_Main.GetDataRow(e.RowHandle); if (!UtilClass.isEqual(row["BILL_NO"], "")) { e.Appearance.BackColor = Color.FromArgb(206, 254, 188); e.Appearance.ForeColor = Color.DarkBlue; } }; textEdit_CUST_NM.EditValueChanged += (sender, e) => { if (UtilClass.isNull(textEdit_CUST_NM.Text)) { labelControl_CUST_CD.Text = ""; } }; gridView_Main.DoubleClick += (sender, e) => { Point aPT = gridControl_Main.PointToClient(Control.MousePosition); GridHitInfo aInfo = gridView_Main.CalcHitInfo(aPT); if (aInfo.InRowCell) { DataRow aRow = gridView_Main.GetFocusedDataRow(); string bill_no = UtilClass.toStr(aRow["BILL_NO"]); if (!UtilClass.isNull(bill_no)) { string message = "계산서번호 " + bill_no + " 로 계산서 발행된 자료입니다.\r\r" + "수정 및 삭제작업을 할 수 없습니다.\r\r" + "계산서 발행을 취소한 후에 작업하시기 바랍니다."; XtraMessageBox.Show(message); return; } updateProc(); } }; dateEdit_FDATE.KeyPress += (sender, e) => { searchProc(); }; m_Timer.Tick += (sender, e) => { DateTime dt = DateTime.Now; string datePart = dt.ToString("yyyy-MM-dd hh:mm:ss"); labelControl_Time.Text = datePart; }; simpleButton_Search.Click += (sender, e) => { searchProc(); }; simpleButton_Print.Click += (sender, e) => { printProc(); }; simpleButton_Excel_Save.Click += (sender, e) => { excelProc(); }; simpleButton_Close.Click += (sender, e) => { this.Close(); }; this.Shown += (sender, e) => { if (m_LoginCancel) { this.Close(); return; } SaveSysLog("현장용 프로그램 로그인 완료."); this.Text = "(주)한미칼라-현장용 " + Application.ProductVersion; //m_Loading = false; dateEdit_SDATE.Focus(); //시간 설정. m_Timer.Interval = 100; m_Timer.Enabled = true; searchProc(); }; } public void SaveSysLog(string strLog) { try { SerializedSqlParam[] aParam = new SerializedSqlParam[] { ClientClass.CreateSqlParameter("REG_ID", SqlDbType.NVarChar, ConstClass._USR_ID), ClientClass.CreateSqlParameter("REG_IP", SqlDbType.NVarChar, ConstClass._IP), ClientClass.CreateSqlParameter("LOG_TEXT", SqlDbType.NVarChar, strLog), }; ResultData resultData = ClientClass.SetData("SaveSysLog", aParam); if (resultData.isError) { throw new Exception(resultData.ResultValue); } } catch (Exception ex) { } } private void selectCustProc() { SelectCustomerForm form = new SelectCustomerForm(textEdit_CUST_NM.Text); if (form.ShowDialog() != System.Windows.Forms.DialogResult.Yes) { return; } textEdit_CUST_NM.Text = form.m_CUST_NN; labelControl_CUST_CD.Text = form.m_CUST_CD; searchProc(); } public void searchProc() { try { this.Cursor = Cursors.WaitCursor; gridControl_Main.DataSource = null; SerializedSqlParam[] aParam = new SerializedSqlParam[] { ClientClass.CreateSqlParameter("COMP_CD", SqlDbType.NVarChar, ConstClass._COMP_CD), ClientClass.CreateSqlParameter("CUST_CD", SqlDbType.NVarChar, labelControl_CUST_CD.Text), ClientClass.CreateSqlParameter("SDATE", SqlDbType.NVarChar, dateEdit_SDATE.DateTime.ToString("yyyy-MM-dd")), ClientClass.CreateSqlParameter("FDATE", SqlDbType.NVarChar, dateEdit_FDATE.DateTime.ToString("yyyy-MM-dd")), ClientClass.CreateSqlParameter("ORDER_BY", SqlDbType.Int, comboBoxEdit_ORDER_BY.SelectedIndex) }; ResultData resultData = ClientClass.GetData("GetWorkOrderManager", aParam); if (resultData.isError) { throw new Exception(resultData.ResultValue); } DataTable aData = resultData.TableData; foreach (DataRow arow in aData.Rows) { if (UtilClass.isEqual(arow["LN_SEQ"], "01")) { continue; } arow["PRINT_POS"] = ""; } gridControl_Main.DataSource = aData; aData.AcceptChanges(); this.Cursor = Cursors.Arrow; } catch (Exception ex) { this.Cursor = Cursors.Arrow; MessageBox.Show(ex.Message); } } public void newProc() { } public void updateProc() { DataRow row = gridView_Main.GetFocusedDataRow(); if (row == null) { return; } string order_no = UtilClass.toStr(row["ORDER_NO"]); WorkManagerPopup form = new WorkManagerPopup(); string str = form.initProc(order_no); if (!UtilClass.isNull(str)) { MessageBox.Show(str); return; } if (form.ShowDialog() == DialogResult.Yes) { searchProc(); for (int i = 0; i < gridView_Main.RowCount; i++) { if (UtilClass.isEqual(gridView_Main.GetDataRow(i)["ORDER_NO"], order_no)) { gridView_Main.FocusedRowHandle = i; break; } } } } private void excelProc() { ExportExcelGrid(gridControl_Main); } private void printProc() { DataTable data = gridControl_Main.DataSource as DataTable; WorkManagerReport report = new WorkManagerReport(); report.SetData(data, dateEdit_SDATE.Text, dateEdit_FDATE.Text ); } private void ExportExcelGrid(DevExpress.XtraGrid.GridControl grid) { SaveFileDialog fd = new SaveFileDialog(); fd.FileName = grid.MainView.ViewCaption; fd.Filter = "Excel(*.xls)|*.xls|PDF(*.pdf)|*.pdf"; if (fd.ShowDialog() == DialogResult.OK) { if (fd.FilterIndex == 1) { if (grid.MainView is GridView) { (grid.MainView as GridView).OptionsPrint.AutoWidth = false; grid.MainView.ExportToXls(fd.FileName, new DevExpress.XtraPrinting.XlsExportOptions(DevExpress.XtraPrinting.TextExportMode.Value, true)); } else { using (DevExpress.XtraExport.ExportExcelProvider ExportProvider = new DevExpress.XtraExport.ExportXlsProviderInternal(fd.FileName)) { DevExpress.XtraGrid.Export.BaseExportLink link = grid.DefaultView.CreateExportLink(ExportProvider as IExportProvider); link.ExportTo(true); } } } else { grid.MainView.ExportToPdf(fd.FileName); } Process ps = new Process(); ps.StartInfo.FileName = fd.FileName; ps.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; ps.Start(); } } private string GetDay(DateTime dt) { string strDay = ""; switch (dt.DayOfWeek) { case DayOfWeek.Monday: strDay = "월요일"; break; case DayOfWeek.Tuesday: strDay = "화요일"; break; case DayOfWeek.Wednesday: strDay = "수요일"; break; case DayOfWeek.Thursday: strDay = "목요일"; break; case DayOfWeek.Friday: strDay = "금요일"; break; case DayOfWeek.Saturday: strDay = "토요일"; break; case DayOfWeek.Sunday: strDay = "일요일"; break; } return strDay; } } }