public List <HDBan> TimHDBan(HDBan hdb) { List <HDBan> list = hdbDAL.GetData(); List <HDBan> kq = new List <HDBan>(); if (hdb.maHDB == null) { kq = list; } if (hdb.maHDB != null) { for (int i = 0; i < list.Count; ++i) { if (list[i].maHDB == hdb.maHDB) { kq.Add(new HDBan(list[i])); } } } else { kq = null; } return(kq); }
// // Phương thức cập nhật thông tin hoá đơn // public void Update(HDBan hdb) { provider.Connect(); string sql = string.Format("UPDATE HDBAN SET MAKH ={0}, MANV ={1}, NGLAP ={2}, THANHTIEN ={3} ", hdb.MaKh, hdb.MaNv, hdb.NgayLap, hdb.ThanhTien); provider.ExecuteQuery(sql); provider.Disconnect(); }
public ActionResult Dathang(FormCollection collection) { List <GioHang> lstGiohang = Laygiohang(); HDBan hd = new HDBan(); KhachHang kh = (KhachHang)Session["Taikhoan"]; hd.MaKH = kh.MaKH; hd.NgayBan = DateTime.Now; data.HDBans.InsertOnSubmit(hd); data.SubmitChanges(); foreach (var item in lstGiohang) { ChitietHDBan cthd = new ChitietHDBan(); cthd.MaHD = hd.MaHD; cthd.MaHoa = item.sMahoa; cthd.SoLuong = item.iSoluong; cthd.DonGia = (double)item.iDonGia; hd.TongTien = (int)item.ithanhTien; data.ChitietHDBans.InsertOnSubmit(cthd); } data.SubmitChanges(); Session["Giohang"] = null; return(RedirectToAction("XacNhan", "Giohang")); }
public ActionResult ConfirmDelete(string id) { HDBan hdb = db.HDBans.Find(id); db.HDBans.Remove(hdb); db.SaveChanges(); return(RedirectToAction("Index")); }
public void Insert(HDBan hdb) { int mahdb = CongCu.TachSo(maHDB) + 1; StreamWriter sw = File.AppendText(txtfile); sw.WriteLine("HDB" + mahdb + "\t" + hdb.maNV + "\t" + hdb.maKH + "\t" + hdb.ngayBan + "\t" + hdb.tongTien); sw.Close(); }
// // Phương thức thêm hoá đơn // public void Add(HDBan hdb) { provider.Connect(); string sql = string.Format("INSERT INTO HDBAN (MAKH, MANV, NGLAP, THANHTIEN) VALUES " + "({0},{1},'{2}',{3})", hdb.MaKh, hdb.MaNv, hdb.NgayLap, hdb.ThanhTien); provider.ExecuteQuery(sql); provider.Disconnect(); }
public ActionResult Edit(HDBan hdb) { if (ModelState.IsValid) { db.Entry(hdb).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(hdb)); }
public ActionResult Create(HDBan hdb) { if (ModelState.IsValid) { db.HDBans.Add(hdb); db.SaveChanges(); return(RedirectToAction("Index")); } return(View()); }
// // Phương thức event khi nhấn In hoá đơn ở tab hoá đơn // private void BtnIn4_Click(object sender, EventArgs e) { int maNV = new TaiKhoanBUS().GetMaNV(_tenDN); Khach kh = new Khach(-1, txtK4.Text, txtDC4.Text, txtSDT4.Text); new KhachBUS().Add(kh); int maKH = new KhachBUS().GetMaKH(txtK4.Text); HDBan hdb = new HDBan(-1, maKH, maNV, dtNgTT4.Value, Convert.ToInt32(txtThanhTien4.Text)); new HDBanBUS().Add(hdb); int maHDB = new ChiTietHDBanBUS().GetMaHDB(maKH, maNV); try { for (int i = 0; i < gridData4.Rows.Count - 1; i++) { int maSP = new SanPhamBUS().GetMaSP(gridData4.Rows[i].Cells[0].Value.ToString()); int soLuong = Convert.ToInt32(gridData4.Rows[i].Cells[1].Value.ToString()); int tong = Convert.ToInt32(gridData4.Rows[i].Cells[3].Value.ToString()); ChiTietHDBan cthdb = new ChiTietHDBan(maHDB, maSP, soLuong, tong); new ChiTietHDBanBUS().Add(cthdb); } MessageBox.Show("Đã lưu hoá đơn vào ổ đĩa D"); frmCryReport f = new frmCryReport { _tenKH = txtK4.Text, _maHDB = maHDB, _tenNV = new TaiKhoanBUS().GetTenNV(_tenDN), _ngLap = dtNgTT4.Value, _tongTien = txtThanhTien4.Text }; f.Show(); } catch { MessageBox.Show("Kiểm tra lại thông tin"); new HDBanBUS().Delete(maHDB.ToString()); new KhachBUS().Delete(kh); int i = Convert.ToInt32(gridData2.Rows[gridData2.RowCount - 1].Cells[0].Value.ToString()); new KhachBUS().Reset(i); gridData4.DataSource = new HDBanBUS().LoadHD(); gridData4.Refresh(); i = Convert.ToInt32(gridData3.Rows[gridData3.RowCount - 1].Cells[0].Value.ToString()); new SanPhamBUS().Reset(i); } }
public HDBan LayMaHDB(string mamv, string makh, string ngayban) { HDBan hdb = null; foreach (HDBan hdban in hdbDAL.GetData()) { if (hdban.maNV == mamv && hdban.maKH == makh && hdban.ngayBan == ngayban) { hdb = new HDBan(hdban); break; } } return(hdb); }
public void ThemHDBan(HDBan hdb) { if (hdb.maNV != "" && hdb.maKH != "" && hdb.ngayBan != "") { hdb.maNV = CongCu.ChuanHoaMa(hdb.maNV); hdb.maKH = CongCu.ChuanHoaMa(hdb.maKH); hdb.ngayBan = CongCu.ChuanHoaMa(hdb.ngayBan); hdbDAL.Insert(hdb); } else { throw new Exception("Dữ liệu sai."); } }
// // Phương thức truy xuất thông tin hoá đơn dựa theo command được truyền vào // public List<HDBan> LoadData(string sql) { provider.Connect(); SqlDataReader reader = provider.ExecuteReader(sql); List<HDBan> list = new List<HDBan>(); while (reader.Read()) { int maHDB= reader.GetInt32(0); int maKH= reader.GetInt32(1); int maNV= reader.GetInt32(2); DateTime ngayLap= reader.GetDateTime(3); int thanhTien= reader.GetInt32(4); HDBan s = new HDBan(maHDB, maKH, maNV, ngayLap, thanhTien); list.Add(s); } provider.Disconnect(); return list; }
// // Phương thức truyền dẫn Add // public void Add(HDBan cthdb) { new HDBanDAO().Add(cthdb); }
public void Nhap(int x, int y, ConsoleColor background_color, ConsoleColor text_color) { do { Console.BackgroundColor = background_color; Console.ForegroundColor = text_color; IHDBanBLL hdban = new HDBanBLL(); INhanVienBLL nhanvien = new NhanVienBLL(); IKhachHangBLL khachhang = new KhachHangBLL(); IMayTinhBLL maytinh = new MayTinhBLL(); IHDNhapBLL hdnhap = new HDNhapBLL(); FormNhanVien fnv = new FormNhanVien(); FormKhachHang fkh = new FormKhachHang(); FormMayTinh fmt = new FormMayTinh(); NhanVienBLL nvBLL = new NhanVienBLL(); KhachHangBLL khBLL = new KhachHangBLL(); MayTinhBLL mtBLL = new MayTinhBLL(); FormHDNhap fhdn = new FormHDNhap(); ICTHDBanBLL cthdban = new CTHDBanBLL(); HDBanBLL hdbBLL = new HDBanBLL(); HDBan hdb = new HDBan(); CTHDBan cthdb = new CTHDBan(); HDBan hd; Console.Clear(); IO.Box(0, 0, 28, 114, ConsoleColor.Black, ConsoleColor.White); IO.BoxTitle(" NHẬP THÔNG TIN HÓA ĐƠN BÁN", x, y, 10, 112); IO.Writexy("Mã nhân viên:", x + 2, y + 3); IO.Writexy("Mã khách hàng:", x + 28, y + 3); IO.Writexy("Ngày bán:", 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("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 + 6); IO.Writexy("Nhập ! để thoát...", x + 4, y + 8); fnv.Hien(x, y + 10, nhanvien.LayDSNhanVien(), 5, 0); do { Console.SetCursorPosition(x + 16, y + 3); hdb.maNV = Console.ReadLine(); if (hdb.maNV == null) { IO.Clear(x + 3, y + 7, 60, ConsoleColor.Black); IO.Writexy("Nhập lại mã nhân viên...", x + 4, y + 7, ConsoleColor.Black, ConsoleColor.White); } else if (hdb.maNV == "!") { return; } else { if (nvBLL.KT_MaNhanVien(CongCu.ChuanHoaMa(hdb.maNV)) == false) { IO.Writexy("Không tồn tại mã nhân viên này...", x + 4, y + 7, ConsoleColor.Black, ConsoleColor.White); IO.Clear(x + 15, y + 3, 12, ConsoleColor.Black); } else { break; } } } while (hdb.maNV == null || nvBLL.KT_MaNhanVien(CongCu.ChuanHoaMa(hdb.maNV)) == false); IO.Clear(x + 3, y + 7, 60, ConsoleColor.Black); IO.Clear(x + 3, y + 8, 60, ConsoleColor.Black); fkh.Hien(x + 16, y + 10, khachhang.LayDSKhachHang(), 5, 0); do { Console.SetCursorPosition(x + 43, y + 3); hdb.maKH = Console.ReadLine(); if (hdb.maKH == null) { IO.Clear(x + 3, y + 7, 60, ConsoleColor.Black); IO.Writexy("Nhập lại mã khách hàng...", x + 4, y + 7, ConsoleColor.Black, ConsoleColor.White); } else { if (khBLL.KT_MaKhachHang(CongCu.ChuanHoaMa(hdb.maKH)) == false) { IO.Writexy("Không tồn tại mã khách hàng này...", x + 4, y + 7, ConsoleColor.Black, ConsoleColor.White); IO.Clear(x + 42, y + 3, 12, ConsoleColor.Black); } else { break; } } } while (hdb.maKH == null || khBLL.KT_MaKhachHang(CongCu.ChuanHoaMa(hdb.maKH)) == false); IO.Clear(x + 3, y + 7, 60, ConsoleColor.Black); fhdn.Hien(x + 13, y + 10, hdnhap.LayDSHDNhap(), 5, 0); IO.Writexy("Nhập ngày bán định dạng 'dd/MM/yyyy'...", x + 4, y + 8, ConsoleColor.Black, ConsoleColor.White); do { Console.SetCursorPosition(x + 65, y + 3); hdb.ngayBan = Console.ReadLine(); if (hdb.ngayBan == null || CongCu.CheckDate(hdb.ngayBan) == false) { IO.Writexy("Nhập lại ngày bán...", x + 4, y + 7, ConsoleColor.Black, ConsoleColor.White); IO.Clear(x + 64, y + 3, 18, ConsoleColor.Black); } } while (hdb.ngayBan == null || CongCu.CheckDate(hdb.ngayBan) == false); hdban.ThemHDBan(hdb); while (true) { hd = hdbBLL.LayMaHDB(hdb.maNV, hdb.maKH, hdb.ngayBan); cthdb.maHDB = hd.maHDB; IO.Clear(x + 3, y + 7, 60, ConsoleColor.Black); fmt.Hien(x + 11, y + 10, maytinh.LayDSMayTinh(), 5, 0); do { IO.Clear(x + 14, y + 5, 13, ConsoleColor.Black); Console.SetCursorPosition(x + 15, y + 5); cthdb.maMT = Console.ReadLine(); if (cthdb.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 (mtBLL.KT_MaMayTinh(CongCu.ChuanHoaMa(cthdb.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 + 14, y + 5, 13, ConsoleColor.Black); } else { break; } } } while (cthdb.maMT == null || mtBLL.KT_MaMayTinh(CongCu.ChuanHoaMa(cthdb.maMT)) == false); IO.Clear(x + 3, y + 8, 60, ConsoleColor.Black); IO.Clear(x + 3, y + 7, 60, ConsoleColor.Black); MayTinh mt = mtBLL.LayMayTinh(CongCu.ChuanHoaMa(cthdb.maMT)); do { IO.Clear(x + 37, y + 5, 14, ConsoleColor.Black); cthdb.soLuong = int.Parse(IO.ReadNumber(x + 38, y + 5)); if (cthdb.soLuong <= 0 || mt.sLCon <= 0 || cthdb.soLuong > mt.sLCon) { IO.Writexy("Nhập lại số lượng...", x + 4, y + 7, ConsoleColor.Black, ConsoleColor.White); IO.Clear(x + 37, y + 5, 14, ConsoleColor.Black); } } while (cthdb.soLuong <= 0 || mt.sLCon <= 0 || cthdb.soLuong > mt.sLCon); IO.Clear(x + 3, y + 7, 60, ConsoleColor.Black); IO.Clear(x + 63, y + 5, 16, ConsoleColor.Black); cthdb.donGia = mt.giaBan; IO.Writexy(cthdb.donGia.ToString(), x + 64, y + 5); IO.Clear(x + 3, y + 7, 60, ConsoleColor.Black); IO.Clear(x + 94, y + 5, 16, ConsoleColor.Black); IO.Writexy(cthdb.thanhTien.ToString(), x + 95, y + 5); cthdban.ThemCTHDBan(cthdb); if (mtBLL.KT_MaMayTinh(cthdb.maMT) == true) { mtBLL.TruSoLuong(mt, cthdb.soLuong); } IO.Clear(x + 3, y + 7, 60, ConsoleColor.Black); Console.SetCursorPosition(x + 34, y + 7); IO.Writexy("Nhập tiếp? (C/K)...", x + 4, y + 7); ConsoleKeyInfo c = Console.ReadKey(); if (c.KeyChar != 'c') { break; } } IO.Clear(x + 93, y + 5, 16, ConsoleColor.Black); IO.Writexy(hdbBLL.TTien(cthdb.maHDB).ToString(), x + 94, y + 3); hdb.tongTien = hdbBLL.TTien(cthdb.maHDB); 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("Hóa đơn bán đã được thêm...", x + 4, y + 7); hdban.XoaHDBan(cthdb.maHDB); hdban.ThemHDBan(hdb); Hien(x + 13, y + 10, hdban.LayDSHDBan(), 5, 1); } } while (true); }
public ActionResult Delete(string id) { HDBan hdb = db.HDBans.Find(id); return(View(hdb)); }