private void itemNamefield_TextChanged(object sender, EventArgs e) { if (String.IsNullOrEmpty(itemNamefield.Text)) { itemLabel.Text = "XXXXXXXXXXX"; IDlabel.Text = "XXXXXXXXXXX"; priceLabel.Text = "0.00"; IDfield.Clear(); } else { String holder = itemNamefield.Text.ToString(); int i; for (i = 0; i < copy.Count && !holder.Equals(copy[i].itemName); i++) { } if (i < copy.Count) { IDfield.Text = copy[i].barCode.ToString(); IDlabel.Text = copy[i].ID.ToString(); priceLabel.Text = copy[i].price.ToString(); itemLabel.Text = copy[i].itemName; } else { IDfield.Clear(); itemLabel.Text = "ITEM NOT FOUND"; } } }
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 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"); } }