Exemplo n.º 1
0
    private void SendFax(BusinessEntities.Orders order)
    {
        StringBuilder Fax = new StringBuilder();

        Fax = Fax.Append(Core.Utility.ReadFile(PhysicalApplicationPath + HtmlFolder + "Fax.html"));
        Fax.Replace("{URL}", BaseSiteUrl);
        Fax.Replace("{ORDERNUMBER}", order.OrderID.ToString());
        Fax.Replace("{ORDERDATE}", GetStoreTime().ToString("MM/dd/yyyy HH:mm"));
        Fax.Replace("{FULLNAME}", txtFirstName.Text + " " + txtLastName.Text);
        Fax.Replace("{ADDRESS}", txtAddress.Text + " " + txtCity.Text + ", " + txtZipCode.Text + ", " + txtState.Text);
        Fax.Replace("{PHONE}", txtTelephone.Text);
        if (!String.IsNullOrEmpty(txtMobile.Text))
        {
            Fax.Replace("{MOBILE}", !String.IsNullOrEmpty(txtTelephone.Text) ? " - " + txtMobile.Text : txtMobile.Text);
        }
        else
        {
            Fax.Replace("{MOBILE}", "");
        }
        if (order.OrderTypeID == BusinessEntities.OrderType.Deliver)
        {
            Fax.Replace("{ORDERDELIVERY}", "Pizzaness Delivery");
        }
        else
        {
            Fax.Replace("{ORDERDELIVERY}", "Self Pickup");
        }

        if (order.PaymentMethod == BusinessEntities.PaymentType.OnlinePayment)
        {
            Fax.Replace("{PAYMENTMETHOD}", "Online Payment");
        }
        else
        {
            Fax.Replace("{PAYMENTMETHOD}", "Cash Payment");
        }
        StringBuilder finalTemplate = new StringBuilder();

        for (int i = 0; i < order.OrderDetailsList.Count; i++)
        {
            BusinessEntities.OrderDetails orderDetail = order.OrderDetailsList.ElementAt(i);
            StringBuilder newTemplate = new StringBuilder();
            newTemplate.Append(Core.Utility.ReadFile(PhysicalApplicationPath + HtmlFolder + "FaxOrderDetailTemplate.html"));
            newTemplate.Replace("{ITEMNUMBER}", (i + 1).ToString());
            newTemplate.Replace("{PRODUCTTYPE}", !String.IsNullOrEmpty(orderDetail.CategoryName) ? orderDetail.CategoryName : "");
            newTemplate.Replace("{PRODUCTNAME}", orderDetail.ProductName);
            newTemplate.Replace("{ITEMQUANTITY}", orderDetail.Quantity.ToString());
            newTemplate.Replace("{ITEMPRICE}", orderDetail.ItemTotal.ToString("C2"));
            newTemplate.Replace("{RECIPENTNAME}", orderDetail.RecipientName);
            newTemplate.Replace("{INSTRUCTION}", orderDetail.Comments);

            StringBuilder optionTemplate = new StringBuilder();

            foreach (BusinessEntities.OrderDetailOptions obj in SessionOrderDetailOptionList.ElementAt(i))
            {
                optionTemplate.Append(Core.Utility.ReadFile(PhysicalApplicationPath + HtmlFolder + "OptionTemplate.html"));
                optionTemplate.Replace("{OPTIONSTYPE}", obj.ProductOptionTypeName);
                optionTemplate.Replace("{OPTIONS}", obj.ProductOptionName);
            }
            StringBuilder toppings = new StringBuilder();
            String        previousAddonTypeName = String.Empty;
            StringBuilder toppingTemplate       = new StringBuilder();
            if (orderDetail.IsGroupProduct)
            {
                List <BusinessEntities.OrderDetailSubProduct> subProducts = orderDetail.OrderDetailSubProducts;
                StringBuilder finalSubProductTemplate = new StringBuilder();
                foreach (BusinessEntities.OrderDetailSubProduct subProduct in subProducts)
                {
                    StringBuilder subProductTemplate = new StringBuilder();
                    subProductTemplate.Append(Core.Utility.ReadFile(PhysicalApplicationPath + HtmlFolder + "SubProductTemplate.html"));
                    subProductTemplate.Replace("{PRODUCTNAME}", subProduct.ProductName);
                    subProductTemplate.Replace("{RECIPENTNAME}", subProduct.RecipientName);
                    subProductTemplate.Replace("{INSTRUCTION}", subProduct.Comments);

                    StringBuilder subProductOptionTemplate = new StringBuilder();

                    if (subProduct.OrderDetailSubProductOptions != null)
                    {
                        foreach (BusinessEntities.OrderDetailSubProductOption subProductOption in subProduct.OrderDetailSubProductOptions)
                        {
                            subProductOptionTemplate.Append(Core.Utility.ReadFile(PhysicalApplicationPath + HtmlFolder + "OptionTemplate.html"));
                            subProductOptionTemplate.Replace("{OPTIONSTYPE}", subProductOption.ProductOptionTypeName);
                            subProductOptionTemplate.Replace("{OPTIONS}", subProductOption.ProductOptionName);
                        }
                    }
                    toppings = new StringBuilder();
                    previousAddonTypeName = String.Empty;
                    toppingTemplate       = new StringBuilder();
                    int j = 1;
                    foreach (BusinessEntities.OrderDetailSubProductAdon obj in subProduct.OrderDetailSubProductAdons)
                    {
                        if (obj.SelectedAdonOption != 0)
                        {
                            if (!obj.AdonTypeName.Equals(previousAddonTypeName))
                            {
                                if (!String.IsNullOrEmpty(toppings.ToString()))
                                {
                                    String subString = Utility.GetSubString(toppingTemplate.ToString(),
                                                                            "<!-- Toppings-->", "<!-- End Topping-->",
                                                                            true);
                                    toppingTemplate.Replace(subString, toppings.ToString());
                                }
                                toppings = new StringBuilder();
                                toppingTemplate.Append(
                                    Core.Utility.ReadFile(PhysicalApplicationPath + HtmlFolder + "ToppingTemplate.html"));
                                toppingTemplate.Replace("{TOPPINGTYPE}", obj.AdonTypeName);
                                previousAddonTypeName = obj.AdonTypeName;
                            }
                            toppings.Append(Utility.GetSubString(toppingTemplate.ToString(), "<!-- Toppings-->",
                                                                 "<!-- End Topping-->", false));
                            if (obj.IsDoubleSelected)
                            {
                                toppings.Replace("{DOUBLE}", "Two times ");
                            }
                            else
                            {
                                toppings.Replace("{DOUBLE}", "");
                            }
                            toppings.Replace("{NAME}", obj.AdonName);
                            toppings.Replace("{OPTION}",
                                             ((BusinessEntities.SelectedOption)obj.SelectedAdonOption).ToString());
                        }
                    }

                    if (!String.IsNullOrEmpty(toppings.ToString()))
                    {
                        String subString = Utility.GetSubString(toppingTemplate.ToString(), "<!-- Toppings-->", "<!-- End Topping-->", true);
                        toppingTemplate.Replace(subString, toppings.ToString());
                    }
                    //if(!String.IsNullOrEmpty(subProduct.CrustType))
                    //    subProductTemplate.Replace("<!-- CrustType -->", subProduct.CrustType);
                    subProductTemplate.Replace("<!-- Options -->", subProductOptionTemplate.ToString());
                    subProductTemplate.Replace("<!-- Topping -->", toppingTemplate.ToString());
                    finalSubProductTemplate.Append(subProductTemplate.ToString());
                    if (j != subProduct.OrderDetailSubProductAdons.Count)
                    {
                        finalSubProductTemplate.Append("<tr><td colspan='2' style='border-top:1px solid black;'></td></tr>");
                    }
                }
                newTemplate.Replace("<!--SubProducts-->", finalSubProductTemplate.ToString());
                toppings        = new StringBuilder();
                toppingTemplate = new StringBuilder();
            }
            foreach (BusinessEntities.OrderDetailAdOns obj in SessionOrderAdonList.ElementAt(i))
            {
                if (obj.SelectedAdonOption != 0)
                {
                    if (!obj.AdonTypeName.Equals(previousAddonTypeName))
                    {
                        if (!String.IsNullOrEmpty(toppings.ToString()))
                        {
                            String subString = Utility.GetSubString(toppingTemplate.ToString(), "<!-- Toppings-->",
                                                                    "<!-- End Topping-->", true);
                            toppingTemplate.Replace(subString, toppings.ToString());
                        }
                        toppings = new StringBuilder();
                        toppingTemplate.Append(
                            Core.Utility.ReadFile(PhysicalApplicationPath + HtmlFolder + "FaxToppingTemplate.html"));
                        toppingTemplate.Replace("{TOPPINGTYPE}", obj.AdonTypeName);
                        previousAddonTypeName = obj.AdonTypeName;
                    }
                    toppings.Append(Utility.GetSubString(toppingTemplate.ToString(), "<!-- Toppings-->",
                                                         "<!-- End Topping-->", false));

                    if (obj.IsDoubleSelected)
                    {
                        toppings.Replace("{DOUBLE}", "Two times ");
                    }
                    else
                    {
                        toppings.Replace("{DOUBLE}", "");
                    }
                    toppings.Replace("{NAME}", obj.AdonName);
                    toppings.Replace("{OPTION}", ((BusinessEntities.SelectedOption)obj.SelectedAdonOption).ToString());
                }
            }
            if (!String.IsNullOrEmpty(toppings.ToString()))
            {
                String subString = Utility.GetSubString(toppingTemplate.ToString(), "<!-- Toppings-->", "<!-- End Topping-->", true);
                toppingTemplate.Replace(subString, toppings.ToString());
            }

            newTemplate.Replace("<!--OrderDetailOptions-->", optionTemplate.ToString());
            newTemplate.Replace("<!--OrderDetailToppings-->", toppingTemplate.ToString());

            finalTemplate.Append(newTemplate.ToString());
            //finalTemplate.Append(optionTemplate.ToString());
            //finalTemplate.Append(toppingTemplate.ToString());
        }
        String DetailTemplate = Utility.GetSubString(Fax.ToString(), "<!--DETAIL TEMPLATE-->", "<!--END DETAIL TEMPLATE-->", true);

        DetailTemplate = DetailTemplate.Replace("<!--DETAILTEMPLATE-->", finalTemplate.ToString());

        Fax.Replace(Utility.GetSubString(Fax.ToString(), "<!--DETAIL TEMPLATE-->", "<!--END DETAIL TEMPLATE-->", true), DetailTemplate.ToString());
        Fax.Replace("{TIP}", order.LineTip.ToString("C2"));
        Fax.Replace("{TOTALPRICE}", order.OrderTotal.ToString("C2"));
        if (order.PaymentMethod == BusinessEntities.PaymentType.CashPayment)
        {
            interfax.InterFax client = new InterFax();
            if (ConfigurationManager.AppSettings["AllowFax"].Equals("true"))
            {
                client.Sendfax(ConfigurationManager.AppSettings["FaxUsername"],
                               ConfigurationManager.AppSettings["FaxPassword"],
                               ConfigurationManager.AppSettings["FaxNumber"],
                               System.Text.Encoding.UTF8.GetBytes(Fax.ToString()), "HTML");
            }
            else
            {
                try
                {
                    Core.Utility.SendEmail(ConfigurationManager.AppSettings["DonotReplyEmail"], SessionUser.Username, String.Empty, ConfigurationManager.AppSettings["OrderReceiveEmail"], "New Order Fax", Fax.ToString(), true);
                }
                catch (Exception ex)
                {
                }
            }
        }
        else
        {
            SessionFax = Fax.ToString();
        }
    }
Exemplo n.º 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            LogManager log = new LogManager();
            log.SaveLogData(HttpContext.Current.Session.SessionID, LogLevel.INFO.ToString(),
                            Logger.ReturnFromPayment.ToString(), Common.ReturnFromOnlinePayment(1), null);
            if (!String.IsNullOrEmpty(Request["x_invoice_num"]))
            {
                log.SaveLogData(HttpContext.Current.Session.SessionID, LogLevel.INFO.ToString(),
                                Logger.ReturnFromPayment.ToString(),
                                Common.ReturnFromOnlinePayment(2, Request["x_invoice_num"]), null);
                Int64  orderId             = Convert.ToInt64(Request["x_invoice_num"]);
                String PaymentStatus       = Request["Bank_Message"];
                String TransactionApproved = Request["Transaction_Approved"];

                if ((!String.IsNullOrEmpty(PaymentStatus) && PaymentStatus.ToLower().Equals("approved")) ||
                    (!String.IsNullOrEmpty(TransactionApproved) && TransactionApproved.ToLower().Equals("yes")))
                {
                    log.SaveLogData(HttpContext.Current.Session.SessionID, LogLevel.INFO.ToString(),
                                    Logger.ReturnFromPayment.ToString(), Common.ReturnFromOnlinePayment(3), null);
                    int result = orderManager.OrderPaid(orderId);
                    if (result > 0)
                    {
                        log.SaveLogData(HttpContext.Current.Session.SessionID, LogLevel.INFO.ToString(),
                                        Logger.ReturnFromPayment.ToString(), Common.ReturnFromOnlinePayment(4), null);

                        //Core.Utility.SendEmail(ConfigurationManager.AppSettings["DonotReplyEmail"], SessionUser.Username,
                        //                   String.Empty, ConfigurationManager.AppSettings["OrderReceiveEmail"], "New Order",
                        //                   SessionEmail, true);
                        InterFax client = new InterFax();
                        if (ConfigurationManager.AppSettings["AllowFax"].Equals("true"))
                        {
                            client.Sendfax(ConfigurationManager.AppSettings["FaxUsername"],
                                           ConfigurationManager.AppSettings["FaxPassword"],
                                           ConfigurationManager.AppSettings["FaxNumber"],
                                           System.Text.Encoding.UTF8.GetBytes(SessionFax), "HTML");
                        }
                        log.SaveLogData(HttpContext.Current.Session.SessionID, LogLevel.INFO.ToString(),
                                        Logger.ReturnFromPayment.ToString(), Common.ReturnFromOnlinePayment(5), null);

                        SessionMessage     = "Your order payment has been completed successfully. Order detail has been sent to your registered email and fax to back office for your order process.";
                        SessionMessageType = MessageType.Success;
                        Response.Redirect("~/Default.aspx");
                        SessionFax = SessionEmail = String.Empty;
                    }
                }
                else
                {
                    if (!String.IsNullOrEmpty(Request["x_response_reason_text"]))
                    {
                        txtMessage.Text = "Error:" + Request["x_response_reason_text"];
                    }
                }
            }
        }
        catch (Exception exception)
        {
            txtMessage.Text = (exception.InnerException != null)
                                  ? exception.InnerException.Message
                                  : exception.Message;
        }
    }