private void AddBtn_Click(object sender, EventArgs e) { if (QuantityUpDown.Value != 0) { bool sameItem = false; foreach (DataGridViewRow row in dataGridView1.Rows) { string item = row.Cells[0].Value.ToString(); if (item == ItemTxtLb.Text) { sameItem = true; } } if (sameItem == false) { var index = dataGridView1.Rows.Add(); dataGridView1.Rows[index].Cells[0].Value = ItemTxtLb.Text; dataGridView1.Rows[index].Cells[1].Value = UnitPriceTxtLb.Text; dataGridView1.Rows[index].Cells[2].Value = QuantityUpDown.Value; dataGridView1.Rows[index].Cells[3].Value = TotalPriceTxtLb.Text; dataGridView1.Rows[index].Cells[4].Value = orderID; dataGridView1.ClearSelection(); string TPtxt = TotalPriceTxtLb.Text.Replace("€", ""); totalprice += Convert.ToInt32(TPtxt); ValueLb.Text = totalprice.ToString() + "€"; QuantityUpDown.Value = 0; UnitPriceTxtLb.ResetText(); TotalPriceTxtLb.ResetText(); ItemTxtLb.ResetText(); QuantityUpDown.Hide(); listBox.ClearSelected(); } else { MessageBox.Show("You cant add the same item", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("You cant add 0 items", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void AddButton_Click(object sender, EventArgs e) { const string error = "You have provided invalid details. Please try again."; var quantity = Convert.ToInt32(QuantityUpDown.Text); var prodCode = ProductCodeComboBox.Text; _connection = DB_Connect.connect(); _connection.Open(); _sda = new SqlDataAdapter(@"SELECT * FROM[Products] WHERE[ProductCode] = '" + prodCode + "'", _connection); _dt = new DataTable(); _sda.Fill(_dt); dataGridView1.Rows.Clear(); if (_dt.Rows.Count == 1 && quantity != 0) { foreach (DataRow unused in _dt.Rows) { NumOfItems = NumOfItems + 1; } _command = new SqlCommand(@"INSERT INTO[Ordered Items]([OrderID], [ProductCode], [Quantity]) VALUES ('" + _randCode + "', '" + prodCode + "', '" + quantity + "')", _connection); _command.ExecuteNonQuery(); _command = new SqlCommand(@"INSERT INTO[Cart]([ProductCode], [Quantity]) VALUES ('" + prodCode + "', '" + quantity + "')", _connection); _command.ExecuteNonQuery(); _sda = new SqlDataAdapter(@"SELECT * FROM[Cart]", _connection); _dt = new DataTable(); _sda.Fill(_dt); dataGridView1.Rows.Clear(); foreach (DataRow item in _dt.Rows) { var n = dataGridView1.Rows.Add(); dataGridView1.Rows[n].Cells[0].Value = item["ProductCode"].ToString(); dataGridView1.Rows[n].Cells[1].Value = item["Quantity"].ToString(); } } else { MessageBox.Show(error); QuantityUpDown.Value = 0; QuantityUpDown.Focus(); } _sda.Dispose(); _connection.Close(); }
private void itemsListBox_SelectedIndexChanged(object sender, EventArgs e) { QuantityUpDown.ResetText(); txtTotal.Clear(); String text = itemsListBox.GetItemText(itemsListBox.SelectedItem); txtItemName.Text = text; query = "select price from items where item_name = '" + text + "'"; DataSet ds = fn.getData(query); try { txtPrice.Text = ds.Tables[0].Rows[0][0].ToString(); } catch { } }
private void PlaceOrderUC_Load(object sender, EventArgs e) { ItemTxtLb.Hide(); TotalPriceTxtLb.Hide(); TotalPriceTxtLb.Text = ""; UnitPriceTxtLb.Hide(); QuantityUpDown.Hide(); query = "select distinct category from items"; DataSet ds = db.getData(query); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { CategoryBox.Items.Add(ds.Tables[0].Rows[i][0].ToString()); } }
private void listBox_SelectedIndexChanged(object sender, EventArgs e) { QuantityUpDown.Value = 0; TotalPriceTxtLb.ResetText(); ItemTxtLb.Show(); UnitPriceTxtLb.Show(); String text = listBox.GetItemText(listBox.SelectedItem); ItemTxtLb.Text = text; query = "select price from items where name = '" + text + "'"; DataSet ds = db.getData(query); try { UnitPriceTxtLb.Text = ds.Tables[0].Rows[0][0].ToString() + "€"; QuantityUpDown.Show(); } catch { UnitPriceTxtLb.Hide(); } }