コード例 #1
0
 private void LoadHoaDon()
 {
     busHoaDon = new BUS.BUSHOADON();
     try
     {
         var _HD = (from a in busHoaDon.LayTatCaHOADON()
                    orderby a.MAHD
                    select new
                    {
                        MaHD = a.MAHD
                    }).Last();
         lblMaHD.Text = (_HD.MaHD + 1).ToString();
         MaHD = _HD.MaHD + 1;
     }
     catch
     {
         lblMaHD.Text = "1";
         MaHD = 1;
     }
 }
コード例 #2
0
        private void btnThanhToan_Click_1(object sender, EventArgs e)
        {
            if (dtoPhieuNhanPhong.Count == busPhieuNhanPhong.LayTatCaPHIEUNHANPHONG().Count)
            {
                if (txtTienNhan.Text.Trim() != "")
                {
                    btnThanhToan.Enabled = false;
                    txtTienThua.Text = (int.Parse(txtTienNhan.Text) - int.Parse(txtTongTien.Text)).ToString();
                    if ((int.Parse(txtTienNhan.Text) - int.Parse(txtTongTien.Text) > 0))
                    {
                        busHoaDon = new BUS.BUSHOADON();
                        DTO.DTOHOADON dtoHoadon = new DTO.DTOHOADON();
                        dtoHoadon.MAHD = MaHD;
                        dtoHoadon.MANV = clsXuLy.MANV;
                        dtoHoadon.MAPHIEU = MaPhieu;
                        dtoHoadon.NGAYHD = DateTime.Now;
                        dtoHoadon.TONGTIEN = int.Parse(txtTongTien.Text);
                        busHoaDon.ThemHOADON(dtoHoadon);
                        BUS.BUSCTCHIETKHAU _busCTCK = new BUS.BUSCTCHIETKHAU();
                        int _mahd = busHoaDon.LayTatCaHOADON().OrderBy(a => a.MAHD).Last().MAHD;

                        #region Them 1 CTCHIETKHAU trong
                        var _dtoCTCK = new DTO.DTOCTCHIETKHAU();
                        _dtoCTCK.MACK = 23;
                        _dtoCTCK.MAHD = _mahd;
                        _dtoCTCK.PHANTRAMCK = 0;
                        _busCTCK.ThemCTCHIETKHAU(_dtoCTCK);
                        #endregion

                        foreach (DataGridViewRow _row in grdCK.Rows)
                        {
                            if (_row.Cells[3].Value != null && (bool)_row.Cells[3].Value == true)
                            {
                                DTO.DTOCTCHIETKHAU _ck = new DTO.DTOCTCHIETKHAU();
                                _ck.MACK = Convert.ToInt32(_row.Cells[0].Value);
                                _ck.MAHD = _mahd;
                                _ck.PHANTRAMCK = Convert.ToInt32(_row.Cells[2].Value);

                                _busCTCK.ThemCTCHIETKHAU(_ck);
                            }
                        }
                        BUS.BUSCTPHUTHU _CTPT = new BUS.BUSCTPHUTHU();

                        #region Them 1 CTPT trong
                        var _dtoPT = new DTO.DTOCTPHUTHU();
                        _dtoPT.MAPT = 15;
                        _dtoPT.MAHD = _mahd;
                        _dtoPT.PHANTRAMPT = 0;
                        _CTPT.ThemCTPHUTHU(_dtoPT);
                        #endregion

                        foreach (DataGridViewRow _row in grdPT.Rows)
                        {
                            if (_row.Cells[3].Value != null && (bool)_row.Cells[3].Value == true)
                            {
                                DTO.DTOCTPHUTHU _pt = new DTO.DTOCTPHUTHU();
                                _pt.MAPT = Convert.ToInt32(_row.Cells[0].Value);
                                _pt.MAHD = _mahd;
                                _pt.PHANTRAMPT = Convert.ToInt32(_row.Cells[2].Value);
                                _CTPT.ThemCTPHUTHU(_pt);
                            }

                        }
                        DTO.DTOPHIEUNHANPHONG _dtoPhieuNhanPhong = new DTO.DTOPHIEUNHANPHONG();
                        _dtoPhieuNhanPhong.MAPHIEU = Convert.ToInt32(lblMaPhieu.Text);
                        _dtoPhieuNhanPhong.MAPHONG = Convert.ToInt32(glkPhong.Text);
                        _dtoPhieuNhanPhong.MANV = clsXuLy.MANV;
                        _dtoPhieuNhanPhong.MAKH = int.Parse(txtMaKH.Text);
                        _dtoPhieuNhanPhong.GIOTRA = DateTime.Now;
                        _dtoPhieuNhanPhong.GIONHAN = dtpNgayNhan.Value;
                        _dtoPhieuNhanPhong.GIAPHONG = int.Parse(lblGia.Text);
                        _dtoPhieuNhanPhong.THANHTOAN = true;
                        busPhieuNhanPhong.CapnhatPHIEUNHANPHONG(_dtoPhieuNhanPhong);
                        DTO.DTOCheckData _cdnp = checkdata.LayTheoMaCheckData("PHIEUNHANPHONG").Last();
                        _cdnp.Version += 1;
                        checkdata.CapnhatCheckData(_cdnp);
                        btnHoaDon_Click(sender, e);
                        btnMakeNew_Click(sender, e);
                    }
                    else
                    {
                        MessageBox.Show("Số tiền nhận ít hơn tổng tiền.", "Chú ý!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        btnThanhToan.Enabled = true;
                    }
                }
                else
                    MessageBox.Show("Bạn cần nhập số tiền nhận.", "Lưu ý!");
            }
            else
            {
                MessageBox.Show("Dữ liệu đã thay đổi, xin refresh lại!");
            }
        }