sap 클립보드 기능 추가
This commit is contained in:
@@ -13,56 +13,266 @@ namespace Project
|
||||
{
|
||||
DateTime redisTryTime = DateTime.Parse("1982-11-23");
|
||||
Boolean bBW = true;
|
||||
|
||||
string getdbdata(object tdata)
|
||||
{
|
||||
if (tdata == null) return string.Empty;
|
||||
return tdata.ToString();
|
||||
}
|
||||
string getMaillist(object orgo)
|
||||
{
|
||||
var org = string.Empty;
|
||||
if (orgo != null) org = orgo.ToString();
|
||||
org = org.Replace(";", ",").Replace(":", ",");
|
||||
string list_to = "";
|
||||
foreach (var item in org.Split(','))
|
||||
{
|
||||
if (item.Trim() != "")
|
||||
{
|
||||
var atindex = item.IndexOf("@");
|
||||
if (atindex != -1)
|
||||
{
|
||||
var dotindex = item.IndexOf(".", atindex + 1);
|
||||
if (dotindex != -1)
|
||||
{
|
||||
//정상이므로 추가한다.
|
||||
if (list_to != "") list_to += ",";
|
||||
list_to += item.Trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return list_to;
|
||||
}
|
||||
|
||||
DateTime ChkAutoDate = DateTime.Now;
|
||||
|
||||
void MakeAutoMail()
|
||||
{
|
||||
var ts = DateTime.Now - ChkAutoDate;
|
||||
if (ts.TotalMinutes < 1) return; //10분마다 자동 생성 데이터를 처리한다
|
||||
Console.WriteLine("Check Auto Make Mail");
|
||||
|
||||
var taData = new dsMSSQLTableAdapters.MailDataTableAdapter();
|
||||
var taList = new dsMSSQLTableAdapters.MailAutoTableAdapter();
|
||||
var dtList = taList.GetByAutoSend();
|
||||
var dtInsert = new dsMSSQL.MailDataDataTable();
|
||||
|
||||
//대상
|
||||
Console.WriteLine("Make Auto Send Mail Data (" + dtList.Rows.Count.ToString() + ")");
|
||||
|
||||
foreach (dsMSSQL.MailAutoRow dr in dtList)
|
||||
{
|
||||
//시간정보가 없는 애들은 처리 하지 않음
|
||||
if (dr.stime.IndexOf(":") == -1) continue;
|
||||
if (dr.sday == null || dr.sday.Length < 2) continue;
|
||||
|
||||
//발신시간을 넘어야 한다
|
||||
var curTime = DateTime.Now.ToString("HH:mm");
|
||||
if (string.Compare(curTime, dr.stime) < 0) continue; //지정된 시간 이전이면 생성 안한다
|
||||
|
||||
//자동생성 구분용 카테고리
|
||||
var cate = string.Format("{0},{1}", dr.sday[0], dr.sday[1]);
|
||||
|
||||
//동륵일
|
||||
var pdate = DateTime.Now.ToString("yyyy-MM-dd");
|
||||
|
||||
//같은날, 같은 atime aidx pdate 의 같이 있으면 이미 생성된것이므로 추가하지 않는다
|
||||
var existData = taData.FindAutoData(dr.idx, dr.stime, pdate, cate);
|
||||
var PreMakeCount = (int)(existData);
|
||||
if (PreMakeCount > 0) continue;
|
||||
|
||||
//전송간격과 대상
|
||||
if (dr.sday[0] == 1)
|
||||
{
|
||||
//week
|
||||
var bitString = Convert.ToString(dr.sday[1], 2).PadLeft(8, '0').ToArray();
|
||||
var weeknum = (int)(DateTime.Now.DayOfWeek);
|
||||
if (bitString[weeknum + 1] == '0') continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
//month
|
||||
if (dr.sday[1] != DateTime.Now.Day) continue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//같은날, 같은 atime aidx pdate 의 같이 있으면 이미 생성된것이므로 추가하지 않는다
|
||||
//생성해야할 자료라면 만들어 준다
|
||||
var newdr = dtInsert.NewMailDataRow();
|
||||
newdr.pdate = pdate;// DateTime.Now.ToString("yyyy-MM-dd");
|
||||
newdr.gcode = dr.gcode;
|
||||
newdr.fromlist = dr.fromlist;
|
||||
newdr.tolist = dr.tolist;
|
||||
newdr.bcc = dr.bcc;
|
||||
newdr.cate = cate;// string.Format("{0},{1}", dr.sday[0], dr.sday[1]); //cate에 해당 자료를 기록한다.
|
||||
newdr.cc = dr.cc;
|
||||
newdr.subject = dr.subject;
|
||||
newdr.body = dr.body;
|
||||
newdr.aidx = dr.idx;
|
||||
newdr.atime = dr.stime;
|
||||
newdr.wuid = "DEV";
|
||||
newdr.wdate = DateTime.Now;
|
||||
dtInsert.AddMailDataRow(newdr);
|
||||
try
|
||||
{
|
||||
taData.Update(newdr);
|
||||
Console.WriteLine("auto make : " + newdr.tolist + ",subject=" + newdr.subject);
|
||||
}
|
||||
catch (Exception eX)
|
||||
{
|
||||
Console.WriteLine("auto make error : " + eX.Message);
|
||||
}
|
||||
}
|
||||
ChkAutoDate = DateTime.Now;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void bw_DoWork(object sender, DoWorkEventArgs e)
|
||||
{
|
||||
while (bBW)
|
||||
{
|
||||
//if (redisConnection == null)
|
||||
//{
|
||||
// var ts = DateTime.Now - redisTryTime;
|
||||
// if (ts.TotalMinutes > 5)
|
||||
// {
|
||||
// Console.WriteLine("redis conn : 10.131.36.57:6379");
|
||||
// try
|
||||
// {
|
||||
// redisConnection = StackExchange.Redis.ConnectionMultiplexer.Connect("10.131.36.57:6379");
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
ServerUtil.IsMailserver = ServerUtil.SendmailSet();
|
||||
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// if (redisConnection.IsConnected)
|
||||
// {
|
||||
// if (this.db == null)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// Console.WriteLine("redis connected setting db");
|
||||
// this.db = redisConnection.GetDatabase();
|
||||
// var getStr = this.db.StringGet("test");
|
||||
// Console.WriteLine(getStr);
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// Pub.log.AddE("REDIS " + ex.Message);
|
||||
// }
|
||||
if (ServerUtil.IsMailserver)
|
||||
{
|
||||
//메일서버역할이 있다.
|
||||
try
|
||||
{
|
||||
var cn = new System.Data.SqlClient.SqlConnection(Properties.Settings.Default.gwcs);
|
||||
var cmd = new System.Data.SqlClient.SqlCommand("", cn);
|
||||
cn.Open();
|
||||
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Console.WriteLine("resetting redis connection");
|
||||
// redisConnection.Dispose();
|
||||
// redisConnection = null;
|
||||
// }
|
||||
//}
|
||||
//1개의데이터 가져오기
|
||||
cmd.CommandText = "SELECT top 1 * FROM MailData WHERE ISNULL(SendOK, 0) = 0 order by wdate";
|
||||
var dar = cmd.ExecuteReader();
|
||||
|
||||
var list_from = string.Empty;// getMaillist(dar["fromlist"]);
|
||||
var list_to = string.Empty;// getMaillist(dar["tolist"]);
|
||||
var list_bcc = string.Empty;// getMaillist(dar["bcc"]);
|
||||
var list_cc = string.Empty;//getMaillist(dar["cc"]);
|
||||
var subject = string.Empty;// getdbdata(dar["subject"]).Trim();
|
||||
var body = string.Empty;//getdbdata(dar["body"]).Trim();
|
||||
var idx = -1;
|
||||
|
||||
|
||||
System.Threading.Thread.Sleep(5000);
|
||||
while (dar.Read())
|
||||
{
|
||||
list_from = getMaillist(dar["fromlist"]);
|
||||
list_to = getMaillist(dar["tolist"]);
|
||||
list_bcc = getMaillist(dar["bcc"]);
|
||||
list_cc = getMaillist(dar["cc"]);
|
||||
|
||||
subject = getdbdata(dar["subject"]).Trim();
|
||||
body = getdbdata(dar["body"]).Trim();
|
||||
idx = (int)dar["idx"];
|
||||
}
|
||||
dar.Close();
|
||||
|
||||
string sendMsg = "";
|
||||
if (list_from == "")
|
||||
{
|
||||
sendMsg = ("보내는 주소가 없습니다");
|
||||
}
|
||||
else if (subject.Trim() == "")
|
||||
{
|
||||
sendMsg = ("메일 제목이 없습니다");
|
||||
}
|
||||
else if (body.Trim() == "")
|
||||
{
|
||||
sendMsg = ("본문이 없습니다");
|
||||
}
|
||||
else if (list_to == "")
|
||||
{
|
||||
sendMsg = ("받는 주소가 없습니다");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
//var body = getdbdata(dar["body"]);
|
||||
body +=
|
||||
"<p>" +
|
||||
"<br />이 메일은 EET 프로그램에서 자동 발신 되었습니다." +
|
||||
"<br />메일이 잘못 전송 되었다면 [<a href='chikyun.kim@amkor.co.kr'>chikyun.kim@amkor.co.kr</a>] 로 문의 주시기 바랍니다" +
|
||||
"</p>";
|
||||
|
||||
//전송을 해야 함
|
||||
var mc = new System.Net.Mail.SmtpClient("10.101.10.6");
|
||||
var msg = new System.Net.Mail.MailMessage
|
||||
(list_from,
|
||||
list_to,
|
||||
subject,
|
||||
body);
|
||||
|
||||
if (list_bcc != "") msg.Bcc.Add(list_bcc);
|
||||
if (list_cc != "") msg.CC.Add(list_cc);
|
||||
msg.IsBodyHtml = true;
|
||||
|
||||
bool msgupdate = false;
|
||||
try
|
||||
{
|
||||
sendMsg = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
cmd.CommandText = "UPDATE MailData SET SendOK = 1, SendMsg = @msg WHERE(idx = @idx) and isnull(sendok,0) = 0";
|
||||
cmd.Parameters.Clear();
|
||||
cmd.Parameters.Add("msg", System.Data.SqlDbType.VarChar).Value = sendMsg;
|
||||
cmd.Parameters.Add("idx", System.Data.SqlDbType.Int).Value = idx;
|
||||
//Console.WriteLine(string.Format("Send Complete index={0},Msg={1}", dar["idx"], sendMsg));
|
||||
//ta.UpdateSendOK(sendMsg, dr.idx);
|
||||
var ucnt = cmd.ExecuteNonQuery();
|
||||
if (ucnt == 1)
|
||||
{
|
||||
mc.Send(msg);
|
||||
Console.WriteLine("send mail to" + list_to + ",subject=" + getdbdata(subject));
|
||||
}
|
||||
}
|
||||
catch (Exception eX)
|
||||
{
|
||||
sendMsg = eX.Message;
|
||||
msgupdate = true;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (msgupdate)
|
||||
{
|
||||
cmd.CommandText = "UPDATE MailData SET SendMsg = @msg WHERE idx = @idx ";
|
||||
cmd.Parameters.Clear();
|
||||
cmd.Parameters.Add("idx", System.Data.SqlDbType.Int).Value = idx;
|
||||
var ucnt = cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
catch (Exception eX)
|
||||
{
|
||||
//sendMsg = eX.Message;
|
||||
//msgupdate = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
cmd.Dispose();
|
||||
cn.Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
System.Threading.Thread.Sleep(1500);
|
||||
try
|
||||
{
|
||||
MakeAutoMail();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
System.Threading.Thread.Sleep(500);
|
||||
}
|
||||
else System.Threading.Thread.Sleep(3000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user