Exemplo n.º 1
0
        private void btnDetailSave_Click(object sender, EventArgs e)
        {
            decimal TongTien = 0;

            if (CheckBill())
            {
                if (dgvDachon.Rows.Count != 0)
                {
                    for (int row = 0; row < dgvDachon.Rows.Count; row++)
                    {
                        ChiTietHoaDon billdetailto = getBillDetail(txtIDBilltoDetail.Text, dgvDachon.Rows[row].Cells[0].Value.ToString(), decimal.Parse(dgvDachon.Rows[row].Cells[3].Value.ToString()), int.Parse(dgvDachon.Rows[row].Cells[2].Value.ToString()));
                        if (_service.getBillDetail(billdetailto.MaHD, billdetailto.MaSP) == null)
                        {
                            _service.CreateBillDetail(billdetailto);
                        }
                        else
                        {
                            _service.UpdateBillDetail(billdetailto);
                        }
                        TongTien += decimal.Parse(dgvDachon.Rows[row].Cells[3].Value.ToString()) * int.Parse(dgvDachon.Rows[row].Cells[2].Value.ToString());
                    }
                }
                else
                {
                    _service.DeleteBillDetailByID(txtIDBilltoDetail.Text);
                }
                HoaDon billtoUpdate = _service.getBill(txtIDBilltoDetail.Text);
                billtoUpdate.TongTien  = TongTien;
                billtoUpdate.TrangThai = "Đang chờ ";
                _service.EditBill(billtoUpdate);
                View();
                ViewErrors();
                BilltoChecked      = billtoUpdate;
                txtTotal.Text      = _service.getBill(txtIDBilltoDetail.Text).TongTien.ToString();
                txtTotalPayed.Text = txtTotal.Text;
                btnPayment.Enabled = true;
                timer.Tick        += new EventHandler(timer_Tick);
                timer.Interval     = (1000) * (30);
                timer.Enabled      = true;
                timer.Start();
            }
        }