protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == "alpha" || e.CommandName == "NoFilter")
        {
            String value = null;
            switch (e.CommandName)
            {
                case ("alpha"):
                    {
                        value = string.Format("{0}%", e.CommandArgument);
                        break;
                    }
                case ("NoFilter"):
                    {
                        value = "%";
                        break;
                    }
            }
            ObjectDataSource1.SelectParameters["LastName"].DefaultValue = value;
            ObjectDataSource1.DataBind();
            RadGrid1.Rebind();
        }
        else if (e.CommandName == "QuickUpdate")
        {
            string UserName, Role;
            var oUser = new User();

            foreach (GridDataItem item in RadGrid1.Items)
            {
                UserName = item.GetDataKeyValue("UserName").ToString();
                Role = ((RadComboBox)item.FindControl("ddlRole")).SelectedValue;

                oUser.ChangeRole(UserName, Role);
            }
        }
        else if (e.CommandName == "DeleteSelected")
        {
            var oAddressBook1 = new AddressBook1();
            var oUser = new User();

            string errorList = "", UserName = "";

            foreach (GridDataItem item in RadGrid1.SelectedItems)
            {
                try
                {
                    var AddressBookID = item.GetDataKeyValue("AddressBookID").ToString();
                    UserName = item["UserName"].Text;
                    oAddressBook1.AddressBook1Delete(AddressBookID);
                    oUser.UserDelete(UserName);
                }
                catch (Exception ex)
                {
                    lblError.Text = ex.Message;
                    if (ex.Message == ((int)ErrorNumber.ConstraintConflicted).ToString())
                        errorList += ", " + UserName;
                }
            }
            if (!string.IsNullOrEmpty(errorList))
            {
                e.Canceled = true;
                string strAlertMessage = "Tài khoản <b>\"" + errorList.Remove(0, 1).Trim() + " \"</b> đang có đơn hàng .<br /> Xin xóa đơn hàng hoặc sử dụng chức năng khoá tài khoản.";
                lblError.Text = strAlertMessage;
            }
            RadGrid1.Rebind();
        }
        else if (e.CommandName == "PerformInsert" || e.CommandName == "Update")
        {
            try
            {
                var command = e.CommandName;
                var row = command == "PerformInsert" ? (GridEditFormInsertItem)e.Item : (GridEditFormItem)e.Item;

                var DistrictID = ((RadComboBox)row.FindControl("ddlDistrict")).SelectedValue;
                var ProvinceID = ((RadComboBox)row.FindControl("ddlProvince")).SelectedValue;
                var RoleName = ((RadComboBox)row.FindControl("ddlRole")).SelectedValue;
                var UserName = ((RadTextBox)row.FindControl("txtUserName")).Text;
                var IsPrimary = "True";
                var CountryID = "1";

                var oUser = new User();


                if (e.CommandName == "PerformInsert")
                {
                    var insertParams = ObjectDataSource1.InsertParameters;

                    insertParams["CountryID"].DefaultValue = CountryID;
                    insertParams["ProvinceID"].DefaultValue = ProvinceID;
                    insertParams["DistrictID"].DefaultValue = DistrictID;
                    insertParams["RoleName"].DefaultValue = RoleName;
                    insertParams["IsPrimary"].DefaultValue = IsPrimary;
                    oUser.ChangeRole(UserName, RoleName);
                }
                else
                {
                    var updateParams = ObjectDataSource1.UpdateParameters;

                    updateParams["CountryID"].DefaultValue = CountryID;
                    updateParams["ProvinceID"].DefaultValue = ProvinceID;
                    updateParams["DistrictID"].DefaultValue = DistrictID;
                    updateParams["RoleName"].DefaultValue = RoleName;
                    updateParams["IsPrimary"].DefaultValue = IsPrimary;
                    oUser.ChangeRole(UserName, RoleName);
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message;
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (!IsPostBack)
        //{
        //    if (Session["OrderNumber"] != null)
        //    {
        //        var oOrder = new Orders();
        //        oOrder.OrdersQuickUpdate_PayStatusID(Session["OrderNumber"].ToString(), "2");
        //        Session["Cart"] = null;
        //        Session["CheckOut"] = null;
        //    }
        //    else
        //        Response.Redirect("~/gio-hang.aspx");
        //}

        if (Session["UserName"] != null)
        {
            string SECURE_SECRET = "";

            //if (Session["PaymentMethod"].ToString() == "onepaynd")
            //    SECURE_SECRET = "A3EFDFABA8653DF2342E8DAC29B51AF0";
            //else if (Session["PaymentMethod"].ToString() == "onepayqt")
            //    SECURE_SECRET = "6D0870CDE5F24F34F3915FB0045120DB";

            if (Session["PaymentMethod"].ToString() == "onepaynd")
                SECURE_SECRET = "04E8DA60020D93506DCC15B7F6A71D26";
            else if (Session["PaymentMethod"].ToString() == "onepayqt")
                SECURE_SECRET = "C7BB42E2BE08E07FDF7210CB381FA04A";

            string hashvalidateResult = "";
            // Khoi tao lop thu vien
            VPCRequest conn = new VPCRequest("http://onepay.vn");
            conn.SetSecureSecret(SECURE_SECRET);
            // Xu ly tham so tra ve va kiem tra chuoi du lieu ma hoa
            hashvalidateResult = conn.Process3PartyResponse(Page.Request.QueryString);
            // Lay gia tri tham so tra ve tu cong thanh toan
            String vpc_TxnResponseCode = conn.GetResultField("vpc_TxnResponseCode", "Unknown");
            string amount = conn.GetResultField("vpc_Amount", "Unknown");
            string localed = conn.GetResultField("vpc_Locale", "Unknown");
            string command = conn.GetResultField("vpc_Command", "Unknown");
            string version = conn.GetResultField("vpc_Version", "Unknown");
            string cardType = conn.GetResultField("vpc_Card", "Unknown");
            string orderInfo = conn.GetResultField("vpc_OrderInfo", "Unknown");
            string merchantID = conn.GetResultField("vpc_Merchant", "Unknown");
            string authorizeID = conn.GetResultField("vpc_AuthorizeId", "Unknown");
            string merchTxnRef = conn.GetResultField("vpc_MerchTxnRef", "Unknown");
            string transactionNo = conn.GetResultField("vpc_TransactionNo", "Unknown");
            string acqResponseCode = conn.GetResultField("vpc_AcqResponseCode", "Unknown");
            string txnResponseCode = vpc_TxnResponseCode;
            string message = conn.GetResultField("vpc_Message", "Unknown");
            var oOrders = new Orders();
            //var oOrderDetail = new OrderDetail();

            var dtCart = Session["Cart"] as DataTable;
            double Amount = 0, sAmount = 0;
            string LastName,
                   FirstName,
                   Address,
                   Email,
                   ProvinceCode,
                   DistrictName,
                   CountryName,
                   Phone,
                   AddressBookID;

            string OrderNumber = Session["OrderNumber"].ToString();
            var UserName = string.IsNullOrEmpty(User.Identity.Name) ? "" : User.Identity.Name;
            var OrderStatusID = "1";
            var ShippingStatusID = "1";
            var PaymentMethodID = Session["PaymentMethod"].ToString();
            var Notes = Session["Message"].ToString();
            var Comission = "";
            var PaymentMethodName = Session["PaymentMethod"] == "money" ? "Tiền Mặt" : (Session["PaymentMethod"] == "onepaynd" ? "Thẻ ATM nội địa qua OnePay" : (Session["PaymentMethod"] == "onepayqt" ? "Thẻ VISA, MASTER qua OnePAY" : "Chuyển khoản trực tiếp"));

            var oAddressBook = new AddressBook();
            var dtAddressBook = oAddressBook.AddressBookSelectOne(Session["ShippingID"].ToString());

            AddressBookID = dtAddressBook.Rows[0]["AddressBookID"].ToString();
            LastName = dtAddressBook.Rows[0]["LastName"].ToString();
            FirstName = dtAddressBook.Rows[0]["FirstName"].ToString();
            Address = dtAddressBook.Rows[0]["Address1"].ToString();
            Email = dtAddressBook.Rows[0]["Email"].ToString();
            ProvinceCode = dtAddressBook.Rows[0]["ProvinceName"].ToString();
            CountryName = dtAddressBook.Rows[0]["CountryName"].ToString();
            DistrictName = dtAddressBook.Rows[0]["DistrictName"].ToString();
            Phone = dtAddressBook.Rows[0]["HomePhone"].ToString();

            var BillingAddressID = AddressBookID;
            var ShippingAddressID = AddressBookID;

            var ShippingPrice = Session["ShippingPrice"];


            var YourName = FirstName + " " + LastName;
            var YourEmail = Email;
            var YourAddress = Address + ", " + DistrictName + ", " + ProvinceCode + ", " + CountryName;

            var To = "*****@*****.**";
            //var To = "*****@*****.**";
            var Subject = "Chúng tôi đã nhận được đơn hàng: " + OrderNumber;
            //var Host = "118.69.199.203";
            //int Port = 25;
            var Host = "smtp.gmail.com";
            int Port = 587;
            //var strMailFromAlias = "*****@*****.**";
            //var Password = "******";
            var strDisplayNameMailFrom = "";
            var From = "*****@*****.**";
            var sPassword = "******";
            //var strDisplayNameMailFrom = "Pandemos - Đặt Hàng";
            //var From = "*****@*****.**";
            //var sPassword = "******";
            bool bEnableSSL = true;

            // Sua lai ham check chuoi ma hoa du lieu
            //if (recive_SecureHash !=doSecureHash)
            if (hashvalidateResult == "CORRECTED" && txnResponseCode.Trim() == "0")
            {
                //Common.ShowAlert(SECURE_SECRET);
                //string Host = "118.69.199.203";
                //int Port = 25;
                //string From = "*****@*****.**";
                //string Password = "******";
                string Body = "<div style='width: 100%; font-size: 11px; font-family: Arial;'>";
                Body += "<h3 style='color: rgb(204,102,0); font-size: 22px; border-bottom-color: gray; border-bottom-width: 1px;border-bottom-style: dashed; margin-bottom: 20px; font-family: Times New Roman;'>Cảm ơn bạn đã đặt hàng/Thanks for Your Order!</h3>";

                Body += "<div style='padding: 10px; background-color: rgb(255,244,234); font-family: Verdana;font-size: 11px; margin-bottom: 20px;'>";
                Body += "<p>Mã số đơn hàng của bạn là <b>" + OrderNumber + "</b>. Chi tiết đơn hàng được liệt kê ở phía dưới. Để theo dõi đơn hàng, xin vui lòng vào mục <a style='font-size: 11px;' href='http://www.pandemos.vn/kiem-tra-don-hang.aspx'>theo dõi đơn hàng</a></p>";
                //Body += "<p>Your order ID is <b>" + OrderNumber + "</b>. A summary of your order is shown below. To view the status of your order <a style='font-size: 11px;' href='http://www.pandemos.vn/theo-doi-don-hang.aspx'>click here.</a></p>";
                Body += "</div>";
                //Body += "<div style='padding: 10px; background-color: rgb(255, 239, 239); font-family: Verdana;font-size: 11px; margin-bottom: 20px;'><p>Để hoàn tất đặt hàng xin vui lòng thanh toán đơn hàng theo một trong các phương thức hiện có trên website</p><p>Your order requires payment before it can be finalized. Please check our website for available methods</p></div>";
                Body += "<div style='padding: 10px; background-color: rgb(255, 239, 239); font-family: Verdana;font-size: 11px; margin-bottom: 20px;'><p>Để hoàn tất đặt hàng xin vui lòng thanh toán đơn hàng theo một trong các phương thức hiện có trên website</p></div>";
                //Body += "<div style='font-family: Verdana; font-size: 11px; margin-bottom: 20px;'><table style='width: 100%' cellpadding='0' cellspacing='0'><tr><td style='width: 50%;'><h4 style='font-size: 18px; margin-bottom: 5px; margin-bottom: 20px;'>Người mua/Buyer</h4><div style='font-size: 11px;font-family: Verdana;'><p><b>" + BuyerName + "</b></p><p>" + Address1 + "</p><p>" + DistrictName1 + "</p><p>" + ProvinceCode1 + "</p></div></td><td style='width: 50%;'><h4 style='font-size: 18px; margin-bottom: 5px; margin-bottom: 20px;'>Người nhận/Recipient</h4><div style='font-size: 11px;font-family: Verdana;'><p><b>" + YourName + "</b></p><p>" + Address + "</p><p>" + DistrictName + "</p><p>" + ProvinceCode + "</p></div></td></tr></table></div>";
                Body += "<div style='font-family: Verdana; font-size: 11px; margin-bottom: 20px;'><table style='width: 100%' cellpadding='0' cellspacing='0'><tr><td style='width: 50%;'><h4 style='font-size: 18px; margin-bottom: 5px; margin-bottom: 20px;'>Người nhận/Recipient</h4><div style='font-size: 11px;font-family: Verdana;'><p><b>" + YourName + "</b></p><p>" + Address + "</p><p>" + DistrictName + "</p><p>" + ProvinceCode + "</p></div></td></tr></table></div>";
                Body += "<div style='font-family: Verdana; font-size: 11px; margin-bottom: 20px;'><h4 style='font-size: 18px;'>Chi tiết đơn hàng/Your Order Contains...</h4>";

                Body += "<div style='font-size: 11px; font-family: Verdana'>";
                //Body += "<p><b>* Hình thức giao hàng</b>: " + DeliveryMethodsEmail + "</p>";
                //Body += "<p><b>* Hình thức thanh toán</b>:" + ServiceName + "</p>";
                Body += "<p><b>* Phương thức thanh toán</b>: " + PaymentMethodName + "</p>";
                //Body += "<p><b>* Ngày - Giờ giao</b>: " + EmailDeliveryDate + "</p>";
                Body += "</div>";

                Body += "<table style='font-size: 11px; font-family: Verdana; padding: 10px; border: 1px solid #C7D7DB; width: 100%;border-collapse: collapse;' cellpadding='0' cellspacing='0'>";
                //Body += "<tr><th align='left' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Sản phẩm/Cart Items</th><th style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Cỡ/Size</th><th style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Số lượng/Qty</th><th align='center' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Giá/Item Price</th><th align='right' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Thành tiền/Item Total</th></tr>";
                Body += "<tr><th align='left' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Sản phẩm/Cart Items</th><th style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Số lượng/Qty</th><th align='center' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Giá/Item Price</th><th align='right' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Thành tiền/Item Total</th></tr>";

                foreach (DataRow dr in dtCart.Rows)
                {
                    string ProductCode = dr["Tag"].ToString();
                    string ProductID = dr["ProductID"].ToString();
                    string ProductName = dr["ProductName"].ToString();
                    string Quantity = dr["Quantity"].ToString();
                    string Price = dr["Price"].ToString();
                    string ProductOptionCategoryName = dr["ProductOptionCategoryName"].ToString();
                    string ProductLengthName = dr["ProductLengthName"].ToString();
                    double tPrice = Convert.ToDouble(Price) * Convert.ToDouble(Quantity);

                    var itemPrice = string.Format("{0:##,###.##}", tPrice).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VND";
                    var sPrice = string.Format("{0:##,###.##}", dr["Price"]).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VND";
                    Amount += Convert.ToDouble(Price) * Convert.ToDouble(Quantity);
                    Body += "<tr>";
                    Body += "<td style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + ProductName + " - " + ProductCode + " - " + ProductOptionCategoryName + " - " + ProductLengthName + "</td>";
                    //Body += "<td align='center' style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + ProductColorName + "</td>";
                    Body += "<td align='center' style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + Quantity + "</td>";
                    Body += "<td align='center' style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + sPrice + "</td>";
                    Body += "<td align='right' style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + itemPrice + "</td>";
                    Body += "</tr>";
                }
                Body += "</table>";
                Body += "<div style='clear: both;'></div>";
                var iShippingPrice =
                    Convert.ToDouble(string.IsNullOrEmpty(ShippingPrice.ToString()) ? "0" : ShippingPrice);
                sAmount = Amount + iShippingPrice;
                //sAmount = Amount;

                var tAmount = string.Format("{0:##,###.##}", Amount).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VNĐ";
                var Shipping = string.Format("{0:##,###.##}", iShippingPrice).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VNĐ";
                var SubTotal = string.Format("{0:##,###.##}", sAmount).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VNĐ";

                Body += "<table style='font-size: 11px; font-family: Verdana; text-align: right; margin: 10px 0; width: 100%; float: right;' cellpadding='0' cellspacing='0'>";
                Body += "<tr><td style='width:85%;'>Thành tiền/Subtotal:</td><td style='width:15%;'>" + tAmount + "</td></tr>";
                Body += "<tr><td>Phí giao hàng/Shipping:</td><td>" + Shipping + "</td></tr>";
                Body += "<tr><td><b>Tổng tiền/Grand Total:</b></td><td><b>" + SubTotal + "</b></td></tr>";
                Body += "</table>";
                Body += "<div style='clear: both;'></div>";
                //Body += "<ul style='font-size: 11px; font-style: italic; padding: 0;margin: 0; list-style-type: none;'>";
                //Body += "<li><b>*</b> Giá sản phẩm chưa bao gồm thuế VAT 10%/ Item price is excluded of 10% VAT</li>";
                //Body += "<li><b>*</b> Xin vui lòng <a style='font-size: 11px;' href='http://www.pandemos.vn/lien-he.aspx'>gọi điện</a> tới Đồng Hồ Anh Minhs-Hoa Trái Cây để thay đổi nếu Quý khách muốn sửa đơn hàng/ Please <a style='font-size: 11px;' href='http://www.pandemos.vn/lien-he.aspx'>call</a> Đồng Hồ Anh Minhs-Hoa Trái Cây if you are in need of making a modification to your Order </li>";
                //Body += "<li><b>*</b> Vui lòng tham khảo các điều khoản về Thay đổi và Hủy đơn hàng trong <a style='font-size: 11px;' href='http://www.pandemos.vn/thoa-thuan-su-dung.aspx'>Thỏa Thuận Sử Dụng</a>/Please check Policy for Order Change and Cancelation in our <a style='font-size: 11px;' href='http://www.pandemos.vn/thoa-thuan-su-dung.aspx'>Term of Use</a></li>";
                //Body += "</ul>";
                Body += "</div>";
                Body += "<div style='font-family:Verdana;font-size:12px;margin-top:10px;'>";
                Body += "<div style='font-size:16px;font-weight:bold;'>=================</div>";
                Body += "<h4 style='font-size:14px;font-family:Verdana;margin:0;padding:0;'>Pandemos</h4>";
                Body += "<div style='font-size:11px;font-family:Verdana;margin-top:5px;padding:0;margin:0;'>";
                Body += "<p>Add: 403, Hai Bà Trưng, Phường 8, Quận 3, Tp HCM.</p>";
                Body += "<p>Tel: (08)3 820 8577 - Hotline: 0902 563 577 </p>";
                //Body += "<p>M: +84 908 xxx xxx>";

                Body += "<p>W: <a href='http://www.pandemos.vn'>www.pandemos.vn</a></p>";
                Body += "<p>E: <a href='mailto:[email protected]'>[email protected]</a></p>";
                Body += "</div>";
                Body += "</div>";
                Body += "</div>";

                //var bSendEmail = Common.SendMail(Host, Port, From, strDisplayNameMailFrom, sPassword, Email, To, Subject, Body, false);
                var bSendEmail = Common.SendMail(Host, Port, From, sPassword, Email, To, Subject, Body, true);
                if (bSendEmail)
                {
                    //oOrders.OrdersInsert1(
                    //    OrderNumber,
                    //    UserName,
                    //    OrderStatusID,
                    //    ShippingStatusID,
                    //    PaymentMethodID,
                    //    BillingAddressID,
                    //    ShippingAddressID,
                    //    Notes,
                    //    Comission,
                    //    "",
                    //    "",
                    //    YourAddress,
                    //    "",
                    //    Email
                    //    );

                    //foreach (DataRow dr in dtCart.Rows)
                    //{
                    //    string ProductID = dr["ProductID"].ToString();
                    //    string Quantity = dr["Quantity"].ToString();
                    //    string Price = dr["Price"].ToString();
                    //    string CreateBy = UserName;
                    //    string ProductOptionCategoryName = dr["ProductOptionCategoryName"].ToString();
                    //    string ProductLengthName = dr["ProductLengthName"].ToString();
                    //    string ProductName = dr["ProductName"].ToString();

                    //    oOrderDetail.OrderDetailInsert1(
                    //       OrderNumber,
                    //       ProductID,
                    //       Quantity,
                    //       Price,
                    //       CreateBy,
                    //       ProductOptionCategoryName,
                    //       ProductLengthName,
                    //       Email
                    //    );
                    //}
                    //OrderNumber = oOrders.OrderID;

                    oOrders.OrdersQuickUpdate_PayStatusID(
                        OrderNumber,
                        "1"
                        );
                }
                //Common.ShowAlert("Bạn đã đặt hàng thành công. Chúng tôi sẽ liên lạc với bạn trong thời gian sớm nhất!");
                vpc_Result.Text = "Giao dịch đã thành công";
                Panel2.Visible = true;
                Session["Cart"] = null;
                Session["CheckOut"] = null;
            }
            else if (hashvalidateResult == "INVALIDATED" && txnResponseCode.Trim() == "0")
            {
                oOrders.OrdersQuickUpdate_PayStatusID(
                        OrderNumber,
                        "2"
                        );
                vpc_Result.Text = "Giao dịch đang chờ xử lý";
                Session["Cart"] = null;
                Session["CheckOut"] = null;
                //Response.Redirect("~/gio-hang.aspx");
            }
            else
            {
                oOrders.OrdersQuickUpdate_PayStatusID(
                        OrderNumber,
                        "3"
                        );
                vpc_Result.Text = "Giao dịch không thành công. Vui lòng tiến hành thanh toán lại";
                Session["Cart"] = null;
                Session["CheckOut"] = null;
                //Response.Redirect("~/gio-hang.aspx");
            }
        }
        else if (Session["Email"] != null)
        {
            string SECURE_SECRET = "";

            //if (Session["PaymentMethod"].ToString() == "onepaynd")
            //    SECURE_SECRET = "A3EFDFABA8653DF2342E8DAC29B51AF0";
            //else if (Session["PaymentMethod"].ToString() == "onepayqt")
            //    SECURE_SECRET = "6D0870CDE5F24F34F3915FB0045120DB";

            if (Session["PaymentMethod"].ToString() == "onepaynd")
                SECURE_SECRET = "04E8DA60020D93506DCC15B7F6A71D26";
            else if (Session["PaymentMethod"].ToString() == "onepayqt")
                SECURE_SECRET = "C7BB42E2BE08E07FDF7210CB381FA04A";

            string hashvalidateResult = "";
            // Khoi tao lop thu vien
            VPCRequest conn = new VPCRequest("http://onepay.vn");
            conn.SetSecureSecret(SECURE_SECRET);
            // Xu ly tham so tra ve va kiem tra chuoi du lieu ma hoa
            hashvalidateResult = conn.Process3PartyResponse(Page.Request.QueryString);
            // Lay gia tri tham so tra ve tu cong thanh toan
            String vpc_TxnResponseCode = conn.GetResultField("vpc_TxnResponseCode", "Unknown");
            string amount = conn.GetResultField("vpc_Amount", "Unknown");
            string localed = conn.GetResultField("vpc_Locale", "Unknown");
            string command = conn.GetResultField("vpc_Command", "Unknown");
            string version = conn.GetResultField("vpc_Version", "Unknown");
            string cardType = conn.GetResultField("vpc_Card", "Unknown");
            string orderInfo = conn.GetResultField("vpc_OrderInfo", "Unknown");
            string merchantID = conn.GetResultField("vpc_Merchant", "Unknown");
            string authorizeID = conn.GetResultField("vpc_AuthorizeId", "Unknown");
            string merchTxnRef = conn.GetResultField("vpc_MerchTxnRef", "Unknown");
            string transactionNo = conn.GetResultField("vpc_TransactionNo", "Unknown");
            string acqResponseCode = conn.GetResultField("vpc_AcqResponseCode", "Unknown");
            string txnResponseCode = vpc_TxnResponseCode;
            string message = conn.GetResultField("vpc_Message", "Unknown");

            var oOrders = new Orders();
            //var oOrderDetail = new OrderDetail();
            var dtCart = Session["Cart"] as DataTable;
            double Amount = 0, sAmount = 0;
            string LastName,
                   FirstName,
                   Address,
                   Email,
                   ProvinceCode,
                   DistrictName,
                   CountryName,
                   Phone,
                   AddressBookID;

            string OrderNumber = Session["OrderNumber"].ToString();
            var UserName = string.IsNullOrEmpty(User.Identity.Name) ? "" : User.Identity.Name;
            var OrderStatusID = "1";
            var ShippingStatusID = "1";
            var PaymentMethodID = Session["PaymentMethod"].ToString();
            var Notes = Session["Message"].ToString();
            var Comission = "";
            var PaymentMethodName = Session["PaymentMethod"] == "money" ? "Tiền Mặt" : (Session["PaymentMethod"] == "onepaynd" ? "Thẻ ATM nội địa qua OnePay" : (Session["PaymentMethod"] == "onepayqt" ? "Thẻ VISA, MASTER qua OnePAY" : "Chuyển khoản trực tiếp"));

            var oAddressBook1 = new AddressBook1();
            var dtAddressBook = oAddressBook1.AddressBook1SelectOne(Session["AddressBookID"].ToString());

            AddressBookID = dtAddressBook.Rows[0]["AddressBookID"].ToString();
            LastName = dtAddressBook.Rows[0]["LastName"].ToString();
            FirstName = dtAddressBook.Rows[0]["FirstName"].ToString();
            Address = dtAddressBook.Rows[0]["Address1"].ToString();
            Email = dtAddressBook.Rows[0]["Email"].ToString();
            ProvinceCode = dtAddressBook.Rows[0]["ProvinceName"].ToString();
            CountryName = dtAddressBook.Rows[0]["CountryName"].ToString();
            DistrictName = dtAddressBook.Rows[0]["DistrictName"].ToString();
            Phone = dtAddressBook.Rows[0]["HomePhone"].ToString();

            var BillingAddressID = AddressBookID;
            var ShippingAddressID = AddressBookID;

            var ShippingPrice = Session["ShippingPrice"];


            var YourName = FirstName + " " + LastName;
            var YourEmail = Email;
            var YourAddress = Address + ", " + DistrictName + ", " + ProvinceCode + ", " + CountryName;

            //var To = "*****@*****.**";
            var To = "*****@*****.**";
            var Subject = "Chúng tôi đã nhận được đơn hàng: " + OrderNumber;
            //var Host = "118.69.199.203";
            //int Port = 25;
            var Host = "smtp.gmail.com";
            int Port = 587;
            //var strMailFromAlias = "*****@*****.**";
            //var Password = "******";
            var strDisplayNameMailFrom = "";
            var From = "*****@*****.**";
            var sPassword = "******";
            //var strDisplayNameMailFrom = "Pandemos - Đặt Hàng";
            //var From = "*****@*****.**";
            //var sPassword = "******";
            bool bEnableSSL = true;
            // Sua lai ham check chuoi ma hoa du lieu
            //if (recive_SecureHash !=doSecureHash)
            if (hashvalidateResult == "CORRECTED" && txnResponseCode.Trim() == "0")
            {
                //Common.ShowAlert(SECURE_SECRET);

                //string Host = "118.69.199.203";
                //int Port = 25;
                //string From = "*****@*****.**";
                //string Password = "******";
                string Body = "<div style='width: 100%; font-size: 11px; font-family: Arial;'>";
                Body += "<h3 style='color: rgb(204,102,0); font-size: 22px; border-bottom-color: gray; border-bottom-width: 1px;border-bottom-style: dashed; margin-bottom: 20px; font-family: Times New Roman;'>Cảm ơn bạn đã đặt hàng/Thanks for Your Order!</h3>";

                Body += "<div style='padding: 10px; background-color: rgb(255,244,234); font-family: Verdana;font-size: 11px; margin-bottom: 20px;'>";
                Body += "<p>Mã số đơn hàng của bạn là <b>" + OrderNumber + "</b>. Chi tiết đơn hàng được liệt kê ở phía dưới. Để theo dõi đơn hàng, xin vui lòng vào mục <a style='font-size: 11px;' href='http://www.pandemos.vn/kiem-tra-don-hang.aspx'>theo dõi đơn hàng</a></p>";
                //Body += "<p>Your order ID is <b>" + OrderNumber + "</b>. A summary of your order is shown below. To view the status of your order <a style='font-size: 11px;' href='http://www.pandemos.vn/theo-doi-don-hang.aspx'>click here.</a></p>";
                Body += "</div>";
                //Body += "<div style='padding: 10px; background-color: rgb(255, 239, 239); font-family: Verdana;font-size: 11px; margin-bottom: 20px;'><p>Để hoàn tất đặt hàng xin vui lòng thanh toán đơn hàng theo một trong các phương thức hiện có trên website</p><p>Your order requires payment before it can be finalized. Please check our website for available methods</p></div>";
                Body += "<div style='padding: 10px; background-color: rgb(255, 239, 239); font-family: Verdana;font-size: 11px; margin-bottom: 20px;'><p>Để hoàn tất đặt hàng xin vui lòng thanh toán đơn hàng theo một trong các phương thức hiện có trên website</p></div>";
                //Body += "<div style='font-family: Verdana; font-size: 11px; margin-bottom: 20px;'><table style='width: 100%' cellpadding='0' cellspacing='0'><tr><td style='width: 50%;'><h4 style='font-size: 18px; margin-bottom: 5px; margin-bottom: 20px;'>Người mua/Buyer</h4><div style='font-size: 11px;font-family: Verdana;'><p><b>" + BuyerName + "</b></p><p>" + Address1 + "</p><p>" + DistrictName1 + "</p><p>" + ProvinceCode1 + "</p></div></td><td style='width: 50%;'><h4 style='font-size: 18px; margin-bottom: 5px; margin-bottom: 20px;'>Người nhận/Recipient</h4><div style='font-size: 11px;font-family: Verdana;'><p><b>" + YourName + "</b></p><p>" + Address + "</p><p>" + DistrictName + "</p><p>" + ProvinceCode + "</p></div></td></tr></table></div>";
                Body += "<div style='font-family: Verdana; font-size: 11px; margin-bottom: 20px;'><table style='width: 100%' cellpadding='0' cellspacing='0'><tr><td style='width: 50%;'><h4 style='font-size: 18px; margin-bottom: 5px; margin-bottom: 20px;'>Người nhận/Recipient</h4><div style='font-size: 11px;font-family: Verdana;'><p><b>" + YourName + "</b></p><p>" + Address + "</p><p>" + DistrictName + "</p><p>" + ProvinceCode + "</p></div></td></tr></table></div>";
                Body += "<div style='font-family: Verdana; font-size: 11px; margin-bottom: 20px;'><h4 style='font-size: 18px;'>Chi tiết đơn hàng/Your Order Contains...</h4>";

                Body += "<div style='font-size: 11px; font-family: Verdana'>";
                //Body += "<p><b>* Hình thức giao hàng</b>: " + DeliveryMethodsEmail + "</p>";
                //Body += "<p><b>* Hình thức thanh toán</b>:" + ServiceName + "</p>";
                Body += "<p><b>* Phương thức thanh toán</b>: " + PaymentMethodName + "</p>";
                //Body += "<p><b>* Ngày - Giờ giao</b>: " + EmailDeliveryDate + "</p>";
                Body += "</div>";

                Body += "<table style='font-size: 11px; font-family: Verdana; padding: 10px; border: 1px solid #C7D7DB; width: 100%;border-collapse: collapse;' cellpadding='0' cellspacing='0'>";
                //Body += "<tr><th align='left' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Sản phẩm/Cart Items</th><th style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Cỡ/Size</th><th style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Số lượng/Qty</th><th align='center' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Giá/Item Price</th><th align='right' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Thành tiền/Item Total</th></tr>";
                Body += "<tr><th align='left' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Sản phẩm/Cart Items</th><th style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Số lượng/Qty</th><th align='center' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Giá/Item Price</th><th align='right' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Thành tiền/Item Total</th></tr>";

                foreach (DataRow dr in dtCart.Rows)
                {
                    string ProductCode = dr["Tag"].ToString();
                    //string ProductID = dr["ProductID"].ToString();
                    string ProductName = dr["ProductName"].ToString();
                    string Quantity = dr["Quantity"].ToString();
                    string Price = dr["Price"].ToString();
                    string ProductOptionCategoryName = dr["ProductOptionCategoryName"].ToString();
                    string ProductLengthName = dr["ProductLengthName"].ToString();
                    double tPrice = Convert.ToDouble(Price) * Convert.ToDouble(Quantity);

                    var itemPrice = string.Format("{0:##,###.##}", tPrice).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VND";
                    var sPrice = string.Format("{0:##,###.##}", dr["Price"]).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VND";
                    Amount += Convert.ToDouble(Price) * Convert.ToDouble(Quantity);
                    Body += "<tr>";
                    Body += "<td style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + ProductName + " - " + ProductCode + " - " + ProductOptionCategoryName + " - " + ProductLengthName + "</td>";
                    //Body += "<td align='center' style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + ProductColorName + "</td>";
                    Body += "<td align='center' style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + Quantity + "</td>";
                    Body += "<td align='center' style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + sPrice + "</td>";
                    Body += "<td align='right' style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + itemPrice + "</td>";
                    Body += "</tr>";
                }
                Body += "</table>";
                Body += "<div style='clear: both;'></div>";
                var iShippingPrice =
                    Convert.ToDouble(string.IsNullOrEmpty(ShippingPrice.ToString()) ? "0" : ShippingPrice);
                sAmount = Amount + iShippingPrice;
                //sAmount = Amount;

                var tAmount = string.Format("{0:##,###.##}", Amount).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VNĐ";
                var Shipping = string.Format("{0:##,###.##}", iShippingPrice).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VNĐ";
                var SubTotal = string.Format("{0:##,###.##}", sAmount).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VNĐ";

                Body += "<table style='font-size: 11px; font-family: Verdana; text-align: right; margin: 10px 0; width: 100%; float: right;' cellpadding='0' cellspacing='0'>";
                Body += "<tr><td style='width:85%;'>Thành tiền/Subtotal:</td><td style='width:15%;'>" + tAmount + "</td></tr>";
                Body += "<tr><td>Phí giao hàng/Shipping:</td><td>" + Shipping + "</td></tr>";
                Body += "<tr><td><b>Tổng tiền/Grand Total:</b></td><td><b>" + SubTotal + "</b></td></tr>";
                Body += "</table>";
                Body += "<div style='clear: both;'></div>";
                //Body += "<ul style='font-size: 11px; font-style: italic; padding: 0;margin: 0; list-style-type: none;'>";
                //Body += "<li><b>*</b> Giá sản phẩm chưa bao gồm thuế VAT 10%/ Item price is excluded of 10% VAT</li>";
                //Body += "<li><b>*</b> Xin vui lòng <a style='font-size: 11px;' href='http://www.pandemos.vn/lien-he.aspx'>gọi điện</a> tới Đồng Hồ Anh Minhs-Hoa Trái Cây để thay đổi nếu Quý khách muốn sửa đơn hàng/ Please <a style='font-size: 11px;' href='http://www.pandemos.vn/lien-he.aspx'>call</a> Đồng Hồ Anh Minhs-Hoa Trái Cây if you are in need of making a modification to your Order </li>";
                //Body += "<li><b>*</b> Vui lòng tham khảo các điều khoản về Thay đổi và Hủy đơn hàng trong <a style='font-size: 11px;' href='http://www.pandemos.vn/thoa-thuan-su-dung.aspx'>Thỏa Thuận Sử Dụng</a>/Please check Policy for Order Change and Cancelation in our <a style='font-size: 11px;' href='http://www.pandemos.vn/thoa-thuan-su-dung.aspx'>Term of Use</a></li>";
                //Body += "</ul>";
                Body += "</div>";
                Body += "<div style='font-family:Verdana;font-size:12px;margin-top:10px;'>";
                Body += "<div style='font-size:16px;font-weight:bold;'>=================</div>";
                Body += "<h4 style='font-size:14px;font-family:Verdana;margin:0;padding:0;'>Pandemos</h4>";
                Body += "<div style='font-size:11px;font-family:Verdana;margin-top:5px;padding:0;margin:0;'>";
                Body += "<p>Add: 403, Hai Bà Trưng, Phường 8, Quận 3, Tp HCM.</p>";
                Body += "<p>Tel: (08)3 820 8577 - Hotline: 0902 563 577 </p>";
                //Body += "<p>M: +84 908 xxx xxx>";

                Body += "<p>W: <a href='http://www.pandemos.vn'>www.pandemos.vn</a></p>";
                Body += "<p>E: <a href='mailto:[email protected]'>[email protected]</a></p>";
                Body += "</div>";
                Body += "</div>";
                Body += "</div>";

                //var bSendEmail = Common.SendMail(Host, Port, From, strDisplayNameMailFrom, sPassword, Email, To, Subject, Body, false);
                var bSendEmail = Common.SendMail(Host, Port, From, sPassword, Email, To, Subject, Body, true);
                if (bSendEmail)
                {
                    //oOrders.OrdersInsert1(
                    //    OrderNumber,
                    //    UserName,
                    //    OrderStatusID,
                    //    ShippingStatusID,
                    //    PaymentMethodID,
                    //    BillingAddressID,
                    //    ShippingAddressID,
                    //    Notes,
                    //    Comission,
                    //    "",
                    //    "",
                    //    YourAddress,
                    //    "",
                    //    Email
                    //    );

                    //foreach (DataRow dr in dtCart.Rows)
                    //{
                    //    string ProductID = dr["ProductID"].ToString();
                    //    string Quantity = dr["Quantity"].ToString();
                    //    string Price = dr["Price"].ToString();
                    //    string CreateBy = UserName;
                    //    string ProductOptionCategoryName = dr["ProductOptionCategoryName"].ToString();
                    //    string ProductLengthName = dr["ProductLengthName"].ToString();
                    //    //string ProductName = dr["ProductName"].ToString();

                    //    oOrderDetail.OrderDetailInsert1(
                    //       OrderNumber,
                    //       ProductID,
                    //       Quantity,
                    //       Price,
                    //       CreateBy,
                    //       ProductOptionCategoryName,
                    //       ProductLengthName,
                    //       Email
                    //    );
                    //}
                    //OrderNumber = oOrders.OrderID;

                    oOrders.OrdersQuickUpdate_PayStatusID(
                        OrderNumber,
                        "1"
                        );
                }
                //Common.ShowAlert("Bạn đã đặt hàng thành công. Chúng tôi sẽ liên lạc với bạn trong thời gian sớm nhất!");
                vpc_Result.Text = "Giao dịch đã thành công";
                Panel2.Visible = true;
                Session["Cart"] = null;
                Session["CheckOut"] = null;
            }
            else if (hashvalidateResult == "INVALIDATED" && txnResponseCode.Trim() == "0")
            {
                oOrders.OrdersQuickUpdate_PayStatusID(
                       OrderNumber,
                       "2"
                       );
                vpc_Result.Text = "Giao dịch đang chờ xử lý";
                Session["Cart"] = null;
                Session["CheckOut"] = null;
                //Response.Redirect("~/gio-hang.aspx");
            }
            else
            {
                oOrders.OrdersQuickUpdate_PayStatusID(
                       OrderNumber,
                       "3"
                       );
                vpc_Result.Text = "Giao dịch không thành công. Vui lòng tiến hành thanh toán lại";
                Session["Cart"] = null;
                Session["CheckOut"] = null;
                //Response.Redirect("~/gio-hang.aspx");
            }
        }
        else
            Response.Redirect("~/login.aspx?returnurl=" + Request.Url.PathAndQuery);
    }
    protected void btnOrder_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {
            var dtCart = Session["Cart"] as DataTable;
            if (dtCart != null)
            {
                var OrderNumber = DateTime.Now.ToString("ddMMyy") + Guid.NewGuid().GetHashCode().ToString("X").Substring(0, 4);
                Session["OrderNumber"] = OrderNumber;
                double Amount = 0, sAmount = 0;
                string LastName,
                       FirstName,
                       Address,
                       Email,
                       Phone,
                       ProvinceCode,
                       DistrictName,
                       CountryName,
                       CountryID,
                       ProvinceID,
                       DistrictID,
                       AddressBookID,
                       strMessage;

                LastName = "";
                FirstName = txtFullName1.Text;
                Address = txtAddress1.Text;
                Email = txtEmail1.Text;
                Phone = txtPhone1.Text;
                ProvinceCode = ddlProvince1.SelectedItem.Text;
                ProvinceID = ddlProvince1.SelectedValue;
                CountryName = "Việt Nam";
                DistrictName = ddlDistrict1.SelectedItem.Text;
                DistrictID = ddlDistrict1.SelectedValue;
                CountryID = "1";
                strMessage = txtMessage1.Text;

                var oAddressBook1 = new AddressBook1();
                if (!string.IsNullOrEmpty(Email))
                {
                    var dvDuplicateEmail = oAddressBook1.AddressBook1SelectAll("", "", "", Email, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "").DefaultView;
                    if (dvDuplicateEmail.Count > 0)
                    {
                        AddressBookID = dvDuplicateEmail[0]["AddressBookID"].ToString();
                        oAddressBook1.AddressBook1Update(AddressBookID, FirstName, LastName, Email, Phone, "", "", "",
                                                         "", Address, "", "", "",
                                                         CountryID, ProvinceID, DistrictID, "True", "True", "True", "");
                    }
                    else
                        AddressBookID = oAddressBook1.AddressBook1Insert1(FirstName, LastName, Email, Phone, "", "", "", "", Address, "", "", "",
                                                  CountryID, ProvinceID, DistrictID, "True", "True", "True", "");
                }

                var ShippingPrice = Session["ShippingPrice"];
                var YourName = FirstName + " " + LastName;
                var YourAddress = Address + ", " + DistrictName + ", " + ProvinceCode + ", " + CountryName;

                var oOrders = new Orders();
                var oOrderDetail = new OrderDetail();
                var dtAddressBook = oAddressBook1.AddressBook1SelectAll("", "", "", Email, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "").DefaultView;
                if (dtAddressBook.Count > 0)
                    AddressBookID = dtAddressBook[0]["AddressBookID"].ToString();
                else
                    AddressBookID = "";

                var OrderID = Session["OrderNumber"].ToString();
                var UserName = string.IsNullOrEmpty(User.Identity.Name) ? "" : User.Identity.Name;
                var OrderStatusID = "1";
                var ShippingStatusID = "1";
                var BillingAddressID = AddressBookID;
                var ShippingAddressID = AddressBookID;
                var Notes = txtMessage1.Text;
                var Comission = "";

                //var To = "*****@*****.**";
                var To = "*****@*****.**";
                var Subject = "Chúng tôi đã nhận được đơn hàng: " + OrderID;
                //var Host = "118.69.199.203";
                //int Port = 25;
                var Host = "smtp.gmail.com";
                int Port = 587;
                var strDisplayNameMailFrom = "";
                var From = "*****@*****.**";
                var sPassword = "******";
                //var strDisplayNameMailFrom = "Pandemos - Đặt Hàng";
                //var From = "*****@*****.**";
                //var sPassword = "******";
                bool bEnableSSL = true;

                if (rbtMoney.Checked)
                {
                    string Body = "<div style='width: 100%; font-size: 11px; font-family: Arial;'>";
                    Body += "<h3 style='color: rgb(204,102,0); font-size: 22px; border-bottom-color: gray; border-bottom-width: 1px;border-bottom-style: dashed; margin-bottom: 20px; font-family: Times New Roman;'>Cảm ơn bạn đã đặt hàng/Thanks for Your Order!</h3>";

                    Body += "<div style='padding: 10px; background-color: rgb(255,244,234); font-family: Verdana;font-size: 11px; margin-bottom: 20px;'>";
                    Body += "<p>Mã số đơn hàng của bạn là <b>" + OrderNumber + "</b>. Chi tiết đơn hàng được liệt kê ở phía dưới. Để theo dõi đơn hàng, xin vui lòng vào mục <a style='font-size: 11px;' href='http://www.pandemos.vn/kiem-tra-don-hang.aspx'>theo dõi đơn hàng</a></p>";
                    //Body += "<p>Your order ID is <b>" + OrderNumber + "</b>. A summary of your order is shown below. To view the status of your order <a style='font-size: 11px;' href='http://www.pandemos.vn/theo-doi-don-hang.aspx'>click here.</a></p>";
                    Body += "</div>";
                    //Body += "<div style='padding: 10px; background-color: rgb(255, 239, 239); font-family: Verdana;font-size: 11px; margin-bottom: 20px;'><p>Để hoàn tất đặt hàng xin vui lòng thanh toán đơn hàng theo một trong các phương thức hiện có trên website</p><p>Your order requires payment before it can be finalized. Please check our website for available methods</p></div>";
                    Body += "<div style='padding: 10px; background-color: rgb(255, 239, 239); font-family: Verdana;font-size: 11px; margin-bottom: 20px;'><p>Để hoàn tất đặt hàng xin vui lòng thanh toán đơn hàng theo một trong các phương thức hiện có trên website</p></div>";
                    //Body += "<div style='font-family: Verdana; font-size: 11px; margin-bottom: 20px;'><table style='width: 100%' cellpadding='0' cellspacing='0'><tr><td style='width: 50%;'><h4 style='font-size: 18px; margin-bottom: 5px; margin-bottom: 20px;'>Người mua/Buyer</h4><div style='font-size: 11px;font-family: Verdana;'><p><b>" + BuyerName + "</b></p><p>" + Address1 + "</p><p>" + DistrictName1 + "</p><p>" + ProvinceCode1 + "</p></div></td><td style='width: 50%;'><h4 style='font-size: 18px; margin-bottom: 5px; margin-bottom: 20px;'>Người nhận/Recipient</h4><div style='font-size: 11px;font-family: Verdana;'><p><b>" + YourName + "</b></p><p>" + Address + "</p><p>" + DistrictName + "</p><p>" + ProvinceCode + "</p></div></td></tr></table></div>";
                    Body += "<div style='font-family: Verdana; font-size: 11px; margin-bottom: 20px;'><table style='width: 100%' cellpadding='0' cellspacing='0'><tr><td style='width: 50%;'><h4 style='font-size: 18px; margin-bottom: 5px; margin-bottom: 20px;'>Người nhận/Recipient</h4><div style='font-size: 11px;font-family: Verdana;'><p><b>" + YourName + "</b></p><p>" + Address + "</p><p>" + DistrictName + "</p><p>" + ProvinceCode + "</p></div></td></tr></table></div>";
                    Body += "<div style='font-family: Verdana; font-size: 11px; margin-bottom: 20px;'><h4 style='font-size: 18px;'>Chi tiết đơn hàng/Your Order Contains...</h4>";

                    Body += "<div style='font-size: 11px; font-family: Verdana'>";
                    //Body += "<p><b>* Hình thức giao hàng</b>: " + DeliveryMethodsEmail + "</p>";
                    //Body += "<p><b>* Hình thức thanh toán</b>:" + ServiceName + "</p>";
                    Body += "<p><b>* Phương thức thanh toán</b>: Tiền mặt</p>";
                    //Body += "<p><b>* Ngày - Giờ giao</b>: " + EmailDeliveryDate + "</p>";
                    Body += "</div>";

                    Body += "<table style='font-size: 11px; font-family: Verdana; padding: 10px; border: 1px solid #C7D7DB; width: 100%;border-collapse: collapse;' cellpadding='0' cellspacing='0'>";
                    //Body += "<tr><th align='left' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Sản phẩm/Cart Items</th><th style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Cỡ/Size</th><th style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Số lượng/Qty</th><th align='center' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Giá/Item Price</th><th align='right' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Thành tiền/Item Total</th></tr>";
                    Body += "<tr><th align='left' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Sản phẩm/Cart Items</th><th style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Số lượng/Qty</th><th align='center' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Giá/Item Price</th><th align='right' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Thành tiền/Item Total</th></tr>";

                    foreach (DataRow dr in dtCart.Rows)
                    {
                        string ProductCode = dr["Tag"].ToString();
                        //string ProductID = dr["ProductID"].ToString();
                        string ProductName = dr["ProductName"].ToString();
                        string Quantity = dr["Quantity"].ToString();
                        string Price = dr["Price"].ToString();
                        string ProductOptionCategoryName = dr["ProductOptionCategoryName"].ToString();
                        string ProductLengthName = dr["ProductLengthName"].ToString();
                        double tPrice = Convert.ToDouble(Price) * Convert.ToDouble(Quantity);

                        var itemPrice = string.Format("{0:##,###.##}", tPrice).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VND";
                        var sPrice = string.Format("{0:##,###.##}", dr["Price"]).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VND";
                        Amount += Convert.ToDouble(Price) * Convert.ToDouble(Quantity);
                        Body += "<tr>";
                        Body += "<td style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + ProductName + " - " + ProductCode + " - " + ProductOptionCategoryName + " - " + ProductLengthName + "</td>";
                        //Body += "<td align='center' style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + ProductColorName + "</td>";
                        Body += "<td align='center' style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + Quantity + "</td>";
                        Body += "<td align='center' style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + sPrice + "</td>";
                        Body += "<td align='right' style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + itemPrice + "</td>";
                        Body += "</tr>";
                    }
                    Body += "</table>";
                    Body += "<div style='clear: both;'></div>";
                    var iShippingPrice =
                        Convert.ToDouble(string.IsNullOrEmpty(ShippingPrice.ToString()) ? "0" : ShippingPrice);
                    sAmount = Amount + iShippingPrice;
                    //sAmount = Amount;

                    var tAmount = string.Format("{0:##,###.##}", Amount).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VNĐ";
                    var Shipping = string.Format("{0:##,###.##}", iShippingPrice).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VNĐ";
                    var SubTotal = string.Format("{0:##,###.##}", sAmount).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VNĐ";

                    Body += "<table style='font-size: 11px; font-family: Verdana; text-align: right; margin: 10px 0; width: 100%; float: right;' cellpadding='0' cellspacing='0'>";
                    Body += "<tr><td style='width:85%;'>Thành tiền/Subtotal:</td><td style='width:15%;'>" + tAmount + "</td></tr>";
                    Body += "<tr><td>Phí giao hàng/Shipping:</td><td>" + Shipping + "</td></tr>";
                    Body += "<tr><td><b>Tổng tiền/Grand Total:</b></td><td><b>" + SubTotal + "</b></td></tr>";
                    Body += "</table>";
                    Body += "<div style='clear: both;'></div>";
                    //Body += "<ul style='font-size: 11px; font-style: italic; padding: 0;margin: 0; list-style-type: none;'>";
                    //Body += "<li><b>*</b> Giá sản phẩm chưa bao gồm thuế VAT 10%/ Item price is excluded of 10% VAT</li>";
                    //Body += "<li><b>*</b> Xin vui lòng <a style='font-size: 11px;' href='http://www.pandemos.vn/lien-he.aspx'>gọi điện</a> tới Đồng Hồ Anh Minhs-Hoa Trái Cây để thay đổi nếu Quý khách muốn sửa đơn hàng/ Please <a style='font-size: 11px;' href='http://www.pandemos.vn/lien-he.aspx'>call</a> Đồng Hồ Anh Minhs-Hoa Trái Cây if you are in need of making a modification to your Order </li>";
                    //Body += "<li><b>*</b> Vui lòng tham khảo các điều khoản về Thay đổi và Hủy đơn hàng trong <a style='font-size: 11px;' href='http://www.pandemos.vn/thoa-thuan-su-dung.aspx'>Thỏa Thuận Sử Dụng</a>/Please check Policy for Order Change and Cancelation in our <a style='font-size: 11px;' href='http://www.pandemos.vn/thoa-thuan-su-dung.aspx'>Term of Use</a></li>";
                    //Body += "</ul>";
                    Body += "</div>";
                    Body += "<div style='font-family:Verdana;font-size:12px;margin-top:10px;'>";
                    Body += "<div style='font-size:16px;font-weight:bold;'>=================</div>";
                    Body += "<h4 style='font-size:14px;font-family:Verdana;margin:0;padding:0;'>Pandemos</h4>";
                    Body += "<div style='font-size:11px;font-family:Verdana;margin-top:5px;padding:0;margin:0;'>";
                    Body += "<p>Add: 403, Hai Bà Trưng , P.8, Quận 3, HCM </p>";
                    Body += "<p>Tel: (08)3 820 8577 - Hotline: 0902 563 577 </p>";
                    //Body += "<p>M: +84 908 xxx xxx>";

                    Body += "<p>W: <a href='http://www.pandemos.vn'>www.pandemos.vn</a></p>";
                    Body += "<p>E: <a href='mailto:[email protected]'>[email protected]</a></p>";
                    Body += "</div>";
                    Body += "</div>";
                    Body += "</div>";

                    var bSendEmail = Common.SendMail(Host, Port, From, sPassword, Email, To, Subject, Body, true);
                    if (bSendEmail)
                    {
                        var PaymentMethodID = "money";
                        oOrders.OrdersInsert1(
                            OrderID,
                            UserName,
                            OrderStatusID,
                            ShippingStatusID,
                            PaymentMethodID,
                            BillingAddressID,
                            ShippingAddressID,
                            Notes,
                            Comission,
                            "",
                            "",
                            YourAddress,
                            "",
                            Email
                            );
                        foreach (DataRow dr in dtCart.Rows)
                        {
                            string ProductID = dr["ProductID"].ToString();
                            string Quantity = dr["Quantity"].ToString();
                            string Price = dr["Price"].ToString();
                            string CreateBy = UserName;
                            string ProductOptionCategoryName = dr["ProductOptionCategoryName"].ToString();
                            string ProductLengthName = dr["ProductLengthName"].ToString();
                            //string ProductName = dr["ProductName"].ToString();
                            //string Type = dr["Tag"].ToString();
                            //string Description = dr["Description"].ToString();

                            oOrderDetail.OrderDetailInsert1(
                               OrderID,
                               ProductID,
                               Quantity,
                               Price,
                               CreateBy,
                               ProductOptionCategoryName,
                               ProductLengthName,
                               Email
                            );
                        }
                        Session["PaymentMethod"] = "money";
                        Session["Message"] = strMessage;
                        Response.Redirect("~/xac-nhan-don-hang.aspx");
                    }
                }
                else if (rbtOnePayNoiDia.Checked)
                {
                    //var dtAddressBook = oAddressBook1.AddressBook1SelectAll("", "", "", Email, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "").DefaultView;
                    //if (dtAddressBook.Count > 0)
                    //    AddressBookID = dtAddressBook[0]["AddressBookID"].ToString();
                    //else
                    //    AddressBookID = "";

                    foreach (DataRow dr in dtCart.Rows)
                    {
                        string Quantity = dr["Quantity"].ToString();
                        string Price = dr["Price"].ToString();
                        Amount += Convert.ToDouble(Price) * Convert.ToDouble(Quantity);
                    }
                    var iShippingPrice =
                        Convert.ToDouble(string.IsNullOrEmpty(ShippingPrice.ToString()) ? "0" : ShippingPrice);
                    sAmount = Amount + iShippingPrice;

                    var PaymentMethodID = "onepaynd";

                    oOrders.OrdersInsert1(
                        OrderNumber,
                        UserName,
                        OrderStatusID,
                        ShippingStatusID,
                        PaymentMethodID,
                        BillingAddressID,
                        ShippingAddressID,
                        Notes,
                        Comission,
                        "",
                        "",
                        YourAddress,
                        "",
                        Email
                        );

                    foreach (DataRow dr in dtCart.Rows)
                    {
                        string ProductID = dr["ProductID"].ToString();
                        string Quantity = dr["Quantity"].ToString();
                        string Price = dr["Price"].ToString();
                        string CreateBy = UserName;
                        string ProductOptionCategoryName = dr["ProductOptionCategoryName"].ToString();
                        string ProductLengthName = dr["ProductLengthName"].ToString();
                        //string ProductName = dr["ProductName"].ToString();

                        oOrderDetail.OrderDetailInsert1(
                           OrderNumber,
                           ProductID,
                           Quantity,
                           Price,
                           CreateBy,
                           ProductOptionCategoryName,
                           ProductLengthName,
                           Email
                        );
                    }

                    var uri = Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, string.Empty) + Request.ApplicationPath;
                    // Core Transaction Fields
                    var vpc_Locale = "vn";
                    var vpc_Version = "2";
                    var vpc_Command = "pay";
                    var vpc_Merchant = "ONEPAY";//Merchant test
                    var vpc_AccessCode = "D67342C2";//AccessCode test
                    //var vpc_Merchant = "PANDEMOS";
                    //var vpc_AccessCode = "JRCFWZTK";
                    var vpc_MerchTxnRef = OrderNumber;
                    var vpc_OrderInfo = OrderNumber;
                    var vpc_Amount = sAmount * 100;
                    var vpc_Currency = "VND";
                    var vpc_ReturnURL = uri + "/thanh-toan-thanh-cong.aspx?ord=" + OrderNumber;
                    //Thong tin khach hang
                    var vpc_SHIP_Street01 = Common.ChangeSymBol(Address);
                    var vpc_SHIP_Provice = Common.ChangeSymBol(DistrictName);
                    var vpc_SHIP_City = Common.ChangeSymBol(ProvinceCode);
                    var vpc_SHIP_Country = "Vietnam";
                    var vpc_Customer_Phone = Common.ChangeSymBol(Phone);
                    var vpc_Customer_Email = Email;
                    var vpc_Customer_Id = "";
                    var vpc_Customer_Name = Common.ChangeSymBol(FirstName);
                    var vpc_TicketNo = "";

                    var vpc_SECURE_SECRET = "A3EFDFABA8653DF2342E8DAC29B51AF0";//Secure Hash test
                    //var vpc_SECURE_SECRET = "04E8DA60020D93506DCC15B7F6A71D26";
                    var vpc_URL_Payment = "https://mtf.onepay.vn/onecomm-pay/vpc.op";//dia chi thanh toan test
                    //var vpc_URL_Payment = "https://onepay.vn/onecomm-pay/vpc.op";//dia chi thanh toan that
                    VPCRequest conn = new VPCRequest(vpc_URL_Payment);
                    conn.SetSecureSecret(vpc_SECURE_SECRET);
                    // Core Transaction Fields
                    conn.AddDigitalOrderField("AgainLink", "http://onepay.vn");
                    conn.AddDigitalOrderField("Title", "onepay paygate");
                    conn.AddDigitalOrderField("vpc_Locale", vpc_Locale);//Chon ngon ngu hien thi tren cong thanh toan (vn/en)
                    conn.AddDigitalOrderField("vpc_Version", vpc_Version);
                    conn.AddDigitalOrderField("vpc_Command", vpc_Command);
                    conn.AddDigitalOrderField("vpc_Merchant", vpc_Merchant);
                    conn.AddDigitalOrderField("vpc_AccessCode", vpc_AccessCode);
                    conn.AddDigitalOrderField("vpc_MerchTxnRef", vpc_MerchTxnRef);
                    conn.AddDigitalOrderField("vpc_OrderInfo", vpc_OrderInfo);
                    conn.AddDigitalOrderField("vpc_Amount", vpc_Amount.ToString());
                    conn.AddDigitalOrderField("vpc_Currency", vpc_Currency);
                    conn.AddDigitalOrderField("vpc_ReturnURL", vpc_ReturnURL);
                    //Thong tin khach hang
                    conn.AddDigitalOrderField("vpc_SHIP_Street01", vpc_SHIP_Street01);
                    conn.AddDigitalOrderField("vpc_SHIP_Provice", vpc_SHIP_Provice);
                    conn.AddDigitalOrderField("vpc_SHIP_City", vpc_SHIP_City);
                    conn.AddDigitalOrderField("vpc_SHIP_Country", vpc_SHIP_Country);
                    conn.AddDigitalOrderField("vpc_Customer_Phone", vpc_Customer_Phone);
                    conn.AddDigitalOrderField("vpc_Customer_Email", vpc_Customer_Email);
                    conn.AddDigitalOrderField("vpc_Customer_Id", vpc_Customer_Id);
                    conn.AddDigitalOrderField("vpc_Customer_Name", vpc_Customer_Name);
                    // Dia chi IP cua khach hang
                    conn.AddDigitalOrderField("vpc_TicketNo", vpc_TicketNo);
                    // Chuyen huong trinh duyet sang cong thanh toan
                    Session["PaymentMethod"] = "onepaynd";
                    Session["Message"] = strMessage;
                    Session["AddressBookID"] = AddressBookID;
                    String url = conn.Create3PartyQueryString();
                    Page.Response.Redirect(url);
                }
                else if (rbtOnePayQuocTe.Checked)
                {
                    //var dtAddressBook = oAddressBook1.AddressBook1SelectAll("", "", "", Email, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "").DefaultView;
                    //if (dtAddressBook.Count > 0)
                    //    AddressBookID = dtAddressBook[0]["AddressBookID"].ToString();
                    //else
                    //    AddressBookID = "";

                    foreach (DataRow dr in dtCart.Rows)
                    {
                        string Quantity = dr["Quantity"].ToString();
                        string Price = dr["Price"].ToString();
                        Amount += Convert.ToDouble(Price) * Convert.ToDouble(Quantity);
                    }
                    var iShippingPrice =
                        Convert.ToDouble(string.IsNullOrEmpty(ShippingPrice.ToString()) ? "0" : ShippingPrice);
                    sAmount = Amount + iShippingPrice;

                    var PaymentMethodID = "onepayqt";

                    oOrders.OrdersInsert1(
                        OrderNumber,
                        UserName,
                        OrderStatusID,
                        ShippingStatusID,
                        PaymentMethodID,
                        BillingAddressID,
                        ShippingAddressID,
                        Notes,
                        Comission,
                        "",
                        "",
                        YourAddress,
                        "",
                        Email
                        );

                    foreach (DataRow dr in dtCart.Rows)
                    {
                        string ProductID = dr["ProductID"].ToString();
                        string Quantity = dr["Quantity"].ToString();
                        string Price = dr["Price"].ToString();
                        string CreateBy = UserName;
                        string ProductOptionCategoryName = dr["ProductOptionCategoryName"].ToString();
                        string ProductLengthName = dr["ProductLengthName"].ToString();
                        //string ProductName = dr["ProductName"].ToString();

                        oOrderDetail.OrderDetailInsert1(
                           OrderNumber,
                           ProductID,
                           Quantity,
                           Price,
                           CreateBy,
                           ProductOptionCategoryName,
                           ProductLengthName,
                           Email
                        );
                    }

                    var uri = Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, string.Empty) + Request.ApplicationPath;
                    // Core Transaction Fields
                    var vpc_Locale = "en";
                    var vpc_Version = "2";
                    var vpc_Command = "pay";
                    var vpc_Merchant = "TESTONEPAY";//Merchant Test
                    var vpc_AccessCode = "6BEB2546";//Access Code Test
                    //var vpc_Merchant = "PANDEMOS";
                    //var vpc_AccessCode = "B94D84AE";
                    var vpc_MerchTxnRef = OrderNumber;
                    var vpc_OrderInfo = OrderNumber;
                    var vpc_Amount = sAmount * 100;
                    var vpc_Currency = "VND";
                    var vpc_ReturnURL = uri + "/thanh-toan-thanh-cong.aspx?ord=" + OrderNumber;
                    //Thong tin khach hang
                    var vpc_SHIP_Street01 = "194 Tran Quang Khai";
                    var vpc_SHIP_Provice = "Hanoi";
                    var vpc_SHIP_City = "Hanoi";
                    var vpc_SHIP_Country = "Vietnam";
                    var vpc_Customer_Phone = "043966668";
                    var vpc_Customer_Email = "*****@*****.**";
                    var vpc_Customer_Id = "onepay_paygate";
                    var vpc_Customer_Name = "";
                    var vpc_TicketNo = "";

                    var vpc_SECURE_SECRET = "6D0870CDE5F24F34F3915FB0045120DB";//Secure Hash test
                    //var vpc_SECURE_SECRET = "C7BB42E2BE08E07FDF7210CB381FA04A";
                    var vpc_URL_Payment = "https://mtf.onepay.vn/vpcpay/vpcpay.op";//dia chi thanh toan test
                    //var vpc_URL_Payment = "https://onepay.vn/vpcpay/vpcpay.op";//dia chi thanh toan that
                    VPCRequest conn = new VPCRequest(vpc_URL_Payment);
                    conn.SetSecureSecret(vpc_SECURE_SECRET);
                    // Core Transaction Fields
                    conn.AddDigitalOrderField("AgainLink", "http://onepay.vn");
                    conn.AddDigitalOrderField("Title", "onepay paygate");
                    conn.AddDigitalOrderField("vpc_Locale", "vn");//Chon ngon ngu hien thi tren cong thanh toan (vn/en)
                    conn.AddDigitalOrderField("vpc_Version", vpc_Version);
                    conn.AddDigitalOrderField("vpc_Command", vpc_Command);
                    conn.AddDigitalOrderField("vpc_Merchant", vpc_Merchant);
                    conn.AddDigitalOrderField("vpc_AccessCode", vpc_AccessCode);
                    conn.AddDigitalOrderField("vpc_MerchTxnRef", vpc_MerchTxnRef);
                    conn.AddDigitalOrderField("vpc_OrderInfo", vpc_OrderInfo);
                    conn.AddDigitalOrderField("vpc_Amount", vpc_Amount.ToString());
                    conn.AddDigitalOrderField("vpc_ReturnURL", vpc_ReturnURL);
                    // Thong tin them ve khach hang. De trong neu khong co thong tin
                    conn.AddDigitalOrderField("vpc_SHIP_Street01", vpc_SHIP_Street01);
                    conn.AddDigitalOrderField("vpc_SHIP_Provice", vpc_SHIP_Provice);
                    conn.AddDigitalOrderField("vpc_SHIP_City", vpc_SHIP_City);
                    conn.AddDigitalOrderField("vpc_SHIP_Country", vpc_SHIP_Country);
                    conn.AddDigitalOrderField("vpc_Customer_Phone", vpc_Customer_Phone);
                    conn.AddDigitalOrderField("vpc_Customer_Email", vpc_Customer_Email);
                    conn.AddDigitalOrderField("vpc_Customer_Id", vpc_Customer_Id);
                    conn.AddDigitalOrderField("vpc_Customer_Name", vpc_Customer_Name);
                    // Dia chi IP cua khach hang
                    conn.AddDigitalOrderField("vpc_TicketNo", vpc_TicketNo);
                    // Chuyen huong trinh duyet sang cong thanh toan
                    Session["PaymentMethod"] = "onepayqt";
                    Session["Message"] = strMessage;
                    Session["AddressBookID"] = AddressBookID;
                    String url = conn.Create3PartyQueryString();
                    Page.Response.Redirect(url);
                }
                else if (rbtEmail.Checked)
                {
                    string Body = "<div style='width: 100%; font-size: 11px; font-family: Arial;'>";
                    Body += "<h3 style='color: rgb(204,102,0); font-size: 22px; border-bottom-color: gray; border-bottom-width: 1px;border-bottom-style: dashed; margin-bottom: 20px; font-family: Times New Roman;'>Cảm ơn bạn đã đặt hàng/Thanks for Your Order!</h3>";

                    Body += "<div style='padding: 10px; background-color: rgb(255,244,234); font-family: Verdana;font-size: 11px; margin-bottom: 20px;'>";
                    Body += "<p>Mã số đơn hàng của bạn là <b>" + OrderNumber + "</b>. Chi tiết đơn hàng được liệt kê ở phía dưới. Để theo dõi đơn hàng, xin vui lòng vào mục <a style='font-size: 11px;' href='http://www.pandemos.vn/kiem-tra-don-hang.aspx'>theo dõi đơn hàng</a></p>";
                    //Body += "<p>Your order ID is <b>" + OrderNumber + "</b>. A summary of your order is shown below. To view the status of your order <a style='font-size: 11px;' href='http://www.pandemos.vn/theo-doi-don-hang.aspx'>click here.</a></p>";
                    Body += "</div>";
                    //Body += "<div style='padding: 10px; background-color: rgb(255, 239, 239); font-family: Verdana;font-size: 11px; margin-bottom: 20px;'><p>Để hoàn tất đặt hàng xin vui lòng thanh toán đơn hàng theo một trong các phương thức hiện có trên website</p><p>Your order requires payment before it can be finalized. Please check our website for available methods</p></div>";
                    Body += "<div style='padding: 10px; background-color: rgb(255, 239, 239); font-family: Verdana;font-size: 11px; margin-bottom: 20px;'><p>Để hoàn tất đặt hàng xin vui lòng thanh toán đơn hàng theo một trong các phương thức hiện có trên website</p></div>";
                    //Body += "<div style='font-family: Verdana; font-size: 11px; margin-bottom: 20px;'><table style='width: 100%' cellpadding='0' cellspacing='0'><tr><td style='width: 50%;'><h4 style='font-size: 18px; margin-bottom: 5px; margin-bottom: 20px;'>Người mua/Buyer</h4><div style='font-size: 11px;font-family: Verdana;'><p><b>" + BuyerName + "</b></p><p>" + Address1 + "</p><p>" + DistrictName1 + "</p><p>" + ProvinceCode1 + "</p></div></td><td style='width: 50%;'><h4 style='font-size: 18px; margin-bottom: 5px; margin-bottom: 20px;'>Người nhận/Recipient</h4><div style='font-size: 11px;font-family: Verdana;'><p><b>" + YourName + "</b></p><p>" + Address + "</p><p>" + DistrictName + "</p><p>" + ProvinceCode + "</p></div></td></tr></table></div>";
                    Body += "<div style='font-family: Verdana; font-size: 11px; margin-bottom: 20px;'><table style='width: 100%' cellpadding='0' cellspacing='0'><tr><td style='width: 50%;'><h4 style='font-size: 18px; margin-bottom: 5px; margin-bottom: 20px;'>Người nhận/Recipient</h4><div style='font-size: 11px;font-family: Verdana;'><p><b>" + YourName + "</b></p><p>" + Address + "</p><p>" + DistrictName + "</p><p>" + ProvinceCode + "</p></div></td></tr></table></div>";
                    Body += "<div style='font-family: Verdana; font-size: 11px; margin-bottom: 20px;'><h4 style='font-size: 18px;'>Chi tiết đơn hàng/Your Order Contains...</h4>";

                    Body += "<div style='font-size: 11px; font-family: Verdana'>";
                    //Body += "<p><b>* Hình thức giao hàng</b>: " + DeliveryMethodsEmail + "</p>";
                    //Body += "<p><b>* Hình thức thanh toán</b>:" + ServiceName + "</p>";
                    Body += "<p><b>* Phương thức thanh toán</b>: Thanh toán bằng chuyển khoản trực tiếp</p>";
                    //Body += "<p><b>* Ngày - Giờ giao</b>: " + EmailDeliveryDate + "</p>";
                    Body += "</div>";

                    Body += "<table style='font-size: 11px; font-family: Verdana; padding: 10px; border: 1px solid #C7D7DB; width: 100%;border-collapse: collapse;' cellpadding='0' cellspacing='0'>";
                    //Body += "<tr><th align='left' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Sản phẩm/Cart Items</th><th style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Cỡ/Size</th><th style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Số lượng/Qty</th><th align='center' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Giá/Item Price</th><th align='right' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Thành tiền/Item Total</th></tr>";
                    Body += "<tr><th align='left' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Sản phẩm/Cart Items</th><th style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Số lượng/Qty</th><th align='center' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Giá/Item Price</th><th align='right' style='padding: 8px 5px; border-collapse: collapse; background-color: rgb(2,11,111);color: #fff;'>Thành tiền/Item Total</th></tr>";

                    foreach (DataRow dr in dtCart.Rows)
                    {
                        string ProductCode = dr["Tag"].ToString();
                        //string ProductID = dr["ProductID"].ToString();
                        string ProductName = dr["ProductName"].ToString();
                        string Quantity = dr["Quantity"].ToString();
                        string Price = dr["Price"].ToString();
                        string ProductOptionCategoryName = dr["ProductOptionCategoryName"].ToString();
                        string ProductLengthName = dr["ProductLengthName"].ToString();
                        double tPrice = Convert.ToDouble(Price) * Convert.ToDouble(Quantity);

                        var itemPrice = string.Format("{0:##,###.##}", tPrice).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VND";
                        var sPrice = string.Format("{0:##,###.##}", dr["Price"]).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VND";
                        Amount += Convert.ToDouble(Price) * Convert.ToDouble(Quantity);
                        Body += "<tr>";
                        Body += "<td style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + ProductName + " - " + ProductCode + " - " + ProductOptionCategoryName + " - " + ProductLengthName + "</td>";
                        //Body += "<td align='center' style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + ProductColorName + "</td>";
                        Body += "<td align='center' style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + Quantity + "</td>";
                        Body += "<td align='center' style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + sPrice + "</td>";
                        Body += "<td align='right' style='padding: 5px; border-collapse: collapse; border-bottom: 1px solid #C7D7DB;'>" + itemPrice + "</td>";
                        Body += "</tr>";
                    }
                    Body += "</table>";
                    Body += "<div style='clear: both;'></div>";
                    var iShippingPrice =
                        Convert.ToDouble(string.IsNullOrEmpty(ShippingPrice.ToString()) ? "0" : ShippingPrice);
                    sAmount = Amount + iShippingPrice;
                    //sAmount = Amount;

                    var tAmount = string.Format("{0:##,###.##}", Amount).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VNĐ";
                    var Shipping = string.Format("{0:##,###.##}", iShippingPrice).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VNĐ";
                    var SubTotal = string.Format("{0:##,###.##}", sAmount).Replace('.', '*').Replace(',', '.').Replace('*', ',') + " VNĐ";

                    Body += "<table style='font-size: 11px; font-family: Verdana; text-align: right; margin: 10px 0; width: 100%; float: right;' cellpadding='0' cellspacing='0'>";
                    Body += "<tr><td style='width:85%;'>Thành tiền/Subtotal:</td><td style='width:15%;'>" + tAmount + "</td></tr>";
                    Body += "<tr><td>Phí giao hàng/Shipping:</td><td>" + Shipping + "</td></tr>";
                    Body += "<tr><td><b>Tổng tiền/Grand Total:</b></td><td><b>" + SubTotal + "</b></td></tr>";
                    Body += "</table>";
                    Body += "<div style='clear: both;'></div>";
                    //Body += "<ul style='font-size: 11px; font-style: italic; padding: 0;margin: 0; list-style-type: none;'>";
                    //Body += "<li><b>*</b> Giá sản phẩm chưa bao gồm thuế VAT 10%/ Item price is excluded of 10% VAT</li>";
                    //Body += "<li><b>*</b> Xin vui lòng <a style='font-size: 11px;' href='http://www.pandemos.vn/lien-he.aspx'>gọi điện</a> tới Đồng Hồ Anh Minhs-Hoa Trái Cây để thay đổi nếu Quý khách muốn sửa đơn hàng/ Please <a style='font-size: 11px;' href='http://www.pandemos.vn/lien-he.aspx'>call</a> Đồng Hồ Anh Minhs-Hoa Trái Cây if you are in need of making a modification to your Order </li>";
                    //Body += "<li><b>*</b> Vui lòng tham khảo các điều khoản về Thay đổi và Hủy đơn hàng trong <a style='font-size: 11px;' href='http://www.pandemos.vn/thoa-thuan-su-dung.aspx'>Thỏa Thuận Sử Dụng</a>/Please check Policy for Order Change and Cancelation in our <a style='font-size: 11px;' href='http://www.pandemos.vn/thoa-thuan-su-dung.aspx'>Term of Use</a></li>";
                    //Body += "</ul>";
                    Body += "</div>";
                    Body += "<div style='font-family:Verdana;font-size:12px;margin-top:10px;'>";
                    Body += "<div style='font-size:16px;font-weight:bold;'>=================</div>";
                    Body += "<h4 style='font-size:14px;font-family:Verdana;margin:0;padding:0;'>Pandemos</h4>";
                    Body += "<div style='font-size:11px;font-family:Verdana;margin-top:5px;padding:0;margin:0;'>";
                    Body += "<p>Add: 403, Hai Bà Trưng , P.8, Quận 3, HCM </p>";
                    Body += "<p>Tel: (08)3 820 8577 - Hotline: 0902 563 577 </p>";
                    //Body += "<p>M: +84 908 xxx xxx>";

                    Body += "<p>W: <a href='http://www.pandemos.vn'>www.pandemos.vn</a></p>";
                    Body += "<p>E: <a href='mailto:[email protected]'>[email protected]</a></p>";
                    Body += "</div>";
                    Body += "</div>";
                    Body += "</div>";

                    //var bSendEmail = Common.SendMail(Host, Port, From, strDisplayNameMailFrom, sPassword, Email, To, Subject, Body, false);
                    var bSendEmail = Common.SendMail(Host, Port, From, sPassword, Email, To, Subject, Body, true);
                    if (bSendEmail)
                    {
                        //var oOrders = new Orders();
                        //var oOrderDetail = new OrderDetail();
                        //var dtAddressBook = oAddressBook1.AddressBook1SelectAll("", "", "", Email, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "").DefaultView;
                        //if (dtAddressBook.Count > 0)
                        //    AddressBookID = dtAddressBook[0]["AddressBookID"].ToString();
                        //else
                        //    AddressBookID = "";
                        //string OrderID = Session["OrderNumber"].ToString();
                        //var UserName = string.IsNullOrEmpty(User.Identity.Name) ? "" : User.Identity.Name;
                        //var OrderStatusID = "1";
                        //var ShippingStatusID = "1";
                        var PaymentMethodID = "transfer";
                        //var BillingAddressID = AddressBookID;
                        //var ShippingAddressID = AddressBookID;
                        //var Notes = txtMessage1.Text;
                        //var Comission = "";

                        oOrders.OrdersInsert1(
                            OrderID,
                            UserName,
                            OrderStatusID,
                            ShippingStatusID,
                            PaymentMethodID,
                            BillingAddressID,
                            ShippingAddressID,
                            Notes,
                            Comission,
                            "",
                            "",
                            YourAddress,
                            "",
                            Email
                            );
                        foreach (DataRow dr in dtCart.Rows)
                        {
                            string ProductID = dr["ProductID"].ToString();
                            string Quantity = dr["Quantity"].ToString();
                            string Price = dr["Price"].ToString();
                            string CreateBy = UserName;
                            string ProductOptionCategoryName = dr["ProductOptionCategoryName"].ToString();
                            string ProductLengthName = dr["ProductLengthName"].ToString();
                            //string ProductName = dr["ProductName"].ToString();
                            //string Type = dr["Tag"].ToString();
                            //string Description = dr["Description"].ToString();

                            oOrderDetail.OrderDetailInsert1(
                               OrderID,
                               ProductID,
                               Quantity,
                               Price,
                               CreateBy,
                               ProductOptionCategoryName,
                               ProductLengthName,
                               Email
                            );
                        }
                        Session["PaymentMethod"] = "transfer";
                        Session["Message"] = strMessage;
                        Response.Redirect("~/xac-nhan-don-hang.aspx");
                    }
                }
            }
        }
    }
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == "alpha" || e.CommandName == "NoFilter")
        {
            String value = null;
            switch (e.CommandName)
            {
                case ("alpha"):
                    {
                        value = string.Format("{0}%", e.CommandArgument);
                        break;
                    }
                case ("NoFilter"):
                    {
                        value = "%";
                        break;
                    }
            }
            ObjectDataSource1.SelectParameters["Company"].DefaultValue = value;
            ObjectDataSource1.DataBind();
            RadGrid1.Rebind();
        }
        else if (e.CommandName == "QuickUpdate")
        {
            string AddressBookID, Priority, IsShowOnHomePage, IsHot, IsNew, IsAvailable;
            var oAđdressBook = new AddressBook1();

            foreach (GridDataItem item in RadGrid1.Items)
            {
                AddressBookID = item.GetDataKeyValue("AddressBookID").ToString();
                //Priority = ((RadNumericTextBox)item.FindControl("txtPriority")).Text.Trim();
                //IsShowOnHomePage = ((CheckBox)item.FindControl("chkIsShowOnHomePage")).Checked.ToString();
                //IsHot = ((CheckBox)item.FindControl("chkIsHot")).Checked.ToString();
                //IsNew = ((CheckBox)item.FindControl("chkIsNew")).Checked.ToString();
                IsAvailable = ((CheckBox)item.FindControl("chkIsAvailable")).Checked.ToString();

                oAđdressBook.AddressBook1QuickUpdate(
                    AddressBookID,
                    IsAvailable
                );
            }
        }
        //else if (e.CommandName == "DeleteSelected")
        //{
        //    string OldImageName;
        //    var oArticle = new Article();

        //    foreach (GridDataItem item in RadGrid1.SelectedItems)
        //    {
        //        OldImageName = ((HiddenField)item.FindControl("hdnImageName")).Value;
        //        DeleteImage(OldImageName);
        //    }
        //}
        else if (e.CommandName == "PerformInsert" || e.CommandName == "Update")
        {
            var command = e.CommandName;
            var row = command == "PerformInsert" ? (GridEditFormInsertItem)e.Item : (GridEditFormItem)e.Item;
            var FileImageName = (RadUpload)row.FindControl("FileImageName");
            var oAddressBook = new AddressBook1();

            string strAddressBookID = ((HiddenField)row.FindControl("hdnAddressBookID")).Value;
            //string strOldImageName = ((HiddenField)row.FindControl("hdnOldImageName")).Value;
            //string strImageName = FileImageName.UploadedFiles.Count > 0 ? FileImageName.UploadedFiles[0].GetName() : "";
            //string strPriority = ((RadNumericTextBox)row.FindControl("txtPriority")).Text.Trim();
            //string strMetaTittle = ((TextBox)row.FindControl("txtMetaTittle")).Text.Trim();
            //string strMetaDescription = ((TextBox)row.FindControl("txtMetaDescription")).Text.Trim();
            //string strArticleTitle = ((TextBox)row.FindControl("txtArticleTitle")).Text.Trim();
            //string strConvertedArticleTitle = Common.ConvertTitle(strArticleTitle);
            //string strDescription = HttpUtility.HtmlDecode(FCKEditorFix.Fix(((RadEditor)row.FindControl("txtDescription")).Content.Trim()));
            //string strContent = HttpUtility.HtmlDecode(FCKEditorFix.Fix(((RadEditor)row.FindControl("txtContent")).Content.Trim()));
            //string strTag = ((TextBox)row.FindControl("txtTag")).Text.Trim();
            //string strArticleCategoryID = ((RadComboBox)row.FindControl("ddlCategory")).SelectedValue;
            //string strIsShowOnHomePage = ((CheckBox)row.FindControl("chkIsShowOnHomePage")).Checked.ToString();
            //string strIsHot = ((CheckBox)row.FindControl("chkIsHot")).Checked.ToString();
            //string strIsNew = ((CheckBox)row.FindControl("chkIsNew")).Checked.ToString();
            string strThanhPho = ((RadComboBox)row.FindControl("ddlProvince")).SelectedValue;
            string strQuan = ((RadComboBox)row.FindControl("ddlDistrict")).SelectedValue;
            string strCompany = ((TextBox)row.FindControl("txtCompany")).Text.Trim();
            string strCompanyEn = ((TextBox)row.FindControl("txtCompanyEn")).Text.Trim();
            string strDiaChi = ((TextBox)row.FindControl("txtAddress")).Text.Trim();
            string strIsAvailable = ((CheckBox)row.FindControl("chkIsAvailable")).Checked.ToString();
            //string strMetaTittleEn = ((TextBox)row.FindControl("txtMetaTittleEn")).Text.Trim();
            //string strMetaDescriptionEn = ((TextBox)row.FindControl("txtMetaDescriptionEn")).Text.Trim();
            //string strArticleTitleEn = ((TextBox)row.FindControl("txtArticleTitleEn")).Text.Trim();
            //string strDescriptionEn = ((RadEditor)row.FindControl("txtDescriptionEn")).Content.Trim();
            //string strContentEn = ((RadEditor)row.FindControl("txtContentEn")).Content.Trim();
            //string strTagEn = ((TextBox)row.FindControl("txtTagEn")).Text.Trim();


            if (e.CommandName == "PerformInsert")
            {
                oAddressBook.AddressBook1Insert(
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                strCompany,
                strCompanyEn,
                strDiaChi,
                "",
                "",
                "",
                "1",
                strThanhPho,
                strQuan,
                strIsAvailable,
                "",
                "",
                ""
                );

                //string strFullPath = "~/res/article/" + strImageName;
                //if (!string.IsNullOrEmpty(strImageName))
                //{
                //    FileImageName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                //    ResizeCropImage.ResizeByCondition(strFullPath, 800, 800);
                //    ResizeCropImage.CreateThumbNailByCondition("~/res/article/", "~/res/article/thumbs/", strImageName, 120, 120);
                //}
                RadGrid1.Rebind();
            }
            else
            {
                var dsUpdateParam = ObjectDataSource1.UpdateParameters;
                //var strOldImagePath = Server.MapPath("~/res/article/" + strOldImageName);
                //var strOldThumbImagePath = Server.MapPath("~/res/article/thumbs/" + strOldImageName);

                dsUpdateParam["Company"].DefaultValue = strCompany;
                dsUpdateParam["CompanyEn"].DefaultValue = strCompanyEn;
                dsUpdateParam["Address1"].DefaultValue = strDiaChi;
                dsUpdateParam["CountryID"].DefaultValue = "1";
                dsUpdateParam["ProvinceID"].DefaultValue = strThanhPho;
                dsUpdateParam["DistrictID"].DefaultValue = strQuan;
                dsUpdateParam["IsPrimary"].DefaultValue = strIsAvailable;

                //if (!string.IsNullOrEmpty(strImageName))
                //{
                //    if (File.Exists(strOldImagePath))
                //        File.Delete(strOldImagePath);
                //    if (File.Exists(strOldThumbImagePath))
                //        File.Delete(strOldThumbImagePath);

                //    strImageName = (string.IsNullOrEmpty(strConvertedArticleTitle) ? "" : strConvertedArticleTitle + "-") + strArticleID + strImageName.Substring(strImageName.LastIndexOf('.'));

                //    string strFullPath = "~/res/article/" + strImageName;

                //    FileImageName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                //    ResizeCropImage.ResizeByCondition(strFullPath, 800, 800);
                //    ResizeCropImage.CreateThumbNailByCondition("~/res/article/", "~/res/article/thumbs/", strImageName, 120, 120);
                //}
            }
        }
        //if (e.CommandName == "DeleteImage")
        //{
        //    var oArticle = new Article();
        //    var lnkDeleteImage = (LinkButton)e.CommandSource;
        //    var s = lnkDeleteImage.Attributes["rel"].ToString().Split('#');
        //    var strArticleID = s[0];
        //    var strImageName = s[1];

        //    oArticle.ArticleImageDelete(strArticleID);
        //    DeleteImage(strImageName);
        //    RadGrid1.Rebind();
        //}
    }