Пример #1
0
        public static void SentAlterEmail(int failedRecordCount, string errorNotes)
        {
            if (failedRecordCount == 0 || string.IsNullOrEmpty(errorNotes) == true)
            {
                return;
            }

            Controler Controler = new Controler();

            Controler.getControler();
            Owner _owner = null;

            foreach (Owner _item in Controler.Owners)
            {
                if (_item.OwnerCode == Common.OwnerCode)
                {
                    _owner = _item;
                    break;
                }
            }



            WComm.MyEmail _mail = new MyEmail();

            if (string.IsNullOrEmpty(System.Configuration.ConfigurationSettings.AppSettings["SMTPServer"]) == true)
            {
                _mail.SMTPServer = "localhost";
            }
            else
            {
                _mail.SMTPServer = System.Configuration.ConfigurationSettings.AppSettings["SMTPServer"].ToString();
            }
            if (string.IsNullOrEmpty(System.Configuration.ConfigurationSettings.AppSettings["LogErrorEmailFrom"]) == true)
            {
                _mail.Address_From = "*****@*****.**";
            }
            else
            {
                _mail.Address_From = System.Configuration.ConfigurationSettings.AppSettings["LogErrorEmailFrom"].ToString();
            }

            if (string.IsNullOrEmpty(System.Configuration.ConfigurationSettings.AppSettings["LogErrorEmailTo"]) == true)
            {
                _mail.Address_To = "*****@*****.**";
            }
            else
            {
                _mail.Address_To = System.Configuration.ConfigurationSettings.AppSettings["LogErrorEmailTo"].ToString();
            }


            _mail.Subject = "Failure : [" + _owner.Name + "]  -- " + Common.ProcessType;


            if (Convert.ToBoolean(System.Configuration.ConfigurationSettings.AppSettings["IsTestMode"].ToString()) == true)
            {
                _mail.Subject = "[Test] " + _mail.Subject;
            }

            string _notes = "";

            _notes = _notes + "Program : " + "FIBI" + "\r\n";
            _notes = _notes + "DATE : " + System.DateTime.Now.ToString("yyyy-MM-dd HH:mm CST") + "\r\n";
            _notes = _notes + "Record(s) : " + failedRecordCount.ToString() + "\r\n" + "\r\n";
            _notes = _notes += "DETAILS : " + "\r\n";
            _notes = _notes + errorNotes + "\r\n\r\n";
            _notes = _notes += "This is a ZOYTO CONFIDENTIAL email. Do not reply to this email.";


            _mail.BodyText = _notes;

            string _mailresult = "";

            try
            {
                _mailresult = _mail.Send();
            }
            catch (Exception ex)
            {
                Common.Log("SentAlterEmail---ER \r\n" + ex.ToString());
            }
            if (string.IsNullOrEmpty(_mailresult) == true)
            {
                Common.Log("SentAlterEmail---OK  Failed Record(s): " + failedRecordCount.ToString());
            }
            else
            {
                Common.Log("SentAlterEmail---ER \r\n" + _mailresult);
            }

            string path     = "App_Log_PHTransfer.log";
            string _message = "Date:" + System.DateTime.Now.ToString() + "\r\n" +
                              "Address From:" + _mail.Address_From + "\r\n" +
                              "Address To:" + _mail.Address_To + "\r\n" +
                              "Address Bcc:" + _mail.Bcc + "\r\n" +
                              "Subject:" + _mail.Subject + "\r\n" +
                              _mail.BodyText + "\r\n" +
                              "SMTP Server:" + _mail.SMTPServer + "\r\n\r\n";

            if (!File.Exists(path))
            {
                using (StreamWriter sw = File.CreateText(path))
                {
                    sw.WriteLine(_message);
                }
            }
            else
            {
                using (StreamWriter sw = File.AppendText(path))
                {
                    if ((File.GetAttributes(path) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                    {
                        File.SetAttributes(path, FileAttributes.Normal);
                    }
                    sw.WriteLine(_message);
                }
            }
        }
Пример #2
0
        public ReturnValue Run(string ownerCode, string action, string oid)
        {
            ReturnValue _result = new ReturnValue();

            #region get Owner List

            Controler Controler = new Controler();
            _result = Controler.getControler();
            if (_result.Success == false)
            {
                Common.ProcessError(_result, true);

                return(_result);
            }

            #endregion

            foreach (Owner owner in Controler.Owners)
            {
                if (ownerCode == "999" || ownerCode == owner.OwnerCode.ToString())
                {
                    #region check and set onwer setting

                    bool enableRun = false;
                    if (owner.Actions.ContainsKey(action.ToUpper()) == true)
                    {
                        enableRun = Convert.ToBoolean(owner.Actions[action.ToUpper()].ToString());
                    }

                    if (enableRun == false)
                    {
                        continue;
                    }

                    Common.OwnerCode  = owner.OwnerCode;
                    WComm.ConInfo.Url = owner.RegSubKey;
                    VCBusiness.BaseOrder Order = Common.CreateObject(owner, "Order") as VCBusiness.BaseOrder;
                    Order.Owner = owner;
                    VCBusiness.BaseProduct Product = Common.CreateObject(owner, "Product") as VCBusiness.BaseProduct;
                    Product.Owner      = owner;
                    Common.ProcessType = action;

                    #endregion

                    #region Run function

                    if (action.ToUpper() == "OrderDownload".ToUpper())
                    {
                        Common.Log("Start OrderDownload");
                        _result = Order.Download();
                    }

                    if (action.ToUpper() == "UpdateShipment".ToUpper())
                    {
                        Common.Log("Start Update Shipment");
                        _result = Order.UpdateShipment();
                    }

                    if (action.ToUpper() == "ProductDownload".ToUpper())
                    {
                        Common.Log("Start Product Download");
                        _result = Product.ProductDownload();
                    }

                    if (action.ToUpper() == "UpdateInventoryStatus".ToUpper())
                    {
                        Common.Log("Start UpdateInventoryStatus");
                        _result = Product.UpdateInventoryStatus();
                    }

                    if (action.ToUpper() == "ShipConfirmEmail".ToUpper())
                    {
                        #region ShipConfirmEmail

                        Common.Log("Start ShipConfirmEmail");

                        VCBusiness.Model.TProgram_Email _tProgram_Email = Common.CreateObject(owner, "TProgram_Email") as VCBusiness.Model.TProgram_Email;
                        _result = _tProgram_Email.getEmailTemplate("SHIP_CONFIRMATION");
                        if (_result.Success == false)
                        {
                            return(_result);
                        }

                        _tProgram_Email = _result.Object as TProgram_Email;


                        VCBusiness.EmailFactory EmailFactory = Common.CreateObject(owner, "EmailFactory") as VCBusiness.EmailFactory;
                        _result = EmailFactory.GetMailContent(int.Parse(oid), 1, _tProgram_Email);
                        if (_result.Success == false)
                        {
                            return(_result);
                        }
                        EmailMessage email = _result.ObjectValue as EmailMessage;

                        _result = EmailFactory.SentEmail(int.Parse(oid), 1, email);
                        if (_result.Success == false)
                        {
                            return(_result);
                        }

                        #endregion
                    }



                    if (action.ToUpper() == "ImportDMOrderDetail".ToUpper())
                    {
                        _result = Order.ImportDMOrderDetail(int.Parse(oid));
                    }

                    if (action.ToUpper() == "GenerateInvoicePDF".ToUpper())
                    {
                        VCBusiness.TecnifibreInvoicePDF TecnifibreInvoicePDF = new TecnifibreInvoicePDF();
                        _result = TecnifibreInvoicePDF.PrintInvoice(int.Parse(oid));
                    }

                    if (action.ToUpper() == "InvoiceEmail".ToUpper())
                    {
                        VCBusiness.TecnifibreEmailFactory EmailFactory = new TecnifibreEmailFactory();
                        _result = EmailFactory.ReSentInvoiceEmail();
                    }

                    #region Tecnifibre

                    Tecnifibre Tecnifibre = new Tecnifibre();

                    if (action.ToUpper() == "TFDueInvoices".ToUpper())
                    {
                        Common.Log("Start TFDueInvoices");
                        _result = Tecnifibre.DueInvoices();
                    }

                    if (action.ToUpper() == "TFPastDue".ToUpper())
                    {
                        Common.Log("Start TFPastDue");
                        _result = Tecnifibre.PastDue();
                    }

                    if (action.ToUpper() == "TFCancelOrder".ToUpper())
                    {
                        Common.Log("Start TFCancelOrder");
                        _result = Tecnifibre.CancelHDOrder();
                    }

                    if (action.ToUpper() == "TFWishList".ToUpper())
                    {
                        Common.Log("Start TFWishList");
                        _result = Tecnifibre.WishList();
                    }


                    #endregion


                    #endregion

                    if (_result.Success == false)
                    {
                        Common.ProcessError(_result, false);
                    }

                    Common.Log("Finish");
                }
            }

            return(_result);
        }