コード例 #1
0
        private void txtitemName_Leave(object sender, EventArgs e)
        {
            try
            {
                _entities = new KBBQEntities();
                if (txtitemName.Text != string.Empty)
                {
                    var checkLedgername = _entities.purchaseProducts.Where(x => x.pName == txtitemName.Text.Trim().ToString()).FirstOrDefault();

                    if (checkLedgername == null)
                    {
                        DialogResult myResult;
                        myResult = MessageBox.Show("No such product exists. Want to create new product?", "Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                        if (myResult == DialogResult.OK)
                        {
                            //frmAddPurchaseProduct ledger = new frmAddPurchaseProduct(0,txtitemName.Text.Trim());
                            //ledger.ShowDialog();

                            purchaseProduct pp = new purchaseProduct();
                            pp.pName = txtitemName.Text.Trim().ToString();

                            _entities.purchaseProducts.Add(pp);
                            _entities.SaveChanges();

                            itemAutocomplete();
                            txtitemName.Focus();
                        }
                        else
                        {
                            txtitemName.Focus();
                        }
                    }
                }
            }
            catch (Exception x)
            {
            }
        }
コード例 #2
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtProductName.Text == string.Empty && txtQuantity.Text == string.Empty && txtWeight.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txtProductName, "Enter all details.");
                    txtProductName.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter all details.";
                }
                else if (txtProductName.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txtProductName, "Enter Product-name");
                    txtProductName.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter Party-name.";
                }
                else if (txtQuantity.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txtQuantity, "Enter Qty.");
                    txtQuantity.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter Qty.";
                }
                else if (txtWeight.Text == string.Empty)
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(txtWeight, "Enter Weight.");
                    txtWeight.Focus();
                    panel3.Visible = true;
                    lblError.Text  = "Enter Weight.";
                }
                else
                {
                    DateTime date = DateTime.ParseExact(dateToday.Text, "dd-MM-yyyy", null);

                    if (btnSubmit.Text == "Submit")
                    {
                        //save code
                        _entities = new KBBQEntities();


                        purchaseProduct proDate = new purchaseProduct();
                        proDate.pName  = txtProductName.Text.Trim().ToString();
                        proDate.qty    = Convert.ToDecimal(txtQuantity.Text);
                        proDate.weight = Convert.ToDecimal(txtWeight.Text);
                        proDate.unit   = comboUnit.Text.ToString();
                        proDate.date   = date;
                        proDate.cdate  = DateTime.Now;

                        _entities.purchaseProducts.Add(proDate);
                        _entities.SaveChanges();

                        clear();
                        MessageBox.Show("Record Added Successfully");
                    }
                    else
                    {
                        //update code

                        _entities = new KBBQEntities();

                        var proDataUpdate = _entities.purchaseProducts.Where(x => x.id == passedId).FirstOrDefault();

                        proDataUpdate.pName  = txtProductName.Text.Trim().ToString();
                        proDataUpdate.qty    = Convert.ToDecimal(txtQuantity.Text);
                        proDataUpdate.weight = Convert.ToDecimal(txtWeight.Text);
                        proDataUpdate.unit   = comboUnit.Text.ToString();
                        proDataUpdate.date   = date;
                        proDataUpdate.udate  = DateTime.Now;

                        _entities.SaveChanges();

                        clear();
                        MessageBox.Show("Record Updated Successfully");
                    }
                }
            }
            catch (Exception x)
            {
                MessageBox.Show(x.ToString());
            }
        }