Exemplo n.º 1
0
    protected void btnUseVoucher_Click(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(txtInputVoucher.Text))
        {
            var productVoucher = new ProductVoucher();

            if (productVoucher.ProductVoucherSelectAll("", txtInputVoucher.Text, "", "", "", "", "", "", "", "1", "1").DefaultView.Count > 0)
            {
                validateVoucher.ErrorMessage = "Voucher <b>\"" + txtInputVoucher.Text + "\"</b> đã sử dụng!";
                validateVoucher.IsValid      = false;
                txtInputVoucher.Text         = "";
            }
            else if (productVoucher.ProductVoucherSelectAll("", txtInputVoucher.Text, "", "", "", "", "", "", "", "0", "0").DefaultView.Count > 0)
            {
                validateVoucher.IsValid = true;
                double ShippingPrice = 0;
                double VoucherPrice  = 0;
                // check voucher da nhap su dung co gia giam chua
                if (Session["SavePrice"] == null)
                {
                    var dataVoucher = productVoucher.ProductVoucherSelectAll("", txtInputVoucher.Text, "", "", "", "", "", "", "", "0", "0").DefaultView;
                    VoucherPrice         = Convert.ToDouble(dataVoucher[0]["VoucherPrice"].ToString());
                    Session["SavePrice"] = VoucherPrice;
                }
                else
                {
                    VoucherPrice = Convert.ToDouble(Session["SavePrice"].ToString());
                }


                double TotalPrice    = 0;
                double SumTotalPrice = 0;
                var    dtCart        = Session["Cart"] as DataTable;
                if (dtCart != null)
                {
                    foreach (DataRow dr in dtCart.Rows)
                    {
                        var Quantity = Convert.ToInt32(string.IsNullOrEmpty(dr["Quantity"].ToString()) ? 0 : dr["Quantity"]);
                        var Price    = Convert.ToDouble(string.IsNullOrEmpty(dr["ProductPrice"].ToString()) ? 0 : dr["ProductPrice"]);
                        TotalPrice += Quantity * Price;
                    }
                    SumTotalPrice          = TotalPrice + ShippingPrice - VoucherPrice;
                    lblSavePrice.Text      = VoucherPrice.ToString() == "0" ? "<strong>0</strong> đ" : "<strong>" + (string.Format("{0:##,###.##}", VoucherPrice).Replace('.', '*').Replace(',', '.').Replace('*', ',')) + "</strong> đ";
                    hdnSavePrice.Value     = VoucherPrice.ToString();
                    hdnSumTotalPrice.Value = SumTotalPrice.ToString();
                    lblSumTotalPrice.Text  = string.IsNullOrEmpty(SumTotalPrice.ToString()) ? "<strong>0</strong> đ" : "<strong>" + (string.Format("{0:##,###.##}", SumTotalPrice).Replace('.', '*').Replace(',', '.').Replace('*', ',')) + "</strong> đ";
                }
                productVoucher.ProductVoucherQuickUpdate(txtInputVoucher.Text, "", "1", "1");
                //ListView1.DataBind();
            }
            else
            {
                validateVoucher.ErrorMessage = "Mã Voucher <b>\"" + txtInputVoucher.Text + "\"</b> không đúng!";
                validateVoucher.IsValid      = false;
                txtInputVoucher.Text         = "";
            }
        }
    }
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == "PerformInsert" || e.CommandName == "Update")
        {
            var command = e.CommandName;
            var row     = command == "PerformInsert" ? (GridEditFormInsertItem)e.Item : (GridEditFormItem)e.Item;
            //var strOrderStatusID = ((RadComboBox)row.FindControl("ddlOrderStatus")).SelectedValue;
            var VoucherCode  = (TextBox)row.FindControl("txtVoucherCode");
            var VoucherPrice = (RadNumericTextBox)row.FindControl("txtVoucherPrice");

            if (e.CommandName == "PerformInsert")
            {
                var strVoucherCode = Guid.NewGuid().GetHashCode().ToString("X");
                //ObjectDataSource1.InsertParameters["VoucherCode"].DefaultValue = "LADY" + Guid.NewGuid().GetHashCode().ToString("X").Substring(0, 4);

                ObjectDataSource1.InsertParameters["VoucherCode"].DefaultValue  = VoucherCode.Text;
                ObjectDataSource1.InsertParameters["VoucherPrice"].DefaultValue = VoucherPrice.Text;
                ObjectDataSource1.InsertParameters["IsReceived"].DefaultValue   = "0";
                ObjectDataSource1.InsertParameters["IsUse"].DefaultValue        = "0";
            }
            //else
            //{
            //    ObjectDataSource1.UpdateParameters["OrderStatusID"].DefaultValue = strOrderStatusID;
            //    ObjectDataSource1.UpdateParameters["UserName"].DefaultValue = User.Identity.Name;
            //}
        }
        else if (e.CommandName == "QuickUpdate")
        {
            string ProductVoucherID, VoucherCode, IsReceived, IsUse, Email;
            var    oProductVoucher = new ProductVoucher();

            foreach (GridDataItem item in RadGrid1.Items)
            {
                ProductVoucherID = item.GetDataKeyValue("ProductVoucherID").ToString();
                VoucherCode      = ((HiddenField)item.FindControl("hdnVoucherCode")).Value;
                IsReceived       = ((CheckBox)item.FindControl("chkIsReceived")).Checked.ToString();
                IsUse            = ((CheckBox)item.FindControl("chkIsUse")).Checked.ToString();
                Email            = ((HiddenField)item.FindControl("hdnEmail")).Value;

                oProductVoucher.ProductVoucherQuickUpdate(
                    VoucherCode,
                    Email,
                    IsReceived,
                    IsUse
                    );
            }
        }
    }
    protected void txtEmail_TextChanged(object sender, EventArgs e)
    {
        var txtEmail         = (TextBox)sender;
        var strEmail         = txtEmail.Text;
        var CustomValidator2 = (CustomValidator)txtEmail.Parent.FindControl("CustomValidator2");
        var lblMessage       = (Label)txtEmail.Parent.FindControl("lblEmailMessage");

        if (!string.IsNullOrEmpty(strEmail))
        {
            var productVoucher = new ProductVoucher();

            if (productVoucher.ProductVoucherSelectByEmail(strEmail).DefaultView.Count > 0)
            {
                CustomValidator2.ErrorMessage = "Email <b>\"" + strEmail + "\"</b> đã tồn tại!";
                CustomValidator2.IsValid      = false;
                lblMessage.Text = "";
            }
            else
            {
                CustomValidator2.IsValid = true;
                lblMessage.Text          = "Email <b>\"" + strEmail + "\"</b> có thể sử dụng.";
            }
        }
    }