コード例 #1
0
ファイル: UC_Product.ascx.cs プロジェクト: Khan291/IMS-1.0
        private void updatecode()
        {
            try
            {
                if (hdprodname.Value != "true")
                {
                    if (hdprodcode.Value != "true")
                    {
                        lblmsgprodname.Text      = string.Empty;
                        lblcheckDoubleError.Text = String.Empty;
                        //  GridViewRow row = GridView1.SelectedRow;
                        int     product_id     = Convert.ToInt32(hdproductid.Value);
                        decimal sales_price    = decimal.Parse(txtSalesPrice.Text);
                        decimal purchase_price = decimal.Parse(txtPurchasePrice.Text);
                        int     cat_id         = Int32.Parse(ddlCategory.SelectedValue);
                        int     unit_id        = Int32.Parse(ddlUnit.SelectedValue);
                        int     godown_id      = Int32.Parse(ddlGodown.SelectedValue);
                        int     rack_id        = Int32.Parse(ddlRack.SelectedValue);
                        //int tax_id = Int32.Parse(ddlTax.SelectedValue);

                        //context.sp_UpdateProduct(companyId, branchId, product_id, cat_id, rack_id, godown_id, tax_id, unit_id, orderlevel, purchase_price, sales_price, txtProductCode.Text, txtHSNCode.Text, txtProductName.Text, User_id, DateTime.Today);

                        var product = context.tbl_product.Where(w => w.product_id == product_id).FirstOrDefault();
                        product.product_name  = txtProductName.Text;
                        product.product_code  = txtProductCode.Text;
                        product.hsn_code      = txtHSNCode.Text;
                        product.purchas_price = decimal.Parse(txtPurchasePrice.Text);
                        product.reorder_level = Convert.ToInt32(txtReorderqty.Text);
                        product.sales_price   = decimal.Parse(txtSalesPrice.Text);
                        product.rack_id       = rack_id;
                        product.category_id   = cat_id;
                        product.godown_id     = godown_id;

                        //Delete Existing Mapping and add new mapping for product and tax group
                        //var tbl_productTaxGroup = new tbl_productTaxGroup { product_id = product_id};
                        //context.tbl_productTaxGroup.Attach(tbl_productTaxGroup);
                        //context.tbl_productTaxGroup.Remove(tbl_productTaxGroup);
                        //context.SaveChanges();
                        foreach (var grpType in context.tbl_productTaxGroup.Where(w => w.product_id == product_id).ToList())
                        {
                            product.tbl_productTaxGroup.Remove(grpType);
                        }

                        for (int i = 0; i < ddlTaxgroup.Items.Count; i++)
                        {
                            if (ddlTaxgroup.Items[i].Selected)
                            {
                                tbl_productTaxGroup productTaxGroup = new tbl_productTaxGroup();
                                ListItem            item            = ddlTaxgroup.Items[i];
                                int groupId = int.Parse(ddlTaxgroup.Items[i].Value);
                                productTaxGroup.product_id = product_id;
                                productTaxGroup.group_id   = groupId;
                                product.tbl_productTaxGroup.Add(productTaxGroup);
                            }
                        }


                        product.unit_id       = unit_id;
                        product.modified_by   = User_id;
                        product.modified_date = DateTime.Now;


                        context.SaveChanges();



                        btnprdUpdate.Visible = false;
                        btnprdSave.Visible   = true;
                        divalert.Visible     = true;
                        clr();
                        lblAlert.Text = "Product Updated Successfully ";
                        ((Product)this.Page).loadDataTable();
                    }
                    else
                    {
                        divalert.Visible = false;
                        lblcheckDoubleError.ForeColor = System.Drawing.Color.Red;
                        lblcheckDoubleError.Text      = "This Product Code name already Exists";
                    }
                }
                else
                {
                    divalert.Visible         = false;
                    lblmsgprodname.ForeColor = System.Drawing.Color.Red;
                    lblmsgprodname.Text      = "This Product Name already Exists";
                }
            }
            catch (Exception ex)
            {
                ErrorLog.saveerror(ex);
                //Do Logging
            }
        }
コード例 #2
0
ファイル: UC_Product.ascx.cs プロジェクト: Khan291/IMS-1.0
        private void savedcode()
        {
            try
            {
                if (hdprodname.Value == "false")
                {
                    if (hdprodname.Value == "false")
                    {
                        lblmsgprodname.Text      = String.Empty;
                        lblcheckDoubleError.Text = String.Empty;
                        tbl_product product = new tbl_product();
                        product.company_id  = companyId;
                        product.branch_id   = branchId;
                        product.category_id = Int32.Parse(ddlCategory.SelectedValue);
                        product.unit_id     = Int32.Parse(ddlUnit.SelectedValue);
                        product.godown_id   = Int32.Parse(ddlGodown.SelectedValue);
                        product.rack_id     = Int32.Parse(ddlRack.SelectedValue);
                        //product.tax_id = Int32.Parse(ddlTax.SelectedValue);
                        product.product_name  = txtProductName.Text;
                        product.product_code  = txtProductCode.Text;
                        product.hsn_code      = txtHSNCode.Text;
                        product.reorder_level = Int32.Parse(txtReorderqty.Text);
                        product.purchas_price = decimal.Parse(txtPurchasePrice.Text);
                        product.sales_price   = decimal.Parse(txtSalesPrice.Text);
                        product.created_by    = User_id;
                        product.created_date  = DateTime.Today;
                        product.status        = true;
                        product.modified_by   = "";
                        product.modified_date = null;
                        ////Shakeeb
                        ////pd.Insert(pd);
                        //Entity Framework Saving Awais

                        foreach (ListItem item in ddlTaxgroup.Items)
                        {
                            if (item.Selected)
                            {
                                tbl_productTaxGroup productTax = new tbl_productTaxGroup();
                                productTax.group_id   = Convert.ToInt32(item.Value);
                                productTax.isSelected = true;
                                product.tbl_productTaxGroup.Add(productTax);
                            }
                        }

                        context.tbl_product.Add(product);
                        context.SaveChanges();
                        clr();
                        divalert.Visible = true;
                        lblAlert.Text    = "Product Saved Successfully ";
                        ((Product)this.Page).loadDataTable();


                        //context.tbl_product.Add(pd);
                        //context.SaveChanges();
                    }
                    else
                    {
                        divalert.Visible = false;
                        lblcheckDoubleError.ForeColor = System.Drawing.Color.Red;
                        lblcheckDoubleError.Text      = "This Product Code name already Exists";
                    }
                }
                else
                {
                    divalert.Visible         = false;
                    lblmsgprodname.ForeColor = System.Drawing.Color.Red;
                    lblmsgprodname.Text      = "This Product name already Exists";
                }
            }
            catch (Exception ex)
            {
                ErrorLog.saveerror(ex);
                //Do Logging
            }
        }