using ClientLib; using ClientLib.CommonService; using DevExpress.XtraEditors; 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.Reflection; using System.Text; using System.Threading; using System.Windows.Forms; namespace HANMI_J_SALE { partial class CollectPopup : XtraForm { public bool m_Changed; private string m_COL_DT; private string m_COL_NO; private string m_COL_CD; private CommonMDI m_Parent; public CollectPopup(CommonMDI parent, DateTime sale_date) { InitializeComponent(); m_COL_NO = ""; m_COL_DT = ""; m_COL_CD = ""; m_Changed = false; dateEdit_COL_DT.DateTime = sale_date; m_Parent = parent; buttonEdit_COL_CD.KeyPress += (sender, e) => { if (!UtilClass.isNull(buttonEdit_COL_CD.Text)) { searchProc(3); } }; buttonEdit_COL_CD.ButtonClick += (sender, e) => { if (e.Button.Index == 0) // 기존정보 검색 { ColCdPopup form = new ColCdPopup(dateEdit_COL_DT.DateTime); if (form.ShowDialog() == DialogResult.Yes) { m_COL_NO = form.m_COL_NO; buttonEdit_COL_CD.Text = form.m_COL_CD; dateEdit_COL_DT.DateTime = UtilClass.toDateTime(form.m_COL_DT); searchProc(3); } } else if (e.Button.Index == 1) // 높은 번호 검색 { searchProc(1); } else // 낮은 번호 검색 { searchProc(2); } }; buttonEdit_CUST_NM.ButtonClick += (sender, e) => { selectCustProc(); }; buttonEdit_CUST_NM.KeyPress += (sender, e) => { if (e.KeyChar == '\r') { selectCustProc(); } }; buttonEdit_ACC_NO.KeyPress += (sender, e) => { if (e.KeyChar == '\r') { selectBankProc(); } }; buttonEdit_ACC_NO.ButtonClick += (sender, e) => { selectBankProc(); }; textEdit_CASH_MY.EditValueChanged += (sender, e) => { calcProc(); }; textEdit_DEP_MY.EditValueChanged += (sender, e) => { calcProc(); }; textEdit_ETC_MY.EditValueChanged += (sender, e) => { calcProc(); }; simpleButton_CANCEL.Click += (sender, e) => { clearProc(); }; simpleButton_INPUT.Click += (sender, e) => { saveProc("I", ""); }; simpleButton_UPDATE.Click += (sender, e) => { saveProc("M", buttonEdit_COL_CD.Text); }; simpleButton_DELETE.Click += (sender, e) => { if (XtraMessageBox.Show("삭제하시겠습니까?", "삭제", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { saveProc("D", buttonEdit_COL_CD.Text); } }; simpleButton_CLOSE.Click += (sender, e) => { this.DialogResult = m_Changed ? DialogResult.Yes : DialogResult.Cancel; this.Close(); }; this.Shown += (sender, e) => { try { SerializedSqlParam[] aParam = new SerializedSqlParam[] { ClientClass.CreateSqlParameter("COMP_CD", SqlDbType.NVarChar, ConstClass._COMP_CD) }; ResultData resultData = ClientClass.GetData("GetSalesUserForLookup", aParam); if (resultData.isError) { throw new Exception(resultData.ResultValue); } UtilClass.SetLookup(lookUpEdit_COL_USR_ID, resultData.TableData, "EMP_NO", "USR_NM"); if (!UtilClass.isNull(m_COL_DT) && !UtilClass.isNull(m_COL_CD)) { searchProc(3); } } catch (Exception ex) { XtraMessageBox.Show(ex.Message); this.Close(); } }; this.FormClosed += (sender, e) => { (m_Parent as CollectMoneyList).m_SALE_DATE = dateEdit_COL_DT.DateTime; }; } public void setData(string col_dt, string col_cd, string col_no) { m_COL_DT = col_dt; m_COL_CD = col_cd; m_COL_NO = col_no; dateEdit_COL_DT.DateTime = Convert.ToDateTime(col_dt); buttonEdit_COL_CD.Text = col_cd; } protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (keyData == (Keys.A | Keys.Alt)) { clearProc(); return true; } else if (keyData == (Keys.I | Keys.Alt)) { saveProc("I", ""); return true; } else if (keyData == (Keys.M | Keys.Alt)) { saveProc("M", buttonEdit_COL_CD.Text); return true; } else if (keyData == (Keys.D | Keys.Alt)) { deleteProc(); return true; } else if (keyData == (Keys.X | Keys.Alt)) { this.DialogResult = m_Changed ? DialogResult.Yes : DialogResult.Cancel; this.Close(); return true; } return base.ProcessCmdKey(ref msg, keyData); } private void selectBankProc() { buttonEdit_ACC_NO.Text = ""; buttonEdit_ACC_NO.Tag = ""; labelControl_BANK_NM.Text = ""; textEdit_ACC_NM.Text = ""; SelectAccNoPopup form = new SelectAccNoPopup(); if (form.ShowDialog() == DialogResult.Yes) { buttonEdit_ACC_NO.Tag = form.m_BANK_CD; buttonEdit_ACC_NO.Text = form.m_ACC_NO; labelControl_BANK_NM.Text = form.m_BANK_NM; textEdit_ACC_NM.Text = form.m_ACC_NM; } } private void calcProc() { textEdit_Total.EditValue = UtilClass.toInt(textEdit_CASH_MY.EditValue) + UtilClass.toInt(textEdit_DEP_MY.EditValue) + UtilClass.toInt(textEdit_ETC_MY.EditValue); } private void selectCustProc() { SelectCustomerForm form = new SelectCustomerForm(buttonEdit_CUST_NM.Text, dateEdit_COL_DT.DateTime); if (form.ShowDialog() != DialogResult.Yes) { return; } buttonEdit_CUST_NM.Text = form.m_CUST_NM; labelControl_CUST_CD.Text = form.m_CUST_CD; textEdit_CUST_USR_NM.Tag = form.m_CUST_USR_ID; textEdit_CUST_USR_NM.Text = form.m_CUST_USR_NM; buttonEdit_CURR_REMAIN_MONEY.EditValue = form.m_CURR_REMAIN_MONEY; textEdit_CASH_MY.Focus(); } private void searchProc(int mode) { try { this.Cursor = Cursors.WaitCursor; SerializedSqlParam[] aParam = new SerializedSqlParam[] { ClientClass.CreateSqlParameter("COMP_CD", SqlDbType.NVarChar, ConstClass._COMP_CD), ClientClass.CreateSqlParameter("COL_DT", SqlDbType.NVarChar, dateEdit_COL_DT.DateTime.ToString("yyyy.MM.dd")), ClientClass.CreateSqlParameter("COL_CD", SqlDbType.NVarChar, buttonEdit_COL_CD.Text), ClientClass.CreateSqlParameter("MODE", SqlDbType.Int, mode) }; ResultData resultData = ClientClass.GetData("GetCollectPopup", aParam); if (resultData.isError) { throw new Exception(resultData.ResultValue); } if (resultData.DataList.Tables[0].Rows.Count > 0) { m_COL_NO = UtilClass.toStr(resultData.DataList.Tables[0].Rows[0]["COL_NO"]); buttonEdit_CUST_NM.Text = UtilClass.toStr(resultData.DataList.Tables[0].Rows[0]["CUST_NM"]); labelControl_CUST_CD.Text = UtilClass.toStr(resultData.DataList.Tables[0].Rows[0]["CUST_CD"]); buttonEdit_CURR_REMAIN_MONEY.EditValue = UtilClass.toInt(resultData.DataList.Tables[0].Rows[0]["CURR_REMAIN_MONEY"]); textEdit_REMAK.Text = UtilClass.toStr(resultData.DataList.Tables[0].Rows[0]["REMARK"]); lookUpEdit_COL_USR_ID.EditValue = resultData.DataList.Tables[0].Rows[0]["COL_USR_ID"]; textEdit_CASH_MY.EditValue = resultData.DataList.Tables[0].Rows[0]["CASH_MY"]; textEdit_DEP_MY.EditValue = resultData.DataList.Tables[0].Rows[0]["DEP_MY"]; textEdit_ETC_MY.EditValue = resultData.DataList.Tables[0].Rows[0]["ETC_MY"]; textEdit_Total.EditValue = resultData.DataList.Tables[0].Rows[0]["TOT_MY"]; buttonEdit_ACC_NO.Text = UtilClass.toStr(resultData.DataList.Tables[0].Rows[0]["ACC_NO"]); buttonEdit_ACC_NO.Tag = UtilClass.toStr(resultData.DataList.Tables[0].Rows[0]["BANK_CD"]); labelControl_BANK_NM.Text = UtilClass.toStr(resultData.DataList.Tables[0].Rows[0]["BANK_NM"]); textEdit_ACC_NM.Text = UtilClass.toStr(resultData.DataList.Tables[0].Rows[0]["BANK_CD"]); } else { clearProc(); } buttonEdit_COL_CD.Text = UtilClass.toStr(resultData.DataList.Tables[1].Rows[0]["COL_CD"]); this.Cursor = Cursors.Arrow; if (mode > 0 && resultData.DataList.Tables[0].Rows.Count < 1) { XtraMessageBox.Show("해당 관리번호가 없습니다. 확인하시길 바랍니다."); } } catch (Exception ex) { this.Cursor = Cursors.Arrow; XtraMessageBox.Show(ex.Message); } } private void clearProc() { m_COL_NO = ""; dateEdit_COL_DT.DateTime = DateTime.Now; buttonEdit_COL_CD.Text = ""; buttonEdit_CUST_NM.Text = ""; labelControl_CUST_CD.Text = ""; textEdit_CUST_USR_NM.Text = ""; buttonEdit_CURR_REMAIN_MONEY.Text = ""; textEdit_CASH_MY.Text = ""; textEdit_DEP_MY.Text = ""; textEdit_ETC_MY.Text = ""; lookUpEdit_COL_USR_ID.ItemIndex = 0; buttonEdit_ACC_NO.Tag = ""; buttonEdit_ACC_NO.Text = ""; labelControl_BANK_NM.Text = ""; textEdit_ACC_NM.Text = ""; textEdit_REMAK.Text = ""; textEdit_Total.Text = ""; } private void saveProc(string mode, string col_cd) { try { this.Cursor = Cursors.WaitCursor; if (UtilClass.isNull(labelControl_CUST_CD.Text)) { buttonEdit_CUST_NM.Focus(); throw new Exception("거래선을 조회하여 선택하십시오."); } // 2019.07.05 khkang 마이너스 금액 입력 가능하도록 변경 //if (UtilClass.toInt(textEdit_Total.EditValue) < 1) if (UtilClass.toInt(textEdit_Total.EditValue) == 0) { textEdit_CASH_MY.Focus(); throw new Exception("금액을 입력하십시오."); } string remark = textEdit_REMAK.Text.Trim(); if (remark.Equals("")) { if (UtilClass.isNull(buttonEdit_ACC_NO.Text)) { remark = "수금"; } else { remark = textEdit_ACC_NM.Text.Trim() + "(" + buttonEdit_ACC_NO.Text.Trim() + ")"; } } string col_usr_id = ""; DataRowView drv = lookUpEdit_COL_USR_ID.Properties.GetDataSourceRowByKeyValue(lookUpEdit_COL_USR_ID.EditValue) as DataRowView; if (drv != null) { col_usr_id = UtilClass.toStr(drv["USR_ID"]); } SerializedSqlParam[] aParam = new SerializedSqlParam[] { ClientClass.CreateSqlParameter("COMP_CD", SqlDbType.NVarChar, ConstClass._COMP_CD), ClientClass.CreateSqlParameter("COL_NO", SqlDbType.NVarChar, m_COL_NO), ClientClass.CreateSqlParameter("COL_DT", SqlDbType.NVarChar, dateEdit_COL_DT.DateTime.ToString("yyyy.MM.dd")), ClientClass.CreateSqlParameter("COL_CD", SqlDbType.NVarChar, col_cd), ClientClass.CreateSqlParameter("CUST_CD", SqlDbType.NVarChar, labelControl_CUST_CD.Text), ClientClass.CreateSqlParameter("CASH_MY", SqlDbType.Int, UtilClass.toInt(textEdit_CASH_MY.EditValue)), ClientClass.CreateSqlParameter("DEP_MY", SqlDbType.Int, UtilClass.toInt(textEdit_DEP_MY.EditValue)), ClientClass.CreateSqlParameter("ETC_MY", SqlDbType.Int, UtilClass.toInt(textEdit_ETC_MY.EditValue)), ClientClass.CreateSqlParameter("BANK_CD", SqlDbType.NVarChar, UtilClass.toStr(buttonEdit_ACC_NO.Tag)), ClientClass.CreateSqlParameter("ACC_NO", SqlDbType.NVarChar, UtilClass.toStr(buttonEdit_ACC_NO.Text)), ClientClass.CreateSqlParameter("COL_USR_ID", SqlDbType.NVarChar, col_usr_id), ClientClass.CreateSqlParameter("REMARK", SqlDbType.NVarChar, remark), ClientClass.CreateSqlParameter("REG_ID", SqlDbType.NVarChar, ConstClass._USR_ID), ClientClass.CreateSqlParameter("MODE", SqlDbType.NVarChar, mode), ClientClass.CreateSqlParameter("RESULT_STR", SqlDbType.NVarChar, "", ParameterDirection.Output, 1000) }; ResultData resultData = ClientClass.SetData("SaveCollectPopup", aParam); if (resultData.isError) { throw new Exception(resultData.ResultValue); } if (!UtilClass.isNull(resultData.ResultValue)) { XtraMessageBox.Show(resultData.ResultValue); } m_Changed = true; this.Cursor = Cursors.Arrow; XtraMessageBox.Show((mode.Equals("I") ? "등록" : "수정") + " 완료"); clearProc(); } catch (Exception ex) { this.Cursor = Cursors.Arrow; XtraMessageBox.Show(ex.Message); } } private void deleteProc() { try { if (XtraMessageBox.Show("삭제하시겠습니까?", "삭제", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { return; } this.Cursor = Cursors.WaitCursor; if (UtilClass.isNull(m_COL_NO)) { throw new Exception("삭제할 자료를 조회하십시오."); } SerializedSqlParam[] aParam = new SerializedSqlParam[] { ClientClass.CreateSqlParameter("COMP_CD", SqlDbType.NVarChar, ConstClass._COMP_CD), ClientClass.CreateSqlParameter("COL_NO", SqlDbType.NVarChar, m_COL_NO) }; ResultData resultData = ClientClass.SetData("DeleteCollectPopup", aParam); if (resultData.isError) { throw new Exception(resultData.ResultValue); } m_Changed = true; m_COL_NO = ""; this.Cursor = Cursors.Arrow; XtraMessageBox.Show("삭제 완료"); clearProc(); } catch (Exception ex) { this.Cursor = Cursors.Arrow; XtraMessageBox.Show(ex.Message); } } } }