Esempio n. 1
0
        public List<ScheduleConfigQuery> GetScheduleConfig(ScheduleConfigQuery query)
        {
            try
            {
                return _secheduleServiceDao.GetScheduleConfig(query);
            }
            catch (Exception ex)
            {

                throw new Exception("SecheduleServiceMgr-->GetScheduleConfig-->" + ex.Message, ex);
            }
        }
        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;          
        }
Esempio n. 3
0
 public List<ScheduleConfigQuery> GetScheduleConfig(ScheduleConfigQuery query)
 {
     StringBuilder sql = new StringBuilder();
     try
     {
         sql.AppendFormat("SELECT `rowid`, `schedule_code`, `parameterCode`, `parameterName`, `value`, `create_user`, `create_time`, `change_user`, `change_time` FROM `schedule_config` WHERE schedule_code = '{0}';", query.schedule_code);
         return _access.getDataTableForObj<ScheduleConfigQuery>(sql.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("ScheduleServiceDao-->GetScheduleConfig-->" + ex.Message, ex);
     }
 }
        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);
            }                  
        }
Esempio n. 5
0
        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;
        }
        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;
        }
Esempio n. 7
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 = 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;
        }
Esempio n. 8
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;
                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;
        }
        //保存排程_config信息 
        public HttpResponseBase SaveScheduleConfigInfo()
        {
            string json = string.Empty;
            try
            {
                ScheduleConfigQuery query = new ScheduleConfigQuery();
                _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString);

                if (!string.IsNullOrEmpty(Request.Params["rowid"]))
                {
                    query.rowid = Convert.ToInt32(Request.Params["rowid"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["schedule_code"]))
                {
                    query.schedule_code = Request.Params["schedule_code"];
                }
                if (!string.IsNullOrEmpty(Request.Params["parameterCode"]))
                {
                    query.parameterCode = Request.Params["parameterCode"];
                }
                if (!string.IsNullOrEmpty(Request.Params["value"]))
                {
                    query.value = Request.Params["value"];
                    query.value = query.value.Replace("\\","\\\\");
                }
                if (!string.IsNullOrEmpty(Request.Params["parameterName"]))
                {
                    query.parameterName = Request.Params["parameterName"];
                }  
                query.create_user = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id;
                query.change_user = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id;
                int _dt = _secheduleServiceMgr.SaveScheduleConfigInfo(query);

                if (_dt > 0)
                {
                    json = "{success:true}";
                }
                else
                {
                    json = "{success:false}";
                }
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "{success:false,totalCount:0,data:[]}";

            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return Response;

        }
Esempio n. 10
0
 public List<ScheduleConfigQuery> GetScheduleConfigList(ScheduleConfigQuery query)// 得到 config表中的記錄
 {
     StringBuilder sql = new StringBuilder();
      StringBuilder sqlCondi = new StringBuilder();
     try
     {
         sql.AppendFormat("SELECT  sc.rowid,sc.schedule_code,sc.parameterCode,sc.value,sc.parameterName, mu1.user_username as create_username,sc.create_time, mu2.user_username as change_username,sc.change_time  FROM schedule_config sc ");
         sqlCondi.Append(" LEFT JOIN schedule_master sm on sm.schedule_code=sc.schedule_code ");
         sqlCondi.Append(" LEFT JOIN manage_user mu1 on mu1.user_id=sc.create_user ");
         sqlCondi.Append(" LEFT JOIN manage_user mu2 on mu2.user_id=sc.change_user ");
         sqlCondi.Append(" where 1=1 ");
         if (!string.IsNullOrEmpty(query.schedule_code))
         {
             sqlCondi.AppendFormat(" and sm.schedule_code='{0}' ", query.schedule_code);
         }
         sql.Append(sqlCondi.ToString());
         return _access.getDataTableForObj<ScheduleConfigQuery>(sql.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("ScheduleServiceDao-->GetScheduleMasterList-->" + ex.Message, ex);
     }
 }
Esempio n. 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;
        }
Esempio n. 12
0
        public bool Start(string schedule_code)
        {
                      
            
            BLL.gigade.Common.MailModel mailModel = new Common.MailModel ();
            mailModel.MysqlConnectionString = mySqlConnectionString;

            string GroupCode = string.Empty;
            string MailTitle = string.Empty;
            string MailBody = string.Empty;
            string hourNum = string.Empty;
            //bool IsSeparate = false;
            //bool IsDisplyName = true;
            string isSendMailToGroup = string.Empty;
           
            try
            {            
                //獲取該排程參數
                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);

                #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("HourNum"))
                    {
                        if (item.value.Trim() == "0")
                        {
                            hourNum = "1";
                        }
                        else
                        {
                            hourNum = item.value;
                        }
                    }
                    else if (item.parameterCode.Equals("isSendMailToGroup"))
                    {
                        isSendMailToGroup = item.value;
                    }
                }
                if (hourNum.Trim() == string.Empty)
                {
                    hourNum = "1";
                }
                #endregion

                //獲取期望到貨日調整記錄(邮件内容)
                #region 獲取期望到貨日調整記錄表格
                DeliverChangeLogQuery aclQuery = new DeliverChangeLogQuery();

                aclQuery.time_start = DateTime.Now.AddHours(-Convert.ToDouble(hourNum));
                aclQuery.time_end = DateTime.Now;
                System.Data.DataTable dclTable = _IDeliverChangeLogDao.GetDeliverChangeLogDataTable(aclQuery);

                System.Data.DataTable dmTable = _IDeliverChangeLogDao.GetDataTable(aclQuery);


                DataTable _dt = new DataTable();
                DataRow dr;
                _dt.Columns.Add("訂單編號", typeof(string));
                _dt.Columns.Add("出貨單號", typeof(string));
                _dt.Columns.Add("供應商名稱", typeof(string));
                _dt.Columns.Add("出貨方式", typeof(string));
                _dt.Columns.Add("異動人", typeof(string));
                _dt.Columns.Add("異動類型", typeof(string));//
                _dt.Columns.Add("異動時間", typeof(string));
                //_dt.Columns.Add("原期望到貨日", typeof(string));
                _dt.Columns.Add("期望到貨日", typeof(string));
                _dt.Columns.Add("期望到貨時段", typeof(string));
                _dt.Columns.Add("備註", typeof(string));
                _dt.Columns.Add("來源IP", typeof(string));
                _dt.Columns.Add("異動時段", typeof(string));
                _dt.Columns.Add("時間", typeof(string));//difftime


                //自行出貨的供應商
                DataTable deliverDt = new DataTable();
                DataRow deliverDr;
                deliverDt.Columns.Add("訂單編號", typeof(string));
                deliverDt.Columns.Add("出貨單號", typeof(string));
                deliverDt.Columns.Add("付款完成時間", typeof(string));
                deliverDt.Columns.Add("供應商編號", typeof(string));
                deliverDt.Columns.Add("供應商郵箱", typeof(string));
                deliverDt.Columns.Add("供應商名稱", typeof(string));     
                deliverDt.Columns.Add("期望到貨日", typeof(string));
                deliverDt.Columns.Add("期望到貨時段", typeof(string));
                deliverDt.Columns.Add("預計到貨日", typeof(string));
                deliverDt.Columns.Add("備註", typeof(string));
               


                if (dclTable.Rows.Count > 0)
                {
                    #region 循環賦值

                    for (int i = 0; i < dmTable.Rows.Count; i++)
                    {
                        #region 自行出貨的供應商的table賦值
                        deliverDr = deliverDt.NewRow();
                        deliverDr["訂單編號"] = dmTable.Rows[i]["order_id"].ToString();
                        deliverDr["出貨單號"] = dmTable.Rows[i]["deliver_id"].ToString();
                        if (Convert.ToInt32(dmTable.Rows[i]["order_date_pay"]) == 0)
                        {
                            deliverDr["付款完成時間"] = "";
                        }
                        else
                        {
                            deliverDr["付款完成時間"] = CommonFunction.GetNetTime(Convert.ToInt32(dmTable.Rows[i]["order_date_pay"])).ToString("yyyy-MM-dd HH:mm:ss");
                        }
                        deliverDr["供應商編號"] = dmTable.Rows[i]["vendor_id"].ToString();
                        deliverDr["供應商郵箱"] = dmTable.Rows[i]["vendor_email"].ToString();
                        deliverDr["供應商名稱"] = dmTable.Rows[i]["vendor_name_full"].ToString();

                        if (Convert.ToDateTime(dmTable.Rows[i]["expect_arrive_date_dm"]).ToString("yyyy-MM-dd") == "0001-01-01")
                        {
                            deliverDr["期望到貨日"] = "";
                        }
                        else
                        {
                            deliverDr["期望到貨日"] = Convert.ToDateTime(dmTable.Rows[i]["expect_arrive_date_dm"]).ToString("yyyy-MM-dd");
                        }
                        //期望到貨時段
                        StringBuilder expectArrivePeriodSb = new StringBuilder();
                        if (dmTable.Rows[i]["expect_arrive_period_dm"].ToString() == "1")
                        {
                            expectArrivePeriodSb.Append("12:00以前");
                        }
                        if (dmTable.Rows[i]["expect_arrive_period_dm"].ToString() == "2")
                        {
                            expectArrivePeriodSb.Append("12:00-17:00");
                        }
                        if (dmTable.Rows[i]["expect_arrive_period_dm"].ToString() == "3")
                        {
                            expectArrivePeriodSb.Append("17:00-20:00");
                        }
                        if (dmTable.Rows[i]["expect_arrive_period_dm"].ToString() == "0")
                        {
                            expectArrivePeriodSb.Append("不限制");
                        }
                        deliverDr["期望到貨時段"] = expectArrivePeriodSb.ToString();
                        if (Convert.ToInt32(dmTable.Rows[i]["deliver_org_days"]) == 0)
                        {
                            deliverDr["預計到貨日"] = "";
                        }
                        else
                        {
                            deliverDr["預計到貨日"] = Convert.ToDateTime(CommonFunction.GetNetTime(Convert.ToInt32(dmTable.Rows[i]["deliver_org_days"]))).ToString("yyyy-MM-dd");
                        }
                        deliverDr["備註"] = dmTable.Rows[i]["dcl_note"].ToString();
                        deliverDt.Rows.Add(deliverDr);                       
                        #endregion
                    }
                    #region MyRegion
                    
                   
                    for (int i = 0; i < dclTable.Rows.Count; i++)
                    {                       
                        dr = _dt.NewRow();
                        StringBuilder sb = new StringBuilder();
                        dr["訂單編號"] = dclTable.Rows[i]["order_id"].ToString();
                        dr["出貨單號"] = dclTable.Rows[i]["deliver_id"].ToString();
                        dr["供應商名稱"] = dclTable.Rows[i]["vendor_name_full"].ToString();
                        if (dclTable.Rows[i]["type"].ToString() == "1")
                        {
                            dr["出貨方式"] = "統倉出貨";
                        }
                        else if (dclTable.Rows[i]["type"].ToString() == "2")
                        {
                            dr["出貨方式"] = "供應商自行出貨";
                        }
                        else
                        //if (dclTable.Rows[i]["type"].ToString() == "101")
                        {
                            dr["出貨方式"] = "其他";
                        }

                        if (dclTable.Rows[i]["dcl_create_type"].ToString() == "1")
                        {
                            dr["異動人"] = dclTable.Rows[i]["dcl_create_username"].ToString();
                            dr["異動類型"] = "前台";
                        }
                        else if (dclTable.Rows[i]["dcl_create_type"].ToString() == "2")
                        {
                            dr["異動人"] = dclTable.Rows[i]["dcl_create_musername"].ToString();
                            dr["異動類型"] = "後台";
                        }
                        dr["異動時間"] = Convert.ToDateTime(dclTable.Rows[i]["dcl_create_datetime"]).ToString("yyyy-MM-dd HH:mm:ss");

                        #region 獲取該出貨單的上一個小時之前的期望到貨日
                        ////aclQuery.time_start = dcl_create_datetime_start.AddHours(-1);
                        //aclQuery.time_end = dcl_create_datetime_end.AddHours(-1);
                        //aclQuery.deliver_id = Convert.ToInt32(dclTable.Rows[i]["deliver_id"]);
                        //System.Data.DataTable Table = _IDeliverChangeLogDao.GetExpectArriveDateByCreatetime(aclQuery);
                        //if (Table.Rows.Count > 0)
                        //{
                        //    if (Convert.ToDateTime(Table.Rows[0]["expect_arrive_date"]).ToString("yyyy-MM-dd") == "0001-01-01")
                        //    {
                        //        dr["原期望到貨日"] = "";
                        //    }
                        //    else
                        //    {
                        //        dr["原期望到貨日"] = Convert.ToDateTime(Table.Rows[0]["expect_arrive_date"]).ToString("yyyy-MM-dd");  
                        //    }                                                   
                        //}
                        //else
                        //{
                        //    dr["原期望到貨日"] = "";
                        //}
                        #endregion

                        if (Convert.ToDateTime(dclTable.Rows[i]["expect_arrive_date_dcl"]).ToString("yyyy-MM-dd") == "0001-01-01")
                        {
                            dr["期望到貨日"] = "";
                        }
                        else
                        {
                            dr["期望到貨日"] = Convert.ToDateTime(dclTable.Rows[i]["expect_arrive_date_dcl"]).ToString("yyyy-MM-dd");
                        }
                        if (dclTable.Rows[i]["expect_arrive_period_dcl"].ToString() == "1")
                        {
                            sb.Append("12:00以前");
                        }
                        if (dclTable.Rows[i]["expect_arrive_period_dcl"].ToString() == "2")
                        {
                            sb.Append("12:00-17:00");
                        }
                        if (dclTable.Rows[i]["expect_arrive_period_dcl"].ToString() == "3")
                        {
                            sb.Append("17:00-20:00");
                        }
                        if (dclTable.Rows[i]["expect_arrive_period_dcl"].ToString() == "0")
                        {
                            sb.Append("不限制");
                        }
                        dr["期望到貨時段"] = sb.ToString();
                        dr["備註"] = dclTable.Rows[i]["dcl_note"].ToString();
                        dr["來源IP"] = dclTable.Rows[i]["dcl_ipfrom"].ToString();
                        TimeSpan ti = aclQuery.time_end-Convert.ToDateTime(dclTable.Rows[i]["dcl_create_datetime"]);
                        dr["異動時段"] = hourNum + "小時以外";
                        dr["時間"] = "0";
                        if (ti.TotalHours < int.Parse(hourNum))
                        {
                            dr["異動時段"] = Convert.ToInt32(ti.TotalHours) + "小時";
                            dr["時間"] = "1";
                        }
                        _dt.Rows.Add(dr);
                        sb.Clear();
                    }
                    #endregion
                    #endregion

                    #region 出貨方式為“供應商自行出貨”的出貨單整理后,發郵件給對應的供應商

                    Dictionary<string, string> vendorDictionary = new Dictionary<string, string>();
                    for (int i = 0; i < deliverDt.Rows.Count; i++)
                    {
                        if (!vendorDictionary.ContainsKey(deliverDt.Rows[i]["出貨單號"].ToString()))
                        {
                            vendorDictionary.Add(deliverDt.Rows[i]["出貨單號"].ToString(), deliverDt.Rows[i]["供應商編號"].ToString());
                        }
                    }

                    List<string> SendEmailVendorIdList = new List<string>();
                    
                    foreach (KeyValuePair<string, string> kvp in vendorDictionary)
                    {
                        DataTable deliverDt_1 = deliverDt.Clone();

                        string MailToAddress_1 = string.Empty;
                        string vendor_name_full = string.Empty;
                        if (!SendEmailVendorIdList.Contains(kvp.Value))
                        {
                            for (int i = 0; i < deliverDt.Rows.Count; i++)
                            {
                                DataRow deliverDr_1 = deliverDt_1.NewRow();
                                if (kvp.Value == deliverDt.Rows[i]["供應商編號"].ToString())
                                {
                                    MailToAddress_1 = deliverDt.Rows[i]["供應商郵箱"].ToString();
                                    vendor_name_full = deliverDt.Rows[i]["供應商名稱"].ToString();

                                    deliverDr_1["訂單編號"] = deliverDt.Rows[i]["訂單編號"].ToString();
                                    deliverDr_1["出貨單號"] = deliverDt.Rows[i]["出貨單號"].ToString();
                                    deliverDr_1["付款完成時間"] = deliverDt.Rows[i]["付款完成時間"].ToString();
                                    //deliverDr_1["供應商編號"] = deliverDt.Rows[i]["供應商編號"].ToString();
                                    //deliverDr_1["供應商郵箱"] = deliverDt.Rows[i]["供應商郵箱"].ToString();
                                    //deliverDr_1["供應商名稱"] = deliverDt.Rows[i]["供應商名稱"].ToString();
                                    deliverDr_1["期望到貨日"] = deliverDt.Rows[i]["期望到貨日"].ToString();
                                    deliverDr_1["期望到貨時段"] = deliverDt.Rows[i]["期望到貨時段"].ToString();
                                    deliverDr_1["預計到貨日"] = deliverDt.Rows[i]["預計到貨日"].ToString();
                                    deliverDr_1["備註"] = deliverDt.Rows[i]["備註"].ToString();

                                    deliverDt_1.Rows.Add(deliverDr_1);
                                }
                            }
                            SendEmailVendorIdList.Add(kvp.Value);
                            BLL.gigade.Common.MailModel mailModel_1 = new Common.MailModel();
                            mailModel_1.MysqlConnectionString = mySqlConnectionString;
                            mailModel_1.MailFromAddress = mailModel.MailFromAddress;
                            mailModel_1.MailHost = mailModel.MailHost;
                            mailModel_1.MailPort = mailModel.MailPort;
                            mailModel_1.MailFromUser = mailModel.MailFromUser;
                            mailModel_1.MailFormPwd = mailModel.MailFormPwd;


                            //string MailBody_1 = "<br/><font size=\"4\">" + "<font color=\"#00BB00\" >" + vendor_name_full + "</font>" + " 您好,在前 " + "<font color=\"#FF0000\" >" + Convert.ToDouble(hourNum)
                            //                      + "</font>" + " 個小時之內,貴公司自行出貨的商品出貨單期望到貨日調整記錄如下:</font><br/><p/>" + GetHtmlByDataTable(deliverDt_1);
                            deliverDt_1.Columns.Remove("供應商編號");
                            deliverDt_1.Columns.Remove("供應商郵箱");
                            deliverDt_1.Columns.Remove("供應商名稱");
                            string MailBody_1 = "<p>吉甲地市集【期望到貨日改變】通知信</p><p><font color=\"#00BB00\" >" + vendor_name_full + "</font> 您好:</p>" +
                                "<p>以下訂單已改變出貨單期望到貨日,訂單資訊如下。</p>" +                                    
                                //"<p>============================================================</p>"+
                                            GetHtmlByDataTable(deliverDt_1) +
                                //"<p>============================================================</p>"+
              "<p>訂單的相關資訊,請至<a href='http://vendor.gigade100.com' style='color:#3399ff;text-decoration: none;'>【後台管理】</a>中查詢。</p>"+
              "<p>※本信由系統寄出,請勿直接回覆!</p>"+
              "有任何問題與建議,歡迎聯絡我們<a href='http://www.gigade100.com/contact_service.php' target='_blank'> <img src='http://www.gigade100.com/images/send_mail.jpg'></a>" +
              "<p>吉甲地市集<a href='http://www.gigade100.com/'>http://www.gigade100.com/</a></p>";

                            string MailTitle_1 = MailTitle;
                            //MailToAddress_1 = "*****@*****.**";
                            BLL.gigade.Common.MailHelper mailHelper = new MailHelper(mailModel_1);
                            //public Boolean SendMailAction(string MailToAddress, string MailTitle, string MailBody)
                            try
                            {
                                mailHelper.SendMailAction(MailToAddress_1, MailTitle_1, MailBody_1 + " ");//給單個供應商發送郵件
                            }
                            catch (Exception)
                            {
                                continue;                               
                            }
                        }                     
                    }
                    #endregion
                }

                #endregion

                if (_dt.Rows.Count == 0)
                {
                    //MailBody = "<br/><p><font size=\"4\">   出貨單期望日在前 <font color=\"#FF0000\" >" + Convert.ToDouble(hourNum) + "</font> 個小時之內沒有調整記錄!</font><p/>";
                }
                else
                {
                    if (isSendMailToGroup.Trim() == "true")
                    {
                        MailBody = "<br/><font size=\"4\">出貨單期望到貨日在前 " + "<font color=\"#FF0000\" >" + Convert.ToDouble(hourNum) + "</font>" + " 個小時之內的調整記錄如下:</font><br/><p/>" + GetHtmlByDataTable(_dt, "時間","0");
                        BLL.gigade.Common.MailHelper mail = new Common.MailHelper(mailModel);
                        mail.SendToGroup(GroupCode, MailTitle, MailBody + " ", false, true); 
                    }                
                }
                return true;
            }
            catch (Exception ex)
            {
                throw new Exception("DeliverChangeLogMgr-->Start-->" + ex.Message, ex);
            }
        } 
Esempio n. 13
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;
                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;
        }
Esempio n. 14
0
        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;
        }
Esempio n. 15
0
        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);
        }
Esempio n. 16
0
        public List<ScheduleConfigQuery> GetScheduleConfigList(ScheduleConfigQuery query)// config 
        {
            try
            {
                List<ScheduleConfigQuery> store = new List<ScheduleConfigQuery>();
                store = _secheduleServiceDao.GetScheduleConfigList(query);
                foreach (var item in store)
                {
                    item.show_create_time = CommonFunction.GetNetTime(item.create_time).ToString("yyyy-MM-dd  HH:mm:ss ");
                    item.show_change_time = CommonFunction.GetNetTime(item.change_time).ToString("yyyy-MM-dd HH:mm:ss ");
                }
                return store;

            }
            catch (Exception ex)
            {

                throw new Exception("SecheduleServiceMgr-->GetScheduleConfigList-->" + ex.Message, ex);
            }
        }
Esempio n. 17
0
 //schedule_config判断是新增 还是 编辑 
 public int SaveScheduleConfigInfo(ScheduleConfigQuery query)
 {
     try
     {
         if (query.rowid == 0)//新增
         {
             return _secheduleServiceDao.ScheduleConfigInfoInsert(query);
         }
         else//編輯
         {
             return _secheduleServiceDao.ScheduleConfigInfoUpdate(query);
         }
     }
     catch (Exception ex)
     {
         throw new Exception("ScheduleServiceMgr-->SaveScheduleConfigInfo-->" + ex.Message);
     }
 }
Esempio n. 18
0
 public int ScheduleConfigInfoInsert(ScheduleConfigQuery query) //插入schedule_config信息
 {
     StringBuilder sql = new StringBuilder();
     query.Replace4MySQL();
     try
     {
         sql.Append("insert into schedule_config ( schedule_code, parameterCode, value,parameterName,create_user,change_user, create_time, change_time) values ");
         sql.AppendFormat("('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')", query.schedule_code, query.parameterCode, query.value, query.parameterName, query.create_user, query.change_user, CommonFunction.GetPHPTime(DateTime.Now.ToString()), CommonFunction.GetPHPTime(DateTime.Now.ToString()));
         return _access.execCommand(sql.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("ScheduleServiceDao-->ScheduleMasterInfoInsert-->" + sql.ToString() + ex.Message);
     }
 }
        } // 獲取 master數據

        public HttpResponseBase GetScheduleConfigList()
        {
            string json = string.Empty;
            ScheduleConfigQuery query = new ScheduleConfigQuery();
            if (!string.IsNullOrEmpty(Request.Params["schedule_code"]))
            {
                query.schedule_code = Request.Params["schedule_code"];
            }
            try
            {
                List<ScheduleConfigQuery> ipodStore = new List<ScheduleConfigQuery>();
                _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString);
                ipodStore = _secheduleServiceMgr.GetScheduleConfigList(query);
                IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
                //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式     
                timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
                json = "{success:true,data:" + JsonConvert.SerializeObject(ipodStore, Formatting.Indented, timeConverter) + "}";//返回json數據
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "{success:false,data:[]}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;

        }// 獲取 config數據
Esempio n. 20
0
 public int ScheduleConfigInfoUpdate(ScheduleConfigQuery query) //更新schedule_config信息
 {
     StringBuilder sql = new StringBuilder();
     query.Replace4MySQL();
     try
     {
         sql.AppendFormat("update schedule_config set schedule_code = '{0}', parameterCode = '{1}', value = '{2}',parameterName='{3}',create_user='******',change_user='******',change_time='{6}' where rowid='{7}' ", query.schedule_code, query.parameterCode, query.value, query.parameterName, query.create_user, query.change_user, CommonFunction.GetPHPTime(DateTime.Now.ToString()), query.rowid);
         return _access.execCommand(sql.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("ScheduleServiceDao-->ScheduleMasterInfoUpdate-->" + sql.ToString() + ex.Message);
     }
 }
        //可以多行刪除數據_config
        public HttpResponseBase ScheduleConfigDelete()
        {
            string json = string.Empty;
            ScheduleConfigQuery query = new ScheduleConfigQuery();
            _secheduleServiceMgr = new ScheduleServiceMgr(mySqlConnectionString);
            try
            {
                string id = Request.Params["id"];
                string[] ids = id.Split(',');
                for (int i = 0; i < ids.Length - 1; i++)
                {
                    query.rowid = int.Parse(ids[i].ToString());
                    _secheduleServiceMgr.ScheduleConfigDelete(query.rowid.ToString());

                }
                json = "{success:true}";
            }
            #region 只刪除一行數據時的代碼段
            //if (!string.IsNullOrEmpty(Request.Params["id"]))
            //{
            //    query.id = Convert.ToUInt32(Request.Params["id"]);
            //}

            //  int _dt = informationMgr.PersonInfromationDelete(query);

            //if (_dt > 0)
            //{
            //    json = "{success:true}";
            //}
            //else
            //{
            //    json = "{success:false}";
            //}  
            #endregion
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "{success:false}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
Esempio n. 22
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;
        }
        public bool SendEMail()
        {
            string json = string.Empty;

            try
            {
                #region
                string schedule_code = "send mail";//Request.Params["schedule_code"].ToString();
                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;
                ScheduleServiceMgr _secheduleServiceMgr;
                List<MailRequest> MR = new List<MailRequest>();
                MailRequest model = new MailRequest();
                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("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;
                        }
                    }
                    else if (!string.IsNullOrEmpty(Request.Params["IsDisplyName"]))
                    {
                        if (Request.Params["IsDisplyName"].ToString().Trim().ToLower() == "false")
                        {
                            IsSeparate = false;
                        }
                        else if (Request.Params["IsDisplyName"].ToString().Trim().ToLower() == "true")
                        {
                            IsSeparate = true;
                        }
                    }
                }
                MailHelper mail = new MailHelper(mailModel);
                _edmcontentMgr = new EdmContentNewMgr(mySqlConnectionString);
                _edmcontentMgr.SendEMail(mail);

                #endregion
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "{success:false}";
            }
            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;
        }
        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
            {
                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;
        }
Esempio n. 27
0
        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;
        }
Esempio n. 28
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;
        }