File name
Commit message
Commit date
File name
Commit message
Commit date
using AegisImplicitMail;
using ClientLib;
using ClientLib.CommonService;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using Popbill.Fax;
using PublicLib;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net.Mail;
using System.Text;
using System.Windows.Forms;
namespace HANMI_SALE
{
public partial class BillManager : PublicLib.CommonMDI
{
private DataTable m_Data, m_CustData;
private string m_EMAIL, m_USER_ID, m_USER_PWD, m_SERVER_ADDR, m_BizNO;
private int m_SERVER_PORT;
private FaxService m_FaxService;
public BillManager()
{
InitializeComponent();
// textEdit_CUST_NM.ImeMode = System.Windows.Forms.ImeMode.Hangul;
gridControl_Main.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Flat;
gridControl_Main.LookAndFeel.UseDefaultLookAndFeel = false;
gridView_Main.Appearance.HeaderPanel.BackColor = Color.FromArgb(170, 204, 255);
m_BizNO = UtilClass.toStr(ConstClass._GET_USER_INFO("BIZ_NO")).Replace("-", "");
m_EMAIL = "";
m_USER_ID = "";
m_USER_PWD = "";
m_SERVER_ADDR = "";
m_SERVER_PORT = 0;
m_CustData = new DataTable();
m_CustData.Columns.Add("SEL_FIELD", typeof(string));
m_CustData.Columns.Add("CUST_CD", typeof(string));
m_CustData.Columns.Add("CUST_NM", typeof(string));
m_CustData.Columns.Add("OWNER_NM", typeof(string));
m_CustData.Columns.Add("FAX_NO", typeof(string));
m_CustData.Columns.Add("EMAIL", typeof(string));
m_CustData.Columns.Add("MAIL_YN", typeof(string));
m_CustData.Columns.Add("FAX_YN", typeof(string));
m_CustData.Columns.Add("SMS_YN", typeof(string));
progressBarControl_Send.Visible = false;
DateTime today = DateTime.Now.Date;
if (today.Day <= 10)
{
today.AddMonths(-1);
}
DateTime firstDay = today.AddDays(1 - today.Day);
DateTime lastDay = firstDay.AddMonths(1).AddDays(-1);
dateEdit_SDATE.DateTime = firstDay;
dateEdit_FDATE.DateTime = lastDay;
simpleButton_PREV_DATE.Click += (sender, e) =>
{
DateTime BaseDate = dateEdit_SDATE.DateTime;
DateTime MonthLastDate = BaseDate.AddDays(0 - BaseDate.Day);
DateTime MonthFirstDate = MonthLastDate.AddDays(1 - MonthLastDate.Day);
dateEdit_SDATE.DateTime = MonthFirstDate;
dateEdit_FDATE.DateTime = MonthLastDate;
searchProc();
};
simpleButton_NEXT_DATE.Click += (sender, e) =>
{
DateTime BaseDate = dateEdit_FDATE.DateTime.AddDays(1);
DateTime MonthFirstDate = BaseDate.AddDays(1 - BaseDate.Day);
DateTime MonthLastDate = MonthFirstDate.AddMonths(1).AddDays(-1);
dateEdit_SDATE.DateTime = MonthFirstDate;
dateEdit_FDATE.DateTime = MonthLastDate;
searchProc();
};
simpleButton_Cust_Search.Click += (sender, e) =>
{
selectCustProc();
};
textEdit_CUST_NM.KeyPress += (sender, e) =>
{
if (e.KeyChar == '\r')
{
selectCustProc();
}
};
textEdit_CUST_NM.EditValueChanged += (sender, e) =>
{
if (UtilClass.isNull(textEdit_CUST_NM.Text))
{
labelControl_CUST_CD.Text = "";
}
};
gridView_Main.CustomDrawCell += (sender, e) =>
{
DataRow row = gridView_Main.GetDataRow(e.RowHandle);
if (UtilClass.isEqual(row["TAG_STR"], "P"))
{
e.Appearance.BackColor = Color.FromArgb(255, 255, 192);
e.Appearance.ForeColor = Color.DarkBlue;
}
else if (UtilClass.isEqual(row["TAG_STR"], "C"))
{
e.Appearance.ForeColor = Color.Red;
}
else if (UtilClass.isEqual(row["TAG_STR"], "N"))
{
e.Appearance.BackColor = Color.FromArgb(192, 255, 192);
e.Appearance.ForeColor = Color.DarkBlue;
}
else if (UtilClass.isEqual(row["TAG_STR"], "M"))
{
e.Appearance.BackColor = Color.FromArgb(224, 224, 224);
e.Appearance.ForeColor = Color.DarkBlue;
}
};
gridView_Main.CustomColumnDisplayText += (sender, e) =>
{
if (e.Column == gridView_Main.Columns["VAT_MY"] && UtilClass.toInt(e.Value) == -1)
{
e.DisplayText = "전월잔액";
}
else if (e.Column == gridView_Main.Columns["VAT_MY"] && UtilClass.toInt(e.Value) == -2)
{
e.DisplayText = "현재잔액";
}
//else if (e.Column == gridView_Main.Columns["ORDER_MY"] && m_bNoJan == true && UtilClass.toInt(e.Value) == int.MinValue)
//{
// e.DisplayText = "--------";
//}
};
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");
//}
};
m_FaxService = null;
simpleButton_FAX_LOG.Click += (sender, e) =>
{
DataView s08 = new DataView(ConstClass._DATA);
s08.RowFilter = "CATE_CD = 'S' and GRP_CD = 'S01' and NO_CD = '08'";
if (s08.Count < 1)
{
XtraMessageBox.Show("팩스 전송을 위한 환경정보가 없습니다.");
}
string userID = UtilClass.toStr(s08[0]["NO_CD_NM"]);
if (UtilClass.isNull(userID))
{
XtraMessageBox.Show("팩스 전송을 위한 팝빌 등록정보가 없습니다.");
return;
}
string url = m_FaxService.GetSentListURL(m_BizNO, userID);
Process.Start(url);
};
this.Shown += (sender, e) =>
{
try
{
DataView s06 = new DataView(ConstClass._DATA);
s06.RowFilter = "CATE_CD = 'S' and GRP_CD = 'S01' and NO_CD = '06'";
DataView s07 = new DataView(ConstClass._DATA);
s07.RowFilter = "CATE_CD = 'S' and GRP_CD = 'S01' and NO_CD = '07'";
DataView s11 = new DataView(ConstClass._DATA);
s11.RowFilter = "CATE_CD = 'S' and GRP_CD = 'S01' and NO_CD = '11'";
if (s06.Count > 0 || s07.Count > 0 || s11.Count > 0)
{
string linkID = UtilClass.toStr(s06[0]["NO_CD_NM"]);
string key = UtilClass.toStr(s07[0]["NO_CD_NM"]);
if (!UtilClass.isNull(linkID) && !UtilClass.isNull(key))
{
m_FaxService = new FaxService(linkID, key);
m_FaxService.IsTest = s11.Count > 0 && UtilClass.isEqual(s11[0]["NO_CD_NM"], "Y");
}
}
DataView s01 = new DataView(ConstClass._DATA);
s01.RowFilter = "CATE_CD = 'S' and GRP_CD = 'S01' and NO_CD = '01'";
if (s01.Count > 0)
{
m_EMAIL = UtilClass.toStr(s01[0]["NO_CD_NM"]);
}
DataView view = new DataView(ConstClass._DATA);
view.RowFilter = "CATE_CD = 'S' and GRP_CD = 'S01' and NO_CD = '01'";
m_USER_ID = UtilClass.toStr(view[0]["NO_CD_NM"]);
view.RowFilter = "CATE_CD = 'S' and GRP_CD = 'S01' and NO_CD = '02'";
m_USER_PWD = UtilClass.toStr(view[0]["NO_CD_NM"]);
view.RowFilter = "CATE_CD = 'S' and GRP_CD = 'S01' and NO_CD = '03'";
m_SERVER_ADDR = UtilClass.toStr(view[0]["NO_CD_NM"]);
view.RowFilter = "CATE_CD = 'S' and GRP_CD = 'S01' and NO_CD = '04'";
m_SERVER_PORT = UtilClass.toInt(view[0]["NO_CD_NM"]);
if (m_FaxService != null)
{
double remainPoint = m_FaxService.GetBalance(m_BizNO);
labelControl_Point.Text = remainPoint.ToString("#,##0") + " P";
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.Message);
this.Close();
}
};
}
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();
}
//private bool m_bNoJan = false;
private bool m_b2018 = false;
public override void searchProc()
{
//if (dateEdit_SDATE.DateTime < new DateTime(2019, 1, 1))
// m_bNoJan = true;
//else if (dateEdit_FDATE.DateTime < new DateTime(2019, 1, 1))
// m_bNoJan = true;
//else
// m_bNoJan = false;
int nYear = 2018;
if (dateEdit_SDATE.DateTime < new DateTime(2019, 1, 1))
{
m_b2018 = true;
nYear = 2018;
}
else
{
m_b2018 = false;
nYear = DateTime.Now.Year - 1;
}
try
{
this.Cursor = Cursors.WaitCursor;
labelControl_PREV_JAN_MY.Text = "";
labelControl_TOT_ORDER_MY.Text = "";
labelControl_TOT_VAT_MY.Text = "";
labelControl_TOT_COL_MY.Text = "";
labelControl_TOT_JAN_MY.Text = "";
gridControl_Main.DataSource = null;
SerializedSqlParam[] aParam = new SerializedSqlParam[] {
ClientClass.CreateSqlParameter("COMP_CD", SqlDbType.NVarChar, ConstClass._COMP_CD),
ClientClass.CreateSqlParameter("ORDER_SDATE", SqlDbType.NVarChar, dateEdit_SDATE.Text),
ClientClass.CreateSqlParameter("ORDER_FDATE", SqlDbType.NVarChar, dateEdit_FDATE.Text),
ClientClass.CreateSqlParameter("CUST_CD", SqlDbType.NVarChar, labelControl_CUST_CD.Text),
ClientClass.CreateSqlParameter("DT", SqlDbType.NVarChar, dateEdit_SDATE.Text),
ClientClass.CreateSqlParameter("PRINT_OPTION", SqlDbType.Int, comboBoxEdit_PRINT_OPTION.SelectedIndex),
ClientClass.CreateSqlParameter("REMARK_CONDITION", SqlDbType.Int, comboBoxEdit_REMARK_CONDITION.SelectedIndex),
ClientClass.CreateSqlParameter("ORDER_DATE", SqlDbType.Int, nYear),
};
ResultData resultData = null;
resultData = ClientClass.GetData("GetBillManager_NEW", aParam);
//if (m_b2018)
// resultData = ClientClass.GetData("GetBillManager2018", aParam);
//else
// resultData = ClientClass.GetData("GetBillManager", aParam);
if (resultData.isError)
{
throw new Exception(resultData.ResultValue);
}
m_CustData.Rows.Clear();
decimal prev_jan_my = 0, tot_jan_my = 0, tot_curr_my = 0, tot_vat_my = 0, tot_order_my = 0, tot_col_my = 0;
decimal now_jan_my = 0, mm_curr_my = 0, mm_vat_my = 0, mm_order_my = 0, mm_sum_my = 0;
string cust_cd = "", yymm = "";
DataRow row;
m_Data = resultData.TableData;
DataTable aData = m_Data.Clone();
DataRow[] rows;
DataRow cRow;
for (int i = 0; i < m_Data.Rows.Count; i++)
{
rows = m_CustData.Select("CUST_CD = '" + UtilClass.toStr(m_Data.Rows[i]["CUST_CD"]) + "'");
if (rows == null || rows.Length < 1)
{
cRow = m_CustData.NewRow();
cRow["SEL_FIELD"] = "Y";
cRow["CUST_CD"] = m_Data.Rows[i]["CUST_CD"];
cRow["CUST_NM"] = m_Data.Rows[i]["CUST_NM"];
cRow["OWNER_NM"] = m_Data.Rows[i]["OWNER_NM"];
cRow["FAX_NO"] = m_Data.Rows[i]["FAX_NO"];
cRow["EMAIL"] = m_Data.Rows[i]["EMAIL"];
cRow["MAIL_YN"] = "N";
cRow["FAX_YN"] = "N";
cRow["SMS_YN"] = "N";
m_CustData.Rows.Add(cRow);
}
if (!UtilClass.isEqual(cust_cd, m_Data.Rows[i]["CUST_CD"]))
{
if (i > 0)
{
// 월계 표현여부
if (checkEdit_MONTH_SUM.Checked && (mm_curr_my + mm_vat_my + mm_order_my) > 0)
{
row = aData.NewRow();
row["ORDER_DATE"] = "";
row["CUST_CD"] = m_Data.Rows[i - 1]["CUST_CD"];
row["FILE_NM"] = "월계";
row["ITEM_NM"] = "";
row["CURR_MY"] = mm_curr_my;
row["VAT_MY"] = mm_vat_my;
row["ORDER_MY"] = mm_order_my;
row["SUM_MY"] = mm_sum_my;
row["LN_RMK"] = "";
row["TAG_STR"] = "M";
row["SEND_MAIL_YN"] = m_Data.Rows[i - 1]["SEND_MAIL_YN"];
row["SEND_FAX_YN"] = m_Data.Rows[i - 1]["SEND_FAX_YN"];
row["SEND_SMS_YN"] = m_Data.Rows[i - 1]["SEND_SMS_YN"];
aData.Rows.Add(row);
}
row = aData.NewRow();
row["ORDER_DATE"] = "☆";
row["CUST_CD"] = m_Data.Rows[i - 1]["CUST_CD"];
row["FILE_NM"] = m_Data.Rows[i - 1]["CUST_NM"];
row["ITEM_NM"] = m_Data.Rows[i - 1]["CUST_CD"];
row["VAT_MY"] = -2;
row["ORDER_MY"] = now_jan_my; //m_bNoJan ? int.MinValue : now_jan_my;
row["SUM_MY"] = mm_sum_my;
row["LN_RMK"] = "";
row["TAG_STR"] = "N";
row["SEND_MAIL_YN"] = m_Data.Rows[i - 1]["SEND_MAIL_YN"];
row["SEND_FAX_YN"] = m_Data.Rows[i - 1]["SEND_FAX_YN"];
row["SEND_SMS_YN"] = m_Data.Rows[i - 1]["SEND_SMS_YN"];
aData.Rows.Add(row);
tot_jan_my += now_jan_my;
}
now_jan_my = 0;
mm_curr_my = 0;
mm_vat_my = 0;
mm_order_my = 0;
mm_sum_my = 0;
yymm = UtilClass.toStr(m_Data.Rows[i]["YYMM"]);
row = aData.NewRow();
row["ORDER_DATE"] = "★";
row["CUST_CD"] = m_Data.Rows[i]["CUST_CD"];
row["FILE_NM"] = m_Data.Rows[i]["CUST_NM"];
row["ITEM_NM"] = m_Data.Rows[i]["CUST_CD"];
row["VAT_MY"] = -1;
row["ORDER_MY"] = m_Data.Rows[i]["PREV_MONTH_MY"]; //m_bNoJan ? int.MinValue : m_Data.Rows[i]["PREV_MONTH_MY"];
row["LN_RMK"] = m_Data.Rows[i]["FAX_NO"];
row["TAG_STR"] = "P";
row["SEND_MAIL_YN"] = m_Data.Rows[i]["SEND_MAIL_YN"];
row["SEND_FAX_YN"] = m_Data.Rows[i]["SEND_FAX_YN"];
row["SEND_SMS_YN"] = m_Data.Rows[i]["SEND_SMS_YN"];
now_jan_my = UtilClass.toInt(m_Data.Rows[i]["PREV_MONTH_MY"]);
prev_jan_my += UtilClass.toInt(m_Data.Rows[i]["PREV_MONTH_MY"]);
aData.Rows.Add(row);
}
if (checkEdit_MONTH_SUM.Checked && !UtilClass.isEqual(yymm, m_Data.Rows[i]["YYMM"]))
{
row = aData.NewRow();
row["ORDER_DATE"] = "";
row["CUST_CD"] = m_Data.Rows[i]["CUST_CD"];
row["FILE_NM"] = "월계";
row["ITEM_NM"] = "";
row["CURR_MY"] = mm_curr_my;
row["VAT_MY"] = mm_vat_my;
row["ORDER_MY"] = mm_order_my;
row["SUM_MY"] = mm_sum_my;
row["LN_RMK"] = "";
row["TAG_STR"] = "M";
row["SEND_MAIL_YN"] = m_Data.Rows[i]["SEND_MAIL_YN"];
row["SEND_FAX_YN"] = m_Data.Rows[i]["SEND_FAX_YN"];
row["SEND_SMS_YN"] = m_Data.Rows[i]["SEND_SMS_YN"];
aData.Rows.Add(row);
mm_curr_my = 0;
mm_vat_my = 0;
mm_order_my = 0;
}
cust_cd = UtilClass.toStr(m_Data.Rows[i]["CUST_CD"]);
yymm = UtilClass.toStr(m_Data.Rows[i]["YYMM"]);
mm_curr_my += UtilClass.toInt(m_Data.Rows[i]["CURR_MY"]);
mm_vat_my += UtilClass.toInt(m_Data.Rows[i]["VAT_MY"]);
mm_order_my += UtilClass.toInt(m_Data.Rows[i]["ORDER_MY"]);
row = aData.NewRow();
row.ItemArray = m_Data.Rows[i].ItemArray;
if (UtilClass.isEqual(row["TAG_STR"], "S"))
{
now_jan_my += UtilClass.toInt(row["ORDER_MY"]);
tot_curr_my += UtilClass.toInt(m_Data.Rows[i]["CURR_MY"]);
tot_vat_my += UtilClass.toInt(m_Data.Rows[i]["VAT_MY"]);
tot_order_my += UtilClass.toInt(m_Data.Rows[i]["ORDER_MY"]);
mm_sum_my += UtilClass.toInt(m_Data.Rows[i]["ORDER_MY"]);
}
else if (UtilClass.isEqual(row["TAG_STR"], "C"))
{
now_jan_my -= UtilClass.toInt(row["CURR_MY"]);
tot_col_my += UtilClass.toInt(row["CURR_MY"]);
}
row["JAN_MY"] = now_jan_my;
aData.Rows.Add(row);
if (i == m_Data.Rows.Count - 1)
{
// 월계 표현여부
if (checkEdit_MONTH_SUM.Checked && (mm_curr_my + mm_vat_my + mm_order_my) > 0)
{
row = aData.NewRow();
row["ORDER_DATE"] = "";
row["CUST_CD"] = m_Data.Rows[i]["CUST_CD"];
row["FILE_NM"] = "월계";
row["ITEM_NM"] = "";
row["CURR_MY"] = mm_curr_my;
row["VAT_MY"] = mm_vat_my;
row["ORDER_MY"] = mm_order_my;
row["SUM_MY"] = mm_sum_my;
row["LN_RMK"] = "";
row["TAG_STR"] = "M";
row["SEND_MAIL_YN"] = m_Data.Rows[i]["SEND_MAIL_YN"];
row["SEND_FAX_YN"] = m_Data.Rows[i]["SEND_FAX_YN"];
row["SEND_SMS_YN"] = m_Data.Rows[i]["SEND_SMS_YN"];
aData.Rows.Add(row);
}
row = aData.NewRow();
row["ORDER_DATE"] = "☆";
row["CUST_CD"] = m_Data.Rows[i]["CUST_CD"];
row["FILE_NM"] = m_Data.Rows[i]["CUST_NM"];
row["ITEM_NM"] = m_Data.Rows[i]["CUST_CD"];
row["VAT_MY"] = -2;
row["ORDER_MY"] = now_jan_my; // m_bNoJan ? int.MinValue : now_jan_my;
row["SUM_MY"] = mm_sum_my;
row["LN_RMK"] = "";
row["TAG_STR"] = "N";
row["SEND_MAIL_YN"] = m_Data.Rows[i]["SEND_MAIL_YN"];
row["SEND_FAX_YN"] = m_Data.Rows[i]["SEND_FAX_YN"];
row["SEND_SMS_YN"] = m_Data.Rows[i]["SEND_SMS_YN"];
aData.Rows.Add(row);
tot_jan_my += now_jan_my;
}
}
labelControl_PREV_JAN_MY.Text = prev_jan_my.ToString("#,##0"); // m_bNoJan ? "--------" : prev_jan_my.ToString("#,##0");
labelControl_TOT_CURR_MY.Text = tot_curr_my.ToString("#,##0");
labelControl_TOT_VAT_MY.Text = tot_vat_my.ToString("#,##0");
labelControl_TOT_ORDER_MY.Text = tot_order_my.ToString("#,##0");
labelControl_TOT_COL_MY.Text = tot_col_my.ToString("#,##0");
labelControl_TOT_JAN_MY.Text = tot_jan_my.ToString("#,##0"); // m_bNoJan ? "--------" : tot_jan_my.ToString("#,##0");
aData.AcceptChanges();
gridControl_Main.DataSource = aData;
this.Cursor = Cursors.Arrow;
}
catch (Exception ex)
{
this.Cursor = Cursors.Arrow;
XtraMessageBox.Show(ex.Message);
}
}
public override void printProc()
{
SelectBillCustForm custForm = new SelectBillCustForm(m_CustData);
if (custForm.ShowDialog() != DialogResult.Yes)
{
return;
}
try
{
this.Cursor = Cursors.WaitCursor;
DataTable rTable = custForm.m_Data;
DataRow[] srows = rTable.Select("SEL_FIELD = 'Y'");
if (srows == null || srows.Length < 1)
{
throw new Exception("선택된 거래처가 없습니다.");
}
DataTable data = m_Data.Clone();
DataRow cRow;
DataRow[] rows;
decimal sum;
decimal curr_my;
DataView dv = new DataView(gridControl_Main.DataSource as DataTable);
foreach (DataRow sRow in srows)
{
rows = m_Data.Select("CUST_CD = '" + UtilClass.toStr(sRow["CUST_CD"]) + "'");
dv.RowFilter = "CUST_CD = '" + UtilClass.toStr(sRow["CUST_CD"]) + "' and ORDER_DATE = '☆'";
sum = 0; curr_my = 0;
for (int i = 0; i < rows.Length; i++)
{
cRow = data.NewRow();
cRow.ItemArray = rows[i].ItemArray;
data.Rows.Add(cRow);
if (UtilClass.isEqual(rows[i]["TAG_STR"], "S"))
{
sum += UtilClass.toInt(rows[i]["ORDER_MY"]);
curr_my += UtilClass.toInt(rows[i]["CURR_MY"]);
}
cRow["TMP_JAN"] = dv.Count > 0 ? UtilClass.toDecimal(dv[0]["ORDER_MY"]) : 0;
cRow["SUM_MY"] = sum;
cRow["SUM_CURR_MY"] = curr_my;
}
}
BillManagerReport report = new BillManagerReport(this);
string order_date = dateEdit_SDATE.Text + " ~ " + dateEdit_FDATE.Text;
//report.SetData(m_Data, data, order_date);
report.setDataBinding(data, order_date);
CommonPreview form = new CommonPreview("청구서", true, true);
form.H1MultiMainSeld = true;
form.SetH1Report(report);
this.Cursor = Cursors.Arrow;
if (form.ShowDialog() == DialogResult.Yes)
{
ResultClass resultClass;
DataTable aData = report.DataSource as DataTable;
if (UtilClass.isEqual(form.m_SendType, "EMAIL"))
{
resultClass = this.mailProc(aData, srows);
}
else
{
if (m_FaxService == null)
{
MessageBox.Show("팩스 전송을 위한 환경이 갖추어지지 않았습니다.");
return;
}
resultClass = this.faxProc(aData, srows);
}
if (!resultClass.isError)
{
this.Cursor = Cursors.WaitCursor;
DataTable sendTable = new DataTable();
sendTable.Columns.Add("CUST_CD", typeof(string));
sendTable.Columns.Add("MAIL_YN", typeof(string));
sendTable.Columns.Add("FAX_YN", typeof(string));
sendTable.Columns.Add("SMS_YN", typeof(string));
DataRow sendRow;
foreach (DataRow ssRow in srows)
{
if (!UtilClass.isEqual(ssRow["MAIL_YN"], "Y") && !UtilClass.isEqual(ssRow["FAX_YN"], "Y")
&& !UtilClass.isEqual(ssRow["SMS_YN"], "Y"))
{
continue;
}
sendRow = sendTable.NewRow();
sendRow["CUST_CD"] = ssRow["CUST_CD"];
sendRow["MAIL_YN"] = ssRow["MAIL_YN"];
sendRow["FAX_YN"] = ssRow["FAX_YN"];
sendRow["SMS_YN"] = ssRow["SMS_YN"];
sendTable.Rows.Add(sendRow);
}
sendTable.TableName = "ADATA";
ResultData data1 = new ResultData();
data1.TableData = sendTable;
ResultData[] dataList = new ResultData[] { data1 };
SerializedSqlParam[] aParam = new SerializedSqlParam[] {
ClientClass.CreateSqlParameter("COMP_CD", SqlDbType.NVarChar, ConstClass._COMP_CD),
ClientClass.CreateSqlParameter("YYMM", SqlDbType.NVarChar, dateEdit_FDATE.DateTime.ToString("yyyy-MM")),
ClientClass.CreateSqlParameter("REG_ID", SqlDbType.NVarChar, ConstClass._USR_ID)
};
ResultData resultData = ClientClass.SetTableData("SaveBillManagerSendLog", dataList, aParam);
if (resultData.isError)
{
throw new Exception(resultData.ResultValue);
}
this.Cursor = Cursors.Arrow;
searchProc();
}
}
}
catch (Exception ex)
{
this.Cursor = Cursors.Arrow;
XtraMessageBox.Show(ex.Message);
}
}
public override void excelProc()
{
this.ExportExcelGrid(gridControl_Main);
}
private void simpleButton_CUST_MAIL_Click(object sender, EventArgs e)
{
CustMailPopup popup = new CustMailPopup("");
popup.ShowDialog();
}
private ResultClass mailProc(DataTable aData, DataRow[] argRows)
{
ResultClass mailResult = new ResultClass();
try
{
this.Cursor = Cursors.WaitCursor;
if (UtilClass.isNull(m_EMAIL) || UtilClass.isNull(m_USER_ID) || UtilClass.isNull(m_USER_PWD) ||
UtilClass.isNull(m_SERVER_ADDR) || UtilClass.toInt(m_SERVER_PORT) < 1)
{
throw new Exception("메일 설정을 먼저 해야 합니다. 개발사에게 연락부탁드립니다.");
}
DataRow[] rows = aData.Select("EMAIL = ''");
if (rows != null && rows.Length > 0)
{
this.Cursor = Cursors.Arrow;
if (XtraMessageBox.Show("메일이 누락된 업체정보가 " + rows.Length + " 건이 있습니다.\n해당업체는 메일발송을 하지 못합니다.\n\n계속 하시겠습니까?", "메일발송", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
{
mailResult.isError = true;
mailResult.ResultStr = "메일 발송 취소";
return mailResult;
}
}
this.Cursor = Cursors.WaitCursor;
BillManagerReport report;
DataTable data = aData.Clone();
DataRow row, aRow;
string email, hp;
ResultClass result;
progressBarControl_Send.Properties.DisplayFormat.FormatString = "{0:#,##0} / " + argRows.Length.ToString("#,##0");
progressBarControl_Send.Position = 0;
progressBarControl_Send.Properties.Minimum = 0;
progressBarControl_Send.Properties.Maximum = argRows.Length;
progressBarControl_Send.Visible = true;
Application.DoEvents();
DataView dataView = new DataView(aData);
for (int i = 0; i < argRows.Length; i++)
{
progressBarControl_Send.Position++;
Application.DoEvents();
dataView.RowFilter = "CUST_CD = '" + UtilClass.toStr(argRows[i]["CUST_CD"]) + "'";
if (dataView.Count < 1)
{
continue;
}
aRow = dataView[0].Row;
email = UtilClass.toStr(aRow["EMAIL"]);
hp = UtilClass.toStr(aRow["TEL_NO"]);
//if (ConstClass._DEBUG_MODE)
//{
// if (i % 3 == 0)
// {
// email = "zeromo@naver.com";
// hp = "010-5571-3734";
// }
// else if (i % 3 == 1)
// {
// email = "jbeauty@naver.com";
// hp = "010-2568-9089";
// }
// else if (i % 3 == 2)
// {
// email = "coldjun@nate.com";
// hp = "010-7179-2554";
// }
// else
// {
// email = "uckuck@daum.net";
// hp = "010-2568-9089";
// }
//}
if (UtilClass.isNull(email))
{
continue;
}
for (int j = 0; j < dataView.Count; j++)
{
row = data.NewRow();
row.ItemArray = dataView[j].Row.ItemArray;
data.Rows.Add(row);
}
report = new BillManagerReport(this);
report.setDataBinding(data, dateEdit_SDATE.Text + " ~ " + dateEdit_FDATE.Text);
result = sendMail(report, email, hp, argRows[i]);
if (result.isError)
{
throw new Exception(result.ResultStr);
}
data.Rows.Clear();
}
this.Cursor = Cursors.Arrow;
XtraMessageBox.Show("메일 발송 완료.");
progressBarControl_Send.Visible = false;
}
catch (Exception ex)
{
this.Cursor = Cursors.Arrow;
progressBarControl_Send.Visible = false;
mailResult.isError = true;
mailResult.ResultStr = ex.Message;
}
return mailResult;
}
private ResultClass faxProc(DataTable aData, DataRow[] argRows)
{
ResultClass faxResult = new ResultClass();
try
{
this.Cursor = Cursors.WaitCursor;
DataView s08 = new DataView(ConstClass._DATA);
s08.RowFilter = "CATE_CD = 'S' and GRP_CD = 'S01' and NO_CD = '08'";
if (s08.Count < 1)
{
throw new Exception("팩스 전송을 위한 환경정보가 없습니다.");
}
string userID = UtilClass.toStr(s08[0]["NO_CD_NM"]);
if (UtilClass.isNull(userID))
{
throw new Exception("팩스 전송을 위한 팝빌 등록정보가 없습니다.");
}
object faxObj = ConstClass._GET_USER_INFO("FAX_NO");
string myFaxNo = UtilClass.toStr(faxObj);
if (UtilClass.isNull(myFaxNo) || UtilClass.isNull(m_BizNO))
{
throw new Exception("회사정보관리에서 팩스번호 및 사업자번호를 입력하신 후, 시스템을 재시작하시길 바랍니다.");
}
DataRow[] rows = aData.Select("FAX_NO = ''");
if (rows != null && rows.Length > 0)
{
this.Cursor = Cursors.Arrow;
if (XtraMessageBox.Show("팩스번호가 누락된 업체정보가 " + rows.Length + " 건이 있습니다.\n해당업체는 팩스발송을 하지 못합니다.\n\n계속 하시겠습니까?", "메일발송", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
{
faxResult.isError = true;
faxResult.ResultStr = "팩스 발송 취소";
return faxResult;
}
}
this.Cursor = Cursors.WaitCursor;
BillManagerReport report;
DataTable data = aData.Clone();
DataRow row, aRow;
string fax, hp, cust_nm;
ResultClass result;
progressBarControl_Send.Properties.DisplayFormat.FormatString = "{0:#,##0} / " + argRows.Length.ToString("#,##0");
progressBarControl_Send.Position = 0;
progressBarControl_Send.Properties.Minimum = 0;
progressBarControl_Send.Properties.Maximum = argRows.Length;
progressBarControl_Send.Visible = true;
Application.DoEvents();
//int sendCnt = 0;
DataView dataView = new DataView(aData);
for (int i = 0; i < argRows.Length; i++)
{
progressBarControl_Send.Position++;
Application.DoEvents();
dataView.RowFilter = "CUST_CD = '" + UtilClass.toStr(argRows[i]["CUST_CD"]) + "'";
if (dataView.Count < 1)
{
continue;
}
aRow = dataView[0].Row;
fax = UtilClass.toStr(aRow["FAX_NO"]);
hp = UtilClass.toStr(aRow["TEL_NO"]);
//if (ConstClass._DEBUG_MODE)
//{
// if (i % 3 == 0)
// {
// fax = "0504-146-3734";
// hp = "010-5571-3734";
// }
// else if (i % 3 == 1)
// {
// fax = "0504-146-3734";
// hp = "010-2568-9089";
// }
// else if (i % 3 == 2)
// {
// fax = "0504-146-3734";
// hp = "010-7179-2554";
// }
//}
if (UtilClass.isNull(fax))
{
continue;
}
for (int j = 0; j < dataView.Count; j++)
{
row = data.NewRow();
row.ItemArray = dataView[j].Row.ItemArray;
data.Rows.Add(row);
}
report = new BillManagerReport(this);
report.setDataBinding(data, dateEdit_SDATE.Text + " ~ " + dateEdit_FDATE.Text);
cust_nm = UtilClass.toStr(aRow["CUST_NM"]);
result = sendFax(userID, m_BizNO, report, myFaxNo, fax, cust_nm, hp, argRows[i]);
if (result.isError)
{
throw new Exception(result.ResultStr);
}
//if (ConstClass._DEBUG_MODE)
//{
// sendCnt++;
// if (sendCnt > 2)
// {
// break;
// }
//}
data.Rows.Clear();
}
if (m_FaxService != null)
{
double remainPoint = m_FaxService.GetBalance(m_BizNO);
labelControl_Point.Text = remainPoint.ToString("#,##0") + " P";
}
this.Cursor = Cursors.Arrow;
XtraMessageBox.Show("팩스 발송 완료.");
progressBarControl_Send.Visible = false;
}
catch (Exception ex)
{
this.Cursor = Cursors.Arrow;
progressBarControl_Send.Visible = false;
faxResult.isError = true;
faxResult.ResultStr = ex.Message;
}
return faxResult;
}
private ResultClass sendMail(BillManagerReport report, string email, string hp, DataRow sendRow)
{
ResultClass result = new ResultClass();
try
{
MimeMailMessage mail = new MimeMailMessage();
mail.AlternateViews.Add(AlternateView.CreateAlternateViewFromString("청구서",
Encoding.UTF8, "text/html"));
mail.IsBodyHtml = false;
mail.Body = "기간 : " + dateEdit_SDATE.Text + " ~ " + dateEdit_FDATE.Text + " 동안 발생한 거래분에 대해 청구서를 발송합니다.";
mail.BodyEncoding = Encoding.UTF8;
mail.SubjectEncoding = Encoding.UTF8;
mail.Subject = ConstClass._COMP_NM + " 청구서(" + dateEdit_SDATE.Text + " ~ " + dateEdit_FDATE.Text + ")";
mail.Sender = new MimeMailAddress(m_EMAIL, getEncodeDisplayName(ConstClass._COMP_NM));
mail.From = new MimeMailAddress(m_EMAIL, getEncodeDisplayName(ConstClass._COMP_NM));
mail.To.Add(email);
string fileName = ConstClass._TEMP_PATH + ConstClass._TEMP_FILE_HEADER + DateTime.Now.ToString("yyyyMMdd_HHmmssfff") + ".pdf";
report.ExportToPdf(fileName);
Application.DoEvents();
MimeAttachment attch = new MimeAttachment(fileName);
Application.DoEvents();
mail.Attachments.Add(attch);
Application.DoEvents();
SmtpSocketClient smtp = new SmtpSocketClient();
smtp.Host = m_SERVER_ADDR;
smtp.Port = m_SERVER_PORT;
smtp.SslType = SslMode.Ssl;
smtp.User = m_USER_ID;
smtp.Password = m_USER_PWD;
smtp.AuthenticationMode = AuthenticationType.Base64;
smtp.SendCompleted += (sendere, ee) =>
{
//if (File.Exists(fileName))
//{
// File.Delete(fileName);
//}
if (ee.Error != null)
{
throw new Exception(ee.Error.Message);
}
else
{
sendRow["MAIL_YN"] = "Y";
if (!UtilClass.isNull(hp) && hp.StartsWith("01"))
{
sendRow["SMS_YN"] = "Y";
string msg = ConstClass._COMP_NM + "에서 기간 : " + dateEdit_SDATE.Text + " ~ " + dateEdit_FDATE.Text + " 동안 발생한 거래분에 대해 청구서를 발송하였습니다.";
//ClientClass.sendSMS(hp, msg);
}
}
};
smtp.SendMail(mail);
}
catch (Exception ex)
{
result.isError = true;
result.ResultStr = ex.Message;
}
return result;
}
private ResultClass sendFax(string userID, string bizNo, BillManagerReport report,
string fromFax, string toFax, string toName, string hp, DataRow sendRow)
{
ResultClass result = new ResultClass();
try
{
string requestNum = "HANMI" + DateTime.Now.ToString("yyyyMMddHHmmssfff");
string fileName = ConstClass._TEMP_PATH + ConstClass._TEMP_FILE_HEADER + DateTime.Now.ToString("yyyyMMdd_HHmmssfff") + ".pdf";
report.ExportToPdf(fileName);
Application.DoEvents();
DateTime? reserveDT = null;
toName = toName + " 귀하";
m_FaxService.SendFAX(bizNo.Replace("-", "").Replace(" ", ""), fromFax, toFax, toName,
fileName, reserveDT, userID, false, "청구서", requestNum);
sendRow["FAX_YN"] = "Y";
if (!UtilClass.isNull(hp) && hp.StartsWith("01"))
{
sendRow["SMS_YN"] = "Y";
string msg = ConstClass._COMP_NM + "에서 기간 : " + dateEdit_SDATE.Text + " ~ " + dateEdit_FDATE.Text + " 동안 발생한 거래분에 대해 청구서를 발송하였습니다.";
//ClientClass.sendSMS(hp, msg);
}
//Application.DoEvents();
//if (File.Exists(fileName))
//{
// File.Delete(fileName);
//}
}
catch (Exception ex)
{
result.isError = true;
result.ResultStr = ex.Message;
}
return result;
}
private string getEncodeDisplayName(string str)
{
var fromEncoding = Encoding.UTF8;
var encodingName = fromEncoding.BodyName.ToLower();
return "=?" + encodingName + "?B?" + TransferEncoder.ToBase64(fromEncoding.GetBytes(str)) + "?=";
}
}
}