Пример #1
0
    protected void BtnAdd_Click(object sender, EventArgs e)
    {
        bool flag = false;

        foreach (GridViewRow gr in gvproductlist.Rows)
        {
            string userId          = Request.Cookies["TUser"]["Id"].ToString();
            bool   isChecked       = ((CheckBox)gr.FindControl("chkProduct")).Checked;
            int    sJurisdictionId = Convert.ToInt32(ddlJurisdiction.SelectedValue);
            int    categoryId      = Convert.ToInt32(ddlCategoryName.SelectedValue);
            int    subcategoryId   = Convert.ToInt32(ddlSubCategoryName.SelectedValue);

            if (isChecked)
            {
                HiddenField hdngrpId  = ((HiddenField)gr.Cells[1].FindControl("HiddenFieldgrpid"));
                string      productId = hdngrpId.Value;

                string InsertProduct = " Insert into Product " +
                                       " Select Name, GSTTaxId, Unit, UnitId, StartDate, EndDate, IsActive, Metatags, Metadesc, Mrp, Offer, BuyWith1FriendExtraDiscount, " +
                                       " BuyWith5FriendExtraDiscount, FixedShipRate, KeyFeatures, Note, IsDeleted, DOC, DOM, VideoName, OGImage, ProductDiscription, JustBougth, " +
                                       " sold, IsOrderDone, ProductMRP, DisplayNameInMsg, ShowMrpInMsg, IsQtyFreeze, DisplayOrder, CategoryID, ProductTemplateID, ProductBanner, " +
                                       " Recommended, '" + dbc.getindiantime().ToString("dd-MMM-yyyy HH:mm:ss") + "' As CreatedOn, " + userId + " as CreatedBy, '' As ModifiedOn, 0 as ModifiedBy, " + sJurisdictionId + " As JurisdictionID, IsApproved, RejectedReason, ApproverID, DiscountType, " +
                                       " Discount, SoshoPrice, MaxQty, MinQty, IsProductDescription, IsFreeShipping, IsFixedShipping, id as ProductMasterId, SubCategoryId " +
                                       " From product where id = " + productId + "; SELECT SCOPE_IDENTITY(); ";
                int Val = dbc.ExecuteQueryWithScalarId(InsertProduct);

                string    SelectAttrIdQry = " SELECT Id FROM Product_ProductAttribute_Mapping WHERE ProductId = " + productId;
                DataTable dtAttributelist = dbc.GetDataTable(SelectAttrIdQry);
                if (dtAttributelist.Rows.Count > 0)
                {
                    for (int nCtr = 0; nCtr < dtAttributelist.Rows.Count; nCtr++)
                    {
                        int    AttributeId = Convert.ToInt32(dtAttributelist.Rows[nCtr]["Id"]);
                        string prodAttrqry = " SELECT Unit, UnitId, Mrp, DiscountType, ISNULL(Discount,0) AS Discount, ISNULL(SoshoPrice,0) AS SoshoPrice, PackingType, ProductImage, " +
                                             " ISNULL(IsActive,0) AS IsActive, ISNULL(IsDeleted,0) IsDeleted, ISNULL(isOutOfStock,0) AS isOutOfStock, " +
                                             " ISNULL(isSelected,0) AS isSelected, ISNULL(MaxQty,0) AS MaxQty, IsNull(MinQty,0) AS MinQty, " +
                                             " ISNULL(IsQtyFreeze,0) AS IsQtyFreeze, ISNULL(IsBestBuy,0) AS IsBestBuy, ISNULL(FreezeQty,0) AS FreezeQty" +
                                             " FROM Product_ProductAttribute_Mapping WHERE Id =" + AttributeId;
                        DataTable dtAttributeDetail = dbc.GetDataTable(prodAttrqry);
                        int       isDeleted         = 0;
                        int       isActive          = 1;
                        int       isOutOfStock      = 0;
                        int       isSelected        = 0;
                        int       IsQtyFreeze       = 0;
                        int       isBestBuy         = 0;

                        if (Convert.ToBoolean(dtAttributeDetail.Rows[0]["IsDeleted"]) == true)
                        {
                            isDeleted = 1;
                        }

                        if (Convert.ToBoolean(dtAttributeDetail.Rows[0]["IsActive"]) == false)
                        {
                            isActive = 0;
                        }

                        if (Convert.ToBoolean(dtAttributeDetail.Rows[0]["isOutOfStock"]) == true)
                        {
                            isOutOfStock = 1;
                        }

                        if (Convert.ToBoolean(dtAttributeDetail.Rows[0]["isSelected"]) == true)
                        {
                            isSelected = 1;
                        }

                        if (Convert.ToBoolean(dtAttributeDetail.Rows[0]["IsQtyFreeze"]) == true)
                        {
                            IsQtyFreeze = 1;
                        }

                        if (Convert.ToBoolean(dtAttributeDetail.Rows[0]["IsBestBuy"]) == true)
                        {
                            isBestBuy = 1;
                        }

                        string InserAttrProduct = " Insert into Product_ProductAttribute_Mapping(ProductId, Unit, UnitId, Mrp, DiscountType, Discount, SoshoPrice, " +
                                                  " PackingType, ProductImage, IsActive, IsDeleted, CreatedOn, CreatedBy, isOutOfStock, " +
                                                  " isSelected, MaxQty, MinQty, IsQtyFreeze, IsBestBuy, FreezeQty, AttributeMasterId) VALUES(" +
                                                  Val + ", '" + dtAttributeDetail.Rows[0]["Unit"] + "', " + dtAttributeDetail.Rows[0]["UnitId"] + ", " +
                                                  dtAttributeDetail.Rows[0]["Mrp"] + ",'" + dtAttributeDetail.Rows[0]["DiscountType"] + "'," + dtAttributeDetail.Rows[0]["Discount"] +
                                                  "," + dtAttributeDetail.Rows[0]["SoshoPrice"] + ",'" + dtAttributeDetail.Rows[0]["PackingType"] + "'," +
                                                  "'" + dtAttributeDetail.Rows[0]["ProductImage"] + "'," + isActive + "," +
                                                  isDeleted + ",'" + dbc.getindiantime().ToString("dd-MMM-yyyy HH:mm:ss") + "'," +
                                                  userId + "," + isOutOfStock + "," + isSelected + "," +
                                                  dtAttributeDetail.Rows[0]["MaxQty"] + "," + dtAttributeDetail.Rows[0]["MinQty"] + "," +
                                                  IsQtyFreeze + "," + isBestBuy + "," +
                                                  dtAttributeDetail.Rows[0]["FreezeQty"] + "," + AttributeId + ")";
                        dbc.ExecuteQuery(InserAttrProduct);
                    }
                }
                DateTime dtCreatedon        = DateTime.Now;
                string   ProductCategoryqry = "INSERT INTO [dbo].[tblCategoryProductLink] ([ProductId],[CategoryId],[SubCategoryId],[IsActive],[IsDeleted],[CreatedDate],[CreatedBy]) VALUES (" + Val + ",'" + categoryId + "'," + subcategoryId + ",1,0,'" + dbc.getindiantime().ToString("dd-MMM-yyyy HH:mm:ss") + "'," + userId + ")";
                dbc.ExecuteQuery(ProductCategoryqry);
                flag = true;
            }
        }
        DataList();
        if (flag)
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Product Assign to Jurisdiction Successfully')", true);
        }
    }