Beispiel #1
0
        public override ReturnValue GetMailContent(int orderId, int releaseID, TProgram_Email mi)
        {
            ReturnValue _result = new ReturnValue();

            System.Globalization.NumberFormatInfo nfi = Utilities.CurrentNumberFormat;


            #region getOrderInfo and Check

            TOrderNu _tOrder = new TOrderNu();
            _result = _tOrder.getOrderById(orderId);
            if (_result.Success == false)
            {
                return(_result);
            }

            _tOrder = _result.Object as TOrderNu;


            if (_tOrder.OrderId == 0)
            {
                _result.Success    = false;
                _result.ErrMessage = "the order doesn't exits";

                return(_result);
            }

            TOrderNu _emailAddress = new TOrderNu();
            _result = _emailAddress.getMailAddress(_tOrder.CustomerId);
            if (_result.Success == false)
            {
                return(_result);
            }

            _emailAddress = _result.Object as TOrderNu;



            TOrder_Line_ItemNu _tOrdersDetail = new TOrder_Line_ItemNu();
            _result = _tOrdersDetail.getOrdersDetail(orderId);
            if (_result.Success == false)
            {
                return(_result);
            }

            EntityList _orderDetails = _result.ObjectList;


            if (_orderDetails.Count == 0)
            {
                _result.Success    = false;
                _result.ErrMessage = "the order doesn't exits";

                return(_result);
            }


            #endregion

            try
            {
                #region setup EmailMessage

                EmailMessage _mail = new EmailMessage();

                if (_emailAddress.MailBCC.IndexOf(";") > 0)
                {
                    _emailAddress.MailBCC = _emailAddress.MailBCC.Remove(_emailAddress.MailBCC.Length - 1, 1);
                }

                if (_emailAddress.MailCC.IndexOf(";") > 0)
                {
                    _emailAddress.MailCC = _emailAddress.MailCC.Remove(_emailAddress.MailCC.Length - 1, 1);
                }

                if (_emailAddress.MailTo.IndexOf(";") > 0)
                {
                    _emailAddress.MailTo = _emailAddress.MailTo.Remove(_emailAddress.MailTo.Length - 1, 1);
                }

                mi.BccAddress = _emailAddress.MailBCC;
                mi.CCAddress  = _emailAddress.MailCC;



                #region Order Summary
                string MailContent = mi.FullText
                                     .Replace("&Firstname", _tOrder.FirstName)
                                     .Replace("&zorderid", _tOrder.OrderId.ToString())
                                     .Replace("&OrderDate", _tOrder.OrderDate.ToString("MM/dd/yyyy"))
                                     .Replace("&ztotalproductamount", _tOrder.TotalProductAmount.ToString("C", nfi))
                                     .Replace("&zTotalShipping", (_tOrder.TotalShipping).ToString("C", nfi))
                                     .Replace("&zTotalTax", _tOrder.TotalTax.ToString("C", nfi))
                                     .Replace("&zTotalOrderAmount", _tOrder.TotalOrderAmount.ToString("C", nfi))
                                     .Replace("&ShippingMethod", _tOrder.ShipMethod)
                                     .Replace("&ShippedDate", _tOrder.ShippedDate.Value.ToString("MM/dd/yyyy"));

                #endregion

                #region Order Detail
                string RepeatTemp = "";

                if (MailContent.IndexOf("&orderinfo") > 0)
                {
                    RepeatTemp = " <table width =\"100%\" cellpadding=\"1\"><tr><td >Item No</td><td>Description</td><td >Unit Price</td><td>Quantity</td></tr>";

                    foreach (TOrder_Line_ItemNu drItem in _orderDetails)
                    {
                        RepeatTemp = RepeatTemp + "<tr><td >" + drItem.PartNumber + "</td><td>" + drItem.ProductName
                                     + "</td><td >" + drItem.Price.ToString("C") + "</td><td>" + drItem.Quantity.ToString() + "</td></tr>";
                    }
                    RepeatTemp = RepeatTemp + "</TABLE>";
                }

                MailContent = MailContent.Replace("&orderinfo", RepeatTemp);
                #endregion

                #region Shipping Detail

                RepeatTemp = "";

                if (MailContent.IndexOf("&shipmentnfo") > 0)
                {
                    RepeatTemp = " <table  width =\"100%\" cellpadding=\"1\">";

                    int _packageNumber = 1;

                    TOrder_Line_Shipment_Carton _tOrder_Line_Shipment_Carton = new TOrder_Line_Shipment_Carton();
                    _result = _tOrder_Line_Shipment_Carton.getOrderLineShipmentCartonByOrderID(orderId, releaseID);
                    if (_result.Success == false)
                    {
                        return(_result);
                    }

                    EntityList cartonList = _result.ObjectList;



                    TOrder_Line_Shipment_ASN _tOrder_Line_Shipment_ASN = new TOrder_Line_Shipment_ASN();
                    _result = _tOrder_Line_Shipment_ASN.getOrderLineShipmentASNByOrderID(orderId, releaseID);
                    if (_result.Success == false)
                    {
                        return(_result);
                    }

                    EntityList asnList = _result.ObjectList;



                    foreach (TOrder_Line_Shipment_Carton _carton in cartonList)
                    {
                        if (asnList.Count != 0)
                        {
                            if (string.IsNullOrEmpty(_carton.PACKAGE_TRACE_ID) == false)
                            {
                                RepeatTemp = RepeatTemp + "<tr><td >Package " + _packageNumber.ToString() + "  Tracking Number:" + _carton.PACKAGE_TRACE_ID + "  " +
                                             "(<a href=\"{0}\">TrackOrder</a>)" + "</td></tr>";
                            }
                            else
                            {
                                RepeatTemp = RepeatTemp + "<tr><td >Package " + _packageNumber.ToString() + "  Tracking Number:N/A</td></tr>";
                            }

                            RepeatTemp = RepeatTemp + "<tr><td ><br /> <table width =\"100%\" cellpadding=\"1\"><tr><td > Item No</td>" +
                                         "<td>Description</td><td>Qty in Package</td></tr>";
                            foreach (TOrder_Line_Shipment_ASN _asn in asnList)
                            {
                                TOrder_Line_ItemNu _orderDetail = this.getOrderLine(_orderDetails, _asn);
                                RepeatTemp = RepeatTemp + " <tr><td >" + _orderDetail.PartNumber + "</td><td>" + _orderDetail.ProductName +
                                             "</td><td>" + Convert.ToInt16(Convert.ToDouble(_asn.PIECES_TO_MOVE)).ToString() + "</td></tr>";
                                RepeatTemp = RepeatTemp.Replace("{0}", _orderDetail.TrackingURL + _carton.PACKAGE_TRACE_ID);
                            }

                            RepeatTemp = RepeatTemp + "</table><br /></td></tr>";

                            _packageNumber++;
                        }
                    }


                    RepeatTemp = RepeatTemp + "</TABLE>";
                }

                MailContent = MailContent.Replace("&shipmentnfo", RepeatTemp);

                #endregion


                _mail.HtmlPart = new HtmlAttachment(MailContent);



                _mail.FromAddress = new EmailAddress(mi.RespondTo);
                _mail.Subject     = mi.Subject;

                if (Common.IsTest == true)
                {
                    string[] maillist = Common.TestMailTo.Split(';');
                    foreach (string _item in maillist)
                    {
                        _mail.AddToAddress(new EmailAddress(_item));
                    }

                    _result.Table = Common.TestMailTo;
                }
                else
                {
                    if (string.IsNullOrEmpty(_emailAddress.MailTo) == true)
                    {
                        _result.Success    = false;
                        _result.ErrMessage = "Email To Address is empty";
                        return(_result);
                    }
                    else
                    {
                        string[] bcclist = _emailAddress.MailTo.Split(';');
                        foreach (string _item in bcclist)
                        {
                            _mail.AddToAddress(new EmailAddress(_item));
                        }
                    }

                    _result.Table = _emailAddress.MailTo;
                }


                if (string.IsNullOrEmpty(mi.BccAddress) == false)
                {
                    string[] bcclist = mi.BccAddress.Split(';');
                    foreach (string _item in bcclist)
                    {
                        _mail.AddBccAddress(new EmailAddress(_item));
                    }
                }
                if (string.IsNullOrEmpty(mi.CCAddress) == false)
                {
                    string[] bcclist = mi.CCAddress.Split(';');
                    foreach (string _item in bcclist)
                    {
                        _mail.AddCcAddress(new EmailAddress(_item));
                    }
                }


                _result.ObjectValue = _mail;

                #endregion
            }
            catch (Exception ex)
            {
                _result.Success    = false;
                _result.ErrMessage = ex.ToString();
            }

            return(_result);
        }
Beispiel #2
0
        public override ReturnValue GetMailContent(int orderId, int releaseID, TProgram_Email mi)
        {
            ReturnValue _result = new ReturnValue();


            System.Globalization.NumberFormatInfo nfi = Utilities.CurrentNumberFormat;

            #region getCustomerInfo
            TOrderTF _tOrder = new TOrderTF();
            _result = _tOrder.getOrderById(orderId);
            if (!_result.Success)
            {
                return(_result);
            }
            _tOrder = _result.Object as TOrderTF;

            if (_tOrder.SourceId == 19)
            {
                _result.Code = 19;
                return(_result);
            }


            TCustomer _tCustomer = new TCustomer();
            _result = _tCustomer.getCustomerById(_tOrder.PWPCustomerId);
            if (!_result.Success)
            {
                return(_result);
            }
            _tCustomer = _result.Object as TCustomer;



            TOrder_Line_Item _tOrder_Line_Item = new TOrder_Line_Item();
            _result = _tOrder_Line_Item.getOrderDetailsByOrderId(_tOrder.OrderId, releaseID);
            if (!_result.Success)
            {
                return(_result);
            }
            EntityList _list = _result.ObjectList;

            if (_list.Count == 0)
            {
                return(_result);
            }

            _tOrder_Line_Item = _list[0] as TOrder_Line_Item;

            TShipMethod _tShipMethod = new TShipMethod();
            _result = _tShipMethod.getShipMethodById(_tOrder_Line_Item.ShipMethodId);
            if (!_result.Success)
            {
                return(_result);
            }
            _tShipMethod = _result.Object as TShipMethod;


            TAddress _tBillAddress = new TAddress();
            _result = _tBillAddress.getAddressById(_tOrder.CustomerAddressId);
            if (!_result.Success)
            {
                return(_result);
            }
            _tBillAddress = _result.Object as TAddress;



            TAddress _tShipAddress = new TAddress();
            _result = _tBillAddress.getAddressById(_tOrder.ShipToAddressId);
            if (!_result.Success)
            {
                return(_result);
            }
            _tShipAddress = _result.Object as TAddress;


            TPaymentArrangement _tPaymentArrangement = new TPaymentArrangement();
            _result = _tPaymentArrangement.getPaymentArrangementList(orderId);
            if (!_result.Success)
            {
                return(_result);
            }
            EntityList _paymentList = _result.ObjectList;


            double _paymentApplied     = 0;
            double _estimatedAmountDue = 0;

            foreach (TPaymentArrangement _item in _paymentList)
            {
                if (_item.PayMethodId == 4)
                {
                    _estimatedAmountDue += _item.Amount;
                }
                else
                {
                    _paymentApplied += _item.Amount;
                }
            }



            #endregion


            try
            {
                #region setup EmailMessage

                EmailMessage _mail = new EmailMessage();

                string MailContent = HttpUtility.HtmlDecode(mi.FullHtml);

                #region filter the email content
                MailContent = MailContent.Replace("[CustomerName]", _tCustomer.FirstName == null ? "" : _tCustomer.FirstName.ToString());
                MailContent = MailContent.Replace("[OrderDate]", _tOrder.OrderDate.ToString("MM/dd/yyyy"));

                string siteURL = "http://admin.tecnifibreusa.com/";
                MailContent = MailContent.Replace("[WebSite]", siteURL);
                MailContent = MailContent.Replace("[OrderNumber]", _tOrder.AltOrderNum);
                MailContent = MailContent.Replace("[PONumber]", _tOrder.PONumber);
                MailContent = MailContent.Replace("[CustomerAcct]", _tCustomer.AltCustNum);
                MailContent = MailContent.Replace("[ShipMethod]", _tShipMethod.Description);

                MailContent = MailContent.Replace("[BillingAddress]", _tBillAddress.Company + "<br> " + _tBillAddress.Address1 + " " + _tBillAddress.Address2 + "<br>" + _tBillAddress.City + ", " + _tBillAddress.StateCode + " " + _tBillAddress.PostalCode);
                MailContent = MailContent.Replace("[ShippingAddress]", _tShipAddress.Company + "<br> " + _tShipAddress.Address1 + " " + _tShipAddress.Address2 + "<br>" + _tShipAddress.City + ", " + _tShipAddress.StateCode + " " + _tShipAddress.PostalCode);

                MailContent = MailContent.Replace("[SubTotal]", (_tOrder.TotalWholeSaleAmount - _tOrder.CompProductAmount).ToString("C", Utilities.CurrentNumberFormat));
                MailContent = MailContent.Replace("[Tax]", "(" + Utilities.Round(_tOrder.TaxRate * 100, 2).ToString() + "%)" + (_tOrder.TotalTax - _tOrder.CompTax).ToString("C", Utilities.CurrentNumberFormat));
                MailContent = MailContent.Replace("[Shipping]", (_tOrder.TotalShipping - _tOrder.CompShipingCost).ToString("C", Utilities.CurrentNumberFormat));
                MailContent = MailContent.Replace("[Discount]", (_tOrder.TotalDiscountAmount + _tOrder.CompProductAmount).ToString("C", Utilities.CurrentNumberFormat));
                MailContent = MailContent.Replace("[OrderTotal]", _tOrder.TotalOrderAmount.ToString("C", Utilities.CurrentNumberFormat));

                MailContent = MailContent.Replace("[PaymentApplied]", _paymentApplied.ToString("C", Utilities.CurrentNumberFormat));
                MailContent = MailContent.Replace("[EstimatedAmountDue]", _estimatedAmountDue.ToString("C", Utilities.CurrentNumberFormat));

                MailContent = MailContent.Replace("[BFirstName]", _tBillAddress.FirstName);
                MailContent = MailContent.Replace("[BLastName]", _tBillAddress.LastName);
                MailContent = MailContent.Replace("[SFirstName]", _tShipAddress.FirstName);
                MailContent = MailContent.Replace("[SLastName]", _tShipAddress.LastName);


                StringBuilder OrderItemHTML = new StringBuilder();

                foreach (TOrder_Line_Item _item in _list)
                {
                    OrderItemHTML.Append("<tr>");
                    OrderItemHTML.Append("  <td>" + _item.LineNum + "</td>");
                    OrderItemHTML.Append("<td>" + _item.PartNumber + "</td>");
                    OrderItemHTML.Append("<td>" + _item.ProductName + "</td>");
                    OrderItemHTML.Append("<td>" + _item.Quantity + "</td>");
                    if (_item.ShippedDate != null)
                    {
                        OrderItemHTML.Append("<td>" + _item.ShippedDate.Value.ToString("MM/dd/yyyy") + "</td>");
                    }
                    else
                    {
                        OrderItemHTML.Append("<td></td>");
                    }
                    OrderItemHTML.Append("<td>" + _item.TrackingNumber + "</td>");
                    OrderItemHTML.Append("<td>" + _item.Price.ToString("C", Utilities.CurrentNumberFormat) + "</td>");
                    OrderItemHTML.Append("<td>" + (_item.DiscountAmount + _item.ComAmount).ToString("C", Utilities.CurrentNumberFormat) + "</td>");
                    OrderItemHTML.Append("<td>" + ((_item.ActualPrice - _item.ComAmount) / _item.Quantity).ToString("C", Utilities.CurrentNumberFormat) + "</td>");
                    OrderItemHTML.Append("<td>" + (_item.ActualPrice - _item.ComAmount).ToString("C", Utilities.CurrentNumberFormat) + "</td>");
                    OrderItemHTML.Append("</tr>");
                }
                #endregion


                MailContent = MailContent.Replace("[Items]", OrderItemHTML.ToString());


                _mail.HtmlPart = new HtmlAttachment(MailContent);


                _mail.FromAddress = new EmailAddress(mi.RespondTo);
                _mail.Subject     = mi.Subject;

                if (Common.IsTest == true)
                {
                    string[] maillist = Common.TestMailTo.Split(';');
                    foreach (string _item in maillist)
                    {
                        _mail.AddToAddress(new EmailAddress(_item));
                    }

                    _result.Table = Common.TestMailTo;
                }
                else
                {
                    if (string.IsNullOrEmpty(_tCustomer.Email) == true)
                    {
                        _result.Success    = false;
                        _result.ErrMessage = "Email To Address is empty";
                        return(_result);
                    }
                    else
                    {
                        _mail.AddToAddress(new EmailAddress(_tCustomer.Email));
                    }

                    _result.Table = _tCustomer.Email;
                }


                if (string.IsNullOrEmpty(mi.BccAddress) == false)
                {
                    string[] bcclist = mi.BccAddress.Split(';');
                    foreach (string _item in bcclist)
                    {
                        if (string.IsNullOrEmpty(_item) == false)
                        {
                            _mail.AddBccAddress(new EmailAddress(_item));
                        }
                    }
                }
                if (string.IsNullOrEmpty(mi.CCAddress) == false)
                {
                    string[] bcclist = mi.CCAddress.Split(';');
                    foreach (string _item in bcclist)
                    {
                        if (string.IsNullOrEmpty(_item) == false)
                        {
                            _mail.AddCcAddress(new EmailAddress(_item));
                        }
                    }
                }


                if (string.IsNullOrEmpty(_tCustomer.OrderEmail) == false)
                {
                    _mail.AddCcAddress(new EmailAddress(_tCustomer.OrderEmail));
                }
                if (string.IsNullOrEmpty(_tCustomer.SecondaryEmail) == false)
                {
                    _mail.AddCcAddress(new EmailAddress(_tCustomer.SecondaryEmail));
                }

                if (string.IsNullOrEmpty(_tCustomer.SalesRepEmail) == false)
                {
                    _mail.AddBccAddress(new EmailAddress(_tCustomer.SalesRepEmail));
                }


                _result.ObjectValue = _mail;

                #endregion
            }
            catch (Exception ex)
            {
                _result.Success    = false;
                _result.ErrMessage = ex.ToString();
            }


            return(_result);
        }
Beispiel #3
0
        public virtual ReturnValue GetMailContent(int orderId, int releaseID, TProgram_Email mi)
        {
            ReturnValue _result = new ReturnValue();

            System.Globalization.NumberFormatInfo nfi = Utilities.CurrentNumberFormat;

            #region getOrderInfo and Check

            TOrder _tOrder = new TOrder();
            _result = _tOrder.getOrderById(orderId);
            if (_result.Success == false)
            {
                return(_result);
            }

            _tOrder = _result.Object as TOrder;


            if (_tOrder.OrderId == 0)
            {
                _result.Success    = false;
                _result.ErrMessage = "the order doesn't exists --getOrderById";

                return(_result);
            }



            TOrder_Line_Item _tOrder_Line_Item = new TOrder_Line_Item();
            _result = _tOrder_Line_Item.getOrderDetailsByOrderId(orderId, releaseID);
            if (_result.Success == false)
            {
                return(_result);
            }

            EntityList _orderDetails = _result.ObjectList;


            if (_orderDetails.Count == 0)
            {
                _result.Success    = false;
                _result.ErrMessage = "the order doesn't exists---getOrdersDetail";

                return(_result);
            }


            #endregion

            try
            {
                #region generate Email Content

                EmailMessage _mail = new EmailMessage();

                #region Order Summary

                string MailContent = HttpUtility.HtmlDecode(mi.FullHtml);

                MailContent = MailContent
                              .Replace("{orderid}", _tOrder.AltOrderNum)
                              .Replace("{firstname}", _tOrder.FirstName)
                              .Replace("{shipmethod}", _tOrder.ShipMethodName)
                              .Replace("{ShipCarrier}", _tOrder.ShipCarrier)
                              .Replace("{CustomerName}", _tOrder.FirstName + " " + _tOrder.LastName)
                              .Replace("{trackingnumber}", _tOrder.TrackingNumber)
                              .Replace("{ShipDate}", _tOrder.ShippedDate.Value.ToString("MM/dd/yyyy"));

                #endregion

                TOrder_Line_Item _shipTo = _orderDetails[0] as TOrder_Line_Item;

                string shipinfo = _shipTo.ShipToAddress + "<br>" + _shipTo.ShipToCity + "," + _shipTo.ShipToState + " " + _shipTo.ShipToZip;

                MailContent = MailContent
                              .Replace("{shipmentnfo}", shipinfo);


                #region Shipping Detail

                string RepeatTemp = "";

                if (MailContent.IndexOf("{orderLine}") > 0)
                {
                    RepeatTemp = " <table  width =\"100%\" cellpadding=\"1\"><tr><td>SKU</td><td>Name</td><td>QTY</td></tr>";

                    foreach (TOrder_Line_Item _item in _orderDetails)
                    {
                        RepeatTemp = RepeatTemp + " <tr><td >" + _item.PartNumber + "</td><td>" + _item.ProductName +
                                     "</td><td>" + _item.Quantity.ToString() + "</td></tr>";
                    }

                    RepeatTemp = RepeatTemp + "</table>";
                }

                MailContent = MailContent.Replace("{orderLine}", RepeatTemp);

                #endregion



                #endregion

                _mail.HtmlPart = new HtmlAttachment(MailContent);

                #region setup EmailMessage

                _mail.FromAddress = new EmailAddress(mi.RespondTo);
                _mail.Subject     = mi.Subject.Replace("[Orderid]", _tOrder.AltOrderNum);

                if (Common.IsTest == true)
                {
                    string[] maillist = Common.TestMailTo.Split(';');
                    foreach (string _item in maillist)
                    {
                        _mail.AddToAddress(new EmailAddress(_item));
                    }

                    _result.Table = Common.TestMailTo;
                }
                else
                {
                    if (string.IsNullOrEmpty(_tOrder.Email) == true)
                    {
                        _result.Success    = false;
                        _result.ErrMessage = "Email To Address is empty";
                        return(_result);
                    }
                    else
                    {
                        string[] bcclist = _tOrder.Email.Split(';');
                        foreach (string _item in bcclist)
                        {
                            _mail.AddToAddress(new EmailAddress(_item));
                        }
                    }
                }

                if (string.IsNullOrEmpty(mi.BccAddress) == false)
                {
                    string[] bcclist = mi.BccAddress.Split(';');
                    foreach (string _item in bcclist)
                    {
                        _mail.AddBccAddress(new EmailAddress(_item));
                    }
                }
                if (string.IsNullOrEmpty(mi.CCAddress) == false)
                {
                    string[] bcclist = mi.CCAddress.Split(';');
                    foreach (string _item in bcclist)
                    {
                        _mail.AddCcAddress(new EmailAddress(_item));
                    }
                }

                #endregion

                _result.ObjectValue = _mail;
            }
            catch (Exception ex)
            {
                _result.Success    = false;
                _result.ErrMessage = ex.ToString();
            }



            return(_result);
        }
Beispiel #4
0
        public static ReturnValue SentEmail(TProgram_Email tProgram_Email, EmailFormat emailFormat, int oId, FileAttachment fileAttachment)
        {
            ReturnValue _result = new ReturnValue();

            bool IsTFTestMode = Convert.ToBoolean(System.Configuration.ConfigurationSettings.AppSettings["IsTFTestMode"].ToString());

            if (tProgram_Email.ContentStatusId != 1)
            {
                return(_result);
            }

            EmailMessage _mail = new EmailMessage();

            if (string.IsNullOrEmpty(tProgram_Email.RespondToName) == true)
            {
                _mail.FromAddress = new EmailAddress(tProgram_Email.RespondTo);
            }
            else
            {
                _mail.FromAddress = new EmailAddress(tProgram_Email.RespondTo, tProgram_Email.RespondToName);
            }


            _mail.Subject = tProgram_Email.Subject;

            if (emailFormat == EmailFormat.Html || emailFormat == EmailFormat.Both)
            {
                _mail.HtmlPart = new HtmlAttachment(tProgram_Email.FullHtml);
            }
            if (emailFormat == EmailFormat.Text || emailFormat == EmailFormat.Both)
            {
                _mail.TextPart = new TextAttachment(tProgram_Email.FullText);
            }


            string _emailto = tProgram_Email.ToAddress;

            if (IsTFTestMode == true)
            {
                if (string.IsNullOrEmpty(Common.TestMailTo) == false)
                {
                    string[] ccList = Common.TestMailTo.Split(';');
                    foreach (string ccAddress in ccList)
                    {
                        _mail.AddToAddress(new EmailAddress(ccAddress));
                    }

                    _emailto = Common.TestMailTo;
                }
            }
            else
            {
                if (string.IsNullOrEmpty(tProgram_Email.CCAddress) == false)
                {
                    string[] ccList = tProgram_Email.CCAddress.Split(';');
                    foreach (string ccAddress in ccList)
                    {
                        if (string.IsNullOrEmpty(ccAddress.Trim()) == false)
                        {
                            _mail.AddCcAddress(new EmailAddress(ccAddress));
                        }
                    }
                }


                if (string.IsNullOrEmpty(tProgram_Email.BccAddress) == false)
                {
                    string[] BccList = tProgram_Email.BccAddress.Split(';');
                    foreach (string bccAddress in BccList)
                    {
                        if (string.IsNullOrEmpty(bccAddress.Trim()) == false)
                        {
                            _mail.AddBccAddress(new EmailAddress(bccAddress));
                        }
                    }
                }
                if (string.IsNullOrEmpty(tProgram_Email.ToAddress) == false)
                {
                    string[] ToAddressList = tProgram_Email.ToAddress.Split(';');
                    foreach (string toAddress in ToAddressList)
                    {
                        if (string.IsNullOrEmpty(toAddress.Trim()) == false)
                        {
                            _mail.AddToAddress(new EmailAddress(toAddress));
                        }
                    }
                }
            }

            if (fileAttachment != null)
            {
                _mail.AddMixedAttachment(fileAttachment);
            }

            App_Log_Mail _mailLog = new App_Log_Mail();

            try
            {
                SmtpServer server = new SmtpServer(System.Configuration.ConfigurationSettings.AppSettings["SMTPServer"].ToString(), 25);

                DotNetOpenMail.SmtpAuth.SmtpAuthToken SmtpAuthToken =
                    new DotNetOpenMail.SmtpAuth.SmtpAuthToken(System.Configuration.ConfigurationSettings.AppSettings["SMTPUserName"].ToString(),
                                                              System.Configuration.ConfigurationSettings.AppSettings["SMTPPassword"].ToString());
                server.SmtpAuthToken = SmtpAuthToken;

                bool _success = _mail.Send(server);

                _mailLog.Success = _success;
                _mailLog.Notes   = "";
            }
            catch (Exception ex)
            {
                _mailLog.Success = false;
                _mailLog.Notes   = ex.ToString();
            }
            finally
            {
                _mailLog.AddressBcc  = "AddressBcc:" + (string.IsNullOrEmpty(tProgram_Email.BccAddress) ? "" : tProgram_Email.BccAddress) + " CCAddress:" + (string.IsNullOrEmpty(tProgram_Email.CCAddress) ? "" : tProgram_Email.CCAddress);
                _mailLog.AddressFrom = tProgram_Email.RespondTo;
                _mailLog.AddressTo   = _emailto;


                if (emailFormat == EmailFormat.Html || emailFormat == EmailFormat.Both)
                {
                    _mailLog.Content = tProgram_Email.FullHtml;
                }
                if (emailFormat == EmailFormat.Text || emailFormat == EmailFormat.Both)
                {
                    _mailLog.Content = tProgram_Email.FullText;
                }

                _mailLog.CreatedOn = System.DateTime.Now;
                _mailLog.Subject   = tProgram_Email.Subject;
                _mailLog.Type      = tProgram_Email.EmailTypeId.ToString();
                _mailLog.OId       = oId.ToString();
                _mailLog.IsTest    = IsTFTestMode;
                _mailLog.Save();
            }

            _result.Success    = _mailLog.Success.Value;
            _result.ErrMessage = _mailLog.Notes;

            if (string.IsNullOrEmpty(_mailLog.AddressTo) == true)
            {
                _result.Success = true;
            }

            return(_result);
        }
Beispiel #5
0
        public ReturnValue WishList()
        {
            ReturnValue _result = new ReturnValue();

            #region get TProgram_Email

            TProgram_EmailTF _tProgram_Email = new TProgram_EmailTF();
            _result = _tProgram_Email.getEmailTemplate("WishList");
            if (_result.Success == false)
            {
                Common.Log("getProgram_InfoList---ER \r\n" + _result.ErrMessage);

                Common.SentAlterEmail(1, _result.ErrMessage);

                return(_result);
            }
            else
            {
                Common.Log("getProgram_InfoList---OK");
            }


            _tProgram_Email = _result.Object as TProgram_EmailTF;

            #endregion


            #region get WishList

            TWishList _tWishList = new TWishList();
            _result = _tWishList.getWishList();
            if (_result.Success == false)
            {
                Common.Log("getWishList---ER \r\n" + _result.ErrMessage);

                Common.SentAlterEmail(1, _result.ErrMessage);

                return(_result);
            }
            else
            {
                Common.Log("getWishList---OK");
            }


            #endregion

            EntityList _list = _result.ObjectList;

            int    _successfulRecord = 0;
            int    _failedRecord     = 0;
            string _errorNotes       = "";

            #region sent email

            foreach (TWishList _item in _list)
            {
                string _content = System.Web.HttpUtility.HtmlDecode(_tProgram_Email.FullHtml);

                TProgram_Email _email = _tProgram_Email.Clone() as TProgram_Email;


                _content = _content.Replace("[CustomerName]", _item.FirstName + " " + _item.LastName);


                _email.ToAddress = _item.Email;

                _email.CCAddress  = _email.CCAddress + ";" + _item.OrderEmail + ";" + _item.SecondaryEmail;
                _email.BccAddress = _email.BccAddress + ";" + _item.SalesRepEmail;



                TWishList_Line_Item _tWishList_Line_Item = new TWishList_Line_Item();
                _result = _tWishList_Line_Item.getWishListLineItemByWishListId(_item.Id);
                if (_result.Success == false)
                {
                    _failedRecord++;
                    _errorNotes = _errorNotes + "WishList : " + _item.Id.ToString() + "-getWishListLineItemByWishListId  ---ER \r\n" + _result.ErrMessage + "\r\n";

                    Common.Log("WishList : " + _item.Id.ToString() + "- getWishListLineItemByWishListId ---ER \r\n" + _result.ErrMessage);

                    continue;
                }
                EntityList _lineItem = _result.ObjectList;

                StringBuilder _sb = new StringBuilder();

                foreach (TWishList_Line_Item _line in _lineItem)
                {
                    _sb.Append("<tr><td style=\"border-right:1px solid #000000;  border-bottom:1px solid #000000;\">" + _line.PartNumber + "</td>" +
                               "<td style=\" border-bottom:1px solid #000000;\">" + _line.Name + "</td></tr>");
                }

                _content = _content.Replace("[ProductList]", _sb.ToString());


                _email.FullHtml = _content;

                _result = SentEmail(_email, EmailFormat.Html, _item.Id, null);

                if (_result.Success == false)
                {
                    _failedRecord++;
                    _errorNotes = _errorNotes + "WishList : " + _item.Id.ToString() + "-  ---ER \r\n" + _result.ErrMessage + "\r\n";

                    Common.Log("WishList : " + _item.Id.ToString() + "-  ---ER \r\n" + _result.ErrMessage);

                    continue;
                }



                _result = _item.updateMailInformedOnByWishListId(_item.Id);
                if (_result.Success == false)
                {
                    _failedRecord++;
                    _errorNotes = _errorNotes + "WishList : " + _item.Id.ToString() + "-  ---ER \r\n" + _result.ErrMessage + "\r\n";

                    Common.Log("WishList : " + _item.Id.ToString() + "-  ---ER \r\n" + _result.ErrMessage);

                    continue;
                }


                _successfulRecord++;
                Common.Log("WishList : " + _item.Id.ToString() + "- DueInvoices ---OK");
            }

            #endregion


            if (_failedRecord != 0)
            {
                Common.SentAlterEmail(_failedRecord, _errorNotes);
            }


            return(_result);
        }
Beispiel #6
0
        public ReturnValue PastDue()
        {
            ReturnValue _result = new ReturnValue();

            #region get TProgram_Email

            TProgram_EmailTF _tProgram_Email = new TProgram_EmailTF();
            _result = _tProgram_Email.getEmailTemplate("10DaysPastDue");
            if (_result.Success == false)
            {
                Common.Log("getProgram_InfoList---ER \r\n" + _result.ErrMessage);

                Common.SentAlterEmail(1, _result.ErrMessage);

                return(_result);
            }
            else
            {
                Common.Log("getProgram_InfoList---OK");
            }


            _tProgram_Email = _result.Object as TProgram_EmailTF;

            #endregion


            #region get Invoices

            TInvoice _ttInvoice = new TInvoice();
            _result = _ttInvoice.getPastDueInvoiceList();
            if (_result.Success == false)
            {
                Common.Log("getPastDueInvoiceList---ER \r\n" + _result.ErrMessage);

                Common.SentAlterEmail(1, _result.ErrMessage);

                return(_result);
            }
            else
            {
                Common.Log("getPastDueInvoiceList---OK");
            }


            #endregion

            EntityList _list = _result.ObjectList;

            int    _successfulRecord = 0;
            int    _failedRecord     = 0;
            string _errorNotes       = "";

            #region sent email

            foreach (TInvoice _item in _list)
            {
                string _content = System.Web.HttpUtility.HtmlDecode(_tProgram_Email.FullHtml);

                TProgram_Email _email = _tProgram_Email.Clone() as TProgram_Email;



                DateTime dt1    = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
                DateTime dt3    = new DateTime(_item.DueDate.Year, _item.DueDate.Month, _item.DueDate.Day);
                int      _aging = dt1.Subtract(dt3).Days;

                _content = _content.Replace("[customeraccount]", _item.CustomerAccount)
                           .Replace("[OrderDate]", _item.OrderDate.ToString("MM/dd/yyyy"))
                           .Replace("[aging]", _aging.ToString())
                           .Replace("[invoiceNo]", _item.InvoiceId.ToString())
                           .Replace("[duedate]", _item.DueDate.ToString("MM/dd/yyyy"));

                _email.ToAddress  = _item.Email;
                _email.FullHtml   = _content;
                _email.CCAddress  = _email.CCAddress + ";" + _item.InvoiceEmail;
                _email.BccAddress = _email.BccAddress + ";" + _item.SalesRepEmail;


                #region attached pdf

                TecnifibreInvoicePDF TecnifibreInvoicePDF = new TecnifibreInvoicePDF();
                _result = TecnifibreInvoicePDF.PrintInvoice(_item.InvoiceId);
                if (_result.Success == false)
                {
                    _failedRecord++;
                    _errorNotes = _errorNotes + "Invoice : " + _item.InvoiceId.ToString() + "- TFInvoicePDFGenerator ---ER \r\n" + _result.ErrMessage + "\r\n";

                    Common.Log("Invoice : " + _item.InvoiceId.ToString() + "- TFInvoicePDFGenerator ---ER \r\n" + _result.ErrMessage);

                    continue;
                }



                string pdffilename = "Invoice/TFInvoice_" + _item.InvoiceId.ToString() + ".pdf";

                FileAttachment fileAttachment = new FileAttachment(new FileInfo(pdffilename));

                fileAttachment.ContentType = "application/pdf";



                #endregion



                _result = SentEmail(_email, EmailFormat.Html, _item.InvoiceId, fileAttachment);

                if (_result.Success == false)
                {
                    _failedRecord++;
                    _errorNotes = _errorNotes + "Invoice : " + _item.InvoiceId.ToString() + "- PastDue ---ER \r\n" + _result.ErrMessage + "\r\n";

                    Common.Log("Invoice : " + _item.InvoiceId.ToString() + "- PastDue ---ER \r\n" + _result.ErrMessage);

                    continue;
                }



                _item.PastDueEmailOn = System.DateTime.Now;
                _result = _item.Update();
                if (_result.Success == false)
                {
                    _failedRecord++;
                    _errorNotes = _errorNotes + "Invoice : " + _item.InvoiceId.ToString() + "- DueInvoices ---ER \r\n" + _result.ErrMessage + "\r\n";

                    Common.Log("Invoice : " + _item.InvoiceId.ToString() + "- DueInvoices ---ER \r\n" + _result.ErrMessage);

                    continue;
                }


                _successfulRecord++;
                Common.Log("Invoice : " + _item.InvoiceId.ToString() + "- DueInvoices ---OK");
            }

            #endregion


            if (_failedRecord != 0)
            {
                Common.SentAlterEmail(_failedRecord, _errorNotes);
            }


            return(_result);
        }