private void btn_AddOrder_Click(object sender, EventArgs e) { bool check = InsertErrorManager.OrderChecker(txt_Customer.Text, comboBox_StoreNames.Text, comboBox1.Text, dateTimePicker.Text, txt_Total.Text); if (check == true) { MessageBox.Show("All field must be filled"); } else { int total = Convert.ToInt32(txt_Total.Text); string orderCode = DaoOrder.AddNewOrder(txt_Customer.Text, comboBox_StoreNames.Text, comboBox1.Text, dateTimePicker.Text, total); int count = datGridView_Items.Rows.Count - 1; for (int i = 0; i < count; i++) { string name = datGridView_Items.Rows[i].Cells[0].Value.ToString(); string strquantity = datGridView_Items.Rows[i].Cells[1].Value.ToString(); string strprice = datGridView_Items.Rows[i].Cells[2].Value.ToString(); int quantity = Convert.ToInt32(strquantity); int price = Convert.ToInt32(strprice); DaoItems.AddItem(name, quantity, price, orderCode); } MessageBox.Show("Order Added, Order Code:" + orderCode); } }
private void btn_ChangeOrder_Click(object sender, EventArgs e) { bool val = InsertErrorManager.OrderChecker(txt_Customer.Text, comboBox_StoreNames.Text, comboBox1.Text, dateTimePicker.Text, txt_Total.Text); if (val == false) { MessageBox.Show("All field must be filled"); } else { int total = Convert.ToInt32(txt_Total.Text); string orderCode = YourOrders.SetCode; if (DaoOrder.UpdateOrder(txt_Customer.Text, comboBox_StoreNames.Text, comboBox1.Text, dateTimePicker.Text, txt_OrderCode.Text)) { DaoItems.DeleteItemsByCode(orderCode); int count = datGridView_Items.Rows.Count - 1; for (int i = 0; i < count; i++) { string name = datGridView_Items.Rows[i].Cells[0].Value.ToString(); string strquantity = datGridView_Items.Rows[i].Cells[1].Value.ToString(); string strprice = datGridView_Items.Rows[i].Cells[2].Value.ToString(); int quantity = Convert.ToInt32(strquantity); int price = Convert.ToInt32(strprice); DaoItems.AddItem(name, quantity, price, orderCode); } MessageBox.Show("Order Saved, Order Code:" + orderCode); } else { MessageBox.Show("Error during the update, try check customer id again"); } } }