public void Insert(CTHDNhap cthdn) { StreamWriter sw = File.AppendText(txtfile); sw.WriteLine(cthdn.maHDN + "\t" + cthdn.maMT + "\t" + cthdn.tenMT + "\t" + cthdn.soLuong + "\t" + cthdn.donGia + "\t" + cthdn.thanhTien); sw.Close(); }
public List <CTHDNhap> LayCTHDNhap(CTHDNhap cthdn) { List <CTHDNhap> list = cthdnDAL.GetData(); List <CTHDNhap> kq = new List <CTHDNhap>(); if (cthdn.maHDN == null) { kq = list; } if (cthdn.maHDN != null) { for (int i = 0; i < list.Count; ++i) { if (list[i].maHDN == cthdn.maHDN) { kq.Add(new CTHDNhap(list[i])); } } } else { kq = null; } return(kq); }
public CTHDNhap LayMT(string mamt) { CTHDNhap cthdn = null; foreach (CTHDNhap cthdnhap in cthdnDAL.GetData()) { if (cthdnhap.maMT == mamt) { cthdn = new CTHDNhap(cthdnhap); break; } } return(cthdn); }
public void ThemCTHDNhap(CTHDNhap cthdn) { if (cthdn.maHDN != "" && cthdn.maMT != "" && cthdn.tenMT != "") { cthdn.maHDN = CongCu.ChuanHoaMa(cthdn.maHDN); cthdn.maMT = CongCu.ChuanHoaMa(cthdn.maMT); cthdn.tenMT = CongCu.ChuanHoaXau(cthdn.tenMT); cthdnDAL.Insert(cthdn); } else { throw new Exception("Dữ liệu sai."); } }
public List <CTHDNhap> GetCTHDNhapByHoaDonNhap(string maHDNhap) { List <CTHDNhap> list = new List <CTHDNhap>(); string query = "SELECT MaCTHDNhap, MaHDNhap, TenSP, SoLuong FROM dbo.CTHDNhap INNER JOIN dbo.SanPham ON CTHDNhap.Ma = SanPham.MaSP WHERE MaHDNhap = '" + maHDNhap + "'"; DataTable data = DataProvider.Instance.ExecuteQuery(query); foreach (DataRow item in data.Rows) { CTHDNhap cthdNhap = new CTHDNhap(item); list.Add(cthdNhap); } return(list); }
public List <CTHDNhap> GetListCTHDNhap() { List <CTHDNhap> list = new List <CTHDNhap>(); string query = "SELECT * FROM dbo.CTHDNhap"; DataTable data = DataProvider.Instance.ExecuteQuery(query); foreach (DataRow item in data.Rows) { CTHDNhap cthdNhap = new CTHDNhap(item); list.Add(cthdNhap); } return(list); }
private void cbbSP_SelectedValueChanged(object sender, EventArgs e) { try { SanPham sp = dt.SanPhams.Where(s => s.Ma == Convert.ToInt32(cbbSP.SelectedValue)).FirstOrDefault(); if (i == 1) { cbbSize.DisplayMember = "TenSize"; cbbSize.ValueMember = "Ma"; cbbSize.DataSource = dt.cbbSize(1); i++; } else { cbbSize.DisplayMember = "TenSize"; cbbSize.ValueMember = "Ma"; cbbSize.DataSource = dt.cbbSize(sp.Ma_LoaiSP); } CTHDNhap CTHDN = dt.CTHDNhaps.Where(s => s.Ma_HDN == Convert.ToInt32(lbMaHD.Text)) .Where(s => s.Ma_SP == Convert.ToInt32(cbbSP.SelectedValue)) .FirstOrDefault(); if (CTHDN == null) { txtSoLuong.ResetText(); txtDonGia.ResetText(); lbThanhTien.Text = "0"; txtDonGia.Enabled = true; } else if (CTHDN != null) { txtDonGia.Text = CTHDN.Soluong.ToString(); txtDonGia.Enabled = false; txtDonGia.Text = CTHDN.DonGia.ToString(); lbThanhTien.Text = "0"; } } catch (Exception) { } }
public long GetNhapPT() { long result = 0; List <CTHDNhap> list = new List <CTHDNhap>(); string query = "SELECT MaCTHDNhap, SoLuong * DonGia as NhapPT FROM dbo.CTHDNhap JOIN dbo.PhuTung ON CTHDNhap.Ma = PhuTung.Ma"; DataTable data = DataProvider.Instance.ExecuteQuery(query); foreach (DataRow item in data.Rows) { CTHDNhap cthdNhap = new CTHDNhap(item, "pt"); list.Add(cthdNhap); } foreach (CTHDNhap item in list) { result += item.NhapPT; } return(result); }
public void Nhap(int x, int y, ConsoleColor background_color, ConsoleColor text_color) { do { Console.BackgroundColor = background_color; Console.ForegroundColor = text_color; IHDNhapBLL hdnhap = new HDNhapBLL(); INhanVienBLL nhanvien = new NhanVienBLL(); INCC_BLL nhacc = new NCC_BLL(); IMayTinhBLL maytinh = new MayTinhBLL(); FormNhanVien fnv = new FormNhanVien(); FormNCC fncc = new FormNCC(); FormMayTinh fmt = new FormMayTinh(); NhanVienBLL nvBLL = new NhanVienBLL(); NCC_BLL nccBLL = new NCC_BLL(); ICTHDNhapBLL cthdnhap = new CTHDNhapBLL(); HDNhapBLL hdnBLL = new HDNhapBLL(); MayTinhBLL mtBLL = new MayTinhBLL(); HDNhap hdn = new HDNhap(); CTHDNhap cthdn = new CTHDNhap(); HDNhap hd; Console.Clear(); IO.Box(0, 0, 28, 114, ConsoleColor.Black, ConsoleColor.White); IO.BoxTitle(" NHẬP THÔNG TIN HÓA ĐƠN NHẬP", x, y, 11, 112); IO.Writexy("Mã nhân viên:", x + 2, y + 3); IO.Writexy("Mã nhà CC:", x + 28, y + 3); IO.Writexy("Ngày nhập:", x + 55, y + 3); IO.Writexy("Tổng tiền:", x + 83, y + 3); IO.Writexy("--------------------------------------------------------------------------------------------------------------", x + 1, y + 4); IO.Writexy("Mã máy tính:", x + 2, y + 5); IO.Writexy("Tên máy tính:", x + 2, y + 6); IO.Writexy("Số lượng:", x + 28, y + 5); IO.Writexy("Đơn giá:", x + 55, y + 5); IO.Writexy("Thành tiền:", x + 83, y + 5); IO.Writexy("--------------------------------------------------------------------------------------------------------------", x + 1, y + 7); IO.Writexy("Nhập ! để thoát...", x + 4, y + 9); fnv.Hien(x, y + 11, nhanvien.LayDSNhanVien(), 5, 0); do { Console.SetCursorPosition(x + 16, y + 3); hdn.maNV = Console.ReadLine(); if (hdn.maNV == null) { IO.Clear(x + 3, y + 8, 60, ConsoleColor.Black); IO.Writexy("Nhập lại mã nhân viên...", x + 4, y + 8, ConsoleColor.Black, ConsoleColor.White); } else if (hdn.maNV == "!") { return; } else { if (nvBLL.KT_MaNhanVien(CongCu.ChuanHoaMa(hdn.maNV)) == false) { IO.Writexy("Không tồn tại mã nhân viên này...", x + 4, y + 8, ConsoleColor.Black, ConsoleColor.White); IO.Clear(x + 15, y + 3, 12, ConsoleColor.Black); } else { break; } } } while (hdn.maNV == null || nvBLL.KT_MaNhanVien(CongCu.ChuanHoaMa(hdn.maNV)) == false); IO.Clear(x + 3, y + 8, 60, ConsoleColor.Black); IO.Clear(x + 3, y + 9, 60, ConsoleColor.Black); fncc.Hien(x + 16, y + 11, nhacc.LayDSNCC(), 5, 0); do { Console.SetCursorPosition(x + 39, y + 3); hdn.maNCC = Console.ReadLine(); if (hdn.maNCC == null) { IO.Clear(x + 3, y + 8, 60, ConsoleColor.Black); IO.Writexy("Nhập lại mã nhà cung cấp...", x + 4, y + 8, ConsoleColor.Black, ConsoleColor.White); } else { if (nccBLL.KT_MaNCC(CongCu.ChuanHoaMa(hdn.maNCC)) == false) { IO.Writexy("Không tồn tại mã nhà cung cấp này...", x + 4, y + 8, ConsoleColor.Black, ConsoleColor.White); IO.Clear(x + 38, y + 3, 16, ConsoleColor.Black); } else { break; } } } while (hdn.maNCC == null || nccBLL.KT_MaNCC(CongCu.ChuanHoaMa(hdn.maNCC)) == false); IO.Clear(x + 3, y + 8, 60, ConsoleColor.Black); IO.Writexy("Nhập ngày nhập định dạng 'dd/MM/yyyy'...", x + 4, y + 9, ConsoleColor.Black, ConsoleColor.White); do { Console.SetCursorPosition(x + 66, y + 3); hdn.ngayNhap = Console.ReadLine(); if (hdn.ngayNhap == null || CongCu.CheckDate(hdn.ngayNhap) == false) { IO.Writexy("Nhập lại ngày nhập...", x + 4, y + 8, ConsoleColor.Black, ConsoleColor.White); IO.Clear(x + 65, y + 3, 17, ConsoleColor.Black); } } while (hdn.ngayNhap == null || CongCu.CheckDate(hdn.ngayNhap) == false); hdnhap.ThemHDNhap(hdn); while (true) { hd = hdnBLL.LayMaHDN(hdn.maNV, hdn.maNCC, hdn.ngayNhap); cthdn.maHDN = hd.maHDN; IO.Clear(x + 3, y + 8, 60, ConsoleColor.Black); fmt.Hien(x + 11, y + 11, maytinh.LayDSMayTinh(), 5, 0); do { IO.Clear(x + 14, y + 5, 12, ConsoleColor.Black); Console.SetCursorPosition(x + 15, y + 5); cthdn.maMT = Console.ReadLine(); if (cthdn.maMT == null) { IO.Clear(x + 3, y + 8, 60, ConsoleColor.Black); IO.Writexy("Nhập lại mã máy tính...", x + 4, y + 8, ConsoleColor.Black, ConsoleColor.White); } } while (cthdn.maMT == null); IO.Clear(x + 3, y + 8, 60, ConsoleColor.Black); if (mtBLL.KT_MaMayTinh(CongCu.ChuanHoaMa(cthdn.maMT)) == true) { MayTinh Mt = mtBLL.LayMayTinh(CongCu.ChuanHoaMa(cthdn.maMT)); IO.Writexy(Mt.tenMT, x + 16, y + 6); cthdn.tenMT = Mt.tenMT; } else { do { IO.Clear(x + 14, y + 6, 90, ConsoleColor.Black); Console.SetCursorPosition(x + 16, y + 6); cthdn.tenMT = Console.ReadLine(); if (cthdn.tenMT == null) { IO.Clear(x + 3, y + 8, 60, ConsoleColor.Black); IO.Writexy("Nhập lại tên máy tính...", x + 4, y + 8, ConsoleColor.Black, ConsoleColor.White); } } while (cthdn.tenMT == null); } IO.Clear(x + 3, y + 9, 60, ConsoleColor.Black); IO.Clear(x + 3, y + 8, 60, ConsoleColor.Black); do { IO.Clear(x + 37, y + 5, 16, ConsoleColor.Black); cthdn.soLuong = int.Parse(IO.ReadNumber(x + 38, y + 5)); if (cthdn.soLuong <= 0) { IO.Writexy("Nhập lại số lượng...", x + 4, y + 8, ConsoleColor.Black, ConsoleColor.White); IO.Clear(x + 37, y + 5, 16, ConsoleColor.Black); } } while (cthdn.soLuong <= 0); IO.Clear(x + 3, y + 8, 60, ConsoleColor.Black); HienCT_N(x, y + 11, cthdnhap.LayDS_CTHDNhap(), 5, 0); do { IO.Clear(x + 63, y + 5, 16, ConsoleColor.Black); cthdn.donGia = double.Parse(IO.ReadNumber(x + 64, y + 5)); if (cthdn.donGia <= 0) { IO.Writexy("Nhập lại đơn giá...", x + 4, y + 8, ConsoleColor.Black, ConsoleColor.White); IO.Clear(x + 63, y + 5, 16, ConsoleColor.Black); } } while (cthdn.donGia <= 0); IO.Clear(x + 3, y + 8, 60, ConsoleColor.Black); IO.Clear(x + 94, y + 5, 16, ConsoleColor.Black); IO.Writexy(cthdn.thanhTien.ToString(), x + 95, y + 5); cthdnhap.ThemCTHDNhap(cthdn); MayTinh mt = mtBLL.LayMayTinh(CongCu.ChuanHoaMa(cthdn.maMT)); if (mtBLL.KT_MaMayTinh(cthdn.maMT) == true) { mtBLL.CongSoLuong(mt, cthdn.soLuong); } else { cthdn.soLuong = cthdn.soLuong; } IO.Clear(x + 3, y + 8, 60, ConsoleColor.Black); Console.SetCursorPosition(x + 34, y + 8); IO.Writexy("Nhập tiếp? (C/K)...", x + 4, y + 8); ConsoleKeyInfo c = Console.ReadKey(); if (c.KeyChar != 'c') { break; } } IO.Clear(x + 93, y + 5, 16, ConsoleColor.Black); IO.Writexy(hdnBLL.TTien(cthdn.maHDN).ToString(), x + 94, y + 3); hdn.tongTien = hdnBLL.TTien(cthdn.maHDN); IO.Clear(x + 3, y + 8, 60, ConsoleColor.Black); IO.Writexy("Enter để nhập, Esc để thoát...", x + 4, y + 8); Console.SetCursorPosition(x + 34, y + 8); ConsoleKeyInfo kt = Console.ReadKey(); if (kt.Key == ConsoleKey.Escape) { break; } else if (kt.Key == ConsoleKey.Enter) { IO.Clear(x + 3, y + 8, 60, ConsoleColor.Black); IO.Writexy("Hóa đơn nhập đã được thêm...", x + 4, y + 8); hdnhap.XoaHDNhap(cthdn.maHDN); hdnhap.ThemHDNhap(hdn); Hien(x + 13, y + 11, hdnhap.LayDSHDNhap(), 5, 1); } } while (true); }
public void Nhap(int x, int y, ConsoleColor background_color, ConsoleColor text_color) { do { Console.BackgroundColor = background_color; Console.ForegroundColor = text_color; IMayTinhBLL maytinh = new MayTinhBLL(); HDNhapBLL hdnBLL = new HDNhapBLL(); MayTinhBLL mtBLL = new MayTinhBLL(); FormHDNhap fcthdn = new FormHDNhap(); CTHDNhapBLL cthdnBLL = new CTHDNhapBLL(); MayTinh mt = new MayTinh(); Console.Clear(); IO.Box(0, 0, 28, 114, ConsoleColor.Black, ConsoleColor.White); IO.BoxTitle(" THÊM GIÁ BÁN MÁY TÍNH", x, y, 10, 110); IO.Writexy("Mã MT:", x + 2, y + 3); IO.Writexy("Tên máy:", x + 43, y + 3); IO.Writexy("Mã nhà CC:", x + 2, y + 5); IO.Writexy("Số lượng còn:", x + 37, y + 5); IO.Writexy("Giá bán:", x + 74, y + 5); IO.Writexy("------------------------------------------------------------------------------------------------------------", x + 1, y + 6); IO.Writexy("Nhập ! để thoát...", x + 4, y + 8); fcthdn.HienCT_N(x - 1, y + 10, cthdnBLL.LayDS_CTHDNhap(), 5, 0); do { Console.SetCursorPosition(x + 9, y + 3); mt.maMT = Console.ReadLine(); if (mt.maMT == null) { IO.Clear(x + 3, y + 7, 60, ConsoleColor.Black); IO.Writexy("Nhập lại mã máy tính...", x + 4, y + 7, ConsoleColor.Black, ConsoleColor.White); } else if (mt.maMT == "!") { return; } else { if (cthdnBLL.KT_MaMT(CongCu.ChuanHoaMa(mt.maMT)) == false) { IO.Writexy("Không tồn tại mã máy tính này...", x + 4, y + 7, ConsoleColor.Black, ConsoleColor.White); IO.Clear(x + 8, y + 3, 10, ConsoleColor.Black); } else if (mtBLL.KT_MaMayTinh(CongCu.ChuanHoaMa(mt.maMT)) == true) { IO.Writexy("Mã máy tính này đã tồn tại...", x + 4, y + 7, ConsoleColor.Black, ConsoleColor.White); IO.Clear(x + 8, y + 3, 10, ConsoleColor.Black); } else { mt.maMT = CongCu.ChuanHoaMa(mt.maMT); } } } while (mt.maMT == null || cthdnBLL.KT_MaMT(CongCu.ChuanHoaMa(mt.maMT)) == false || mtBLL.KT_MaMayTinh(CongCu.ChuanHoaMa(mt.maMT)) == true); IO.Clear(x + 3, y + 7, 60, ConsoleColor.Black); IO.Clear(x + 3, y + 8, 60, ConsoleColor.Black); CTHDNhap ctn = cthdnBLL.LayMT(CongCu.ChuanHoaMa(mt.maMT)); IO.Writexy(ctn.tenMT, x + 52, y + 3); mt.tenMT = ctn.tenMT; IO.Clear(x + 3, y + 7, 60, ConsoleColor.Black); mt.maNCC = hdnBLL.LayMaNCC(CongCu.ChuanHoaMa(mt.maMT)); IO.Writexy(mt.maNCC, x + 13, y + 5); IO.Writexy(ctn.soLuong.ToString(), x + 51, y + 5); mt.sLCon = ctn.soLuong; fcthdn.HienCT_N(x - 1, y + 10, cthdnBLL.LayDS_CTHDNhap(), 5, 0); IO.Clear(x + 13, y + 7, 60, ConsoleColor.Black); do { mt.giaBan = double.Parse(IO.ReadNumber(x + 83, y + 5)); if (mt.giaBan <= 0) { IO.Writexy("Nhập lại giá bán...", x + 4, y + 7, ConsoleColor.Black, ConsoleColor.White); IO.Clear(x + 82, y + 5, 20, ConsoleColor.Black); } else if (mt.giaBan <= ctn.donGia) { IO.Writexy("Nhập lại giá bán lớn hơn giá nhập...", x + 4, y + 7, ConsoleColor.Black, ConsoleColor.White); IO.Clear(x + 82, y + 5, 20, ConsoleColor.Black); } } while (mt.giaBan < 0 || mt.giaBan <= ctn.donGia); IO.Clear(x + 3, y + 7, 60, ConsoleColor.Black); IO.Writexy("Enter để nhập, Esc để thoát...", x + 4, y + 7); Console.SetCursorPosition(x + 34, y + 7); ConsoleKeyInfo kt = Console.ReadKey(); if (kt.Key == ConsoleKey.Escape) { break; } else if (kt.Key == ConsoleKey.Enter) { IO.Clear(x + 3, y + 7, 60, ConsoleColor.Black); IO.Writexy("Giá bán đã được thêm...", x + 4, y + 7); maytinh.ThemMayTinh(mt); Hien(x + 9, y + 10, maytinh.LayDSMayTinh(), 5, 1); } } while (true); }