public static Boolean updateStockQty(ItemDTO item) { int result = 0; try { string query = "update pos.item SET quantity=@quantity where itemcode=@itemcode"; MySqlCommand command = new MySqlCommand(query, conn); command.Parameters.AddWithValue("@quantity", item.getQuantity()); command.Parameters.AddWithValue("@itemcode", item.getItemCode()); conn.Open(); result = command.ExecuteNonQuery(); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); conn.Close(); return(false); } Console.Read(); conn.Close(); if (result > 0) { return(true); } else { return(false); } }
private void CmbItemCode_SelectedIndexChanged(object sender, EventArgs e) { /*ItemDTO item = new ItemDTO(); * item = ItemController.searchItem((cmbItemCode.SelectedItem).ToString()); * txtItemDescription.Text = item.getItemName(); * txtQtyOnHand.Text = (item.getQuantity()).ToString(); * txtUnitPrice.Text = (item.getPrice()).ToString(); * codeOfItem = item.getItemCode();*/ ItemDTO item = new ItemDTO(); item = ItemController.searchItemDescription((cmbItemDescription.SelectedItem).ToString()); txtItemCode.Text = item.getItemCode(); txtQtyOnHand.Text = (item.getQuantity()).ToString(); txtUnitPrice.Text = (item.getPrice()).ToString(); codeOfItem = item.getItemCode(); }
private void BtnRemoveItems_Click(object sender, EventArgs e) { if (tblCheckOut.SelectedCells.Count > 0) { int row = tblCheckOut.CurrentCell.RowIndex; String curValue = tblCheckOut.CurrentCell.Value.ToString(); DataGridViewRow selectedRow = tblCheckOut.Rows[row]; string code = selectedRow.Cells[0].Value.ToString(); txtTotalAmount.Text = (double.Parse(txtTotalAmount.Text) - double.Parse(selectedRow.Cells[4].Value.ToString())).ToString(); ItemDTO current = ItemController.searchItem(code); ItemController.updateStockQty(new ItemDTO(code, "", int.Parse(selectedRow.Cells[3].Value.ToString()) + current.getQuantity(), 0.0)); int qty = int.Parse(selectedRow.Cells[3].Value.ToString()); txtQtyOnHand.Text = (current.getQuantity() + qty).ToString(); tblCheckOut.Rows.RemoveAt(row); } else { MessageBox.Show("Please select a column"); } }
public static Boolean addNewItem(ItemDTO itemDTO) { int result = 0; try { String query = "INSERT INTO pos.item (itemcode,itemname,quantity,price) VALUES (@itemcode, @itemname, @quantity,@price)"; MySqlCommand command = new MySqlCommand(query, conn); //Console.WriteLine(custDTO.getNic() + " " + custDTO.getName()); command.Parameters.AddWithValue("@itemcode", itemDTO.getItemCode()); command.Parameters.AddWithValue("@itemname", itemDTO.getItemName()); command.Parameters.AddWithValue("@quantity", itemDTO.getQuantity()); command.Parameters.AddWithValue("@price", itemDTO.getPrice()); conn.Open(); result = command.ExecuteNonQuery(); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); // MessageBox.Show("exception occured"); conn.Close(); return(false); } Console.Read(); conn.Close(); if (result > 0) { return(true); } else { return(false); } }