예제 #1
0
        //Thêm chi tiet phiếu - Xuất dữ liệu
        private void btnSaveOfDetailOut_Click(object sender, EventArgs e)
        {
            int          flag       = 0;
            Decimal      TotalMoney = 0;
            DialogResult dlr        = Decimal.Parse(txtTotaltoEdit.Text) > 0 ? MessageBox.Show("Bạn có muốn thay đổi chi tiết phiếu ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk)
                : MessageBox.Show("Bạn có muốn lưu không? ", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);

            if (dlr == DialogResult.Yes)
            {
                for (int row = 0; row < dgvDetailOut.Rows.Count; row++)
                {
                    String       IDProduct      = dgvDetailOut.Rows[row].Cells[0].Value.ToString();
                    Decimal      Price          = decimal.Parse(dgvDetailOut.Rows[row].Cells[3].Value.ToString());
                    int          Quality        = int.Parse(dgvDetailOut.Rows[row].Cells[2].Value.ToString());
                    ChiTietPhieu coupondetailto = getCouponDetail(txtIDCouponDetailOut.Text, IDProduct, Price, Quality);
                    if (_service.getDetailCoupon(txtIDCouponDetailOut.Text, IDProduct) == null)
                    {
                        if (!_service.CreateDetailCoupon(coupondetailto))
                        {
                            flag = 1;
                        }
                        MessageBox.Show("1");
                    }
                    else
                    {
                        if (!_service.UpdateDetailCoupon(coupondetailto))
                        {
                            flag = 1;
                        }
                        MessageBox.Show("2");
                    }
                    TotalMoney += Price * Quality;
                }
                if (flag == 0)
                {
                    PhieuNhapXuat Target = _service.getCoupon(txtIDCouponDetailOut.Text);
                    Target.TongTien = TotalMoney;
                    _service.EditCoupon(Target);
                    View();
                }
                else
                {
                    MessageBox.Show("Lỗi: Hệ thống đang bận vui lòng thử lại sau", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }