private void btn_Save_Click(object sender, EventArgs e) { if (_itemOUT == false && _suppDAO.CheckSupplierByID(this.cBoxID.Text) == false) { MessageBox.Show("Sorry, Supplier not found, please insert another supplier ID.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); this.cBoxID.Focus(); } else if (_itemOUT == true && _custDAO.CheckCustomerByID(this.cBoxID.Text) == false) { MessageBox.Show("Sorry, Customer not found, please insert another supplier ID.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); this.cBoxID.Focus(); } else { if (MessageBox.Show("Are you sure to add this data ? ", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { string transNumber = _transDAO.GetTransactionNumberNext(); List <Transaction> listTrans = new List <Transaction>(); foreach (DataGridViewRow row in this.dgvTransaction.Rows) { if (Convert.ToInt32(row.Cells[3].Value) > 0) { if (_itemOUT) { listTrans.Add(new Transaction { transactionID = this.txtBox_TransID.Text, transactionNumber = transNumber, transactionDate = this.dtp_TransDate.Value.ToShortDateString(), itemData = _itemDAO.GetItemByID(row.Cells[0].Value.ToString()), suppData = null, custData = _custDAO.GetCustomerByID(this.cBoxID.Text), qtyBefore = Convert.ToInt32(row.Cells[2].Value), qtyTrans_IN = 0, qtyTrans_OUT = Convert.ToInt32(row.Cells[3].Value), qtyAfter = Convert.ToInt32(row.Cells[4].Value) }); } else { listTrans.Add(new Transaction { transactionID = this.txtBox_TransID.Text, transactionNumber = transNumber, transactionDate = this.dtp_TransDate.Value.ToShortDateString(), itemData = _itemDAO.GetItemByID(row.Cells[0].Value.ToString()), suppData = _suppDAO.GetSupplierByID(this.cBoxID.Text), custData = null, qtyBefore = Convert.ToInt32(row.Cells[2].Value), qtyTrans_IN = Convert.ToInt32(row.Cells[3].Value), qtyTrans_OUT = 0, qtyAfter = Convert.ToInt32(row.Cells[4].Value) }); } } transNumber = $"{(int.Parse(transNumber) + 1).ToString("00000")}"; _itemDAO.UpdateQuantity(row.Cells[0].Value.ToString(), Convert.ToInt32(row.Cells[4].Value)); } _transDAO.AddTransaction(listTrans); _itemDAO.UpdateAllItem(); this.Close(); } } }