private void btnRegesterSale_Click(object sender, EventArgs e) { Sale mySale = new Sale(); mySale.setSale_id(Convert.ToInt32(txtSaleID.Text)); //checks to see if the user is paying by credit sets the customer id to the selected customer id and the sale status to U(Unpayed) if (rdoCredit.Checked) { mySale.setCustomer_id(Convert.ToInt32(grdCust.Rows[grdCust.CurrentCell.RowIndex].Cells[0].Value)); mySale.setStatus("U"); } //if the user is paying by cash sets the sales customer id to null and sets the sale status to P(Payed) else { mySale.setStatus(Convert.ToString('P')); mySale.setCustomer_id(0); } mySale.setSaleDate(String.Format("{0:dd-MMM-yy}", DateTime.Now)); mySale.setSaleValue(Convert.ToDecimal(txtSaleValue.Text)); mySale.addSale(); int i = 0; grdCart.Rows[i].Selected = true; //goes through each row of the shopping cart adding each item to the databace while (i < grdCart.RowCount) { Saleitem newSaleItem = new Saleitem(); newSaleItem.setSale_id(Convert.ToInt32(txtSaleID.Text)); newSaleItem.setStock_id(Convert.ToInt32(grdCart.Rows[i].Cells[0].Value)); newSaleItem.setQtysold(Convert.ToInt32(grdCart.Rows[i].Cells[2].Value)); newSaleItem.setPrice(Convert.ToDecimal(grdCart.Rows[i].Cells[6].Value)); newSaleItem.addSaleitem(); Stock.replaceStock(Convert.ToInt32(grdCart.Rows[i].Cells[0].Value), Convert.ToInt32(grdCart.Rows[i].Cells[2].Value)); i++; } MessageBox.Show("Sale has been registered. Your Sale ID is " + txtSaleID.Text + ". Remember this incase you need to return your items."); this.Close(); parent.Show(); }