Example #1
0
 private bool SetGiaTriChoPhieuNhapHang()
 {
     try
     {
         string mancc = cbmanhacungcap.EditValue.ToString();
         if (txtmaphieunhaphang.Text != "")
         {
             if (muaHangBUS.LayPhieuNhapHangTheoMaPhieuNhapHang(txtmaphieunhaphang.Text))
             {
                 try
                 {
                     if (txttongtien.Text != "0" && grvrootmuahang.GetRowCellValue(0, "Mã Hàng").ToString() != "Gõ vào đây")
                     {
                         try
                         {
                             for (int i = 0; i < grvrootmuahang.RowCount - 1; i++)
                             {
                                 HangHoaPhu hhp = new HangHoaPhu();
                                 ctpnh.MaPhieuNhapHang = txtmaphieunhaphang.Text;
                                 ctpnh.MaSanPham       = grvrootmuahang.GetRowCellValue(i, "Mã Hàng").ToString();
                                 hhp.mhh          = grvrootmuahang.GetRowCellValue(i, "Mã Hàng").ToString();
                                 ctpnh.TenSanPham = grvrootmuahang.GetRowCellValue(i, "Tên Hàng").ToString();
                                 ctpnh.DonVi      = grvrootmuahang.GetRowCellValue(i, "Đơn Vị").ToString();
                                 ctpnh.SoLuong    = int.Parse(grvrootmuahang.GetRowCellValue(i, "Số Lượng").ToString());
                                 hhp.soluong      = int.Parse(grvrootmuahang.GetRowCellValue(i, "Số Lượng").ToString());
                                 ctpnh.DonGia     = float.Parse(grvrootmuahang.GetRowCellValue(i, "Đơn Giá").ToString());
                                 ctpnh.ThanhTien  = float.Parse(grvrootmuahang.GetRowCellValue(i, "Thành Tiền").ToString());
                                 ctpnh.GhiChu     = (grvrootmuahang.GetRowCellValue(i, "Ghi Chú").ToString());
                             }
                         }
                         catch
                         {
                             MessageBox.Show("Phiếu rỗng không thể lưu.", "Cảnh báo Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                             return(false);
                         }
                         PNH_DTO.MaPNH         = txtmaphieunhaphang.Text;
                         PNH_DTO.MaNV          = cbnhanvien.EditValue.ToString();
                         PNH_DTO.MaNCC         = cbtennhacungcap.EditValue.ToString();
                         PNH_DTO.DiaChi        = txtdiachi.Text;
                         PNH_DTO.GhiChu        = txtghichu.Text;
                         PNH_DTO.MaKho         = cbkhocongty.EditValue.ToString();
                         PNH_DTO.SoVAT         = txtsohdvat.Text;
                         PNH_DTO.SoPhieuVT     = txtsophieuviettay.Text;
                         PNH_DTO.DK_ThanhToan  = cbdktt.EditValue.ToString();
                         PNH_DTO.HT_ThanhToan  = cbhttt.EditValue.ToString();
                         PNH_DTO.HanThanhToan  = txthanthanhtoan.EditValue.ToString();
                         PNH_DTO.NgayLap       = cbngay.EditValue.ToString();
                         PNH_DTO.VAT           = txtvat.Text;
                         PNH_DTO.CK            = txtchietkhau.Text;
                         PNH_DTO.TongThanhTien = int.Parse(thanhtien.ToString());
                     }
                     else
                     {
                         MessageBox.Show("Phiếu rỗng không thể lưu.", "Cảnh báo Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                         return(false);
                     }
                 }catch
                 {
                     MessageBox.Show("Phiếu rỗng không thể lưu.", "Cảnh báo Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                     return(false);
                 }
             }
             else
             {
                 MessageBox.Show("Mã Phiếu Nhập Hàng Đã Tồn Tại", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 return(false);
             }
         }
         else
         {
             MessageBox.Show("Mã Phiếu Nhập Hàng không được rỗng.", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
             txtmaphieunhaphang.Text = muaHangBUS.PhatSinhMaPhieu(tentkdn);
             return(false);
         }
     }
     catch
     {
         MessageBox.Show("Vui Lòng chọn nhà cung cấp.", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return(false);
     }
     return(true);
 }