protected void lnkDownOrder_Click(object sender, EventArgs e)
    {
        var lnkDownOrder = (LinkButton)sender;
        var strProductOptionCategoryID = lnkDownOrder.Attributes["rel"];
        var oProductOptionCategory     = new ProductOptionCategory();

        oProductOptionCategory.ProductOptionCategoryDownOrder(strProductOptionCategoryID);
        RadGrid1.Rebind();
    }
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == "QuickUpdate")
        {
            string ProductOptionCategoryID, IsShowOnMenu, IsShowOnHomePage, IsAvailable;
            var    oProductOptionCategory = new ProductOptionCategory();

            foreach (GridDataItem item in RadGrid1.Items)
            {
                ProductOptionCategoryID = item.GetDataKeyValue("ProductOptionCategoryID").ToString();
                IsShowOnMenu            = ((CheckBox)item.FindControl("chkIsShowOnMenu")).Checked.ToString();
                IsShowOnHomePage        = ((CheckBox)item.FindControl("chkIsShowOnHomePage")).Checked.ToString();
                IsAvailable             = ((CheckBox)item.FindControl("chkIsAvailable")).Checked.ToString();

                oProductOptionCategory.ProductOptionCategoryQuickUpdate(
                    ProductOptionCategoryID,
                    IsShowOnMenu,
                    IsShowOnHomePage,
                    IsAvailable
                    );
            }
        }
        else if (e.CommandName == "DeleteSelected")
        {
            var oProductOptionCategory = new ProductOptionCategory();
            var errorList = "";

            foreach (GridDataItem item in RadGrid1.SelectedItems)
            {
                var isChildCategoryExist      = oProductOptionCategory.ProductOptionCategoryIsChildrenExist(item.GetDataKeyValue("ProductOptionCategoryID").ToString());
                var ProductOptionCategoryName = ((Label)item.FindControl("lblProductOptionCategoryName")).Text;
                if (isChildCategoryExist)
                {
                    errorList += ", " + ProductOptionCategoryName;
                }
                else
                {
                    string strImageName = ((HiddenField)item.FindControl("hdnImageName")).Value;

                    if (!string.IsNullOrEmpty(strImageName))
                    {
                        string strSavePath = Server.MapPath("~/res/productoptioncategory/" + strImageName);
                        if (File.Exists(strSavePath))
                        {
                            File.Delete(strSavePath);
                        }
                    }
                }
            }
            if (!string.IsNullOrEmpty(errorList))
            {
                e.Canceled = true;
                string strAlertMessage = "Danh mục <b>\"" + errorList.Remove(0, 1).Trim() + "\"</b> đang có danh mục con.<br /> Xin xóa danh mục con trong danh mục này hoặc thiết lập hiển thị = \"không\".";
                lblError.Text = strAlertMessage;
            }
        }
        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");

            string strProductOptionCategoryName          = ((RadTextBox)row.FindControl("txtProductOptionCategoryName")).Text.Trim();
            string strProductOptionCategoryNameEn        = "";
            string strConvertedProductOptionCategoryName = Common.ConvertTitle(strProductOptionCategoryName);
            string strDescription       = HttpUtility.HtmlDecode(FCKEditorFix.Fix(((RadEditor)row.FindControl("txtDescription")).Content.Trim()));
            string strDescriptionEn     = "";
            string strContent           = HttpUtility.HtmlDecode(FCKEditorFix.Fix(((RadEditor)row.FindControl("txtContent")).Content.Trim()));
            string strContentEn         = "";
            string strMetaTitle         = ((RadTextBox)row.FindControl("txtMetaTitle")).Text.Trim();
            string strMetaTitleEn       = "";
            string strMetaDescription   = ((RadTextBox)row.FindControl("txtMetaDescription")).Text.Trim();
            string strMetaDescriptionEn = "";
            string strImageName         = FileImageName.UploadedFiles.Count > 0 ? FileImageName.UploadedFiles[0].GetName() : "";
            string strParentID          = ((RadComboBox)row.FindControl("ddlParent")).SelectedValue;
            string strIsAvailable       = ((CheckBox)row.FindControl("chkIsAvailable")).Checked.ToString();
            string strIsShowOnMenu      = ((CheckBox)row.FindControl("chkIsShowOnMenu")).Checked.ToString();
            string strIsShowOnHomePage  = ((CheckBox)row.FindControl("chkIsShowOnHomePage")).Checked.ToString();
            string strProductID         = string.IsNullOrEmpty(Request.QueryString["pi"]) ? "" : Request.QueryString["pi"].ToString();

            var oProductOptionCategory = new ProductOptionCategory();

            if (e.CommandName == "PerformInsert")
            {
                strImageName = oProductOptionCategory.ProductOptionCategoryInsert(
                    strProductOptionCategoryName,
                    strProductOptionCategoryNameEn,
                    strConvertedProductOptionCategoryName,
                    strDescription,
                    strDescriptionEn,
                    strContent,
                    strContentEn,
                    strMetaTitle,
                    strMetaTitleEn,
                    strMetaDescription,
                    strMetaDescriptionEn,
                    strImageName,
                    strParentID,
                    strIsShowOnMenu,
                    strIsShowOnHomePage,
                    strIsAvailable,
                    strProductID
                    );

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

                if (!string.IsNullOrEmpty(strImageName))
                {
                    FileImageName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                    ResizeCropImage.ResizeByCondition(strFullPath, 26, 26);
                }
                RadGrid1.Rebind();
                lstChoosedColor.DataBind();
            }
            else
            {
                var dsUpdateParam = ObjectDataSource1.UpdateParameters;
                var strProductOptionCategoryID = row.GetDataKeyValue("ProductOptionCategoryID").ToString();
                var strOldImageName            = ((HiddenField)row.FindControl("hdnImageName")).Value;
                var strOldImagePath            = Server.MapPath("~/res/productoptioncategory/" + strOldImageName);

                dsUpdateParam["ProductOptionCategoryName"].DefaultValue          = strProductOptionCategoryName;
                dsUpdateParam["ConvertedProductOptionCategoryName"].DefaultValue = strConvertedProductOptionCategoryName;
                dsUpdateParam["Description"].DefaultValue      = strDescription;
                dsUpdateParam["Content"].DefaultValue          = strContent;
                dsUpdateParam["IsAvailable"].DefaultValue      = strIsAvailable;
                dsUpdateParam["ImageName"].DefaultValue        = strImageName;
                dsUpdateParam["ParentID"].DefaultValue         = strParentID;
                dsUpdateParam["IsShowOnMenu"].DefaultValue     = strIsShowOnMenu;
                dsUpdateParam["IsShowOnHomePage"].DefaultValue = strIsShowOnHomePage;
                dsUpdateParam["IsAvailable"].DefaultValue      = strIsAvailable;
                dsUpdateParam["ProductID"].DefaultValue        = strProductID;

                if (!string.IsNullOrEmpty(strImageName))
                {
                    var strFullPath = "~/res/productoptioncategory/" + strConvertedProductOptionCategoryName + "-" + strProductOptionCategoryID + strImageName.Substring(strImageName.LastIndexOf('.'));

                    if (File.Exists(strOldImagePath))
                    {
                        File.Delete(strOldImagePath);
                    }

                    FileImageName.UploadedFiles[0].SaveAs(Server.MapPath(strFullPath));
                    ResizeCropImage.ResizeByCondition(strFullPath, 26, 26);
                }
                RadGrid1.Rebind();
                lstChoosedColor.DataBind();
            }
        }
        if (e.CommandName == "DeleteImage")
        {
            var oProductOptionCategory = new ProductOptionCategory();
            var lnkDeleteImage         = (LinkButton)e.CommandSource;
            var s = lnkDeleteImage.Attributes["rel"].ToString().Split('#');
            var strProductOptionCategoryID = s[0];
            var strImageName = s[1];

            oProductOptionCategory.ProductOptionCategoryImageDelete(strProductOptionCategoryID);
            DeleteImage(strImageName);
            RadGrid1.Rebind();
        }
    }
    protected void lstProductDetails_ItemCommand(object sender, ListViewCommandEventArgs e)
    {
        var    item = e.Item as ListViewDataItem;
        var    cmd  = e.CommandName;
        var    ProductOptionCategoryID = (item.FindControl("hdnProductOptionCategoryID") as HiddenField).Value;
        var    ProductID              = (item.FindControl("hdnProductID") as HiddenField).Value;
        var    ProductName            = (item.FindControl("hdnProductName") as HiddenField).Value;
        var    ProductLengthID        = ""; //(item.FindControl("hdnProductLengthID") as HiddenField).Value;
        var    ProductLengthName      = ""; //(item.FindControl("hdnProductLengthName") as HiddenField).Value;
        var    Quantity               = "1";
        double Price                  = Convert.ToDouble((item.FindControl("hdnPrice") as HiddenField).Value);
        string ProductSizeColorID1    = "";
        string ImageColor             = "";
        string ImageName              = "";
        string QuantityList           = "";
        int    SizeColorQuantity1     = 0;
        var    oProductSizeColor      = new ProductSizeColor();
        var    oProductOptionCategory = new ProductOptionCategory();
        var    oProductImage          = new ProductImage();

        var oShoppingCart = new ShoppingCart();

        if (cmd == "AddToCart")
        {
            if (ProductID != "")
            {
                if (oShoppingCart.HasItem(ProductID) && oShoppingCart.HasColor(ProductOptionCategoryID))
                {
                    var dtCart = HttpContext.Current.Session["Cart"] as DataTable;

                    string a = (from DataRow dr in dtCart.Rows
                                where dr["ProductID"].ToString() == ProductID
                                select dr).FirstOrDefault()["Quantity"].ToString();
                    oShoppingCart.UpdateQuantity(ProductID, ProductLengthID, ProductOptionCategoryID, (Convert.ToInt32(a) + Convert.ToInt32(1)).ToString());
                }
                else
                {
                    var dv = oProductSizeColor.ProductSizeColorSelectAll(ProductLengthID, ProductOptionCategoryID, ProductID, "True",
                                                                         "True", "", "True").DefaultView;
                    var dv2 = oProductOptionCategory.ProductOptionCategorySelectOne(ProductOptionCategoryID).DefaultView;
                    var dv3 = oProductImage.ProductImageSelectAll(ProductID, "True", "", "True").DefaultView;
                    if (dv.Count != 0 || dv2.Count != 0)
                    {
                        ProductSizeColorID1 = dv[0]["ProductSizeColorID"].ToString();
                        ImageColor          = dv2[0]["ImageName"].ToString();
                        SizeColorQuantity1  = Convert.ToInt32(dv[0]["Quantity"].ToString()) - Convert.ToInt32(dv[0]["QuantitySale"].ToString());
                        for (int i = 1; i <= SizeColorQuantity1; i++)
                        {
                            QuantityList = QuantityList + i + ",";
                        }
                    }
                    else
                    {
                        ProductSizeColorID1 = "";
                        ImageColor          = "";
                        SizeColorQuantity1  = 0;
                    }

                    if (dv3.Count != 0)
                    {
                        ImageName = dv3[0]["ImageName"].ToString();
                    }
                    else
                    {
                        ImageName = "";
                    }


                    oShoppingCart.CreateCart(ProductID,
                                             ImageName,
                                             ImageColor,
                                             ProductName,
                                             "",
                                             "",
                                             ProductOptionCategoryID,
                                             "",
                                             ProductLengthID,
                                             ProductLengthName,
                                             ProductSizeColorID1,
                                             Quantity,
                                             SizeColorQuantity1.ToString(),
                                             Price,
                                             false
                                             );
                }
            }


            //ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "runtime", "myconfirmPopup('" + "<strong>" + ProductName + " - " + ProductCode + " - " + ProductOptionCategoryName + "</strong><br/> đã được thêm vào giỏ hàng" + "')", true);
        }
    }
Exemplo n.º 4
0
 public ProductOptionCategoryViewModel(int skuId, ProductOptionCategory category)
 {
 }
 public ProductOptionCategoryViewModel(int selectedOptionID, ProductOptionCategory category)
 {
     SelectedOptionId = selectedOptionID;
     Category         = category;
 }