private void btnBoSung_Click(object sender, EventArgs e) { DataTable dt = ThamSo_BUS.GetThamSoAll(); if (dt.Rows.Count != 0) { int nhapMin = int.Parse(dt.Rows[0].ItemArray[2].ToString()); int luongTonMax = int.Parse(dt.Rows[0].ItemArray[4].ToString()); int tiLeDonGiaBan = int.Parse(dt.Rows[0].ItemArray[1].ToString()); CT_PhieuNhapSach_DTO c = new CT_PhieuNhapSach_DTO(); try { c.MaPNS = int.Parse(txtMaPhieuNhap.Text); } catch (FormatException) { MessageBox.Show("Mã phiếu nhập không được để trống"); return; } try { c.MaSach = int.Parse(txtMaSach.Text); } catch (FormatException) { MessageBox.Show("Mã sách không được để trống"); return; } try { if (int.Parse(txtSoLuong.Text) < nhapMin) { MessageBox.Show(string.Format("Số lượng phải lớn hơn số lượng quy định ({0} quyển)", nhapMin)); return; } else { c.SoLuongNhap = int.Parse(txtSoLuong.Text); } } catch (FormatException) { MessageBox.Show("Số lượng phải là kiểu số"); return; } try { if (txtDonGiaNhap.Text != "") { c.DonGiaNhap = UInt64.Parse(txtDonGiaNhap.Text); } else { MessageBox.Show("Đơn giá nhập không được để trống"); return; } } catch (FormatException) { MessageBox.Show("Đơn giá nhập phải là kiểu số"); return; } DataTable dt2 = ThamSo_BUS.SelectSoLuongTon(c.MaSach); int luongTon = int.Parse(dt2.Rows[0].ItemArray[4].ToString()); int soLuongTonNew = luongTon + int.Parse(txtSoLuong.Text); c.ThanhTien = (UInt64)c.SoLuongNhap * c.DonGiaNhap; if (luongTon < luongTonMax) { string ketQua = PhieuNhapSach_BUS.ThemChiTietPhieuNhap(c); if (ketQua != "Success") { MessageBox.Show(ketQua); } else { Sach_DTO s = new Sach_DTO(); s.MaSach = int.Parse(txtMaSach.Text); s.SoLuongTon = soLuongTonNew; s.DonGiaBan = (UInt64)(double.Parse(txtDonGiaNhap.Text) * (double)tiLeDonGiaBan / 100); Sach_BUS.UpdateSoLuongTonVaDonGiaBan(s); PhieuNhapSach_DTO p = new PhieuNhapSach_DTO(); p.MaPNS = int.Parse(txtMaPhieuNhapCT.Text); PhieuNhapSach_BUS.CapNhatTongTien(p); HienThiCTPhieuNhap(); MessageBox.Show("Thành công"); } } else { MessageBox.Show("Chỉ nhập các đầu sách có lượng tồn ít hơn theo quy định"); } } else { MessageBox.Show("Không lấy được các tham số"); return; } }