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); } }
public static ItemDTO searchItemDescription(String description) { ItemDTO itemDTO = new ItemDTO(); try { String query = "select * from item where itemname=@itemname;"; MySqlCommand command = new MySqlCommand(query, conn); command.Parameters.AddWithValue("@itemname", description); conn.Open(); MySqlDataReader dataReader = command.ExecuteReader(); //int count = 0; while (dataReader.Read()) { itemDTO.setItemCode(dataReader["itemcode"].ToString()); itemDTO.setItemName(dataReader["itemname"].ToString()); itemDTO.setPrice(double.Parse(dataReader["price"].ToString())); itemDTO.setQuantity(int.Parse(dataReader["quantity"].ToString())); //Console.WriteLine(dataReader["itemcode"] + " " + dataReader["itemname"] + " " + dataReader["quantity"] + " " + dataReader["price"]); //count++; } } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); conn.Close(); return(null); } Console.Read(); conn.Close(); return(itemDTO); }