public static bool CapNhatCTHDXuat(CTHDXuatDTO cthd)
        {
            string query = "UPDATE tblCTHDXuat SET SoLuong = @SoLuong WHERE MaHDXuat = @MaHDXuat AND MaNL = @MaNL";

            SqlParameter[] pars = new SqlParameter[3];
            pars[0] = new SqlParameter("@MaHDXuat", cthd.MaHDXuat);
            pars[1] = new SqlParameter("@MaNL", cthd.MaNL);
            pars[2] = new SqlParameter("@SoLuong", cthd.SoLuong);
            return(DataProvider.ExecuteUpdateQuery(query, pars) == 1);
        }
Beispiel #2
0
 void GetInfoResultCTHDXuat()
 {
     if (cthd == null)
     {
         cthd = new CTHDXuatDTO();
     }
     cthd.MaHDXuat = Convert.ToInt32(txtMaHD_CTHD.Text);
     cthd.MaNL     = cboMaNL.SelectedValue.ToString();
     cthd.SoLuong  = Convert.ToInt32(txtSoLuongConLai.Text);
     cthd.DonGia   = Convert.ToInt32(txtDonGia.Text);
 }
        public static bool ThemCTHDHDXuat(CTHDXuatDTO cthd)
        {
            string query = "INSERT INTO tblCTHDXuat(MaHDXuat,MaNL,DonGia,SoLuong) VALUES(@MaHDXuat,@MaNL,@DonGia,@SoLuong)";

            SqlParameter[] pars = new SqlParameter[4];
            pars[0] = new SqlParameter("@MaHDXuat", cthd.MaHDXuat);
            pars[1] = new SqlParameter("@MaNL", cthd.MaNL);
            pars[2] = new SqlParameter("@DonGia", cthd.DonGia);
            pars[3] = new SqlParameter("@SoLuong", cthd.SoLuong);
            return(DataProvider.ExecuteInsertQuery(query, pars) == 1);
        }
Beispiel #4
0
 private void GetDuLieu()
 {
     cthdxDTO = new List <CTHDXuatDTO>();
     for (int i = 0; i < gridView2.RowCount; i++)
     {
         CTHDXuatDTO ct = new CTHDXuatDTO();
         ct.MaCTHoaDonXuat = hdxbus.TangHD();
         ct.MaSP           = gridView2.GetRowCellValue(i, "MaSP").ToString();
         ct.SoLuong        = Convert.ToInt32(gridView2.GetRowCellValue(i, "SoLuong").ToString());
         ct.ThanhTien      = Convert.ToDouble(gridView2.GetRowCellValue(i, "ThanhTien").ToString());
         ct.GiaBan         = Convert.ToInt32(gridView2.GetRowCellValue(i, "GiaTien").ToString());
         cthdxDTO.Add(ct);
     }
 }
Beispiel #5
0
        private void btnHoanTat_Click(object sender, EventArgs e)
        {
            if (dgvDSCTHDXuat.Rows.Count == 0)
            {
                MessageBox.Show("Bạn chưa thêm thông CTHD xuất!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else
            {
                if (hd != null)
                {
                    hd.NgayXuat = dtpNgayXuat.Value;
                    if (HDXuatBUS.CapNhatTrangThaiHD(hd.MaHDXuat, 1) && HDXuatBUS.HoanTatHD(hd))
                    {
                        LoadDSHDXuat();
                        //MessageBox.Show("Tạo hóa đơn thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.None);

                        // Cập nhật nguyên liệu số lượng tồn kho - giảm
                        for (int i = 0; i < dgvDSCTHDXuat.Rows.Count; i++)
                        {
                            DataTable dt = NguyenLieuBUS.LayDSMaNL();
                            foreach (DataRow dr in dt.Rows)
                            {
                                NguyenLieuDTO nl = new NguyenLieuDTO();
                                nl.MaNL = dr["MaNL"].ToString();
                                if (dgvDSCTHDXuat.Rows[i].Cells["colMaNL_CTHD"].Value.ToString() == nl.MaNL)
                                {
                                    cthd          = new CTHDXuatDTO();
                                    cthd.MaHDXuat = Convert.ToInt32(dgvDSCTHDXuat.Rows[i].Cells["colMaHDXuat_CTHD"].Value);
                                    cthd.MaNL     = dgvDSCTHDXuat.Rows[i].Cells["colMaNL_CTHD"].Value.ToString();
                                    int sltk = NguyenLieuBUS.LaySoLuongTKNL(cthd.MaNL) - CTHDXuatBUS.LaySoLuongHienTai(cthd.MaHDXuat, cthd.MaNL);
                                    if (NguyenLieuBUS.CapNhatSoLuongTonKhoGiam(cthd.MaHDXuat, cthd.MaNL, sltk))
                                    {
                                        //MessageBox.Show("Cập nhật số lượng tồn kho thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.None);
                                    }
                                    else
                                    {
                                        MessageBox.Show("Cập nhật số lượng tồn kho thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Tạo hóa đơn thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Beispiel #6
0
        public bool ThemCTHoaDonXuat(CTHDXuatDTO CTHoaDonXuatDTO)
        {
            string CauLenh = "INSERT INTO ChiTietHoaDonXuat (MaCTHoaDonXuat, MaSP, GiaBan, SoLuong, ThanhTien, TrangThai) VALUES ('{0}','{1}','{2}','{3}','{4}','1')";

            try
            {
                SqlConnection conn = DataProvider_QLCHTapHoa.TaoKetNoi();
                int           kq   = DataProvider_QLCHTapHoa.ThucThiCauLenh(String.Format(CauLenh, CTHoaDonXuatDTO.MaCTHoaDonXuat, CTHoaDonXuatDTO.MaSP, CTHoaDonXuatDTO.GiaBan, CTHoaDonXuatDTO.SoLuong, CTHoaDonXuatDTO.ThanhTien, CTHoaDonXuatDTO.TrangThai = 1), conn);
                return(kq != 0);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Beispiel #7
0
 private void SetInfoCTHD()
 {
     if (dgvDSCTHDXuat.SelectedRows.Count > 0)
     {
         if (cthd == null)
         {
             cthd = new CTHDXuatDTO();
         }
         txtMaHD_CTHD.Text     = cthd.MaHDXuat.ToString();
         cboMaNL.SelectedValue = cthd.MaNL;
         txtDonGia.Text        = cthd.DonGia.ToString();
         txtSoLuongConLai.Text = cthd.SoLuong.ToString();
     }
     else
     {
         SetFormCTHD();
     }
 }
Beispiel #8
0
 private void dgvDSCTHDXuat_SelectionChanged(object sender, EventArgs e)
 {
     if (dgvDSCTHDXuat.SelectedRows.Count > 0)
     {
         DataGridViewRow dgvRow = dgvDSCTHDXuat.CurrentRow;
         cthd          = new CTHDXuatDTO();
         cthd.MaHDXuat = Convert.ToInt32(dgvRow.Cells["colMaHDXuat_CTHD"].Value.ToString());
         cthd.MaNL     = dgvRow.Cells["colMaNL_CTHD"].Value.ToString();
         cthd.SoLuong  = Convert.ToInt32(dgvRow.Cells["colSoLuong"].Value.ToString());
         cthd.DonGia   = Convert.ToInt32(dgvRow.Cells["colDonGia"].Value.ToString());
         SetInfoCTHD();
         SettingText();
         lblSLTK.Text = NguyenLieuBUS.LaySoLuongTKNL(cthd.MaNL).ToString();
     }
     else
     {
         SetInfoCTHD();
     }
     AddStatus(2);
 }
Beispiel #9
0
        public List <CTHDXuatDTO> DSCTHDXuat(string MaHD)
        {
            List <CTHDXuatDTO> lstcthdx = new List <CTHDXuatDTO>();
            string             caulenh  = "SELECT MaCTHoaDonXuat, sp.TenSP, GiaBan, cthdx.SoLuong, ThanhTien, cthdx.TrangThai FROM ChiTietHoaDonXuat cthdx INNER JOIN SanPham sp ON  cthdx.MaSP=sp.MaSP WHERE MaCTHoaDonXuat='" + MaHD + "' AND cthdx.TrangThai=1";
            SqlConnection      conn     = DataProvider_QLCHTapHoa.TaoKetNoi();
            SqlDataReader      dr       = DataProvider_QLCHTapHoa.TruyVanDuLieu(caulenh, conn);

            while (dr.Read())
            {
                CTHDXuatDTO chitiet = new CTHDXuatDTO();
                chitiet.MaCTHoaDonXuat = dr[0].ToString();
                chitiet.MaSP           = dr[1].ToString();
                chitiet.GiaBan         = int.Parse(dr[2].ToString());
                chitiet.SoLuong        = int.Parse(dr[3].ToString());
                chitiet.ThanhTien      = int.Parse(dr[4].ToString());
                chitiet.TrangThai      = int.Parse(dr[5].ToString());
                lstcthdx.Add(chitiet);
            }
            dr.Close();
            conn.Close();
            return(lstcthdx);
        }
Beispiel #10
0
 void AddStatus(int k)
 {
     if (k == 1) // Khi chọn 1 dòng - thông tin hóa đơn nhập
     {
         bool t = true;
         gboTTCTHDXuat.Enabled = t;
         btnTaoHD.Hide();
         btnHoanTat.Show();
         btnCapNhatCTHD.Hide();
         btnXoaCTHD.Enabled = !t;
         if (hd.TrangThai == 0)
         {
             panel2.Enabled      = t;
             dtpNgayXuat.Enabled = t;
             btnHoanTat.Enabled  = t;
             btnXoaHD.Enabled    = !t;
             btnLamMoiHD.Enabled = !t;
         }
         else
         {
             panel2.Enabled      = !t;
             dtpNgayXuat.Enabled = !t;
             btnHoanTat.Enabled  = !t;
             btnXoaHD.Enabled    = t;
             btnLamMoiHD.Enabled = t;
         }
     }
     else if (k == -1) // Khi làm mới tạo để tạo hóa đơn nhập
     {
         hd = null;    //Thêm vào để sửa trường hợp mới load frmHDNhap không thể thêm
         bool t = true;
         gboTTCTHDXuat.Enabled = !t;
         btnTaoHD.Enabled      = t;
         btnTaoHD.Show();
         btnHoanTat.Hide();
         btnXoaHD.Enabled     = !t;
         btnLamMoiHD.Enabled  = t;
         txtMaHD_CTHD.Enabled = !t;
         btnHoanTat.Enabled   = !t;
         dtpNgayXuat.Enabled  = t;
     }
     else if (k == 2) //Khi chọn 1 dòng CTHD
     {
         bool t = false;
         btnThemCTHD.Enabled    = t;
         btnXoaCTHD.Enabled     = !t;
         cboMaNL.Enabled        = t;
         btnThemCTHD.Visible    = t;
         btnCapNhatCTHD.Visible = !t;
     }
     else if (k == -2)// Khi làm mới cthd nhập
     {
         cthd = null;
         bool t = true;
         btnThemCTHD.Enabled    = t;
         btnXoaCTHD.Enabled     = !t;
         cboMaNL.Enabled        = t;
         btnThemCTHD.Visible    = t;
         btnCapNhatCTHD.Visible = !t;
     }
     else if (k == 3) //chkTrangThaiHuyHD.Checked = true -> LoadDSHDNhapBiHuy
     {
         bool t = false;
         btnTaoHD.Visible    = t;
         btnXoaHD.Visible    = t;
         btnLamMoiHD.Visible = t;
         btnHoanTat.Visible  = t;
         btnKhoiPhuc.Visible = !t;
         if (dgvDSHDXuat.Rows.Count > 0)
         {
             btnKhoiPhuc.Enabled = !t;
         }
         else
         {
             btnKhoiPhuc.Enabled = t;
         }
     }
     else if (k == -3)//chkTrangThaiHuyHD.Checked = false -> LoadDSHDNhap
     {
         bool t = true;
         btnKhoiPhuc.Visible = !t;
         btnXoaHD.Visible    = t;
         btnLamMoiHD.Visible = t;
         btnHoanTat.Visible  = t;
         btnHoanTat.Enabled  = t;
     }
 }
Beispiel #11
0
        private void btnThemCTHD_Click(object sender, EventArgs e)
        {
            if (txtMaHD_CTHD.Text == "" || txtSoLuongConLai.Text == "" || txtDonGia.Text == "")
            {
                MessageBox.Show("Mời bạn nhập đầy đủ thông tin CTHD xuất!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            else if (Convert.ToInt32(txtSoLuongConLai.Text) >= NguyenLieuBUS.LaySoLuongTKNL(cboMaNL.SelectedValue.ToString()) || Convert.ToInt32(txtSoLuongConLai.Text) >= Convert.ToInt32(lblSLTK.Text))
            {
                MessageBox.Show("Số lượng còn lại không được bằng hoặc vượt quá số lượng tồn kho!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                if (cthd == null)
                {
                    GetInfoResultCTHDXuat();
                    cthd.SoLuong = NguyenLieuBUS.LaySoLuongTKNL(cthd.MaNL) - Convert.ToInt32(txtSoLuongConLai.Text);
                    if (!CTHDXuatBUS.KiemTraMaNLTonTai(cthd.MaHDXuat, cthd.MaNL))
                    {
                        if (CTHDXuatBUS.ThemCTHDHDXuat(cthd))
                        {
                            if (hd != null)
                            {
                                hd.MaHDXuat = Convert.ToInt32(txtMaHD_CTHD.Text);
                                //Tổng tiền = tổng tiền HD + vs Tiền mới của 1 món ăn mói thêm vào
                                hd.TongTien = HDXuatBUS.LayTongTienHDXuat(hd.MaHDXuat) + (Convert.ToInt32(Convert.ToInt32(txtDonGia.Text) * cthd.SoLuong));
                                if (HDXuatBUS.CapNhatHDXuat(hd.MaHDXuat, hd.TongTien))
                                {
                                    //MessageBox.Show("Thêm thông tin CTHD xuất thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.None);
                                    LoadDSCTHDXuat(hd.MaHDXuat);
                                    txtTongTien.Text = HDXuatBUS.LayTongTienHDXuat(cthd.MaHDXuat).ToString();
                                }
                            }
                            cthd = null;
                        }
                        else
                        {
                            MessageBox.Show("Thêm thông tin CTHD xuất thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        int sltk = NguyenLieuBUS.LaySoLuongTKNL(cthd.MaNL) - CTHDXuatBUS.LaySoLuongHienTai(cthd.MaHDXuat, cthd.MaNL);
                        cthd.SoLuong = (CTHDXuatBUS.LaySoLuongHienTai(cthd.MaHDXuat, cthd.MaNL) + (sltk - Convert.ToInt32(txtSoLuongConLai.Text)));
                        if (CTHDXuatBUS.CapNhatSoLuong(cthd.SoLuong, cthd.MaHDXuat, cthd.MaNL))
                        {
                            hd.TongTien = HDXuatBUS.LayTongTienHDXuat(hd.MaHDXuat) + (Convert.ToInt32(Convert.ToInt32(txtDonGia.Text) * (sltk - Convert.ToInt32(txtSoLuongConLai.Text))));
                            if (HDXuatBUS.CapNhatHDXuat(hd.MaHDXuat, hd.TongTien))
                            {
                                LoadDSCTHDXuat(hd.MaHDXuat);
                                txtTongTien.Text = HDXuatBUS.LayTongTienHDXuat(cthd.MaHDXuat).ToString();

                                //MessageBox.Show("Thêm số lượng thông tin CTHD xuất thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.None);
                            }
                        }
                        cthd = null;
                    }
                    AddStatus(-2);
                }
            }
        }
 public static bool CapNhatCTHDXuat(CTHDXuatDTO cthd)
 {
     return(CTHDXuatDAO.CapNhatCTHDXuat(cthd));
 }
 public static bool ThemCTHDHDXuat(CTHDXuatDTO cthd)
 {
     return(CTHDXuatDAO.ThemCTHDHDXuat(cthd));
 }
Beispiel #14
0
 public bool ThemCTHoaDonXuat(CTHDXuatDTO CTHoaDonXuatDTO)
 {
     return(cthdxdao.ThemCTHoaDonXuat(CTHoaDonXuatDTO));
 }