Example #1
0
        private void BtnUpdate_Click(object sender, EventArgs e)
        {
            ProductBAL PB = new ProductBAL();

            if (TxtProductName.Text.Trim() != "")
            {
                PB.Product_Name = TxtProductName.Text.Trim();
                if (CMBBrandValueMember != 0)
                {
                    PB.Brand_ID = CMBBrandValueMember;
                    if (TxtCost.Text.Trim() != "")
                    {
                        PB.Product_Cost = Convert.ToDecimal(TxtCost.Text.Trim());
                        if (TxtSellingRate.Text.Trim() != "")
                        {
                            PB.Selling_Rate = Convert.ToDecimal(TxtSellingRate.Text.Trim());
                            PB.Description  = TxtDescription.Text.Trim();
                            PB.Product_ID   = ProductID;
                            ProductDAL PD     = new ProductDAL();
                            int        result = PD.UpdateProduct(PB);
                            if (result > 0)
                            {
                                MessageBox.Show("Product Updated Successfully");
                                LoadDGVProducts();
                            }
                            else
                            {
                                MessageBox.Show("Something Went Wrong");
                            }
                        }
                        else
                        {
                            MessageBox.Show("Please Enter the selling price of the product");
                            TxtSellingRate.Focus();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please Enter the Product Cost");
                        TxtCost.Focus();
                    }
                }
                else
                {
                    MessageBox.Show("Please Select the Brand Name");
                }
            }
            else
            {
                MessageBox.Show("Product Name cannot be blank");
                TxtProductName.Focus();
            }
        }
Example #2
0
    protected void btnsubmit_Click(object sender, EventArgs e)
    {
        try
        {
            //validation
            if (TxtProductName.Text.Length <= 0)
            {
                lblmsg.Text = "Enter product name. "; return;
            }
            string strcount = objDb.ExecuteScaler("select count(*) from ProductMaster where ProductName='" + TxtProductName.Text + "' and ProductCompanyID=" + Convert.ToString(Session["UserID"]));

            if (DdlCategory.Text == "-1")
            {
                lblmsg.Text = "Select category. "; return;
            }

            if (objValidation.IsNumeric(TxtPrice.Text) == false)
            {
                lblmsg.Text = "Enter product price. "; return;
            }


            string strqr = "";
            if (Request.QueryString.Count > 0)
            {
                if (int.Parse(strcount) > 1)
                {
                    lblmsg.Text = "Duplicate product name are not allowed.";

                    TxtProductName.Focus();
                    return;
                }

                strqr = "update ProductMaster set ProductName='" + TxtProductName.Text.Replace("'", "''") + "',ProductDescription='" + TxtDescription.Text.Replace("'", "''") + "', ProductCatId=" + DdlCategory.SelectedItem.Value + ", Price=" + TxtPrice.Text + " where ProductID=" + Convert.ToString(Request.QueryString["id"]);
            }
            else
            {
                if (int.Parse(strcount) >= 1)
                {
                    lblmsg.Text = "Duplicate product name are not allowed.";

                    TxtProductName.Focus();
                    return;
                }

                strqr = "insert into ProductMaster (ProductName,ProductDescription,ProductCatId,ProductCompanyID,Price) values ('" + TxtProductName.Text.Replace("'", "''") + "','" + TxtDescription.Text.Replace("'", "''") + "'," + DdlCategory.SelectedItem.Value + "," + Convert.ToString(Session["UserID"]) + "," + TxtPrice.Text + ")";
            }
            string ret = objDb.ExecuteInsertUpdate(strqr);
            if (ret == "" || ret == null || ret == "0")
            {
                lblmsg.Text = "Error : " + objDb.returnMsg; return;
            }
            this.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script language=\"javaScript\">" + "alert('Record saved successfully!');" + "window.location.href='ProductMaster.aspx';" + "<" + "/script>");

            //Response.Redirect("ProductMaster.aspx");
        }
        catch (Exception ex)
        {
            lblmsg.Text = "Error : " + ex.Message.ToString();
        }
    }
Example #3
0
 private void BtnInsertUpdate_Click(object sender, EventArgs e)
 {
     try
     {
         if (DropDownItemName.SelectedIndex <= 0)
         {
             messageShow.singlemsgtext("Please select the Item Name");
             DropDownItemName.Focus();
             return;
         }
         if (string.IsNullOrEmpty(TxtProductName.Text.ToString()))
         {
             messageShow.singlemsgtext("Product name should not be empty");
             TxtProductName.Focus();
             return;
         }
         if (string.IsNullOrEmpty(TxtMinimumStockNotify.Text.ToString()))
         {
             messageShow.singlemsgtext("Minimum stock notification should not be empty");
             TxtMinimumStockNotify.Focus();
             return;
         }
         else
         {
             if (Convert.ToInt32(TxtMinimumStockNotify.Text.ToString()) < 0)
             {
                 messageShow.singlemsgtext("Minimum stock notification should be greater than zero");
                 TxtMinimumStockNotify.Focus();
                 return;
             }
         }
         var product_master = new ProductMaster
         {
             ProductName = TxtProductName.Text.ToString(),
             MinimumStockNotification = Convert.ToInt32(TxtMinimumStockNotify.Text.ToString()),
             ItemCode      = Convert.ToInt32(((KeyValuePair <string, string>)DropDownItemName.SelectedItem).Key.ToString()),
             ProductCode   = ProductCode,
             OperationType = BtnInsertUpdate.Text.ToString() == "Save" ? 1 : 2
         };
         int id = _instanceRepository.InsertUpdateDeleteProductMaster(product_master);
         if (id >= 1)
         {
             messageShow.singlemsgtext(product_master.OperationType == 1 ? "New Product added successfully" : "Product updated successfully");
             product_master.ProductName = "";
             ResetControlles();
         }
         else if (id == -1)
         {
             messageShow.singlemsgtext("The product name already exists, please try another name!");
         }
         else
         {
             messageShow.singlemsgtext("Error in Product insert/update");
         }
     }
     catch (Exception _exception)
     {
         CmC.InsertException(_exception);
         messageShow.singlemsgtext(CmC.ExceptionErrorMessage);
     }
 }
        /// <summary>
        /// Saving Product
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (TxtProductNumber.Text == "")
                {
                    MessageBox.Show("Enter Product Number");
                    TxtProductNumber.Focus();
                }
                else if (TxtProductName.Text == "")
                {
                    MessageBox.Show("Enter Product Name");
                    TxtProductName.Focus();
                }
                else if (TxtPrice.Text == "")
                {
                    MessageBox.Show("Enter Price");
                    TxtPrice.Focus();
                }
                else if (ComboColor.SelectedIndex == -1)
                {
                    MessageBox.Show("Select Color");
                    ComboColor.Focus();
                }
                else if (ComboClass.SelectedIndex == -1)
                {
                    MessageBox.Show("Select Class");
                    ComboClass.Focus();
                }
                else
                {
                    string message = "Are you sure you want save this record";
                    if (MessageBox.Show(message, "confirmation", MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Information) == System.Windows.Forms.DialogResult.Yes)
                    {
                        string selectedComboColor = ComboColor.Items[ComboColor.SelectedIndex].ToString();
                        string selectedComboClass = ComboClass.Items[ComboClass.SelectedIndex].ToString();

                        Product objproduct = new Product();
                        objproduct.Color         = selectedComboColor;
                        objproduct.Description   = TxtDescription.Text;
                        objproduct.Name          = TxtProductName.Text;
                        objproduct.Price         = Convert.ToDecimal(TxtPrice.Text);
                        objproduct.ProductNumber = TxtProductNumber.Text;
                        objproduct.ProductClass  = selectedComboClass;
                        objproduct.CreatedDate   = DateTime.Now;
                        objproduct.CLientIDToken = ShareObject.CLientIDToken;
                        // Calling Business Layer
                        ProductBL.AddProduct(objproduct);
                        // Binding data to DataGridView
                        DGData.DataSource = ProductBL.GetData(ShareObject.CLientIDToken);
                        DGData.ReadOnly   = true;
                        Clear();
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }