using ClientLib; using ClientLib.CommonService; using DevExpress.XtraEditors; using DevExpress.XtraGrid; using DevExpress.XtraGrid.Views.Grid.ViewInfo; 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; namespace HANMI_J_SALE { public partial class CollectMoneyList : PublicLib.CommonMDI { private decimal m_CASH_MY, m_DEP_MY, m_ETC_MY, m_COL_MY; private string m_Date; public DateTime m_SALE_DATE; public CollectMoneyList() { InitializeComponent(); m_Date = ""; m_SALE_DATE = DateTime.Now.Date.AddDays(-1); gridControl_Main.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Flat; gridControl_Main.LookAndFeel.UseDefaultLookAndFeel = false; gridView_Main.Appearance.HeaderPanel.BackColor = Color.FromArgb(170, 204, 255); m_CASH_MY = 0; m_DEP_MY = 0; m_ETC_MY = 0; m_COL_MY = 0; dateEdit_SDATE.DateTime = dateEdit_FDATE.DateTime = DateTime.Now; buttonEdit_CUST_NM.ButtonClick += (sender, e) => { selectCustProc(); }; buttonEdit_CUST_NM.EditValueChanged += (sender, e) => { if (UtilClass.isNull(buttonEdit_CUST_NM.Text)) { labelControl_CUST_CD.Text = ""; } }; buttonEdit_CUST_NM.KeyPress += (sender, e) => { if (e.KeyChar == '\r') { selectCustProc(); } }; gridView_Main.DoubleClick += (sender, e) => { Point aPT = gridControl_Main.PointToClient(Control.MousePosition); GridHitInfo aInfo = gridView_Main.CalcHitInfo(aPT); if (aInfo.InRowCell) { DataRow row = gridView_Main.GetFocusedDataRow(); CollectPopup form = new CollectPopup(this, m_SALE_DATE); if (UtilClass.isNull(row["COL_DT"])) { return; } form.setData(UtilClass.toStr(row["COL_DT"]), UtilClass.toStr(row["COL_CD"]), UtilClass.toStr(row["COL_NO"])); form.ShowDialog(); if (form.m_Changed) { searchProc(); } } }; gridView_Main.CustomDrawCell += (sender, e) => { DataRow row = gridView_Main.GetDataRow(e.RowHandle); if (UtilClass.isEqual(row["TAG_STR"], "C") || UtilClass.isEqual(row["TAG_STR"], "D")) { e.Appearance.BackColor = Color.WhiteSmoke; } else if (UtilClass.isEqual(row["TAG_STR"], "T")) { e.Appearance.BackColor = Color.LightGreen; } }; gridView_Main.CustomDrawFooterCell += (sender, e) => { if (e.Column == gridView_Main.Columns["CASH_MY"]) { e.Info.DisplayText = m_CASH_MY.ToString("#,##0"); } else if (e.Column == gridView_Main.Columns["DEP_MY"]) { e.Info.DisplayText = m_DEP_MY.ToString("#,##0"); } else if (e.Column == gridView_Main.Columns["ETC_MY"]) { e.Info.DisplayText = m_ETC_MY.ToString("#,##0"); } else if (e.Column == gridView_Main.Columns["COL_MY"]) { e.Info.DisplayText = m_COL_MY.ToString("#,##0"); } }; this.Shown += (sender, e) => { try { SerializedSqlParam[] aParam = new SerializedSqlParam[] { ClientClass.CreateSqlParameter("COMP_CD", SqlDbType.NVarChar, ConstClass._COMP_CD) }; ResultData resultData = ClientClass.GetData("GetCollectMoneyListForLookup", aParam); if (resultData.isError) { throw new Exception(resultData.ResultValue); } DataRow row; row = resultData.DataList.Tables[0].NewRow(); row["USR_ID"] = ""; row["EMP_NO"] = ""; row["USR_NM"] = "전체담당자"; resultData.DataList.Tables[0].Rows.InsertAt(row, 0); UtilClass.SetLookup(lookUpEdit_SALES_USER, resultData.DataList.Tables[0], "EMP_NO", "USR_NM", true); row = resultData.DataList.Tables[1].NewRow(); row["MST_DEPT_CD"] = ""; row["DEPT_CD"] = ""; row["DEPT_NM"] = "전체부서"; resultData.DataList.Tables[1].Rows.InsertAt(row, 0); UtilClass.SetLookup(lookUpEdit_DEPT, resultData.DataList.Tables[1], "DEPT_CD", "DEPT_NM", true); } catch (Exception ex) { XtraMessageBox.Show(ex.Message); this.Close(); } }; } private void selectCustProc() { SelectCustomerForm form = new SelectCustomerForm(buttonEdit_CUST_NM.Text, DateTime.Now); if (form.ShowDialog() != DialogResult.Yes) { return; } buttonEdit_CUST_NM.Text = form.m_CUST_NM; labelControl_CUST_CD.Text = form.m_CUST_CD; searchProc(); } public override void searchProc() { try { this.Cursor = Cursors.WaitCursor; gridControl_Main.DataSource = null; string dept_cd = ""; DataRowView drv = lookUpEdit_DEPT.Properties.GetDataSourceRowByKeyValue(lookUpEdit_DEPT.EditValue) as DataRowView; if (drv != null) { dept_cd = UtilClass.toStr(drv["MST_DEPT_CD"]); } SerializedSqlParam[] aParam = new SerializedSqlParam[] { ClientClass.CreateSqlParameter("COMP_CD", SqlDbType.NVarChar, ConstClass._COMP_CD), 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("CUST_CD", SqlDbType.NVarChar, labelControl_CUST_CD.Text), ClientClass.CreateSqlParameter("CUST_USR_ID", SqlDbType.NVarChar, lookUpEdit_SALES_USER.EditValue), ClientClass.CreateSqlParameter("MST_DEPT_CD", SqlDbType.NVarChar, lookUpEdit_DEPT.EditValue), ClientClass.CreateSqlParameter("REMARK_CUST_USR_ID", SqlDbType.NVarChar, checkEdit_REMARK_CUST_USR_ID.Checked ? "Y" : "N"), ClientClass.CreateSqlParameter("REMARK_COL_USR_ID", SqlDbType.NVarChar, checkEdit_REMARK_COL_USR_ID.Checked ? "Y" : "N"), ClientClass.CreateSqlParameter("SORT", SqlDbType.Int, checkEdit_CustSort.Checked ? 0 : 1) }; ResultData resultData = ClientClass.GetData("GetCollectMoneyList", aParam); if (resultData.isError) { throw new Exception(resultData.ResultValue); } DataTable data = resultData.TableData.Clone(); DataTable aData = resultData.TableData; if (aData.Rows.Count < 1) { throw new Exception("조회된 결과가 없습니다."); } m_Date = dateEdit_SDATE.DateTime.ToString("yyyy.MM.dd") + " - " + dateEdit_FDATE.DateTime.ToString("yyyy.MM.dd"); m_CASH_MY = 0; m_DEP_MY = 0; m_ETC_MY = 0; m_COL_MY = 0; decimal cash_my_day = 0, dep_my_day = 0, etc_my_day = 0, col_my_day = 0; decimal cash_my_cust = 0, dep_my_cust = 0, etc_my_cust = 0, col_my_cust = 0; int cnt_cust = 0; string col_dt = "", cust_cd = ""; DataRow row; for (int i = 0; i < aData.Rows.Count; i++) { row = data.NewRow(); row.ItemArray = aData.Rows[i].ItemArray; data.Rows.Add(row); if (checkEdit_CustSort.Checked) { if (checkEdit_CustSum.Checked) { if (!UtilClass.isNull(cust_cd) && !UtilClass.isEqual(cust_cd, aData.Rows[i]["CUST_CD"])) { if (cnt_cust > 1) { row = data.NewRow(); row["COL_DT"] = " "; row["CUST_NM"] = "▷거래선계"; row["CASH_MY"] = cash_my_cust; row["DEP_MY"] = dep_my_cust; row["ETC_MY"] = etc_my_cust; row["COL_MY"] = col_my_cust; row["TAG_STR"] = "C"; data.Rows.InsertAt(row, data.Rows.Count - 1); } cash_my_cust = 0; dep_my_cust = 0; etc_my_cust = 0; col_my_cust = 0; cnt_cust = 0; } } if (checkEdit_DaySum.Checked) { if (!UtilClass.isNull(col_dt) && !UtilClass.isEqual(col_dt, aData.Rows[i]["COL_DT"])) { row = data.NewRow(); row["COL_DT"] = " "; row["CUST_NM"] = "▷일 자 계"; row["CASH_MY"] = cash_my_day; row["DEP_MY"] = dep_my_day; row["ETC_MY"] = etc_my_day; row["COL_MY"] = col_my_day; row["TAG_STR"] = "D"; data.Rows.InsertAt(row, data.Rows.Count - 1); cash_my_day = 0; dep_my_day = 0; etc_my_day = 0; col_my_day = 0; //cnt_cust = 0; } } } else { if (checkEdit_DaySum.Checked) { if (!UtilClass.isNull(col_dt) && !UtilClass.isEqual(col_dt, aData.Rows[i]["COL_DT"])) { row = data.NewRow(); row["COL_DT"] = " "; row["CUST_NM"] = "▷일 자 계"; row["CASH_MY"] = cash_my_day; row["DEP_MY"] = dep_my_day; row["ETC_MY"] = etc_my_day; row["COL_MY"] = col_my_day; row["TAG_STR"] = "D"; data.Rows.InsertAt(row, data.Rows.Count - 1); cash_my_day = 0; dep_my_day = 0; etc_my_day = 0; col_my_day = 0; //cnt_cust = 0; } } if (checkEdit_CustSum.Checked) { if (!UtilClass.isNull(cust_cd) && !UtilClass.isEqual(cust_cd, aData.Rows[i]["CUST_CD"])) { if (cnt_cust > 1) { row = data.NewRow(); row["COL_DT"] = " "; row["CUST_NM"] = "▷거래선계"; row["CASH_MY"] = cash_my_cust; row["DEP_MY"] = dep_my_cust; row["ETC_MY"] = etc_my_cust; row["COL_MY"] = col_my_cust; row["TAG_STR"] = "C"; data.Rows.InsertAt(row, data.Rows.Count - 1); } cash_my_cust = 0; dep_my_cust = 0; etc_my_cust = 0; col_my_cust = 0; cnt_cust = 0; } } } col_dt = UtilClass.toStr(aData.Rows[i]["COL_DT"]); cust_cd = UtilClass.toStr(aData.Rows[i]["CUST_CD"]); cash_my_day += UtilClass.toDecimal(aData.Rows[i]["CASH_MY"]); dep_my_day += UtilClass.toDecimal(aData.Rows[i]["DEP_MY"]); etc_my_day += UtilClass.toDecimal(aData.Rows[i]["ETC_MY"]); col_my_day += UtilClass.toDecimal(aData.Rows[i]["COL_MY"]); cash_my_cust += UtilClass.toDecimal(aData.Rows[i]["CASH_MY"]); dep_my_cust += UtilClass.toDecimal(aData.Rows[i]["DEP_MY"]); etc_my_cust += UtilClass.toDecimal(aData.Rows[i]["ETC_MY"]); col_my_cust += UtilClass.toDecimal(aData.Rows[i]["COL_MY"]); m_CASH_MY += UtilClass.toDecimal(aData.Rows[i]["CASH_MY"]); m_DEP_MY += UtilClass.toDecimal(aData.Rows[i]["DEP_MY"]); m_ETC_MY += UtilClass.toDecimal(aData.Rows[i]["ETC_MY"]); m_COL_MY += UtilClass.toDecimal(aData.Rows[i]["COL_MY"]); cnt_cust++; } if (checkEdit_CustSum.Checked && cnt_cust > 1) { DataRow cRow = data.NewRow(); cRow["COL_DT"] = " "; cRow["CUST_NM"] = "▷거래선계"; cRow["CASH_MY"] = cash_my_cust; cRow["DEP_MY"] = dep_my_cust; cRow["ETC_MY"] = etc_my_cust; cRow["COL_MY"] = col_my_cust; cRow["TAG_STR"] = "C"; data.Rows.Add(cRow); } if (checkEdit_DaySum.Checked) { DataRow dRow = data.NewRow(); dRow["COL_DT"] = " "; dRow["CUST_NM"] = "▷일 자 계"; dRow["CASH_MY"] = cash_my_day; dRow["DEP_MY"] = dep_my_day; dRow["ETC_MY"] = etc_my_day; dRow["COL_MY"] = col_my_day; dRow["TAG_STR"] = "D"; data.Rows.Add(dRow); } DataRow sRow = data.NewRow(); sRow["COL_DT"] = "★"; sRow["CUST_NM"] = "▷합 계"; sRow["CASH_MY"] = m_CASH_MY; sRow["DEP_MY"] = m_DEP_MY; sRow["ETC_MY"] = m_ETC_MY; sRow["COL_MY"] = m_COL_MY; sRow["TAG_STR"] = "T"; data.Rows.Add(sRow); textEdit_CASH_MY_SUM.EditValue = m_CASH_MY; textEdit_DEP_MY_SUM.EditValue = m_DEP_MY; textEdit_ETC_MY_SUM.EditValue = m_ETC_MY; textEdit_COL_MY_SUM.EditValue = m_COL_MY; data.AcceptChanges(); gridControl_Main.DataSource = data; this.Cursor = Cursors.Arrow; } catch (Exception ex) { this.Cursor = Cursors.Arrow; XtraMessageBox.Show(ex.Message); } } public override void newProc() { try { CollectPopup form = new CollectPopup(this, m_SALE_DATE); form.ShowDialog(); if (form.m_Changed) { searchProc(); } } catch (Exception ex) { XtraMessageBox.Show(ex.Message); } } public override void printProc() { try { if (gridControl_Main.DataSource == null) { return; } DataTable data = (gridControl_Main.DataSource as DataTable).Copy(); if (data.Rows.Count < 1) { return; } this.Cursor = Cursors.WaitCursor; data.Columns.Add("COL_DT_DISP", typeof(string)); DataView view = new DataView(data); view.RowFilter = "COL_DT <> ' ' and COL_DT <> ' ' and COL_DT <> '☆' and COL_DT <> '★'"; view.Sort = "COL_DT asc, CUST_NM asc"; DataTable aData = view.ToTable(); foreach (DataRow row in aData.Rows) { row["COL_DT_DISP"] = UtilClass.toStr(row["COL_DT"]).Substring(5, 5).Replace(".", "/"); } CollectMoneyReport report = new CollectMoneyReport(); report.setData(aData, m_Date); CommonPreview preview = new CommonPreview("수금내역", false, false); preview.SetH1Report(report); preview.ShowDialog(); this.Cursor = Cursors.Arrow; } catch (Exception ex) { this.Cursor = Cursors.Arrow; MessageBox.Show(ex.Message); } } public override void excelProc() { if (gridControl_Main.DataSource == null) { return; } this.ExportExcelGrid(gridControl_Main); } } }