private void grdCustomerSearch_CellClick(object sender, DataGridViewCellEventArgs e) { DataSet ds = new DataSet(); txtTotal.Text = "0.00"; grdIssue.DataSource = Saleitem.getMatchingInvoice(ds, Convert.ToInt32(grdCustomerSearch.Rows[grdCustomerSearch.CurrentCell.RowIndex].Cells[0].Value)).Tables["ss"]; grdIssue.AllowUserToAddRows = false; Customer Invoice = new Customer(); Invoice.getCustomer(Convert.ToInt32(grdCustomerSearch.Rows[grdCustomerSearch.CurrentCell.RowIndex].Cells[0].Value)); int i = 0; while (i < grdIssue.RowCount) { txtTotal.Text = Convert.ToString(Convert.ToDecimal(txtTotal.Text) + Convert.ToDecimal(grdIssue.Rows[i].Cells[5].Value)); i++; } if (grdIssue.RowCount == 0) { grpPayInvoice.Visible = false; MessageBox.Show(Convert.ToString(grdCustomerSearch.Rows[grdCustomerSearch.CurrentCell.RowIndex].Cells[2].Value)+" "+ Convert.ToString(grdCustomerSearch.Rows[grdCustomerSearch.CurrentCell.RowIndex].Cells[1].Value)+" does not owe the company any money"); } else { grpPayInvoice.Visible = true; } }
private void btnSrh_Click(object sender, EventArgs e) { Regex numeric = new Regex("^[0-9]*$"); if (txtSaleID.Text.Equals("")) { MessageBox.Show("Sale ID was left blank"); txtSaleID.Focus(); return; } else if (!numeric.IsMatch(txtSaleID.Text)) { MessageBox.Show("Sale ID must use numeric characters"); txtSaleID.Clear(); txtSaleID.Focus(); return; } else { DataSet ds = new DataSet(); grdCart.DataSource = Saleitem.getMatchingSaleItem(ds, Convert.ToInt32(txtSaleID.Text)).Tables["ss"]; grdCart.AllowUserToAddRows = false; if (grdCart.RowCount == 0) { grpStock.Visible = false; MessageBox.Show(Convert.ToString(txtSaleID.Text) + " : This Sale id did not take place on this system"); txtSaleID.Text = ""; } else { int sum = 0; for (int i = 0; i < grdCart.RowCount; i++) { sum += Convert.ToInt32(grdCart.Rows[i].Cells[2].Value); } if (sum <= 0) { grpStock.Visible = false; MessageBox.Show(Convert.ToString(txtSaleID.Text) + " : This Sale id already has all items returned"); txtSaleID.Text = ""; } else { grpStock.Visible = true; txtSaleID.ReadOnly = true; } } } }
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(); }
private void btnReturnItem_Click(object sender, EventArgs e) { Regex numeric = new Regex("^[0-9]*$"); if (txtQtySold.Text.Equals("")) { MessageBox.Show("Quantity Sold was left blank"); txtQtySold.Focus(); return; } else if (!numeric.IsMatch(txtQtySold.Text)) { MessageBox.Show("Quantity Sold must use numeric characters"); txtQtySold.Clear(); txtQtySold.Focus(); return; } else if (Convert.ToInt16(txtQtySold.Text) > Convert.ToInt32(grdCart.Rows[grdCart.CurrentCell.RowIndex].Cells[2].Value)) { MessageBox.Show("The quantity you are returning is greater than the quantity you have bought"); } else { grdCart.Rows[0].Selected = true; Saleitem.returnStock(Convert.ToInt32(grdCart.Rows[grdCart.CurrentCell.RowIndex].Cells[0].Value), Convert.ToInt16(txtQtySold.Text), Convert.ToInt16(txtSaleID.Text)); Sale.returnSale(Convert.ToInt32(txtSaleID.Text), Convert.ToDecimal(grdCart.Rows[grdCart.CurrentCell.RowIndex].Cells[2].Value) * Convert.ToInt16(txtQtySold.Text)); if (rdoTrue.Checked) { Stock.returnStock(Convert.ToInt32(grdCart.Rows[grdCart.CurrentCell.RowIndex].Cells[0].Value), Convert.ToInt32(txtQtySold.Text)); } MessageBox.Show("Item has been returned"); this.Close(); parent.Show(); } }