Ejemplo n.º 1
0
 private void luuHD_Click(object sender, EventArgs e)
 {
     if (!hdb_BUS.CheckMaHDB(txtMaHD.Text))
     {
         hdB.MaHDB    = txtMaHD.Text;
         hdB.MaKH     = cbBMaKH.Text;
         hdB.MaNV     = cbBMaNV.Text;
         hdB.NgayBan  = dateNgayBan.Value;
         hdB.TongTien = double.Parse(txtTongTien.Text);
         hdb_BUS.ThemHDB(hdB);
         for (int i = 0; i < lvCTHDB.Items.Count; i++)
         {
             int    soLuong   = int.Parse(lvCTHDB.Items[i].SubItems[2].Text);
             long   thanhTien = long.Parse(lvCTHDB.Items[i].SubItems[4].Text);
             string maHH      = lvCTHDB.Items[i].Text;
             ChiTietHoaDonBan_DTO cTHDB_DTO = new ChiTietHoaDonBan_DTO();
             cTHDB_DTO.MaHDB     = txtMaHD.Text;
             cTHDB_DTO.MaHH      = maHH;
             cTHDB_DTO.SoLuong   = soLuong;
             cTHDB_DTO.ThanhTien = thanhTien;
             cTHDB_DTO.KhuyenMai = 0;
             cTHDB_DTO.GiamGia   = 0;
             cTHDB_BUS.ThemCTHDB(cTHDB_DTO);
         }
     }
     if (hdb_BUS.CheckMaHDB(txtMaHD.Text))
     {
         cTHDB_BUS.XoaCTHDB(txtMaHD.Text);
         for (int i = 0; i < lvCTHDB.Items.Count; i++)
         {
             int    soLuong   = int.Parse(lvCTHDB.Items[i].SubItems[2].Text);
             long   thanhTien = long.Parse(lvCTHDB.Items[i].SubItems[4].Text);
             string maHH      = lvCTHDB.Items[i].Text;
             ChiTietHoaDonBan_DTO cTHDB_DTO = new ChiTietHoaDonBan_DTO();
             cTHDB_DTO.MaHDB     = txtMaHD.Text;
             cTHDB_DTO.MaHH      = maHH;
             cTHDB_DTO.SoLuong   = soLuong;
             cTHDB_DTO.ThanhTien = thanhTien;
             cTHDB_DTO.KhuyenMai = 0;
             cTHDB_DTO.GiamGia   = 0;
             cTHDB_BUS.ThemCTHDB(cTHDB_DTO);
         }
     }
     //for (int i = 0; i < lvCTHDB.Items.Count; i++)
     //{
     //    if (cTHDB_BUS.checkCTHDB(txtMaHD.Text, lvCTHDB.Items[i].Text))
     //    {
     //        int soLuong = int.Parse(lvCTHDB.Items[i].SubItems[2].Text);
     //        long thanhTien = long.Parse(lvCTHDB.Items[i].SubItems[4].Text);
     //        string maHH = lvCTHDB.Items[i].Text;
     //        cTHDB_BUS.CapNhatCTHDB(soLuong, thanhTien, txtMaHD.Text, maHH);
     //    }
     //}
     trangThaiBanDau();
     loadDuLieu();
     luuHD.Enabled = huyHD.Enabled = false;
 }