Пример #1
0
 private void btnSubmit_Click(object sender, EventArgs e)
 {
     try
     {
         if (checkCredit.Checked == true)
         {
             //operation
             creditor.SetFirstname(txtFirstname.Text);
             creditor.SetLasttname(txtLastname.Text);
             if (string.IsNullOrEmpty(txtContact.Text))
             {
                 if (MessageBox.Show("Creditor's Contact is empty\ncontinue ?", "Contact Error", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                 {
                     creditor.SetContact("");
                 }
                 else
                 {
                     throw new Exception("Please provide contact infor and continue");
                 }
             }
             else
             {
                 if (txtContact.Text.Length < 11 || txtContact.Text.Length > 11)
                 {
                     throw new Exception("Creditor's Contact has Invalid length of digits");
                 }
                 creditor.SetContact(txtContact.Text);
             }
             setsales.SetQuantity(txtquantity.Text);
             setsales.SetSellinPrice(txtSelingPrice.Text);
             if (setsales.getItemID() <= 0)
             {
                 throw new Exception("Item Not found, Select and item");
             }
             if (!radioBtnNo.Checked && !radioBtnYes.Checked)
             {
                 throw new Exception("Select Yes or No for discount");
             }
             if (string.IsNullOrEmpty(txtTotal.Text) | txtTotal.Text == "0")
             {
                 throw new Exception("Total cost not provided Renter Quantity");
             }
             var qtyAvailable = 0;
             var qtySold      = 0;
             qtyAvailable = ItemSales.checkItemQuantity(setsales.getItemID());
             qtySold      = ItemSales.checkItemQuantitySold(setsales.getItemID());
             if (qtyAvailable <= qtySold)
             {
                 txtquantity.Text = "0";
                 throw new Exception("Item Selected is not available in Stock\nsales could not complete");
             }
             if (qtyAvailable < qtySold + setsales.GetQuantity())
             {
                 throw new Exception("Quantity entered is greater than available Stock\nsales could not complete");
             }
             if (checkAddstudentName.Checked == true && NameID == null)
             {
                 throw new Exception("Student name is NOT Selected");
             }
             var discount = txtPercent.Text;
             var NewQty   = qtyAvailable - (qtySold + setsales.GetQuantity());
             ItemSales.makeSale(setsales.getItemID(), NewQty, setsales.GetQuantity().ToString(), txtAmount.Text, txtTotal.Text, dateTimeAdded, discount, 1, NameID);
             Clear();
             success = 10;
             Infortimer.Start();
         }
         else
         {
             //TO INSERT
             setsales.SetQuantity(txtquantity.Text);
             setsales.SetSellinPrice(txtSelingPrice.Text);
             var qtyAvail = 0;
             var qtySold  = 0;
             if (setsales.getItemID() <= 0)
             {
                 throw new Exception("Item Not found, Select and item");
             }
             qtyAvail = ItemSales.checkItemQuantity(setsales.getItemID());
             qtySold  = ItemSales.checkItemQuantitySold(setsales.getItemID());
             if (qtyAvail <= qtySold)
             {
                 txtquantity.Text = "0";
                 throw new Exception("Selected item is not available in Stock\nsales could not complete");
             }
             if (qtyAvail < qtySold + setsales.GetQuantity())
             {
                 throw new Exception("Selected item Quantity is greater than available Stock\nsales could not complete");
             }
             if (checkAddstudentName.Checked == true && NameID == null)
             {
                 throw new Exception("Student name is NOT Selected");
             }
             if (string.IsNullOrEmpty(txtTotal.Text) | txtTotal.Text == "0")
             {
                 throw new Exception("Total cost not provided Renter Quantity");
             }
             var discount = txtPercent.Text;
             var NewQty   = qtyAvail - (qtySold + setsales.GetQuantity());
             ItemSales.makeSale(setsales.getItemID(), NewQty, setsales.GetQuantity().ToString(), txtAmount.Text, txtTotal.Text, dateTimeAdded, discount, 0, NameID);
             Clear();
             success = 10;
             Infortimer.Start();
         }
     }catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Sales Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }