Exemple #1
0
        private void btnCancel_Click(object sender, EventArgs e)
        {
            int     IDTrans = int.Parse(dgvHistory.Rows[RowIndex].Cells[0].Value.ToString());
            DataRow row     = dt.Rows.Find(IDTrans);
            string  status  = row.Field <string>(4).ToString();

            if (status.Equals("Active")) // neu status eq 'Active' means Admin has not approve yet. - > allow cancel
            {
                if (MessageBox.Show("Are you really want to cancel :( ", "Notice", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    // Cong lai so luong trong bang tree
                    TreeBLL   treeBLL  = new TreeBLL();
                    OrderBLL  orderBLL = new OrderBLL();
                    DataTable dtOrders = new DataTable();
                    dtOrders = orderBLL.getOrders(IDTrans);

                    foreach (DataRow r in dtOrders.Rows)
                    {
                        string name     = r.Field <string>(2).ToString();
                        int    quantity = int.Parse(r.Field <int>(3).ToString());
                        treeBLL.IncreaseQuantity(name, quantity);
                    }


                    // update database and update table
                    TransactionBLL transactionBLL = new TransactionBLL();
                    if (transactionBLL.CancelOrdering(IDTrans))
                    {
                        MessageBox.Show("Canceled!");
                        row["Status"] = "Cancel";
                        dgvHistory.Refresh();
                    }
                }
            }
            else if (status.Equals("Delivering"))
            {
                MessageBox.Show("Cannot cancel your order cuz it's delivering");
            }
            else
            {
                MessageBox.Show("It's alreadly canceled");
            }
        }