private void button6_AddItem_Click(object sender, EventArgs e) { string brand_name = comboBox_BrandName.Text; string model_name = comboBox2_model.Text; string fuel_type = comboBox3_fuel.Text; string engine_capacity = comboBox4_engine.Text; string year = comboBox5_year.Text; string cat_name = comboBox6_category.Text; string part_name = comboBox7_part.Text; string Inventory_ItemCode; if (brand_name != "" && model_name != "" && fuel_type != "" && engine_capacity != "" && year != "" && cat_name != "" && part_name != "") { String[] ar = new String[4]; DatabaseConnections db = new DatabaseConnections(); string Brand_id = db.GetId(brand_name, "Brand"); string Model_id = db.GetId(model_name, "Model"); string Fuel_id = db.GetId(fuel_type, "Fuel"); string Engine_Id = db.GetId(engine_capacity, "Engine"); string Year_id = db.GetId(year, "Yearr"); string Cat_id = db.GetId(cat_name, "Category"); string Part_id = db.GetId(part_name, "SparePart"); Inventory_ItemCode = Brand_id + Model_id + Fuel_id + Engine_Id + Year_id + Cat_id + Part_id; ar[0] = Inventory_ItemCode; ar[1] = db.getItemDetails_String(Inventory_ItemCode); ar[2] = db.get_unit_price("100" + Inventory_ItemCode); //MessageBox.Show(Inventory_ItemCode); long QuantityHand = db.CheckQuantity(Inventory_ItemCode); if (QuantityHand >= 0) { int quantity = Convert.ToInt32(quantity_box.Text); ar[3] = quantity.ToString(); int total = Convert.ToInt32(total_box.Text); int unit_pr = Convert.ToInt32(ar[2]); // to get the sum total = total + unit_pr * quantity; //set total total_box.Text = total.ToString(); // things to do :deduct from stock/print bill/record to log/ clear row etc. ListViewItem itm = new ListViewItem(ar); listView1.Items.Add(itm); comboBox_BrandName.Text = null; comboBox2_model.Text = null; comboBox3_fuel.Text = null; comboBox4_engine.Text = null; comboBox5_year.Text = null; comboBox6_category.Text = null; comboBox7_part.Text = null; quantity_box.Text = null; } else { MessageBox.Show("Check all the fiels. Invalid Itemcode.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Can't keep empty fields", "Warinning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void pictureBoxDeleteButton_Click(object sender, EventArgs e) { String itemCode = textBox_ItemCode_DeleteStock.Text; String repeatitemCode = textBox_RepeatItemCode_DeleteStock.Text; string description = textBoxDescription_DeleteItem.Text; string date = dateTimePicker_DeleteItem.Value.ToString(); if (itemCode == repeatitemCode && (itemCode != "" || repeatitemCode != "")) { DatabaseConnections db = new DatabaseConnections(); long QuantityHand = db.CheckQuantity(itemCode); DialogResult result1 = MessageBox.Show("ItemCode : " + itemCode + "\n Item Name : " + db.getItemDetails_String(itemCode), "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result1 == DialogResult.Yes && QuantityHand == 0) { DatabaseConnections db1 = new DatabaseConnections(); textBox_ItemCode_DeleteStock.Text = null; textBox_RepeatItemCode_DeleteStock.Text = null; textBoxDescription_DeleteItem.Text = null; db1.DeleteItem(itemCode); db1.Delete_Clear_Details(itemCode, description, date, "Delete"); } else if (result1 == DialogResult.Yes && QuantityHand > 0) { DialogResult result = MessageBox.Show("Item Quantity is " + QuantityHand + " Please clear the stock before delete the Item.", "Warnning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (result == DialogResult.OK) { Stock_Control stock = new Stock_Control(4); stock.Show(); } else { this.Hide(); textBox_ItemCode_DeleteStock.Text = null; textBox_RepeatItemCode_DeleteStock.Text = null; textBoxDescription_DeleteItem.Text = null; } } else if (result1 == DialogResult.Yes && QuantityHand == -1) { MessageBox.Show("Invalid ItemCode", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); textBox_ItemCode_DeleteStock.Text = null; textBox_RepeatItemCode_DeleteStock.Text = null; textBoxDescription_DeleteItem.Text = null; } else { textBox_ItemCode_DeleteStock.Text = null; textBox_RepeatItemCode_DeleteStock.Text = null; textBoxDescription_DeleteItem.Text = null; } } else { MessageBox.Show("Check Item Code", "", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error); } }