Ejemplo n.º 1
0
        private void btnAddFinishProduct_Click(object sender, EventArgs e)
        {
            if (txtFinishProductAvgCost.Text.Equals("") || txtProductCode.Text.Equals("") || txtFinishProductDescription.Text.Equals(""))
            {
                MessageBox.Show(this, "Please Fill all Fields", "Blank Fields", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
            else
            {
                try
                {
                    objFinishProduct.FinishProductCode        = txtProductCode.Text;
                    objFinishProduct.BasicProduct             = objbasicProductDL.Get(cmbBasicProduct.SelectedValue.ToString());
                    objFinishProduct.FinishProductPackingType = objPackingTypeDL.Get(Convert.ToInt64(cmbPackType.SelectedValue));
                    objFinishProduct.FinishProductDescription = txtFinishProductDescription.Text;
                    objFinishProduct.BasicProductQty          = Convert.ToDecimal(txtBasicProductQty.Text);
                    objFinishProduct.FinishProductAvgCost     = Convert.ToDecimal(txtFinishProductAvgCost.Text);
                    if (chkEnablePr.Checked == true)
                    {
                        objFinishProduct.FinishProductStatus = true;
                    }
                    else
                    {
                        objFinishProduct.FinishProductStatus = false;
                    }
                    objFinishProduct.PrimaryFinishProductCode = txtProductCode.Text;
                    objFinishProduct.PrimaryFinishProductQty  = 1;
                    objFinishProduct.FinishProductType        = "Primary";

                    int x;
                    x = objFinishProductDL.Add(objFinishProduct);
                    gvFinishProduct.DataSource = objFinishProductDL.GetDataView("Primary", cmbBasicProduct.SelectedValue.ToString());

                    if (x > 0)
                    {
                        MessageBox.Show(this, "Succesfully Added to Database", "Succesfull", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        this.ClearFinishProduct();
                    }
                    else if (x == -1)
                    {
                        MessageBox.Show(this, "Product Code already in the Database,Please enter another Product Code", "Problem with Product Code", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                catch (FormatException)
                {
                    MessageBox.Show(this, "Please enter valid data", "Input Data Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                }
            }
        }