public bool Start(string schedule_code)
        {
            DataTable table = UpdateAddress();
            if(table.Rows.Count>0)
            {
                string mailBody = GetHtmlByDataTable(table);
                MailModel mailModel = new MailModel();
                mailModel.MysqlConnectionString = mySqlConnectionString;
                string GroupCode = string.Empty;
                string MailTitle = string.Empty;
                //獲取該排程參數
                List<ScheduleConfigQuery> store_config = new List<ScheduleConfigQuery>();
                ScheduleConfigQuery query_config = new ScheduleConfigQuery();
                query_config.schedule_code = schedule_code;
                ScheduleServiceMgr _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString);
                store_config = _secheduleServiceMgr.GetScheduleConfig(query_config);
                foreach (ScheduleConfigQuery item in store_config)
                {
                    if (item.parameterCode.Equals("MailFromAddress"))
                    {
                        mailModel.MailFromAddress = item.value;
                    }
                    else if (item.parameterCode.Equals("MailHost"))
                    {
                        mailModel.MailHost = item.value;
                    }
                    else if (item.parameterCode.Equals("MailPort"))
                    {
                        mailModel.MailPort = item.value;
                    }
                    else if (item.parameterCode.Equals("MailFromUser"))
                    {
                        mailModel.MailFromUser = item.value;
                    }
                    else if (item.parameterCode.Equals("EmailPassWord"))
                    {
                        mailModel.MailFormPwd = item.value;
                    }
                    else if (item.parameterCode.Equals("GroupCode"))
                    {
                        GroupCode = item.value;
                    }
                    else if (item.parameterCode.Equals("MailTitle"))
                    {
                        MailTitle = item.value;
                    }
                }

                MailHelper mail = new MailHelper(mailModel);
                return mail.SendToGroup(GroupCode, MailTitle, mailBody, false, true);
            }
            return true;          
        }
        public bool Start(string schedule_code)
        {
            bool result = false;
            try
            {
                if (string.IsNullOrEmpty(schedule_code))
                {
                    return result;
                }
                string GroupCode = string.Empty;
                string MailTitle = string.Empty;

                StringBuilder strbody = new StringBuilder();
                MailModel mailModel = new MailModel();
                mailModel.MysqlConnectionString = mySqlConnectionString;
                //獲取該排程參數
                List<ScheduleConfigQuery> store_config = new List<ScheduleConfigQuery>();
                ScheduleConfigQuery query_config = new ScheduleConfigQuery();
                query_config.schedule_code = schedule_code;
                _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString);
                store_config = _secheduleServiceMgr.GetScheduleConfig(query_config);
                #region FTP參數賦值
                foreach (ScheduleConfigQuery item in store_config)
                {
                    if (item.parameterCode.Equals("MailFromAddress"))
                    {
                        mailModel.MailFromAddress = item.value;
                    }
                    else if (item.parameterCode.Equals("MailHost"))
                    {
                        mailModel.MailHost = item.value;
                    }
                    else if (item.parameterCode.Equals("MailPort"))
                    {
                        mailModel.MailPort = item.value;
                    }
                    else if (item.parameterCode.Equals("MailFromUser"))
                    {
                        mailModel.MailFromUser = item.value;
                    }
                    else if (item.parameterCode.Equals("EmailPassWord"))
                    {
                        mailModel.MailFormPwd = item.value;
                    }
                    else if (item.parameterCode.Equals("GroupCode"))
                    {
                        GroupCode = item.value;
                    }
                    else if (item.parameterCode.Equals("MailTitle"))
                    {
                        MailTitle = item.value;
                    }
                    else if (item.parameterCode.Equals("MailTitle"))
                    {
                        MailTitle = item.value;
                    }
                
                }
                #endregion

                MailHelper mail = new MailHelper(mailModel);

                OrderMasterQuery query = new OrderMasterQuery();
                query.order_date_pay_endTime = DateTime.Now;
                query.order_date_pay_startTime = query.order_date_pay_endTime.AddHours(-1);
                StringBuilder sbMailBody = new StringBuilder();
                try
                {
                      bool isSHow = false;
                      string html =GetBigAmountMailBody(query,out isSHow);
                      if (isSHow)
                      {
                          sbMailBody.AppendLine(html);
                      }
                }
                catch (Exception ex)
                {
                    throw new Exception("CheckOrderAmountMgr-->GetBigAmountMailBody-->" + "大金額訂單排程:" + ex.Message);
                }
                try
                {
                     bool isSHow = false;
                     string html = GetBigOrderNumbersMailBody(query, out isSHow);
                     if (isSHow)
                     {
                         sbMailBody.AppendLine(html);
                     }
                }
                catch (Exception ex)
                {
                    throw new Exception("CheckOrderAmountMgr-->GetBigOrderNumbersMailBody-->"+"一小時多次付款客戶異常訂單付款通知:"+ ex.Message);
                }
                try
                {
                    bool isSHow = false;
                    string html = FirstBuyEmail(query, out isSHow);
                    if (isSHow)
                    {
                        sbMailBody.AppendLine(html);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("CheckOrderAmountMgr-->OtherTWPay-->" + "首購超過5000訂單付款檢查:" + ex.Message);
                }
                try
                {
                    bool isSHow = false;
                    string html = OtherTWPay(query, out isSHow);
                    if (isSHow)
                    {
                        sbMailBody.AppendLine(html);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("CheckOrderAmountMgr-->OtherTWPay-->" + "異地信用卡付款付款訂單通知:" + ex.Message);
                }

                if (!String.IsNullOrEmpty(sbMailBody.ToString()))
                {
                    mail.SendToGroup(GroupCode, MailTitle, sbMailBody.ToString(), false, true);//發送郵件給群組
                }
                result= true;
            }
            catch (Exception ex)
            {
                throw new Exception("CheckOrderAmount-->Start-->" + ex.Message);
            }
            return result;
        }
        public bool Start(string schedule_code)
        {
            if (string.IsNullOrEmpty(schedule_code))
            {
                return false;
            }
            MailModel mailModel = new MailModel();
            mailModel.MysqlConnectionString = mySqlConnectionString;

            string GroupCode = string.Empty;
            string MailTitle = string.Empty;
            string MailBody = string.Empty;
            bool IsSeparate = false;
            bool IsDisplyName = true;
            string requestUrl = string.Empty;
            try
            {               
                //獲取該排程參數
                List<ScheduleConfigQuery> store_config = new List<ScheduleConfigQuery>();
                ScheduleConfigQuery query_config = new ScheduleConfigQuery();
                query_config.schedule_code = schedule_code;
                _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString);
                store_config = _secheduleServiceMgr.GetScheduleConfig(query_config);
                #region mailhelp賦值
                foreach (ScheduleConfigQuery item in store_config)
                {
                    if (item.parameterCode.Equals("MailFromAddress"))
                    {
                        mailModel.MailFromAddress = item.value;
                    }
                    else if (item.parameterCode.Equals("MailHost"))
                    {
                        mailModel.MailHost = item.value;
                    }
                    else if (item.parameterCode.Equals("MailPort"))
                    {
                        mailModel.MailPort = item.value;
                    }
                    else if (item.parameterCode.Equals("MailFromUser"))
                    {
                        mailModel.MailFromUser = item.value;
                    }
                    else if (item.parameterCode.Equals("EmailPassWord"))
                    {
                        mailModel.MailFormPwd = item.value;
                    }
                    else if (item.parameterCode.Equals("GroupCode"))
                    {
                        GroupCode = item.value;
                    }
                    else if (item.parameterCode.Equals("MailTitle"))
                    {
                        MailTitle = item.value;
                    }
                    else if (item.parameterCode.Equals("MailTitle"))
                    {
                        MailTitle = item.value;
                    }
                    else if (item.parameterCode.Equals("requestUrl"))
                    {
                        requestUrl = item.value;
                    }
                    //else if (item.parameterCode.Equals("MailBody"))
                    //{
                    //    MailBody = item.value;
                    //}
                    //else if (item.parameterCode.Equals("IsSeparate"))
                    //{
                    //    if (item.value.ToString().Trim().ToLower() == "false")
                    //    {
                    //        IsSeparate = false;
                    //    }
                    //    else if (item.value.ToString().Trim().ToLower() == "true")
                    //    {
                    //        IsSeparate = true;
                    //    }
                    //}
                    //else if (item.parameterCode.Equals("IsDisplyName"))
                    //{
                    //    if (item.value.ToString().Trim().ToLower() == "false")
                    //    {
                    //        IsDisplyName = false;
                    //    }
                    //    else if (item.value.ToString().Trim().ToLower() == "true")
                    //    {
                    //        IsDisplyName = true;
                    //    }
                    //}
                }
                #endregion

                int result = 0;
                int resultmes = 0;
                
                StringBuilder str = new StringBuilder();
                StringBuilder sqlstrall = new StringBuilder();
                InvoiceWinningNumberDao invoiceWinningNumberDao = new InvoiceWinningNumberDao(mySqlConnectionString);


                #region 獲取網頁里的數據,轉化成json字符串
                string urlone = "https://www.einvoice.nat.gov.tw/PB2CAPIVAN/invapp/InvApp?version=0.2&action=QryWinningList&invTerm=";
                string urltwo = "&appID=EINV5201502271601";
                string dateone = string.Empty;
                if (DateTime.Now.Month >= 10)
                {
                    if (DateTime.Now.Month == 11)
                    {
                        dateone = (DateTime.Now.Year - 1911).ToString() + (DateTime.Now.Month - 1);
                    }
                    else
                    {
                        dateone = (DateTime.Now.Year - 1911).ToString() + DateTime.Now.Month;
                    }
                }
                else if (DateTime.Now.Month == 1)
                {
                    dateone = (DateTime.Now.AddMonths(-1).Year - 1911).ToString() + "12";
                }
                else
                {
                    if (DateTime.Now.Month % 2 == 1)
                    {
                        dateone = (DateTime.Now.Year - 1911).ToString() + "0" + (DateTime.Now.Month - 1);
                    }
                    else
                    {
                        dateone = (DateTime.Now.Year - 1911).ToString() + "0" + DateTime.Now.Month;
                    }
                }
                string url = string.Empty;
                if (requestUrl.Trim() == string.Empty)
                {
                    url = urlone + dateone + urltwo;
                }
                else
                {
                    url = requestUrl;
                }                              

                string json = GetPage(url, "utf-8");
                ResultClass rc = new ResultClass();               
                #endregion

                MailHelper mail = new MailHelper(mailModel);
                int year = 0;
                int month = 0;
                string[,] strarray = new string[,]{};
                bool isHaveInfo = false;
                try//判斷如果出錯發郵件
                {
                    rc = JsonConvert.DeserializeObject<ResultClass>(json); 
                    year = Convert.ToInt32(rc.invoYm.Substring(0, 3));
                    month = Convert.ToInt32(rc.invoYm.Substring(3, 2));


                    strarray = new string[20,2] { { "superPrizeNo", rc.superPrizeNo }, { "spcPrizeNo", rc.spcPrizeNo }, { "spcPrizeNo2", rc.spcPrizeNo2 }, 
                                                  { "spcPrizeNo3", rc.spcPrizeNo3 }, { "firstPrizeNo1", rc.firstPrizeNo1 }, { "firstPrizeNo2", rc.firstPrizeNo2 }, 
                                                  { "firstPrizeNo3", rc.firstPrizeNo3 }, { "firstPrizeNo4", rc.firstPrizeNo4 }, { "firstPrizeNo5", rc.firstPrizeNo5 },
                                                  { "firstPrizeNo6", rc.firstPrizeNo6 }, { "firstPrizeNo7", rc.firstPrizeNo7 }, { "firstPrizeNo8", rc.firstPrizeNo8 }, 
                                                  { "firstPrizeNo9", rc.firstPrizeNo9 }, { "firstPrizeNo10", rc.firstPrizeNo10 }, { "sixthPrizeNo1", rc.sixthPrizeNo1 },
                                                  { "sixthPrizeNo2", rc.sixthPrizeNo2 }, { "sixthPrizeNo3", rc.sixthPrizeNo3 }, { "sixthPrizeNo4", rc.sixthPrizeNo4 }, 
                                                  { "sixthPrizeNo5", rc.sixthPrizeNo5 }, { "sixthPrizeNo6", rc.sixthPrizeNo6 } };
                    isHaveInfo = true;
                }
                catch (Exception ex)
                {
                    MailBody = "<p/><a href=" + url + ">" + url + "</a>" + " 該鏈接中未讀到數據!";                     
                    mail.SendToGroup(GroupCode, MailTitle, MailBody + " ", IsSeparate, IsDisplyName);
                    //throw new Exception(ex.Message);
                }
                if (isHaveInfo)//如果從鏈接中讀到數據
                {
                    for (int i = 0; i < strarray.GetLength(0); i++)
                    {
                        sqlstrall.AppendFormat(invoiceWinningNumberDao.ReturnInsertSql(year, month, strarray[i, 0].ToString(), strarray[i, 1].ToString()));
                    }
                    if (!string.IsNullOrEmpty(sqlstrall.ToString()))
                    {
                        result = invoiceWinningNumberDao.ResultOfExeInsertSql(sqlstrall.ToString());
                    }
                    else
                    {
                        resultmes = 1;//設置其大於0
                    }
                    if (result > 0)
                    {
                        MailBody = "<p/>執行成功";
                        mail.SendToGroup(GroupCode, MailTitle, MailBody + " ", IsSeparate, IsDisplyName);
                    }
                    else
                    {
                        if (resultmes > 0)
                        {
                            MailBody = "<p/>數據都已經存在";
                            mail.SendToGroup(GroupCode, MailTitle, MailBody + " ", IsSeparate, IsDisplyName);
                        }                       
                    }
                }             
            }
            catch (Exception ex)
            {
                MailHelper mail = new MailHelper(mailModel);
                MailBody = "<p/>執行失敗";
                mail.SendToGroup(GroupCode, MailTitle, MailBody + " ", IsSeparate, IsDisplyName);  
                throw new Exception("WinningInvoiceSynchronismMgr-->Start-->" + ex.Message);
            }
            return true;
        }
        public bool Start(string schedule_code)
        {
            if (string.IsNullOrEmpty(schedule_code))
            {
                return false;
            }
            PromotionsAmountGiftDao giftDao = new PromotionsAmountGiftDao(mySqlConnectionString);
            try
            {
                DataTable dtProd = giftDao.GetProdStock();
                StringBuilder str = new StringBuilder();
                if (dtProd.Rows.Count > 0)
                {
                    str.Append("<style>.wid100{width:100px;text-align: right;} td{padding:2px;}</style>");
                    str.AppendFormat("當前贈品庫存狀態");
                    str.Append("<table  cellspacing='1' cellpadding='3' border='1' style='border-collapse: collapse'>");
                    str.AppendFormat("<tr style='text-align: center; background-color: #f4faff; color: #0076c8; font-weight: bold;'><th>活動編號</th><th  style='background-color: #db7093;'>活動名稱</th><th  style='background-color: #EEEE00;' >商品編號</th><th style='background-color: #b4eeb4;' >商品細項編號</th><th style='background-color:#AEEEEE'>庫存數量</th></tr>");


                    foreach (DataRow row in dtProd.Rows)
                    {
                        str.AppendFormat("<tr><td style='width:100px;text-align: center;'>{0}</td><td>{1}</td><td class='wid100'>{2}</td><td class='wid100'>{3}</td><td class='wid100'>{4}</td></tr>", row["id"], row["event_name"], row["product_id"], row["item_id"], GetString(row["kucun"].ToString()));
                    }

                    str.AppendFormat("</table>");
                }
                //else
                //{
                //    str.Append("<span style='color:red;'><b>沒有適合條件的數據<b></span>");
                //}

                List<ScheduleConfigQuery> store_config = new List<ScheduleConfigQuery>();
                ScheduleConfigQuery query_config = new ScheduleConfigQuery();
                query_config.schedule_code = schedule_code;
                _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString);
                store_config = _secheduleServiceMgr.GetScheduleConfig(query_config);
                string GroupCode = string.Empty;
                string EmailTile = string.Empty;
                MailModel mailModel = new MailModel();
                mailModel.MysqlConnectionString = mySqlConnectionString;
                foreach (ScheduleConfigQuery item in store_config)
                {
                    if (item.parameterCode.Equals("MailFromAddress"))
                    {
                        mailModel.MailFromAddress = item.value;
                    }
                    else if (item.parameterCode.Equals("MailHost"))
                    {
                        mailModel.MailHost = item.value;
                    }
                    else if (item.parameterCode.Equals("MailPort"))
                    {
                        mailModel.MailPort = item.value;
                    }
                    else if (item.parameterCode.Equals("MailFromUser"))
                    {
                        mailModel.MailFromUser = item.value;
                    }
                    else if (item.parameterCode.Equals("EmailPassWord"))
                    {
                        mailModel.MailFormPwd = item.value;
                    }
                    else if (item.parameterCode.Equals("GroupCode"))
                    {
                        GroupCode = item.value;
                    }
                    else if (item.parameterCode.Equals("MailTitle"))
                    {
                        EmailTile = item.value;
                    }
                }
                MailHelper mHelper = new MailHelper(mailModel);
                if (str.ToString().Length > 0)
                {
                    if (mHelper.SendToGroup(GroupCode, EmailTile, str.ToString()+" ", false, true))
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                return true; 
            }
            catch (Exception ex)
            {
                throw new Exception("PromotionsAmountGiftMgr-->Start-->" + ex.Message);
            }
        }
        public bool Start(string schedule_code)
        {
            if (string.IsNullOrEmpty(schedule_code))
            {
                return false;
            }
            try
            {
                MailModel mailModel = new MailModel();
                mailModel.MysqlConnectionString = mySqlConnectionString;

                string GroupCode = string.Empty;
                string MailTitle = string.Empty;
                string MailBody = string.Empty;
                bool IsSeparate = true;
                bool IsDisplyName = true;

                //獲取該排程參數
                List<ScheduleConfigQuery> store_config = new List<ScheduleConfigQuery>();
                ScheduleConfigQuery query_config = new ScheduleConfigQuery();
                query_config.schedule_code = schedule_code;
                _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString);
                store_config = _secheduleServiceMgr.GetScheduleConfig(query_config);

                #region mailhelp賦值
                foreach (ScheduleConfigQuery item in store_config)
                {
                    if (item.parameterCode.Equals("MailFromAddress"))
                    {
                        mailModel.MailFromAddress = item.value;
                    }
                    else if (item.parameterCode.Equals("MailHost"))
                    {
                        mailModel.MailHost = item.value;
                    }
                    else if (item.parameterCode.Equals("MailPort"))
                    {
                        mailModel.MailPort = item.value;
                    }
                    else if (item.parameterCode.Equals("MailFromUser"))
                    {
                        mailModel.MailFromUser = item.value;
                    }
                    else if (item.parameterCode.Equals("EmailPassWord"))
                    {
                        mailModel.MailFormPwd = item.value;
                    }
                    else if (item.parameterCode.Equals("GroupCode"))
                    {
                        GroupCode = item.value;
                    }
                    else if (item.parameterCode.Equals("MailTitle"))
                    {
                        MailTitle = item.value;
                    }                    
                    //else if (item.parameterCode.Equals("MailBody"))
                    //{
                    //    MailBody = item.value;
                    //}
                    //else if (item.parameterCode.Equals("IsSeparate"))
                    //{
                    //    if (item.value.ToString().Trim().ToLower() == "false")
                    //    {
                    //        IsSeparate = false;
                    //    }
                    //    else if (item.value.ToString().Trim().ToLower() == "true")
                    //    {
                    //        IsSeparate = true;
                    //    }
                    //}
                    //else if (item.parameterCode.Equals("IsDisplyName"))
                    //{
                    //    if (item.value.ToString().Trim().ToLower() == "false")
                    //    {
                    //        IsDisplyName = false;
                    //    }
                    //    else if (item.value.ToString().Trim().ToLower() == "true")
                    //    {
                    //        IsDisplyName = true;
                    //    }
                    //}
                }
                #endregion
                ///獲取用戶登陸信息
                long login_start = 0;
                long login_end = 0;
                int errorCount = 0;             
                login_start = CommonFunction.GetPHPTime(DateTime.Now.ToString("yyyy/MM/dd HH:00:00"));
                login_end = CommonFunction.GetPHPTime(DateTime.Now.ToString("yyyy/MM/dd HH:59:59"));
                errorCount = 2;//登錄錯誤次數
                string start_time = CommonFunction.GetNetTime(login_start).ToString("yyyy/MM/dd HH:mm:ss");
                string end_time = CommonFunction.GetNetTime(login_end).ToString("yyyy/MM/dd HH:mm:ss");

                StringBuilder sql = new StringBuilder();
                sql.AppendFormat(@" select login_ipfrom,login_mail,t.parameterName as login_error_from,count(login_type) as total
from user_login_attempts ula
left join (select parameterName,parameterCode from t_parametersrc where parameterType ='user_login_type') t on ula.login_type=t.parameterCode
where login_createdate>='{0}' and login_createdate<='{1}' 
         and ula.login_ipfrom in (select login_ipfrom from user_login_attempts where login_createdate>='{0}' and login_createdate<='{1}' 
                                    GROUP BY login_ipfrom HAVING count(login_ipfrom)>='{2}')  
GROUP BY login_ipfrom,login_type,login_mail ;", login_start, login_end, errorCount);
                DataTable _dt = _accessMySql.getDataTable(sql.ToString());
                DataTable _newDt = new DataTable();
                                                       
                DataRow dr;
                _newDt.Columns.Add("異常IP", typeof(string));
                _newDt.Columns.Add("登入帳號", typeof(string));
                _newDt.Columns.Add("失敗次數", typeof(string));
                _newDt.Columns.Add("錯誤登入來源", typeof(string));          
                _newDt.Columns.Add("登入日期區間", typeof(string));

                if (_dt.Rows.Count > 0)
                {
                    for (int i = 0; i < _dt.Rows.Count; i++)
                    {
                        dr = _newDt.NewRow();
                        dr["異常IP"] = _dt.Rows[i]["login_ipfrom"];
                        dr["登入帳號"] = _dt.Rows[i]["login_mail"];
                        dr["失敗次數"] = _dt.Rows[i]["total"];
                        dr["錯誤登入來源"] = _dt.Rows[i]["login_error_from"];
                        dr["登入日期區間"] = start_time + " ~ " + end_time;
                        
                        _newDt.Rows.Add(dr);
                    }
                }

                if (_newDt.Rows.Count > 0)
                {
                    MailBody = GetHtmlByDataTable(_newDt);
                    //MailBody = "<br/><font size=\"4\">   在 " + "<font color=\"#FF0000\" >" + start_time + " ~ " + end_time + "</font>" + " 的一個小時里,用戶登錄異常記錄如下:</font><br/><p/>" + GetHtmlByDataTable(_newDt);
                    MailHelper mail = new MailHelper(mailModel);
                   // mail.SendToGroup(GroupCode, MailTitle, MailBody + " ", IsSeparate, IsDisplyName);
                    mail.SendToGroup(GroupCode, MailTitle, MailBody + " ", false, true);
                }
                else
                {
                    //MailBody = "<br/><p><font size=\"4\">    在 <font color=\"#FF0000\" >" + start_time + " ~ " + end_time + "</font> 的一個小時里,沒有用戶登錄異常的記錄!</font><p/>";

                }
                
            }
            catch (Exception ex)
            {
                throw new Exception("CheckUnsafeLoginMgr-->Start-->" + ex.Message);
            }
            return true;
        }
        public bool Start(string schedule_code)
        {
            if (string.IsNullOrEmpty(schedule_code))
            {
                return false;
            }
            try
            {
                MailModel mailModel = new MailModel();
                mailModel.MysqlConnectionString = mySqlConnectionString;

                string GroupCode = string.Empty;
                string MailTitle = string.Empty;
                string MailBody = string.Empty;
                string requestUrl = string.Empty;
                //bool IsSeparate = true;
                //bool IsDisplyName = true;

                //獲取該排程參數
                List<ScheduleConfigQuery> store_config = new List<ScheduleConfigQuery>();
                ScheduleConfigQuery query_config = new ScheduleConfigQuery();
                query_config.schedule_code = schedule_code;
                _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString);
                store_config = _secheduleServiceMgr.GetScheduleConfig(query_config);

                #region mailhelp賦值
                foreach (ScheduleConfigQuery item in store_config)
                {
                    if (item.parameterCode.Equals("MailFromAddress"))
                    {
                        mailModel.MailFromAddress = item.value;
                    }
                    else if (item.parameterCode.Equals("MailHost"))
                    {
                        mailModel.MailHost = item.value;
                    }
                    else if (item.parameterCode.Equals("MailPort"))
                    {
                        mailModel.MailPort = item.value;
                    }
                    else if (item.parameterCode.Equals("MailFromUser"))
                    {
                        mailModel.MailFromUser = item.value;
                    }
                    else if (item.parameterCode.Equals("EmailPassWord"))
                    {
                        mailModel.MailFormPwd = item.value;
                    }
                    else if (item.parameterCode.Equals("GroupCode"))
                    {
                        GroupCode = item.value;
                    }
                    else if (item.parameterCode.Equals("MailTitle"))
                    {
                        MailTitle = item.value;
                    }
                    else if (item.parameterCode.Equals("requestUrl"))
                    {
                        requestUrl = item.value;
                    }                  
                }
                #endregion

                
                StreamReader sr;                               
                HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(requestUrl);
                httpRequest.Timeout = 10000;
                httpRequest.Method = "GET";
                HttpWebResponse httpResponse;
                try
                {
                     httpResponse = (HttpWebResponse)httpRequest.GetResponse();                         
                }
                catch (Exception ex)
                {
                    MailBody = "URL請求失敗,失敗原因:" + ex.Message;
                    MailHelper mail = new MailHelper(mailModel);
                    mail.SendToGroup(GroupCode, MailTitle, MailBody + " ", false, true);
                    throw new Exception(ex.Message);
                }

                if (httpResponse.StatusCode == HttpStatusCode.OK)
                {
                    sr = new StreamReader(httpResponse.GetResponseStream(), System.Text.Encoding.UTF8);
                    string result = sr.ReadToEnd();
                    result = result.Trim();
                    if (result == "success")
                    {
                        MailBody = "更新成功";
                        MailHelper mail = new MailHelper(mailModel);
                        mail.SendToGroup(GroupCode, MailTitle, MailBody + " ", false, true);
                    }
                    else if (result == "error")
                    {
                        MailBody = "更新失敗";
                        MailHelper mail = new MailHelper(mailModel);
                        mail.SendToGroup(GroupCode, MailTitle, MailBody + " ", false, true);
                    }
                    else
                    {
                        MailBody = "請求遠端返回的值不為 success 或者 error ";
                        MailHelper mail = new MailHelper(mailModel);
                        mail.SendToGroup(GroupCode, MailTitle, MailBody + " ", false, true);
                    }
                }
                else
                {
                    MailBody = "URL請求失敗,失敗原因:遠端響應狀態為 " + httpResponse.StatusCode;
                    MailHelper mail = new MailHelper(mailModel);
                    mail.SendToGroup(GroupCode, MailTitle, MailBody + " ", false, true);
                }                      
            }
            catch (Exception ex)
            {
                throw new Exception("CheckUrlResultMgr-->Start-->" + ex.Message);
            }
            return true;
        }
        public void SendMail(string schedule_code, string info)
        {
            MailModel mailModel = new MailModel();
            mailModel.MysqlConnectionString = mySqlConnectionString;

            string GroupCode = string.Empty;
            string MailTitle = string.Empty;
            string MailBody = string.Empty;
            bool IsSeparate = false;
            bool IsDisplyName = true;

            try
            {
                //獲取該排程參數
                List<ScheduleConfigQuery> store_config = new List<ScheduleConfigQuery>();
                ScheduleConfigQuery query_config = new ScheduleConfigQuery();
                query_config.schedule_code = schedule_code;
                _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString);
                store_config = _secheduleServiceMgr.GetScheduleConfig(query_config);

                #region mailModel賦值
                foreach (ScheduleConfigQuery item in store_config)
                {
                    if (item.parameterCode.Equals("MailFromAddress"))
                    {
                        mailModel.MailFromAddress = item.value;
                    }
                    else if (item.parameterCode.Equals("MailHost"))
                    {
                        mailModel.MailHost = item.value;
                    }
                    else if (item.parameterCode.Equals("MailPort"))
                    {
                        mailModel.MailPort = item.value;
                    }
                    else if (item.parameterCode.Equals("MailFromUser"))
                    {
                        mailModel.MailFromUser = item.value;
                    }
                    else if (item.parameterCode.Equals("EmailPassWord"))
                    {
                        mailModel.MailFormPwd = item.value;
                    }
                    else if (item.parameterCode.Equals("GroupCode"))
                    {
                        GroupCode = item.value;
                    }
                    else if (item.parameterCode.Equals("MailTitle"))
                    {
                        MailTitle = item.value;
                    }
                }
                MailBody = info;
                #endregion

                MailHelper mail = new MailHelper(mailModel);
                mail.SendToGroup(GroupCode, MailTitle, MailBody + " ", IsSeparate, IsDisplyName);
            }
            catch (Exception ex)
            {
                throw new Exception("SendOrderInfoToBlackCatFTPMgr-->SendMail-->" + ex.Message);
            }                  
        }
        public bool Start(string schedule_code)
        {
            if (string.IsNullOrEmpty(schedule_code))
            {
                return false;
            }
            try
            {
                string ftpServerIP = string.Empty;
                string newfilename = string.Empty;
                string ftpUserID = string.Empty;
                string ftpPassword = string.Empty;
                string localPath_1 = string.Empty;
                string localPath_2 = "c:\\EOD_TCAT";

                //獲取該排程參數
                List<ScheduleConfigQuery> store_config = new List<ScheduleConfigQuery>();
                ScheduleConfigQuery query_config = new ScheduleConfigQuery();
                query_config.schedule_code = schedule_code;
                _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString);
                store_config = _secheduleServiceMgr.GetScheduleConfig(query_config);

                #region FTP參數賦值
                foreach (ScheduleConfigQuery item in store_config)
                {
                    if (item.parameterCode.Equals("FtpSite"))
                    {
                        ftpServerIP = item.value;
                    }
                    else if (item.parameterCode.Equals("ftpuser"))
                    {
                        ftpUserID = item.value;
                    }
                    else if (item.parameterCode.Equals("ftppassword"))
                    {
                        ftpPassword = item.value;
                    }
                    else if (item.parameterCode.Equals("localPath_1"))//文件生成保存路徑(本地)
                    {
                        localPath_1 = item.value;
                    }
                    else if (item.parameterCode.Equals("localPath_2"))//文件上傳成功轉移路徑(本地)
                    {
                        localPath_2 = item.value;
                    }
                }
                newfilename = ftpUserID + DateTime.Now.ToString("MMddHH") + ".eod";//要上傳的文件的名稱
                //string localFilePath_1 = "F:\\" + newfilename; //本地文件路徑
                string localFilePath_1 = localPath_1 + "\\" + newfilename; //本地文件路徑,要上傳的文件路徑
                string localFilePath_2 = localPath_2 + "\\" + DateTime.Now.ToString("yyyyMMdd") + "\\" + newfilename; //本地文件路徑
                #endregion



                
                StringBuilder sb = new StringBuilder();
                DataTable lteDT = logisticsTcatEodDao.GetOrderInfoForTcat();
                              
                //有需要上傳的數據

                bool localPath1Bool = true; 
                if (lteDT.Rows.Count > 0)
                {
                    #region 要上傳的文件生成
                    /// <summary>
                    /// 生成eod文件
                    /// </summary>
                    /// <returns></returns>

                    try
                    {                          
                        string[] eodArrary = new string[lteDT.Rows.Count];
                        StringBuilder fileDataSb = new StringBuilder();

                        for (int i = 0; i < lteDT.Rows.Count; i++)
                        {
                            DataRow lteRow = lteDT.Rows[i];
                            for (int j = 0; j < lteDT.Columns.Count; j++)
                            {
                                if (j == 21)
                                {
                                    string deliveryDateStr = Convert.ToDateTime(lteRow[j]).ToString("yyyyMMddHHmmss");
                                    sb.AppendFormat("{0}|", deliveryDateStr);
                                }
                                else
                                {
                                    sb.AppendFormat("{0}|", lteRow[j].ToString());
                                }                          
                            }
                            eodArrary[i] = sb.ToString().Substring(0, sb.ToString().Length - 1);
                            sb.Clear();
                            if (i == 0)
                            {
                                fileDataSb.Append(eodArrary[i]);
                            }
                            else
                            {
                                fileDataSb.Append("\r\n" + eodArrary[i]);
                            }
                        }
                        if (!Directory.Exists(localPath_1))
                        {                          
                            Directory.CreateDirectory(localPath_1);
                        }
                        if (!File.Exists(localFilePath_1))//本地文件(要上傳的文件)存在
                        {
                            FileStream fs1 = new FileStream(localFilePath_1, FileMode.Create, FileAccess.Write);//创建写入文件 
                            StreamWriter sw = new StreamWriter(fs1, Encoding.GetEncoding("big5"));
                            sw.Write(fileDataSb.ToString());//开始写入值
                            sw.Close();
                            fs1.Close();
                        }
                        else
                        {
                            FileStream fs = new FileStream(localFilePath_1, FileMode.Truncate, FileAccess.Write);
                            StreamWriter sr = new StreamWriter(fs, Encoding.GetEncoding("big5"));//GetEncoding("Utf8")
                            sr.Write(fileDataSb.ToString());//开始写入值
                            sr.Close();
                            fs.Close();
                        }
                    }
                    catch (Exception ex)
                    {
                        localPath1Bool = false;
                        string str = "eod文件生成失敗,失敗的原因:" + ex.Message;
                        SendMail(schedule_code, str);
                        throw new Exception(ex.Message);
                    }
                    

                    #endregion


                    #region FTP上傳
                    /// <summary>
                    /// FTP上傳
                    /// </summary>
                    bool result = false;
                    if (localPath1Bool)
                    {
                        try
                        {
                            string filePath = localFilePath_1;//本地的文件路徑
                            result = UploadFTP(ftpServerIP, filePath, ftpUserID, ftpPassword);
                        }
                        catch (Exception ex)
                        {
                            int index = ex.Message.LastIndexOf("-->");
                            //int index1 = ex.Message.LastIndexOfAny(new char[] {'>'});
                            int subStrLeng = index + 3;
                            string errorMessage = ex.Message.Substring(subStrLeng, ex.Message.Length - subStrLeng);
                            string str = newfilename + " 文件上傳失敗,失敗的原因:" + errorMessage;
                            SendMail(schedule_code, str);
                            throw new Exception(ex.Message);
                        }
                    }
                                     
                
                    if (result)//上傳成功,更新 upload_time為當前時間,轉移文件,發送郵件
                    {

                        logisticsTcatEodDao.UpdateUploadTime();//更新 upload_time為當前時間

                        bool localPath2Bool = true;
                        try
                        {
                             //要上傳的文件的名稱                           
                            localFilePath_2 = localPath_2 + "\\" + DateTime.Now.ToString("yyyyMMdd") + "\\" + ftpUserID + DateTime.Now.ToString("MMddHHmmss") + ".eod";
                            if (!Directory.Exists(localPath_2 + "\\" + DateTime.Now.ToString("yyyyMMdd")))
                            {
                                Directory.CreateDirectory(localPath_2 + "\\" + DateTime.Now.ToString("yyyyMMdd"));
                            }                           
                            if (File.Exists(localFilePath_1))
                            {
                                File.Move(localFilePath_1, localFilePath_2);
                            }
                            //if (!File.Exists(localFilePath_2))//本地文件(要上傳的文件)存在
                            //{
                            //    FileStream fs2 = new FileStream(localFilePath_2, FileMode.Create, FileAccess.Write);//创建写入文件 
                            //    FileStream fs1 = new FileStream(localFilePath_1, FileMode.Open);
                            //    StreamReader sr = new StreamReader(fs1, Encoding.GetEncoding("big5"));
                            //    StreamWriter sw = new StreamWriter(fs2, Encoding.GetEncoding("big5"));
                            //    sw.Write(sr.ReadToEnd());//开始写入值
                            //    sw.Close();
                            //    fs1.Close();
                            //}
                            //else
                            //{
                            //    FileStream fs2 = new FileStream(localFilePath_2, FileMode.Truncate, FileAccess.Write);//创建写入文件 
                            //    FileStream fs1 = new FileStream(localFilePath_1, FileMode.Open);
                            //    StreamReader sr = new StreamReader(fs1, Encoding.GetEncoding("big5"));
                            //    StreamWriter sw = new StreamWriter(fs2, Encoding.GetEncoding("big5"));//Big5
                            //    sw.Write(sr.ReadToEnd());//开始写入值
                            //    sw.Close();
                            //    fs1.Close();
                            //}
                        }
                        catch (Exception ex)
                        {
                            localPath2Bool = false;
                            string str1 =  newfilename + " 文件上傳成功。"+"數據庫upload_time欄位更新成功,但是該文件在本地保存失敗,失敗的原因:" + ex.Message;
                            SendMail(schedule_code, str1);
                            throw new Exception(ex.Message);
                        }

                        if (localPath2Bool)
                        {
                            string str = newfilename + " 文件上傳成功,全部操作執行成功";//全部執行成功
                            SendMail(schedule_code, str);
                        }
                        
                     
                    }                                                 
                    #endregion
                   
                }
                else//沒有需要上傳的數據,發送郵件
                {
                    string str = "沒有要上傳的資料";
                    SendMail(schedule_code, str);
                }                        
            }
            catch (Exception ex)
            {               
                throw new Exception("SendOrderInfoToBlackCatFTPMgr-->Start-->" + ex.Message);
            }           
            return true;
        }
        public bool Start(string schedule_code)
        {
            if (string.IsNullOrEmpty(schedule_code))
            {
                return false;
            }
            try
            {
                string ftpServerIP = string.Empty;
                string filename = string.Empty;
                string ftpUserID = string.Empty;
                string ftpPassword = string.Empty;
                string localPath_1 = string.Empty;
                string localPath_2 = string.Empty;

                //獲取該排程參數
                List<ScheduleConfigQuery> store_config = new List<ScheduleConfigQuery>();
                ScheduleConfigQuery query_config = new ScheduleConfigQuery();
                query_config.schedule_code = schedule_code;
                _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString);
                store_config = _secheduleServiceMgr.GetScheduleConfig(query_config);

                #region FTP參數賦值
                foreach (ScheduleConfigQuery item in store_config)
                {
                    if (item.parameterCode.Equals("FtpSite"))
                    {
                        ftpServerIP = item.value;
                    }
                    else if (item.parameterCode.Equals("ftpuser"))
                    {
                        ftpUserID = item.value;
                    }
                    else if (item.parameterCode.Equals("ftppassword"))
                    {
                        ftpPassword = item.value;
                    }
                    else if (item.parameterCode.Equals("localPath_1"))//下載的文件保存路徑(本地)
                    {
                        localPath_1 = item.value;
                    }
                    else if (item.parameterCode.Equals("localPath_2"))//下載的文件保存路徑(本地)
                    {
                        localPath_2 = item.value;
                    } 
                }             
                #endregion

                bool localPath1Bool = true; 
                try
                {
                    if (!Directory.Exists(localPath_1))
                    {
                        Directory.CreateDirectory(localPath_1);
                    }
                }
                catch(Exception ex)
                {
                    localPath1Bool = false;
                    string str1 = " 參數 localPath_1 有問題,創建路徑(保存下載文件)失敗,失敗的原因:" + ex.Message;
                    SendMail(schedule_code, str1);
                    throw new Exception(ex.Message);
                }
              

                #region FTP下載
                /// <summary>
                /// FTP下載
                /// </summary>
                string fileContentStr = string.Empty;
                bool result = false;
                if (localPath1Bool)
                {
                    try
                    {
                        string filePath = localPath_1;//下載保存文件路徑
                        result = DownloadFTP(filePath, ftpServerIP, ftpUserID, ftpPassword);
                    }
                    catch (Exception ex)
                    {
                        int index = ex.Message.LastIndexOf("-->");
                        int subStrLeng = index + 3;
                        string errorMessage = ex.Message.Substring(subStrLeng, ex.Message.Length - subStrLeng);
                        string str = "sod文件下載失敗,失敗的原因:" + errorMessage;
                        SendMail(schedule_code, str);
                        throw new Exception(ex.Message);
                    }
                }
               
               

                if (result)//下載成功后,插入數據,轉移文件,發送郵件
                {               
                    string[] filenames = Directory.GetFiles(localPath_1, "*.sod");


                    #region 循環讀取文件,插入數據
                    /// <summary>
                    /// 循環讀取文件,插入數據
                    /// </summary>
                    foreach (string file in filenames)
                    {
                        string localFilePath_1 = file;
                        if (File.Exists(localFilePath_1))
                        {
                            FileStream fs = new FileStream(localFilePath_1, FileMode.Open, FileAccess.Read);//创建写入文件                        
                            StreamReader readSr = new StreamReader(fs, Encoding.GetEncoding("big5"));

                            fileContentStr = readSr.ReadToEnd();//开始讀取值
                            readSr.Close();
                            fs.Close();
                        }
                        string[] array1 = fileContentStr.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);//數據數組
                        for (int i = 0; i < array1.Length; i++)//循環插入數據
                        {
                            string[] array2 = new string[] { };
                            array2 = array1[i].Split(new string[] { "|" }, StringSplitOptions.None);//欄位數組

                            string year = array2[3].ToString().Substring(0, 4);
                            string month = array2[3].ToString().Substring(4, 2);
                            string day = array2[3].ToString().Substring(6, 2);
                            string hour = array2[3].ToString().Substring(8, 2);
                            string minute = array2[3].ToString().Substring(10, 2);
                            string second = array2[3].ToString().Substring(12, 2);
                            string delivery_status_time = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;

                            
                            LogisticsTcatSodQuery query = new LogisticsTcatSodQuery ();                            
                            query.delivery_number = array2[0];
                            query.order_id = Convert.ToInt32(array2[1]);
                            query.delivery_status_time = Convert.ToDateTime(delivery_status_time);
                            query.status_id = array2[5];
                            DataTable selDT = logisticsTcatSodDao.GetRepeatInfo(query);

                            if (selDT.Rows.Count == 0)//如果數據已經存在,不插入
                            {
                                LogisticsTcatSod model = new LogisticsTcatSod();
                                model.delivery_number = array2[0];
                                model.order_id = Convert.ToInt32(array2[1]);
                                model.station_name = array2[2];
                                model.delivery_status_time = Convert.ToDateTime(delivery_status_time);
                                model.customer_id = array2[4];
                                model.status_id = array2[5];
                                model.status_note = array2[6];
                                model.specification = array2[7];
                                logisticsTcatSodDao.InsertReceiveFromTcatFTP(model);                               
                            }
                        }
                    } 
                    #endregion


                    #region 循環轉移文件
                    /// <summary>
                    /// 循環轉移文件
                    /// </summary>
                    if (filenames.Length > 0)
                    {
                        bool localPath2Bool = true;
                        foreach (string file in filenames)
                        {
                            int index = file.LastIndexOfAny(new char[] { '/', '\\' });
                            int subStrLeng = index + 1;
                            string localFilePath_1 = file;
                            string localFilePath_2 = localPath_2 + "\\" + DateTime.Now.ToString("yyyyMMdd") + "\\" + file.Substring(subStrLeng, file.Length - subStrLeng).Replace(".", DateTime.Now.ToString("mmss") + ".");

                            
                            try
                            {
                                //轉移文件
                                if (!Directory.Exists(localPath_2 + "\\" + DateTime.Now.ToString("yyyyMMdd")))
                                {
                                    Directory.CreateDirectory(localPath_2 + "\\" + DateTime.Now.ToString("yyyyMMdd"));
                                }
                                if (File.Exists(localFilePath_1))
                                {
                                    File.Move(localFilePath_1, localFilePath_2);
                                }
                                //if (!File.Exists(localFilePath_2))//本地文件(处理过的文件保存)存在
                                //{
                                //    FileStream fs2 = new FileStream(localFilePath_2, FileMode.Create, FileAccess.Write);//创建写入文件 
                                //    FileStream fs1 = new FileStream(localFilePath_1, FileMode.Open);
                                //    StreamReader sr = new StreamReader(fs1, Encoding.GetEncoding("big5"));
                                //    StreamWriter sw = new StreamWriter(fs2, Encoding.GetEncoding("big5"));
                                //    sw.Write(sr.ReadToEnd());//开始写入值
                                //    sw.Close();
                                //    fs1.Close();
                                //}
                                //else
                                //{
                                //    FileStream fs2 = new FileStream(localFilePath_2, FileMode.Truncate, FileAccess.Write);//创建写入文件 
                                //    FileStream fs1 = new FileStream(localFilePath_1, FileMode.Open);
                                //    StreamReader sr = new StreamReader(fs1, Encoding.GetEncoding("big5"));
                                //    StreamWriter sw = new StreamWriter(fs2, Encoding.GetEncoding("big5"));//Big5
                                //    sw.Write(sr.ReadToEnd());//开始写入值
                                //    sw.Close();
                                //    fs1.Close();
                                //}
                            }
                            catch (Exception ex)
                            {
                                localPath2Bool = false;
                                string str1 = " sod文件下載成功,數據庫更新成功。" + "但是該文件在本地保存失敗,失敗的原因:" + ex.Message;                                
                                SendMail(schedule_code, str1);
                                throw new Exception(ex.Message);
                            }
                        }

                        if (localPath2Bool)
                        {
                            //所有操作都執行成功
                            string downLoadSuccess = "sod文件下載成功,所有操作都執行成功";
                            SendMail(schedule_code, downLoadSuccess);
                        }                       
                    }
                    else
                    {
                        string downLoadNull = "沒有要下載的sod文件";
                        SendMail(schedule_code, downLoadNull);
                    }
                     
                    #endregion                  
                }
                #endregion

            }
            catch (Exception ex)
            {
                throw new Exception("ReceiveStatusFromTCatMgr-->Start-->" + ex.Message);
            }
            return true;
        }
Exemple #10
0
        public bool Start(string schedule_code)
        {
            bool result = false;
            FileManagement _fileHelper = new FileManagement();
           
            try
            {
                if (string.IsNullOrEmpty(schedule_code))
                {
                    return result;
                }
                string GroupCode = string.Empty;
                string MailTitle = string.Empty;

                StringBuilder strbody = new StringBuilder();
                MailModel mailModel = new MailModel();
                mailModel.MysqlConnectionString = mySqlConnectionString;
                //獲取該排程參數
                List<ScheduleConfigQuery> store_config = new List<ScheduleConfigQuery>();
                ScheduleConfigQuery query_config = new ScheduleConfigQuery();
                query_config.schedule_code = schedule_code;
                _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString);
                store_config = _secheduleServiceMgr.GetScheduleConfig(query_config);
                #region FTP參數賦值
                foreach (ScheduleConfigQuery item in store_config)
                {
                    if (item.parameterCode.Equals("MailFromAddress"))
                    {
                        mailModel.MailFromAddress = item.value;
                    }
                    else if (item.parameterCode.Equals("MailHost"))
                    {
                        mailModel.MailHost = item.value;
                    }
                    else if (item.parameterCode.Equals("MailPort"))
                    {
                        mailModel.MailPort = item.value;
                    }
                    else if (item.parameterCode.Equals("MailFromUser"))
                    {
                        mailModel.MailFromUser = item.value;
                    }
                    else if (item.parameterCode.Equals("EmailPassWord"))
                    {
                        mailModel.MailFormPwd = item.value;
                    }
                    else if (item.parameterCode.Equals("GroupCode"))
                    {
                        GroupCode = item.value;
                    }
                    else if (item.parameterCode.Equals("MailTitle"))
                    {
                        MailTitle = item.value;
                    }
                    else if (item.parameterCode.Equals("MailTitle"))
                    {
                        MailTitle = item.value;
                    }
                    else if (item.parameterCode.Equals("filepath"))
                    {
                        stockExcelsavePath = item.value.Trim().ToLower();;
                    }
                }
                stockExcelsavePathSuccess = Path.Combine(stockExcelsavePath, "success");
                stockExcelsavePathFail = Path.Combine(stockExcelsavePath, "fail");
                stockExcelsavePathIgnore = Path.Combine(stockExcelsavePath, "ignore");
                #endregion

                MailHelper mail = new MailHelper(mailModel);
                string[] files = _fileHelper.GetAllFiles(stockExcelsavePath, @"*.*");
                string consoleFile = String.Empty;
                string lastFile = files.Max<String>();
                if (files.Length < 1)
                {
                    mail.SendToGroup(GroupCode, MailTitle, "今日沒有文件倒入", false, true);//發送郵件給群組
                }
                #region 創建四個Datata來保存數據
                DataTable _dtSucess = new DataTable();//更新成功的數據
                _dtSucess.Columns.Add("商品編號", typeof(string));
                _dtSucess.Columns.Add("商品細項編號", typeof(string));
                _dtSucess.Columns.Add("商品ERP編號", typeof(string));
                _dtSucess.Columns.Add("商品名稱", typeof(string));
                _dtSucess.Columns.Add("規格", typeof(string));
                _dtSucess.Columns.Add("庫存", typeof(string));
                DataTable _dtFail = new DataTable();//更新失敗的數據
                _dtFail.Columns.Add("商品編號", typeof(string));
                _dtFail.Columns.Add("商品細項編號", typeof(string));
                _dtFail.Columns.Add("商品ERP編號", typeof(string));
                _dtFail.Columns.Add("商品名稱", typeof(string));
                _dtFail.Columns.Add("規格", typeof(string));
                _dtFail.Columns.Add("庫存", typeof(string));
                DataTable _dtIgnore = new DataTable();//跳過更新的數據
                _dtIgnore.Columns.Add("商品ERP編號", typeof(string));
                DataTable _dtErrorTable = new DataTable();//打不開Excel文件的數據
                _dtErrorTable.Columns.Add("路徑", typeof(string));
                _dtErrorTable.Columns.Add("描述", typeof(string));
                #endregion
                foreach (string file in files)
                {
                    if (lastFile == file)//只操作最新的文件
                    {
                      
                        int num = 0;
                        StringBuilder errorLog = GetStockMessageFromFile(file, ref _dtSucess, ref _dtFail, ref _dtIgnore, ref _dtIgnore);
                        if (String.IsNullOrEmpty(errorLog.ToString()))
                        {
                            string newFileName = file.Substring(file.LastIndexOf("\\"));
                            _fileHelper.MoveOneFile(file, stockExcelsavePathSuccess, newFileName);
                            MailTitle = "ERP庫存更新提醒";
                            mail.SendToGroup(GroupCode, MailTitle, "更新成功數量:" + num + "文件名称:" + newFileName, false, true);//發送郵件給群組
                        }
                        else
                        {
                            string newFileName = file.Substring(file.LastIndexOf("\\"));
                            string errorNewFileName = newFileName.Substring(0, newFileName.LastIndexOf(".")) + "_err.xls";
                            string errorlogNewFileName = stockExcelsavePathFail + newFileName.Substring(0, newFileName.LastIndexOf(".")) + "_err.txt";
                            _fileHelper.MoveOneFile(file, stockExcelsavePathFail, errorNewFileName);
                            SaveErrorLog(errorLog, errorlogNewFileName, newFileName);
                            MailTitle = "ERP庫存更新異常提醒";
                            StringBuilder sbMailBody = new StringBuilder();
                            if (_dtSucess.Rows.Count > 0)
                            {
                                sbMailBody.AppendLine("更新成功商品");
                                sbMailBody.AppendLine(GetHtmlByDataTable(_dtSucess));
                            }
                            if (_dtFail.Rows.Count > 0)
                            {
                                sbMailBody.AppendLine("更新失敗商品");
                                sbMailBody.AppendLine(GetHtmlByDataTable(_dtFail));
                            }
                            if (_dtIgnore.Rows.Count > 0)
                            {
                                sbMailBody.AppendLine("跳過更新商品");
                                sbMailBody.AppendLine(GetHtmlByDataTable(_dtIgnore));
                            }
                            if (_dtErrorTable.Rows.Count > 0)
                            {
                                sbMailBody.AppendLine("打不開Excel文件的數據");
                                sbMailBody.AppendLine(GetHtmlByDataTable(_dtErrorTable));
                            }
                            mail.SendToGroup(GroupCode, MailTitle, sbMailBody.ToString(), false, true);//發送郵件給群組

                        }
                            

                        
                    }
                    else//忽略過時文件
                    {
                        string newFileName = file.Substring(file.LastIndexOf("\\"));
                        _fileHelper.MoveOneFile(file, stockExcelsavePathIgnore, newFileName);
                    }

                }

               
               // StringBuilder sbMailBody = new StringBuilder();

                result = true;
            }
            catch (Exception ex)
            {
                throw new Exception("CheckOrderAmount-->Start-->" + ex.Message);
            }
            return result;
        }
Exemple #11
0
        public bool Start(string schedule_code)
        {
            if (string.IsNullOrEmpty(schedule_code))
            {
                return false;
            }
            try
            {
                MailModel mailModel = new MailModel();
                mailModel.MysqlConnectionString = mySqlConnectionString;

                string GroupCode = string.Empty;
                string MailTitle = string.Empty;
                string MailBody = string.Empty;
                bool IsSeparate = false;
                bool IsDisplyName = true;

                //獲取該排程參數
                List<ScheduleConfigQuery> store_config = new List<ScheduleConfigQuery>();
                ScheduleConfigQuery query_config = new ScheduleConfigQuery();
                query_config.schedule_code = schedule_code;
                _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString);
                store_config = _secheduleServiceMgr.GetScheduleConfig(query_config);
                #region mailhelp賦值
                foreach (ScheduleConfigQuery item in store_config)
                {
                    if (item.parameterCode.Equals("MailFromAddress"))
                    {
                        mailModel.MailFromAddress = item.value;
                    }
                    else if (item.parameterCode.Equals("MailHost"))
                    {
                        mailModel.MailHost = item.value;
                    }
                    else if (item.parameterCode.Equals("MailPort"))
                    {
                        mailModel.MailPort = item.value;
                    }
                    else if (item.parameterCode.Equals("MailFromUser"))
                    {
                        mailModel.MailFromUser = item.value;
                    }
                    else if (item.parameterCode.Equals("EmailPassWord"))
                    {
                        mailModel.MailFormPwd = item.value;
                    }
                    else if (item.parameterCode.Equals("GroupCode"))
                    {
                        GroupCode = item.value;
                    }
                    else if (item.parameterCode.Equals("MailTitle"))
                    {
                        MailTitle = item.value;
                    }
                    else if (item.parameterCode.Equals("MailTitle"))
                    {
                        MailTitle = item.value;
                    }
                    else if (item.parameterCode.Equals("MailBody"))
                    {
                        MailBody = item.value;
                    }
                    else if (item.parameterCode.Equals("IsSeparate"))
                    {
                        if (item.value.ToString().Trim().ToLower() == "false")
                        {
                            IsSeparate = false;
                        }
                        else if (item.value.ToString().Trim().ToLower() == "true")
                        {
                            IsSeparate = true;
                        }
                    }
                    else if (item.parameterCode.Equals("IsDisplyName"))
                    {
                        if (item.value.ToString().Trim().ToLower() == "false")
                        {
                            IsDisplyName = false;
                        }
                        else if (item.value.ToString().Trim().ToLower() == "true")
                        {
                            IsDisplyName = true;
                        }
                    }
                }
                #endregion
                ///獲取用戶登陸信息
                ///
                int totalCount = 0;
                List<ManageLoginQuery> list = new List<ManageLoginQuery>();
                ManageLoginMgr _managelogionMgr = new ManageLoginMgr(mySqlConnectionString);
                ManageLoginQuery query = new ManageLoginQuery();
                query.Start = Convert.ToInt32("0");
                query.Limit = Convert.ToInt32("999");

                query.login_start = CommonFunction.GetPHPTime(DateTime.Now.AddHours(-1).ToString());
                query.login_end = CommonFunction.GetPHPTime(DateTime.Now.ToString());

                DataTable _dt = new DataTable();
                DataRow dr;
                _dt.Columns.Add("登入編號", typeof(string));
                _dt.Columns.Add("登入人名稱", typeof(string));
                _dt.Columns.Add("登入時間", typeof(string));
                _dt.Columns.Add("來源IP", typeof(string));
                list = _managelogionMgr.GetManageLoginList(query, out totalCount);
                foreach (var item in list)
                {
                    dr = _dt.NewRow();
                    dr["登入編號"] = item.loginID.ToString();
                    dr["登入人名稱"] = item.user_name.ToString();
                    dr["登入時間"] = CommonFunction.DateTimeToString(item.login_createtime);
                    dr["來源IP"] = item.login_ipfrom.ToString();
                    _dt.Rows.Add(dr);
                }
                if (_dt.Rows.Count > 0)
                {
                    MailBody = GetHtmlByDataTable(_dt);
                    /////////////////
                    _secheduleServiceMgr.SendMail(mailModel, GroupCode, MailTitle, MailBody, IsSeparate, IsDisplyName);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("UserLoginLogMgr-->Start-->" + ex.Message);
            }
            return true;
        }
        public bool Start(string schedule_code)
        {

            string json = string.Empty;
            if (string.IsNullOrEmpty(schedule_code))
            {
                return false;
            }
            try
            {
                MailModel mailModel = new MailModel();
                mailModel.MysqlConnectionString = mySqlConnectionString;
                string GroupCode = string.Empty;
                string MailTitle = string.Empty;
                int HourNum = 0;

                List<ScheduleConfigQuery> store_config = new List<ScheduleConfigQuery>();
                ScheduleConfigQuery query_config = new ScheduleConfigQuery();

                query_config.schedule_code = schedule_code;
                _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString);
                store_config = _secheduleServiceMgr.GetScheduleConfig(query_config);
                foreach (ScheduleConfigQuery item in store_config)
                {
                    if (item.parameterCode.Equals("MailFromAddress"))
                    {
                        mailModel.MailFromAddress = item.value;
                    }
                    else if (item.parameterCode.Equals("MailHost"))
                    {
                        mailModel.MailHost = item.value;
                    }
                    else if (item.parameterCode.Equals("MailPort"))
                    {
                        mailModel.MailPort = item.value;
                    }
                    else if (item.parameterCode.Equals("MailFromUser"))
                    {
                        mailModel.MailFromUser = item.value;
                    }
                    else if (item.parameterCode.Equals("EmailPassWord"))
                    {
                        mailModel.MailFormPwd = item.value;
                    }
                    else if (item.parameterCode.Equals("GroupCode"))
                    {
                        GroupCode = item.value;
                    }
                    else if (item.parameterCode.Equals("MailTitle"))
                    {
                        MailTitle = item.value;
                    }
                    else if (item.parameterCode.Equals("HourNum"))
                    {
                        HourNum = int.Parse(item.value);
                    }
                    
                }
                string MailBody = string.Empty;
                //獲取history修改中的itemid
                string items=string.Empty;
                if (HourNum > 0)
                {
                    items = GetHistoryItemid(HourNum);
                }
                else
                {
                    items = "ALL";
                }
                DataTable _dt = GetDataTable(items);
                DataTable _newdt = new DataTable();
                _newdt.Columns.Add("商品名稱", typeof(String));
                _newdt.Columns.Add("商品編號", typeof(String));
                _newdt.Columns.Add("商品細項編號", typeof(String));
                _newdt.Columns.Add("商品規格", typeof(String));
                _newdt.Columns.Add("異常原因", typeof(String));
                _newdt.Columns.Add("item_money", typeof(String));
                _newdt.Columns.Add("item_cost", typeof(String));
                _newdt.Columns.Add("event_money", typeof(String));
                _newdt.Columns.Add("event_cost", typeof(String));
                _newdt.Columns.Add("event_start", typeof(String));
                _newdt.Columns.Add("event_end", typeof(String));
                //
                for (int i = 0; i < _dt.Rows.Count; i++)
                {
                    DataRow newRow = _newdt.NewRow();
                    newRow[0] = _dt.Rows[i]["product_name"];
                    newRow[1] = _dt.Rows[i]["product_id"];
                    newRow[2] = _dt.Rows[i]["item_id"];
                    newRow[3] = _dt.Rows[i]["prod_sz"];

                    int item_money = _dt.Rows[i]["item_money"] == DBNull.Value ? 0 : Convert.ToInt32(_dt.Rows[i]["item_money"]);
                    int item_cost = _dt.Rows[i]["item_cost"] == DBNull.Value ? 0 : Convert.ToInt32(_dt.Rows[i]["item_cost"]);
                    int event_money = _dt.Rows[i]["event_money"] == DBNull.Value ? 0 : Convert.ToInt32(_dt.Rows[i]["event_money"]);
                    int event_cost = _dt.Rows[i]["event_cost"] == DBNull.Value ? 0 : Convert.ToInt32(_dt.Rows[i]["event_cost"]);
                    int event_start = _dt.Rows[i]["event_start"] == DBNull.Value ? 0 : Convert.ToInt32(_dt.Rows[i]["event_start"]);
                    int event_end = _dt.Rows[i]["event_end"] == DBNull.Value ? 0 : Convert.ToInt32(_dt.Rows[i]["event_end"]);
                    newRow[5] = item_money;
                    newRow[6] = item_cost;
                    newRow[7] = event_money;
                    newRow[8] = event_cost;
                    newRow[9] = event_start;
                    newRow[10] = event_end;
                    if(item_money==0)
                    {
                        newRow[4] = "商品價格為零";
                    }
                    else if(item_money>item_cost)
                    {
                        newRow[4] = "商品價格大於成本價";
                    }
                    else if(event_money==0 && event_end > CommonFunction.GetPHPTime())
                    {
                        newRow[4] = "商品活動價格為零";
                    }
                    else if(event_money>event_cost && event_end > CommonFunction.GetPHPTime())
                    {
                        newRow[4] = "商品活動價格大於商品活動成本價格";
                    }
                    _newdt.Rows.Add(newRow);

                }
                if (_newdt.Rows.Count > 0)
                {
                    MailBody = GetHtmlByDataTable(_newdt);
                    /////////////////
                    _secheduleServiceMgr.SendMail(mailModel, GroupCode, MailTitle, MailBody, false, true);
                }

            }
            catch (Exception ex)
            {
                throw new Exception("CheckProductPriceMgr-->Start-->" + ex.Message);
            }
            return true;
        }
        public bool Start(string schedule_code)
        {
            string b = @"{'code':0,'data':{'country':'\u4e2d\u56fd','country_id':'CN','area':'\u534e\u4e2d','area_id':'400000','region':'\u6cb3\u5357\u7701','region_id':'410000','city':'\u90d1\u5dde\u5e02','city_id':'410100','county':'','county_id':'-1','isp':'\u8054\u901a','isp_id':'100026','ip':'115.60.75.15'}}";
            string source = "\u534e\u4e2d\u4e2d\u56fd";
            //string ip = "60.249.127.62";
            string cd = source;
            //GetMessageByIP(ip);

            DataTable userOtherLogin = GetUserLoginDataTable();
            string mailBody = GetHtmlByDataTable(userOtherLogin);
            CodeData codeData = JsonConvert.DeserializeObject<CodeData>(b);
            IPMessage ipMessage = JsonConvert.DeserializeObject<IPMessage>(codeData.data.ToString());

            MailModel mailModel = new MailModel();
            mailModel.MysqlConnectionString = mySqlConnectionString;

            string GroupCode = string.Empty;
            string MailTitle = string.Empty;
            //獲取該排程參數
            List<ScheduleConfigQuery> store_config = new List<ScheduleConfigQuery>();
            ScheduleConfigQuery query_config = new ScheduleConfigQuery();
            query_config.schedule_code = schedule_code;
            ScheduleServiceMgr _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString);
            store_config = _secheduleServiceMgr.GetScheduleConfig(query_config);
            foreach (ScheduleConfigQuery item in store_config)
            {
                if (item.parameterCode.Equals("MailFromAddress"))
                {
                    mailModel.MailFromAddress = item.value;
                }
                else if (item.parameterCode.Equals("MailHost"))
                {
                    mailModel.MailHost = item.value;
                }
                else if (item.parameterCode.Equals("MailPort"))
                {
                    mailModel.MailPort = item.value;
                }
                else if (item.parameterCode.Equals("MailFromUser"))
                {
                    mailModel.MailFromUser = item.value;
                }
                else if (item.parameterCode.Equals("EmailPassWord"))
                {
                    mailModel.MailFormPwd = item.value;
                }
                else if (item.parameterCode.Equals("GroupCode"))
                {
                    GroupCode = item.value;
                }
                else if (item.parameterCode.Equals("MailTitle"))
                {
                    MailTitle = item.value;
                }
            }

            MailHelper mail = new MailHelper(mailModel);
            if (userOtherLogin.Rows.Count>0)
            {
                return mail.SendToGroup(GroupCode, MailTitle,mailBody, false, true);
            }
            return true;
        }
        public bool Start(string schedule_code,DateTime startTime)
        {

            DeliverStatusDao dsDao = new DeliverStatusDao(mySqlConnectionString);
           // DateTime startTime = DateTime.Now;
            string HourNum = string.Empty;
            MailModel mailModel = new MailModel();
            mailModel.MysqlConnectionString = mySqlConnectionString;

            string GroupCode = string.Empty;
            string MailTitle = string.Empty;
            string MailBody = string.Empty;
            //bool IsSeparate = false;
            //bool IsDisplyName = true;
            //獲取該排程參數
            List<ScheduleConfigQuery> store_config = new List<ScheduleConfigQuery>();
            ScheduleConfigQuery query_config = new ScheduleConfigQuery();
            query_config.schedule_code = schedule_code;
            ScheduleServiceMgr _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString);
            store_config = _secheduleServiceMgr.GetScheduleConfig(query_config);
            foreach (ScheduleConfigQuery item in store_config)
            {
                if (item.parameterCode.Equals("HourNum"))
                {
                    HourNum = item.value;
                }
                else if (item.parameterCode.Equals("MailFromAddress"))
                {
                    mailModel.MailFromAddress = item.value;
                }
                else if (item.parameterCode.Equals("MailHost"))
                {
                    mailModel.MailHost = item.value;
                }
                else if (item.parameterCode.Equals("MailPort"))
                {
                    mailModel.MailPort = item.value;
                }
                else if (item.parameterCode.Equals("MailFromUser"))
                {
                    mailModel.MailFromUser = item.value;
                }
                else if (item.parameterCode.Equals("MailFormPwd"))
                {
                    mailModel.MailFormPwd = item.value;
                }
                else if (item.parameterCode.Equals("GroupCode"))
                {
                    GroupCode = item.value;
                }
                else if (item.parameterCode.Equals("MailTitle"))
                {
                    MailTitle = item.value;
                }
                else if (item.parameterCode.Equals("MailTitle"))
                {
                    MailTitle = item.value;
                }
                else if (item.parameterCode.Equals("MailBody"))
                {
                    MailBody = item.value;
                }
            }
            IDeliverMasterImplMgr DeliverMaster = new DeliverMasterMgr(mySqlConnectionString);
            DataTable table = DeliverMaster.GetDeliverMaster(HourNum);
            int delNumber = table.Rows.Count;
            int updateNumber = 0;
            if (delNumber > 0)
            {
                DeliveryInfo Model;
                LogisticsTcatSodDao LTSDao=new LogisticsTcatSodDao(mySqlConnectionString);
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    table.Rows[i]["gettime"] = "";
                    Model =LTSDao.GetLogisticsTcatSod(table.Rows[i]["delivery_code"].ToString());
                    if (Model.Status == "順利送達")
                    {
                        table.Rows[i]["gettime"] = Model.CreateTime;
                        updateNumber++;
                        DeliverStatus dsmodel = new DeliverStatus();

                        dsmodel.freight_type = 11;//物流配送模式
                        dsmodel.Logistics_providers = 1;//物流商
                        dsmodel.deliver_id = Int64.Parse(table.Rows[i]["deliver_id"].ToString());
                        dsmodel.state = 99;
                        dsmodel.settime = Model.CreateTime;
                        dsmodel.endtime = Model.CreateTime;
                        dsDao.InsertDeliverStatus(dsmodel);
                    }
                }
            }
            DateTime endTime = DateTime.Now;
            TimeSpan ts = endTime - startTime;
            double Second = ts.TotalSeconds;
            int num1 = 0;//期望到貨日<運達時間的物流單個數
            int num2 = 0;//期望到貨日>今天的物流單個數
            MailHelper mail = new MailHelper(mailModel);
            StringBuilder sbmailBody = new StringBuilder();
            string tablestr = GetHtmlByDataTable(GetSendTable(table), out num1, out num2);
            sbmailBody.Append("物流狀態抓取排程執行成功<br/>");
            sbmailBody.Append("更新<span style=\"font-size:large;\">" + delNumber + "</span>個出貨單<br/>");
            sbmailBody.Append("更新<span style=\"font-size:large;\">" + updateNumber + "</span>個物流單<br/>");
            sbmailBody.Append("期望到貨日小於運達時間的物流單個數:<span style=\"font-size:large;\">" + num1 + "</span><br/>");
            sbmailBody.Append("期望到貨日小於今天的物流單個數:<span style=\"font-size:large;\">" + num2 + "</span><br/>");
            sbmailBody.Append("共耗時<span style=\"font-size:large;\">" + Second + "</span>秒<br/>");
            sbmailBody.Append("更新出貨單詳情如下:<br/><br/>");
            sbmailBody.Append(tablestr);
            return mail.SendToGroup(GroupCode, MailTitle,sbmailBody.ToString(), false, true);
        }
        public bool Start(string schedule_code)
        {
            bool result = false;

            try
            {
                if (string.IsNullOrEmpty(schedule_code))
                {
                    return result;
                }
                productItemMgr = new ProductItemMgr(mySqlConnectionString);
                _paraMgr = new ParameterMgr(mySqlConnectionString);
                ProductItemQuery query = new ProductItemQuery();
                ArrivalNotice arriva = new ArrivalNotice();
                MailModel mailModel = new MailModel();
                mailModel.MysqlConnectionString = mySqlConnectionString;
                string GroupCode = string.Empty;
                string MailTitle = string.Empty;
                string MailBody = string.Empty;
                string NOSuggestCountMsg = "今天沒有要採購的商品";//沒有要採購的商品提示
                string sumDays = "60";//採購總天數
                string periodDays = "1";//採購週期天數
                ScheduleServiceMgr _secheduleServiceMgr;

                //獲取該排程參數
                List<ScheduleConfigQuery> store_config = new List<ScheduleConfigQuery>();
                ScheduleConfigQuery query_config = new ScheduleConfigQuery();
                query_config.schedule_code = schedule_code;
                _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString);
                store_config = _secheduleServiceMgr.GetScheduleConfig(query_config);
                #region FTP參數賦值
                foreach (ScheduleConfigQuery item in store_config)
                {
                    if (item.parameterCode.Equals("MailFromAddress"))
                    {
                        mailModel.MailFromAddress = item.value;
                    }
                    else if (item.parameterCode.Equals("MailHost"))
                    {
                        mailModel.MailHost = item.value;
                    }
                    else if (item.parameterCode.Equals("MailPort"))
                    {
                        mailModel.MailPort = item.value;
                    }
                    else if (item.parameterCode.Equals("MailFromUser"))
                    {
                        mailModel.MailFromUser = item.value;
                    }
                    else if (item.parameterCode.Equals("EmailPassWord"))
                    {
                        mailModel.MailFormPwd = item.value;
                    }
                    else if (item.parameterCode.Equals("GroupCode"))
                    {
                        GroupCode = item.value;
                    }
                    else if (item.parameterCode.Equals("MailTitle"))
                    {
                        MailTitle = item.value;
                    }
                    else if (item.parameterCode.Equals("MailTitle"))
                    {
                        MailTitle = item.value;
                    }
                    else if (item.parameterCode.Equals("MailBody"))
                    {
                        MailBody = item.value;
                    }
                    else if (item.parameterCode.Equals("sumDays"))
                    {
                        sumDays = item.value;
                    }
                    else if (item.parameterCode.Equals("periodDays"))
                    {
                        periodDays = item.value;
                    }
                    else if (item.parameterCode.Equals("NOSuggestCountMsg"))
                    {
                        NOSuggestCountMsg = item.value;
                    }
                }
                #endregion
                Parametersrc p = new Parametersrc();
                List<Parametersrc> list = new List<Parametersrc>();
                p.ParameterType = "Food_Articles";
                list = _paraMgr.GetAllKindType(p.ParameterType);
                for (int i = 0; i < list.Count; i++)/*要禁用的食品錧和用品館的商品*/
                {
                    if (!string.IsNullOrEmpty(list[i].ParameterCode))
                    {
                        query.category_ID_IN += list[i].ParameterCode + ",";
                    }
                }
                query.sumDays = int.Parse(sumDays);
                query.periodDays = int.Parse(periodDays);
                query.category_ID_IN = query.category_ID_IN.TrimEnd(',');
                query.sale_status = 100;
                query.Is_pod = 0;
                query.stockScope = 2;
                query.prepaid = -1;
                query.IsPage = false;
                int totalCount = 0;

                DataTable dt = productItemMgr.GetSuggestPurchaseInfo(query, out totalCount);
                MailHelper mail = new MailHelper(mailModel);
                if (dt.Rows.Count > 0)
                {
                    DataTable dtExcel = new DataTable();
                    dtExcel.Columns.Add("行號", typeof(String));
                    dtExcel.Columns.Add("供應商編號", typeof(String));
                    dtExcel.Columns.Add("供應商名稱", typeof(String));//
                    dtExcel.Columns.Add("商品編號", typeof(String));
                    dtExcel.Columns.Add("商品細項編號", typeof(String));
                    dtExcel.Columns.Add("商品ERP編號", typeof(String));
                    dtExcel.Columns.Add("商品名稱", typeof(String));
                    //dtExcel.Columns.Add("商品狀態", typeof(String));
                    //dtExcel.Columns.Add("販售狀態", typeof(String));
                    dtExcel.Columns.Add("規格", typeof(String));
                    // dtExcel.Columns.Add("規格二", typeof(String));
                    dtExcel.Columns.Add("庫存量", typeof(String));
                    dtExcel.Columns.Add("後台庫存量", typeof(String));
                    dtExcel.Columns.Add("安全存量", typeof(String));
                    dtExcel.Columns.Add("建議採購量", typeof(String));//ipo_qty
                    dtExcel.Columns.Add("未驗收數量", typeof(String));
                    dtExcel.Columns.Add("補貨通知人數", typeof(String));
                    dtExcel.Columns.Add("成本", typeof(String));
                    dtExcel.Columns.Add("價格", typeof(String));
                    dtExcel.Columns.Add("上架時間", typeof(String));
                    dtExcel.Columns.Add("下架時間", typeof(String));
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        #region
                        DataRow newRow = dtExcel.NewRow();
                        newRow[0] = i + 1;
                        newRow[1] = Convert.ToInt64(dt.Rows[i]["vendor_id"]);
                        newRow[2] = dt.Rows[i]["vendor_name_full"];
                        newRow[3] = dt.Rows[i]["product_id"];
                        newRow[4] = dt.Rows[i]["item_id"];
                        newRow[5] = dt.Rows[i]["erp_id"];
                        newRow[6] = dt.Rows[i]["product_name"];
                        //newRow[7] = dt.Rows[i]["product_status_string"];
                        //newRow[8] = dt.Rows[i]["sale_name"];
                        newRow[7] = dt.Rows[i]["spec_title_1"];

                        newRow[8] = dt.Rows[i]["item_stock"];
                        newRow[9] = dt.Rows[i]["iinvd_stock"];
                        newRow[10] = dt.Rows[i]["item_alarm"];
                        if (string.IsNullOrEmpty(dt.Rows[i]["sum_total"].ToString()))
                        {
                            newRow[11] = 0;
                        }
                        #region
                        else
                        {
                            double sum_total = 0;
                            int safe_stock_amount = 0;
                            int item_stock = 0;
                            int item_alarm = 0;
                            int procurement_days = 0;
                            if (double.TryParse(dt.Rows[i]["sum_total"].ToString(), out sum_total))
                            {
                                sum_total = Convert.ToDouble(dt.Rows[i]["sum_total"]);
                            }
                            if (int.TryParse(dt.Rows[i]["safe_stock_amount"].ToString(), out safe_stock_amount))
                            {
                                safe_stock_amount = Convert.ToInt32(dt.Rows[i]["safe_stock_amount"]);
                            }
                            if (int.TryParse(dt.Rows[i]["item_stock"].ToString(), out item_stock))
                            {
                                item_stock = Convert.ToInt32(dt.Rows[i]["item_stock"]);
                            }
                            if (int.TryParse(dt.Rows[i]["item_alarm"].ToString(), out item_alarm))
                            {
                                item_alarm = Convert.ToInt32(dt.Rows[i]["item_alarm"]);
                            }
                            if (int.TryParse(dt.Rows[i]["procurement_days"].ToString(), out procurement_days))
                            {
                                procurement_days = Convert.ToInt32(dt.Rows[i]["procurement_days"]);
                            }
                            if (item_stock - procurement_days * sum_total / query.sumDays * query.periodDays <= item_alarm)
                            {
                                //建議採購量:供應商的進貨天數*採購調整系數*近3個月的平均每周銷售數量(最小值為1)

                                double suggestPurchaseTemp = (procurement_days + safe_stock_amount) * (sum_total / query.sumDays) * query.periodDays + ((item_alarm - item_stock) > 0 ? (item_alarm - item_stock) : 0);

                                if (suggestPurchaseTemp <= int.Parse(dt.Rows[i]["min_purchase_amount"].ToString()))   //最小值為1
                                {
                                    newRow[11] = dt.Rows[i]["min_purchase_amount"];
                                }
                                else
                                {
                                    int suggestPurchase = Convert.ToInt32(suggestPurchaseTemp);
                                    if (suggestPurchase < suggestPurchaseTemp)
                                    {
                                        newRow[11] = Convert.ToInt32(suggestPurchaseTemp) + 1;
                                    }
                                    else
                                    {
                                        newRow[11] = Convert.ToInt32(suggestPurchaseTemp);
                                    }
                                }
                            }

                        }
                        #endregion
                        newRow[12] = dt.Rows[i]["ipo_qty"];
                        newRow[13] = dt.Rows[i]["NoticeGoods"];

                        newRow[14] = dt.Rows[i]["item_cost"];
                        newRow[15] = dt.Rows[i]["item_money"];
                        newRow[16] = string.IsNullOrEmpty(dt.Rows[i]["product_start"].ToString()) ? " " : DateTime.Parse(dt.Rows[i]["product_start"].ToString()).ToString("yyyy-MM-dd hh:mm:ss");
                        newRow[17] = string.IsNullOrEmpty(dt.Rows[i]["product_end"].ToString()) ? "" : DateTime.Parse(dt.Rows[i]["product_end"].ToString()).ToString("yyyy-MM-dd hh:mm:ss");
                        dtExcel.Rows.Add(newRow);
                        #endregion
                    }


                    string EmailContent = GetMail(dtExcel);
                    mail.SendToGroup(GroupCode, MailTitle, EmailContent, false, true);//發送郵件給群組
                }
                else
                {
                    mail.SendToGroup(GroupCode, MailTitle, NOSuggestCountMsg, false, true);//發送郵件給群組 
                }
                result = true;
            }
            catch (Exception ex)
            {
                throw new Exception("SendOrderInfoToBlackCatFTPMgr-->Start-->" + ex.Message);
            }
            return result;
        }
Exemple #16
0
        public bool Start(string schedule_code)
        {

            string json = string.Empty;
            if (string.IsNullOrEmpty(schedule_code))
            {
                return false;
            }
            try
            {
                MailModel mailModel = new MailModel();
                mailModel.MysqlConnectionString = mySqlConnectionString;
                string GroupCode = string.Empty;
                string MailTitle = string.Empty;
                string filepath = string.Empty;
                string ftpuser = string.Empty;
                string ftppassword = string.Empty;
                string EmptyFilesPrompt = string.Empty;
                string ExistFilesPrompt = string.Empty;
                string NotExistDirectory = string.Empty;
                //string NotExistFtpDirectory = string.Empty;
                int isEmpty = -1;

                List<ScheduleConfigQuery> store_config = new List<ScheduleConfigQuery>();
                ScheduleConfigQuery query_config = new ScheduleConfigQuery();

                query_config.schedule_code = schedule_code;
                _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString);
                store_config = _secheduleServiceMgr.GetScheduleConfig(query_config);
                foreach (ScheduleConfigQuery item in store_config)
                {
                    if (item.parameterCode.Equals("MailFromAddress"))
                    {
                        mailModel.MailFromAddress = item.value;
                    }
                    else if (item.parameterCode.Equals("MailHost"))
                    {
                        mailModel.MailHost = item.value;
                    }
                    else if (item.parameterCode.Equals("MailPort"))
                    {
                        mailModel.MailPort = item.value;
                    }
                    else if (item.parameterCode.Equals("MailFromUser"))
                    {
                        mailModel.MailFromUser = item.value;
                    }
                    else if (item.parameterCode.Equals("EmailPassWord"))
                    {
                        mailModel.MailFormPwd = item.value;
                    }
                    else if (item.parameterCode.Equals("GroupCode"))
                    {
                        GroupCode = item.value;
                    }
                    else if (item.parameterCode.Equals("MailTitle"))
                    {
                        MailTitle = item.value;
                    }
                    else if (item.parameterCode.Equals("filepath"))
                    {
                        filepath = item.value;
                    }
                    else if (item.parameterCode.Equals("ftpuser"))
                    {
                        ftpuser = item.value.Trim();
                    }
                    else if (item.parameterCode.Equals("ftppassword"))
                    {
                        ftppassword = item.value.Trim();
                    }
                    else if (item.parameterCode.Equals("EmptyFilesPrompt"))
                    {
                        EmptyFilesPrompt = item.value.Trim();
                    }
                    else if (item.parameterCode.Equals("ExistFilesPrompt"))
                    {
                        ExistFilesPrompt = item.value.Trim();
                    }
                    else if (item.parameterCode.Equals("NotExistDirectory"))
                    {
                        NotExistDirectory = item.value.Trim();
                    }
                    //else if (item.parameterCode.Equals("NotExistFtpDirectory"))
                    //{
                    //    NotExistFtpDirectory = item.value.Trim();
                    //}
                }
                string mailBody = string.Empty;
                #region  統計目錄內容
                string[] filepaths = filepath.Split(';');
                for (int i = 0; i < filepaths.Length; i++)
                {
                    if (string.IsNullOrEmpty(filepaths[i].Trim()))
                    {
                        continue;
                    }
                    //判斷是否為FTP路徑
                    if (filepaths[i].Trim().ToLower().ToString().Contains("ftp:"))
                    {
                        if (string.IsNullOrEmpty(ftpuser) || string.IsNullOrEmpty(ftppassword))
                        {
                            mailBody += "<h3>" + (i + 1).ToString() + "." + "目錄 " + filepaths[i] + "需要的FTP賬號或密碼沒有設定!" + "</h3>";
                            //mailBody += "<br>" + (i + 1).ToString() + "." + "目錄 " + filepaths[i] + " " + "需要的FTP賬號或密碼沒有設定!" + "<br>";
                        }
                        else
                        {
                            mailBody += GetFtpContent(filepaths[i].Trim(), ftpuser, ftppassword, i, EmptyFilesPrompt, ExistFilesPrompt, NotExistDirectory, out isEmpty);
                        }

                    }
                    //判斷路徑是否正確
                    else if (!Directory.Exists(filepaths[i]))
                    {
                        mailBody += "<h3>" + (i + 1).ToString() + "." + "目錄 " + filepaths[i] + " " + NotExistDirectory + "</h3>";
                        //mailBody += "<br>" + (i + 1).ToString() + "." + "目錄 " + filepaths[i] + " " + NotExistDirectory + "<br>";
                        isEmpty = -1;
                    }
                    //判斷路徑下是否有文件
                    else if (Directory.GetFiles(filepaths[i]).Length == 0)
                    {
                        mailBody += "<h3>" + (i + 1).ToString() + "." + "目錄 " + filepaths[i] + " " + EmptyFilesPrompt + "</h3>";
                        //mailBody += "<br>" + (i + 1).ToString() + "." + "目錄 " + filepaths[i] + " " + EmptyFilesPrompt + "<br>";
                        isEmpty = 1;
                    }
                    else if (Directory.GetFiles(filepaths[i]).Length > 0)
                    {
                        string Content = "<h3>" + (i + 1).ToString() + "." + "目錄 " + filepaths[i] + " " + ExistFilesPrompt + "</h3>";
                        //string Content = "<br>" + (i + 1).ToString() + "." + "目錄 " + filepaths[i] + " " + ExistFilesPrompt + "<br>";
                        string[] files = Directory.GetFiles(filepaths[i]);
                        for (int j = 0; j < files.Length; j++)
                        {
                            FileInfo info = new FileInfo(files[j]);
                            files[j] = info.Name;
                            Content += "<h5>" + "(" + (j + 1).ToString() + ")" + files[j] + "</h5>";
                            //Content += "(" + (j + 1).ToString() + ")" + files[j] + "<br>";
                        }
                        mailBody += Content;
                        isEmpty = 0;
                    }
                }
                #endregion
                if (isEmpty == 0 && string.IsNullOrEmpty(ExistFilesPrompt))
                {

                }
                else if (isEmpty == 1 && string.IsNullOrEmpty(EmptyFilesPrompt))
                {

                }
                else
                {
                    MailHelper mail = new MailHelper(mailModel);
                    mail.SendToGroup(GroupCode, MailTitle, mailBody+" ", false, false);//發送郵件
                }

            }
            catch (Exception ex)
            {
                throw new Exception("SetConfigXmlMgr-->Start-->" + ex.Message);
            }
            return true;
        }