메일 전송 폼 추가완료

This commit is contained in:
Chikyun
2019-03-03 22:17:19 +09:00
parent 78456a7462
commit 671491636f
14 changed files with 2301 additions and 144 deletions

View File

@@ -7,6 +7,9 @@ using System.Linq;
using System.Text;
using System.Windows.Forms;
using util = FCOMMON.Util;
using NetOffice;
using Outlook = NetOffice.OutlookApi;
using NetOffice.OutlookApi.Enums;
namespace FPJ0000
{
@@ -22,24 +25,134 @@ namespace FPJ0000
//이 목록에 해당하는 프로젝트 정보를 저장한다.
dsPRJTableAdapters.ProjectsTableAdapter taproj = new dsPRJTableAdapters.ProjectsTableAdapter();
foreach(var pidx in idxlist_)
dsPRJTableAdapters.ProjectsMailListTableAdapter tamail = new dsPRJTableAdapters.ProjectsMailListTableAdapter();
dsMailTableAdapters.MailFormTableAdapter taform = new dsMailTableAdapters.MailFormTableAdapter();
dsPRJTableAdapters.ProjectsHistoryTableAdapter taHist = new dsPRJTableAdapters.ProjectsHistoryTableAdapter();
var mailformDt = taform.GetData("PM");
dsMail.MailFormRow drForm = null;
if (mailformDt != null && mailformDt.Rows.Count > 0) drForm = mailformDt.Rows[0] as dsMail.MailFormRow;
foreach (var pidx in idxlist_)
{
if (pidx < 0) continue;
var prjdt = taproj.GetbyIDX(pidx);
string updateHistory = "<ul>";
var dtHIst = taHist.GetbySendMail(pidx);
if (dtHIst != null)
{
foreach (dsPRJ.ProjectsHistoryRow drhist in dtHIst.Rows)
{
if (drhist.remark.Trim() == "") continue;
updateHistory += "<li>drhist.remark</li>";
}
}
updateHistory += "</ul>";
var newdr = this.dsMail.MailData.NewMailDataRow();
newdr.wuid = FCOMMON.info.Login.no;
newdr.wdate = DateTime.Now;
newdr.cate = "PM";
newdr.pdate = DateTime.Now.ToShortDateString();
if(prjdt != null && prjdt.Rows.Count > 0)
dsPRJ.ProjectsRow prjdr = null;
//양식의 제목과 본문을 업데이트
if (drForm != null)
{
var prjdr = prjdt.Rows[0] as dsPRJ.ProjectsRow;
newdr.subject = drForm.subject;
newdr.body = drForm.body;
}
if (prjdt != null && prjdt.Rows.Count > 0)
{
prjdr = prjdt.Rows[0] as dsPRJ.ProjectsRow;
newdr.prj_ddate = prjdr.ddate;
newdr.prj_name = prjdr.name;
newdr.prj_status = prjdr.status;
newdr.subject = string.Format(newdr.subject, prjdr.name, prjdr.status, prjdr.ddate, updateHistory);
newdr.body = string.Format(newdr.body, prjdr.name, prjdr.status, prjdr.ddate, updateHistory);
}
//메일전송대상 정보를 불러온다.
var maillist = tamail.GetData(pidx);
if (maillist != null && maillist.Rows.Count > 0)
{
//양식의 tolist/cc/bcc 추가
if (drForm != null)
{
var buffer = drForm.tolist.Split(';');
foreach (var address in buffer)
{
if (address.Trim() == "") continue;
if (newdr.tolist.Contains(address) == false)
{
if (newdr.tolist != "") newdr.tolist += ";";
newdr.tolist += address;
}
}
buffer = drForm.cc.Split(';');
foreach (var address in buffer)
{
if (address.Trim() == "") continue;
if (newdr.cc.Contains(address) == false)
{
if (newdr.cc != "") newdr.cc += ";";
newdr.cc += address;
}
}
buffer = drForm.bcc.Split(';');
foreach (var address in buffer)
{
if (address.Trim() == "") continue;
if (newdr.bcc.Contains(address) == false)
{
if (newdr.bcc != "") newdr.bcc += ";";
newdr.bcc += address;
}
}
}
foreach (dsPRJ.ProjectsMailListRow drmail in maillist.Rows)
{
if (drmail.div == "TO")
{
if (newdr.tolist.Contains(drmail.address) == false)
{
if (newdr.tolist != "") newdr.tolist += ";";
newdr.tolist += drmail.address;
}
}
else if (drmail.div == "CC")
{
if (newdr.cc.Contains(drmail.address) == false)
{
if (newdr.cc != "") newdr.cc += ";";
newdr.cc += drmail.address;
}
}
else if (drmail.div == "BCC")
{
if (newdr.bcc.Contains(drmail.address) == false)
{
if (newdr.bcc != "") newdr.bcc += ";";
newdr.bcc += drmail.address;
}
}
}
}
//메일전송 폼을 불러온다.
this.dsMail.MailData.AddMailDataRow(newdr);
}
}
@@ -50,12 +163,12 @@ namespace FPJ0000
this.FormClosed += fPartList_FormClosed;
this.KeyPreview = true;
this.KeyDown += fPartList_KeyDown;
//RefreshData();
FPUtil.ColSizeLoad(ref this.fpSpread1, fn_fpcolsize);
}
void fPartList_KeyDown(object sender, KeyEventArgs e)
{
@@ -67,8 +180,8 @@ namespace FPJ0000
}
void RefreshData()
{
//if(dsPRJ.HasChanges())
@@ -77,9 +190,10 @@ namespace FPJ0000
// if (dlg != System.Windows.Forms.DialogResult.Yes) return;
//}
try {
try
{
this.ta.Fill(this.dsMail.MailData);
}
catch (Exception ex)
{
@@ -94,14 +208,14 @@ namespace FPJ0000
{
SaveFileDialog sd = new SaveFileDialog();
sd.Filter = "excel|*.xls";
if(sd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
if (sd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
fpSpread1.SaveExcel(sd.FileName,
FarPoint.Excel.ExcelSaveFlags.SaveAsViewed
FarPoint.Excel.ExcelSaveFlags.SaveAsViewed
| FarPoint.Excel.ExcelSaveFlags.NoFormulas
| FarPoint.Excel.ExcelSaveFlags.SaveCustomColumnHeaders );
| FarPoint.Excel.ExcelSaveFlags.SaveCustomColumnHeaders);
}
//dv1.ExportData("partlist.csv");
}
@@ -150,13 +264,36 @@ namespace FPJ0000
{
this.Validate();
this.bs.EndEdit();
//아웃룩에서 데이터를 표시한다.
var drv = this.bs.Current as DataRowView;
if (drv == null) return;
var dr = drv.Row as dsMail.MailDataRow;
Outlook.Application outlookApplication = new Outlook.Application();
var newMail = outlookApplication.CreateItem(OlItemType.olMailItem) as Outlook.MailItem;
newMail.Display();
newMail.Subject = dr.subject; // this.tbSubject.Text.Trim(); // dr.title;
newMail.To = dr.tolist; // to;
newMail.CC = dr.cc;// tbCC.Text.Trim();
newMail.BCC = dr.bcc; // tbBCC.Text.Trim();
// newMail.BodyFormat = OlBodyFormat.olFormatHTML;
newMail.HTMLBody = dr.body; //
newMail.Send();
FCOMMON.Util.MsgI("메일이 전송되었습니다.\n\n전송된 메일은 아웃룩의 보낸편지함 혹은 그룹웨어의 보낸편지함에서 확인할 수 있습니다.");
try
{
this.ta.Update(this.dsMail.MailData);
this.ta.Update(dr);
dr.AcceptChanges();
}
catch(Exception ex)
catch (Exception ex)
{
FCOMMON.Util.MsgE("Save error\n\n" +ex.Message);
FCOMMON.Util.MsgE("전송 오류\n\n" + ex.Message);
}
}
@@ -164,5 +301,81 @@ namespace FPJ0000
{
}
private void toolStripButton3_Click(object sender, EventArgs e)
{
string msg = bs.Count.ToString() + "건의 메일을 일괄 전송 하시겠습니까?\n" +
"전송은 아웃룩을 통해서 진행되므로 아웃룩이 보낼수 있는 상태인지 확인하시기 바랍니다";
var dlg = FCOMMON.Util.MsgQ(msg);
if (dlg != System.Windows.Forms.DialogResult.Yes) return;
//프로그레스바
this.prb1.Maximum = this.bs.Count;
this.prb1.Minimum = 0;
this.prb1.Value = 0;
Outlook.Application outlookApplication = new Outlook.Application();
int cntSend = 0;
foreach (dsMail.MailDataRow dr in this.dsMail.MailData.Rows)
{
if (prb1.Value < prb1.Maximum) prb1.Value += 1;
if (dr.tolist.Trim() == "")
{
FCOMMON.Util.MsgE("받을 주소가 없어서 진행하지 않습니다\n" + dr.subject);
continue;
}
try
{
var newMail = outlookApplication.CreateItem(OlItemType.olMailItem) as Outlook.MailItem;
newMail.Display();
newMail.Subject = dr.subject;
newMail.To = dr.tolist;// to;
newMail.CC = dr.cc;// tbCC.Text.Trim();
newMail.BCC = dr.bcc;// tbBCC.Text.Trim();
// newMail.BodyFormat = OlBodyFormat.olFormatHTML;
newMail.HTMLBody = dr.body; //
newMail.Send();
cntSend += 1;
dr.EndEdit();
ta.Update(dr);
dr.AcceptChanges();
}
catch (Exception ex)
{
FCOMMON.Util.MsgE("메일 전송 오류\n\n"+ex.Message);
}
}
FCOMMON.Util.MsgI(cntSend.ToString() + " 건의 메일이 전송되었습니다.\n\n전송된 메일은 아웃룩의 보낸편지함 혹은 그룹웨어의 보낸편지함에서 확인할 수 있습니다.");
}
private void toolStripButton2_Click(object sender, EventArgs e)
{
//아웃룩에서 데이터를 표시한다.
var drv = this.bs.Current as DataRowView;
if (drv == null) return;
var dr = drv.Row as dsMail.MailDataRow;
try
{
Outlook.Application outlookApplication = new Outlook.Application();
var newMail = outlookApplication.CreateItem(OlItemType.olMailItem) as Outlook.MailItem;
newMail.Display();
newMail.Subject = dr.subject; // this.tbSubject.Text.Trim(); // dr.title;
newMail.To = dr.tolist; // to;
newMail.CC = dr.cc;// tbCC.Text.Trim();
newMail.BCC = dr.bcc; // tbBCC.Text.Trim();
// newMail.BodyFormat = OlBodyFormat.olFormatHTML;
newMail.HTMLBody = dr.body; //
}
catch(Exception ex)
{
util.MsgE("전송실패\n\n" + ex.Message + "\n\n" +
"아웃룩의 설정이 정상인지 확인하세요");
}
}
}
}