Ejemplo n.º 1
0
    protected void imgbtnApproveJob_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in gvImportjob.Rows)
        {
            if (row.RowType == DataControlRowType.DataRow)
            {
                bool isChecked = row.Cells[0].Controls.OfType <CheckBox>().FirstOrDefault().Checked;
                if (isChecked)
                {
                    string lblsku = row.Cells[1].Controls.OfType <Label>().FirstOrDefault().Text;
                    string Id     = row.Cells[2].Controls.OfType <Label>().FirstOrDefault().Text;

                    productManager objprodct = new productManager();
                    DataTable      dtpro     = new DataTable();
                    try
                    {
                        objprodct.sku = Convert.ToString(lblsku);
                        // get the data from temp table
                        objprodct.id = Convert.ToInt32(Id);
                        dtpro        = objprodct.GetSingleImportProductValue();

                        string productId        = null;
                        string productName      = null;
                        string sku              = null;
                        string isVarientProduct = null;
                        string categoryname     = null;
                        string brandname        = null;
                        string price            = null;
                        string minimumQuantity  = null;
                        string inventory        = null;


                        //errorMsg = string.Empty;
                        bool checkValid = false;

                        if (dtpro.Rows.Count > 0)
                        {
                            productName      = Convert.ToString(dtpro.Rows[0]["productname"]);
                            sku              = Convert.ToString(dtpro.Rows[0]["sku"]);
                            isVarientProduct = Convert.ToString(dtpro.Rows[0]["isvarientproduct"]);
                            categoryname     = Convert.ToString(dtpro.Rows[0]["categoryname"]);
                            brandname        = Convert.ToString(dtpro.Rows[0]["brandname"]);
                            price            = Convert.ToString(dtpro.Rows[0]["price"]);
                            minimumQuantity  = Convert.ToString(dtpro.Rows[0]["minimumquantity"]);
                            inventory        = Convert.ToString(dtpro.Rows[0]["inventory"]);

                            //checkValidDataProduct
                            if (Convert.ToByte(dtpro.Rows[0]["ismasterproduct"]) == Convert.ToByte(true))
                            {
                                checkValid = checkValidDataMasterProduct(productName, sku, categoryname, brandname);
                            }
                            else
                            {
                                if (isVarientProduct.ToLower() == "false") // single product
                                {
                                    checkValid = checkValidDataProduct(productName, sku, categoryname, brandname, price, minimumQuantity, inventory);
                                }
                                else
                                {
                                    checkValid = checkValidDataSinglsProduct(productName, sku, price, minimumQuantity, inventory);
                                }
                            }

                            if (checkValid == false)
                            {
                                objprodct.FileError           = errorMsg;
                                objprodct.FileErrorLineNumber = Convert.ToInt32(1);
                                objprodct.updateSingleImportProduct();
                            }
                            else
                            {
                                objprodct.productName        = Server.HtmlEncode(Convert.ToString(dtpro.Rows[0]["productname"]));
                                objprodct.productDescription = Server.HtmlEncode(Convert.ToString(dtpro.Rows[0]["productdescription"]));
                                objprodct.sku              = Convert.ToString(dtpro.Rows[0]["sku"]);
                                objprodct.barcode          = Convert.ToString(dtpro.Rows[0]["barcode"]);
                                objprodct.isVarientProduct = Convert.ToByte(dtpro.Rows[0]["isvarientproduct"]);
                                objprodct.varientItem      = Convert.ToString(dtpro.Rows[0]["varientItem"]);
                                if (Request.QueryString["filetp"] == "3")
                                {
                                    objprodct.isMasterProduct = Convert.ToByte(1);
                                }
                                else
                                {
                                    objprodct.isMasterProduct = Convert.ToByte(dtpro.Rows[0]["ismasterproduct"]);
                                }
                                objprodct.price           = Convert.ToDecimal(dtpro.Rows[0]["price"]);
                                objprodct.cost            = Convert.ToDecimal(dtpro.Rows[0]["cost"]);
                                objprodct.minimumQuantity = Convert.ToInt32(dtpro.Rows[0]["minimumquantity"]);
                                objprodct.inventory       = Convert.ToInt32(dtpro.Rows[0]["inventory"]);
                                objprodct.isactive        = Convert.ToByte(dtpro.Rows[0]["isactive"]);
                                objprodct.isFeatured      = Convert.ToByte(dtpro.Rows[0]["isfeatured"]);


                                int count = objprodct.GetProdutctidCount();
                                if (count > 0)
                                {
                                    objprodct.productId = Convert.ToInt32(count);
                                    objprodct.UpdateItem();
                                    objprodct.isStatus = Convert.ToByte(1);
                                    objprodct.UpdateTempTableStatus();
                                }
                                else
                                {
                                    objprodct.InsertItem();
                                    objprodct.isStatus = Convert.ToByte(1);
                                    objprodct.UpdateTempTableStatus();
                                }

                                objprodct.productId = Convert.ToInt32(count);

                                #region product language

                                objprodct.DeleteProductLanguage();

                                objprodct.languageId = Convert.ToInt32(1);
                                objprodct.InsertProductLanguageItem();

                                objprodct.languageId         = Convert.ToInt32(2);
                                objprodct.productName        = Convert.ToString(dtpro.Rows[0]["ArabicName"]);
                                objprodct.productDescription = Convert.ToString(dtpro.Rows[0]["ArabicDesc"]);
                                objprodct.InsertProductLanguageItem();

                                #endregion

                                // add master product in product master table
                                int master_proid = 0;
                                if (Convert.ToString(dtpro.Rows[0]["master_product_parent"]) != "")
                                {
                                    objprodct.masterProductName = Convert.ToString(dtpro.Rows[0]["master_product_parent"]);
                                    master_proid = objprodct.getMasterProductid();
                                }

                                // add brand in brand product table
                                int brand_id = 0;
                                if (Convert.ToString(dtpro.Rows[0]["brandname"]) != "")
                                {
                                    objprodct.brandname = Convert.ToString(dtpro.Rows[0]["brandname"]);
                                    brand_id            = objprodct.getBrandId();
                                }

                                // add category in product category table
                                int cat_id    = 0;
                                int sub_catid = 0;
                                objprodct.CategoryName    = Convert.ToString(dtpro.Rows[0]["categoryname"]);    // category name
                                objprodct.subcategoryname = Convert.ToString(dtpro.Rows[0]["subcategoryname"]); // sub category name

                                if (Convert.ToString(dtpro.Rows[0]["categoryname"]) != "")
                                {
                                    cat_id = Convert.ToInt32(objprodct.getCategoryId());
                                }
                                if (cat_id > 0)
                                {
                                    if (Convert.ToString(dtpro.Rows[0]["subcategoryname"]) != "")
                                    {
                                        objprodct.parentid = Convert.ToInt32(cat_id);
                                        sub_catid          = Convert.ToInt32(objprodct.GetCategoryidByParentID());
                                    }
                                }
                                else
                                {
                                    if (Convert.ToString(dtpro.Rows[0]["subcategoryname"]) != "")
                                    {
                                        objprodct.CategoryName = Convert.ToString(dtpro.Rows[0]["subcategoryname"]);
                                        cat_id = Convert.ToInt32(objprodct.getCategoryId());
                                    }
                                }

                                if (objprodct.productId > 0)
                                {
                                    //product language
                                    objprodct.languageId = 1;
                                    //objprodct.UpdateProductLanguage();

                                    //product
                                    objprodct.DeleteProductCategory();

                                    //if (sub_catid > 0) { objprodct.categoryId = sub_catid; } else { objprodct.categoryId = cat_id; }
                                    //objprodct.InsertProductCategroyItem();

                                    if (sub_catid > 0)
                                    {
                                        objprodct.categoryId = sub_catid; objprodct.InsertProductCategroyItem();
                                    }
                                    objprodct.categoryId = cat_id; objprodct.InsertProductCategroyItem();

                                    // brand
                                    if (brand_id > 0)
                                    {
                                        objprodct.DeleteProductBrand(); objprodct.barndId = brand_id; objprodct.InsertProductBrandItem();
                                    }

                                    //master product
                                    if (master_proid > 0)
                                    {
                                        objprodct.DeleteMasterProductLink(); objprodct.masterProductId = master_proid; objprodct.InsertMasterProductLinkItem();
                                    }
                                }
                                else
                                {
                                    objprodct.DeleteProductCategory();
                                    //objprodct.DeleteProductBrand();

                                    int product_id = objprodct.getmaxid();
                                    objprodct.productId = product_id;

                                    //product language
                                    objprodct.languageId = 1;  // productname,productdescription from upside to here
                                    objprodct.InsertProductLanguageItem();


                                    //product
                                    //if (sub_catid > 0) { objprodct.categoryId = sub_catid; } else { objprodct.categoryId = cat_id; }
                                    //objprodct.InsertProductCategroyItem();
                                    if (sub_catid > 0)
                                    {
                                        objprodct.categoryId = sub_catid; objprodct.InsertProductCategroyItem();
                                    }
                                    objprodct.categoryId = cat_id; objprodct.InsertProductCategroyItem();

                                    // brand
                                    if (brand_id > 0)
                                    {
                                        objprodct.barndId = brand_id; objprodct.InsertProductBrandItem();
                                    }

                                    // master product
                                    if (master_proid > 0)
                                    {
                                        objprodct.masterProductId = master_proid; objprodct.InsertMasterProductLinkItem();
                                    }
                                }

                                // update validation message in tempproduct
                                objprodct.FileError           = Server.HtmlEncode(errorMsg);
                                objprodct.FileErrorLineNumber = Convert.ToInt32(0);
                                objprodct.updateSingleImportProduct();
                            }
                        }

                        //gvAdmin.EditIndex = -1;
                        //BindContents();
                    }
                    catch (Exception ex)
                    {
                        //throw ex;
                    }
                    finally { objprodct = null; dtpro = null; }
                }
            }
        }
        BindContents();
        lblmsg.Visible = true;
        lblmsgs.Text   = "Approved job successfully";
    }
Ejemplo n.º 2
0
    public string updateMasterProduct(string productid, string productName, string sku, string productDescription, string ddlPopCategoryProduct, string ddlPopBrandProduct, string ArabicName, string ArabicDiscription)
    {
        productManager objproduct = new productManager();

        if (productName != "" && sku != "")
        {
            objproduct.productId          = Convert.ToInt32(productid);
            objproduct.productName        = productName;
            objproduct.sku                = sku;
            objproduct.productDescription = productDescription;
            objproduct.barcode            = "";
            objproduct.isVarientProduct   = 0;
            objproduct.isMasterProduct    = 1;
            objproduct.price              = 0;
            objproduct.cost               = 0;
            objproduct.minimumQuantity    = 0;
            objproduct.inventory          = 0;
            objproduct.varientItem        = "";
            objproduct.isactive           = 1;
            objproduct.isFeatured         = 0;
            objproduct.varientItem        = "";

            if (objproduct.TitleExist())
            {
                return("Product name is already exist");
            }
            if (objproduct.SkuExist())
            {
                return("Product sku is already exist");
            }

            objproduct.UpdateItem();

            objproduct.QRCOde = UploadQRCode(sku);
            objproduct.UpdateQRCode();

            //int maxid = objproduct.getmaxid();
            objproduct.productId = Convert.ToInt32(productid);

            if (ddlPopCategoryProduct != null || ddlPopCategoryProduct != "0")
            {
                objproduct.DeleteProductCategory();

                string[] PopCategory = ddlPopCategoryProduct.Split(',');
                for (int i = 0; i < PopCategory.Count(); i++)
                {
                    objproduct.productId  = Convert.ToInt32(productid);
                    objproduct.categoryId = Convert.ToInt32(PopCategory[i]);
                    objproduct.InsertProductCategroyItem();
                }
            }
            if (ddlPopBrandProduct != null || ddlPopBrandProduct != "0")
            {
                objproduct.DeleteProductBrand();
                string[] PopBrand = ddlPopBrandProduct.Split(',');
                for (int j = 0; j < PopBrand.Count(); j++)
                {
                    objproduct.productId = Convert.ToInt32(productid);
                    objproduct.barndId   = Convert.ToInt32(PopBrand[j]);
                    objproduct.InsertProductBrandItem();
                }
            }

            //language entry
            objproduct.DeleteProductLanguage();

            objproduct.languageId = 1;
            objproduct.InsertProductLanguageItem();

            objproduct.languageId         = 2;
            objproduct.productName        = Server.HtmlEncode(ArabicName);
            objproduct.productDescription = Server.HtmlEncode(ArabicDiscription);
            objproduct.InsertProductLanguageItem();

            return("Master product updated successfully");
        }
        else
        {
            return("Error in update master product");
        }
    }