private void checkOutfield_Click(object sender, EventArgs e) { DBConnect transaction = new DBConnect(); if (data.check != 0) { data.check = 0; } if (listView1.Items.Count > 0) { String totalQuery = "UPDATE transactionlog SET total=" + data.sum + "WHERE transactionID=" + data.transID + ""; double total = Double.Parse(totalField.Text); checkoutscreen last = new checkoutscreen(total); last.Show(); transaction.insertLog(totalQuery);// repurposed code last.FormClosing += (obj, args) => { this.Close(); }; } else { //deleting transaction when it has no items String query = "UPDATE transactionlog SET remark='RETURNED' WHERE transactionID=" + data.transID + ""; transaction.insertLog(query);//repurposed code this.Close(); } }
private void button2_Click(object sender, EventArgs e) { DBConnect peepee = new DBConnect(); Transucc1 local = new Transucc1(); int check = Convert.ToInt32(qtyField.Value); String query; query = "SELECT*FROM product WHERE bar_code='" + IDfield.Text + "'"; //GETS BARCODE FROM DB AND STORES IN LOCAL CLASS peepee.getItem(local, query); String log = "INSERT INTO purchaselog(itemID,purchaseDate,qty,transactionID) VALUES(" + local.ID + ",curdate()," + check + "," + data.transID + ")"; if (local.qty - check >= 0) { String purchase = IDfield.Text; int qty = (int)qtyField.Value; double price = local.price * qty; //variable computes price times qty data.sum += price; //updates global price local.qty = check; //assigns the item holder qty to it's right value local.price = price; //assigns the item prices to it's right value peepee.transaction(this.trans, purchase, qty, local); //changes quantity then puts item in transaction global totalField.Text = data.sum.ToString(); //reset fields IDfield.Clear(); qtyField.Value = 1; IDlabel.Text = local.ID.ToString(); itemLabel.Text = local.itemName.ToString(); itemNamefield.Clear(); int holder = local.barCode; int i; for (i = 0; i < copy.Count && holder != copy[i].barCode; i++) { } //finds item in inventory copy if (i < copy.Count) { int x; for (x = listView1.Items.Count - 1; x >= 0 && listView1.Items[x].SubItems[1].Text != copy[i].barCode.ToString(); x--) { } //finds item in list view if (x >= 0) { incrementSubItem(x, local);//increments list view and purchase log when item already exists } else { updateList(local.itemName.ToString(), price, qty, local.barCode); //FUNCTION ADDS TO LISTVIEW peepee.insertLog(log); //inserts item into log } } } else if (String.IsNullOrEmpty(IDfield.Text)) { MessageBox.Show("Please enter barcode/name"); } else { MessageBox.Show("Insufficient stocks"); } }
private void incrementSubItem(int indx, Transucc1 x) { DBConnect update = new DBConnect(); int qty = int.Parse(listView1.Items[indx].SubItems[2].Text); String query = "UPDATE purchaselog SET qty=qty+'" + qty + "'WHERE itemID='" + x.ID + "' AND transactionID='" + data.transID + "'"; double total = Double.Parse(listView1.Items[indx].SubItems[3].Text); qty += x.qty; total += x.price; listView1.Items[indx].SubItems[2].Text = qty.ToString(); listView1.Items[indx].SubItems[3].Text = total.ToString(); update.insertLog(query);//increments purchase log quantity }
private void button1_Click(object sender, EventArgs e) { DBConnect edit = new DBConnect(); int barcode; if (!String.IsNullOrEmpty(IDfield.Text)) { barcode = int.Parse(IDfield.Text); int qty = (int)qtyField.Value; int x; int i; for (i = 0; i < copy.Count && barcode != copy[i].barCode; i++) { } //finds item in inventory copy if (i < copy.Count) { for (x = listView1.Items.Count - 1; x >= 0 && listView1.Items[x].SubItems[1].Text != barcode.ToString(); x--) { } //finds item in list view if (x >= 0) { int qtyDec = int.Parse(listView1.Items[x].SubItems[2].Text); //gets qty purchased double priceDec = Double.Parse(listView1.Items[x].SubItems[3].Text); //gets total price of purchased item String query = "INSERT INTO purchaselog(itemID, purchaseDate, qty, transactionID,remark) VALUES(" + copy[i].ID + ", curdate(), " + qty + ", " + data.transID + ",'RETURNED')"; String query2 = "UPDATE product SET product_qty = product_qty + '" + qty + "'WHERE bar_code = '" + barcode + "'"; if (qtyDec - qty > 0) { qtyDec -= qty; priceDec -= (copy[i].price * qty); listView1.Items[x].SubItems[2].Text = qtyDec.ToString(); listView1.Items[x].SubItems[3].Text = priceDec.ToString(); data.sum -= (double)(copy[i].price * qty); totalField.Text = data.sum.ToString(); edit.insertLog(query); edit.insertLog(query2); IDfield.Clear(); qtyField.Value = 1; itemNamefield.Clear(); } else if (qtyDec - qty == 0) { listView1.Items[x].Remove(); edit.insertLog(query); data.sum -= (copy[i].price * qty); totalField.Text = data.sum.ToString(); edit.insertLog(query); edit.insertLog(query2); IDfield.Clear(); qtyField.Value = 1; itemNamefield.Clear(); } else { MessageBox.Show("Invalid Amount"); } } else { MessageBox.Show("Item not purchased"); } } else { MessageBox.Show("Item not found"); } } else { MessageBox.Show("Please enter barcode/name"); } }