public XuatHang getDetailsById(int id) { string query = string.Format("SELECT * FROM dbo.XuatHang WHERE id = {0}", id); DataTable data = ExcuteQuery(query); XuatHang xh = new XuatHang(data.Rows[0]); return(xh); }
public ActionResult UpdateXuatHang(XuatHang xuatHang) { if (xuatHang == null) { return(BadRequest()); } _repository.UpdateXuatHangAsync(xuatHang); return(Ok("Update XuatHang Successful!")); }
public bool add(XuatHang O) { try { return(dal.add(O)); } catch (Exception ex) { throw ex; } }
public bool update(XuatHang O) { try { return(dal.update(O)); } catch (Exception ex) { throw ex; } }
public List <XuatHang> getListHide() { List <XuatHang> dsXH = new List <XuatHang>(); string query = "SELECT * FROM dbo.XuatHang WHERE hide = 1"; DataTable data = ExcuteQuery(query); foreach (DataRow item in data.Rows) { XuatHang nh = new XuatHang(item); dsXH.Add(nh); } return(dsXH); }
public List <XuatHang> getListByStringMH(string str) { List <XuatHang> dsXH = new List <XuatHang>(); string query = string.Format("SELECT * FROM dbo.XuatHang WHERE dbo.XuatHang.idMH IN (SELECT dbo.MatHang.id FROM dbo.MatHang WHERE name LIKE N'%{0}%') AND hide = 0", str); DataTable data = ExcuteQuery(query); foreach (DataRow item in data.Rows) { XuatHang nh = new XuatHang(item); dsXH.Add(nh); } return(dsXH); }
public List <XuatHang> getListByNameNV(string str) { List <XuatHang> dsXH = new List <XuatHang>(); string query = string.Format("SELECT * FROM dbo.XuatHang WHERE dbo.XuatHang.idNV IN (SELECT dbo.NhanVien.id FROM dbo.NhanVien WHERE name = N'{0}')", str); DataTable data = ExcuteQuery(query); foreach (DataRow item in data.Rows) { XuatHang nh = new XuatHang(item); dsXH.Add(nh); } return(dsXH); }
public int InsertData(XuatHang XH) { SqlParameter[] para = { new SqlParameter("maPX", XH.MaPX), new SqlParameter("ngayXuat", XH.NgayXuat), new SqlParameter("tongTien", XH.TongTien), new SqlParameter("maHH", XH.MaHH), new SqlParameter("soLuong", XH.SoLuong), new SqlParameter("donGia", XH.DonGia), }; return(ExcuteSQL("ThemXH", para)); }
public JsonResult PostExport(string ma) { bool success = true; string message = "Kết quả: Xuất báo cáo thành công."; try { var daoNH = new XuatHangDao(); XuatHang obj_PXK = daoNH.GetByID(ma); List <ChiTietXuat> lst_CT_PXK = obj_PXK.ChiTietXuats.OrderBy(obj => (obj.ID)).ToList(); List <DT_XuatKho> lst_DT_XK = new List <DT_XuatKho>(); for (int i = 0; i < lst_CT_PXK.Count; i++) { DT_XuatKho obj_DT_XK = new DT_XuatKho(); obj_DT_XK.STT = (i + 1).ToString(); obj_DT_XK.Mat_Hang = lst_CT_PXK.ElementAt(i).HangHoa.TenHH.ToString(); obj_DT_XK.So_Luong = lst_CT_PXK.ElementAt(i).SoLuong.ToString(); obj_DT_XK.DVT = lst_CT_PXK.ElementAt(i).HangHoa.DonViTinh.Ten; obj_DT_XK.Don_Gia = lst_CT_PXK.ElementAt(i).DonGia.ToString(); obj_DT_XK.Ma_Kho = lst_CT_PXK.ElementAt(i).MaKho.ToString(); obj_DT_XK.Thanh_Tien = (int.Parse(obj_DT_XK.So_Luong) * double.Parse(obj_DT_XK.Don_Gia)).ToString(); lst_DT_XK.Add(obj_DT_XK); } System.Web.HttpContext.Current.Session["Khach_Hang"] = obj_PXK.KhachHang1.TenKH; System.Web.HttpContext.Current.Session["SDT"] = obj_PXK.KhachHang1.SDT; System.Web.HttpContext.Current.Session["Dia_Chi"] = obj_PXK.KhachHang1.DiaChi; System.Web.HttpContext.Current.Session["Thu_Kho"] = obj_PXK.ThuKho; System.Web.HttpContext.Current.Session["Nguoi_Lap"] = obj_PXK.NguoiLapPhieu; System.Web.HttpContext.Current.Session["Dien_Giai"] = obj_PXK.DienGiai; System.Web.HttpContext.Current.Session["So_CT"] = obj_PXK.IDXuat; System.Web.HttpContext.Current.Session["Ngay_HT"] = obj_PXK.NgayXuat.Value.Day.ToString() + "/" + obj_PXK.NgayXuat.Value.Month.ToString() + "/" + obj_PXK.NgayXuat.Value.Year.ToString(); System.Web.HttpContext.Current.Session["Tong_Tien"] = String.Format("{0:0,0}", obj_PXK.TongTien.Value); System.Web.HttpContext.Current.Session["Tien_Chu"] = CommonFunction.ConvertCurrency(obj_PXK.TongTien.Value); System.Web.HttpContext.Current.Session["Data_Source"] = lst_DT_XK; } catch (Exception ex) { success = false; message = "Kết quả: " + ex.ToString() + "."; } return(Json(new { success = success, message = message })); }
public bool add(XuatHang O) { string query = string.Format("INSERT INTO dbo.XuatHang(idMH,idNV,soluong,thanhtien) VALUES ({0},{1},{2},{3})", O.idMH, O.idNV, O.soluong, O.thanhtien); try { ExcuteNonQuery(query); return(true); } catch (Exception ex) { throw ex; } }
public bool update(XuatHang O) { string query = string.Format("UPDATE dbo.XuatHang SET soluong = {0} WHERE id = {1}", O.soluong, O.id); try { ExcuteNonQuery(query); return(true); } catch (Exception ex) { throw ex; } }
public int getIdAndInsert(XuatHang O) { int check = 0; string query = string.Format("INSERT INTO dbo.XuatHang(idMH,idNV,soluong,thanhtien) output INSERTED.ID VALUES ({0},{1},{2},{3})", O.idMH, O.idNV, O.soluong, O.thanhtien); try { check = (int)ExcuteScalar(query); } catch (Exception ex) { throw ex; } return(check); }
private void button2_Click(object sender, EventArgs e) { XuatHang hh = new XuatHang() { Dock = DockStyle.Fill, TopLevel = false, TopMost = true }; hh.FormBorderStyle = FormBorderStyle.None; this.panelControl.Controls.Add(hh); foreach (Control ctrl in panelControl.Controls) { if (ctrl != hh) { ctrl.Dispose(); } } hh.Show(); }
private void btnLuuX_Click(object sender, EventArgs e) { id = 0; int dem = -1; XuatHangBLL bll = new XuatHangBLL(); MatHangBLL mhb = new MatHangBLL(); KhuyenMaiBLL kmb = new KhuyenMaiBLL(); for (int i = 0; i < lvMHX.Items.Count; i++) { XuatHang xh = new XuatHang(); xh.idMH = int.Parse(lvMHX.Items[i].SubItems[0].Text); xh.idNV = int.Parse(lvMHX.Items[i].SubItems[1].Text); xh.soluong = int.Parse(lvMHX.Items[i].SubItems[2].Text); xh.thanhtien = float.Parse(lvMHX.Items[i].SubItems[3].Text); MatHang mh = mhb.getDetailsById(xh.idMH); KhuyenMai km = kmb.getDetailsByIdMH(xh.idMH); float gia; if (km != null) { if (km.typegia == 0) { gia = mh.giaban - mh.giaban / 100 * km.gia; } else { gia = mh.giaban - km.gia; } } else { gia = mh.giaban; } mh.soluong -= xh.soluong; xh.thanhtien = xh.soluong * gia; try { if ((id = bll.getIdAndInsert(xh)) != 0) { mhb.update(mh); dem++; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } if (ckReportX.Checked == true) { id = id - dem; tcAdd.Controls.Clear(); tcAdd.Controls.Add(HoaDonBan); loadReport(2); } else { if (lvMHX.Items.Count != 0) { MessageBox.Show("Xuất Mặt Hàng thành công."); Close(); } else { MessageBox.Show("Chưa có dữ liệu"); } } }
void Them_Click(object sender, EventArgs e) { // Mặt hàng if (Fn == Function.MAT_HANG) { MatHang mh = new MatHang(); if (cboDM.SelectedValue == null) { MessageBox.Show("Danh mục trống."); return; } else { mh.idDM = int.Parse(cboDM.SelectedValue.ToString()); } mh.name = txtName.Text; mh.soluong = 0; if (mh.name == "") { MessageBox.Show("Tên mặt hàng không được bỏ trống."); txtName.Focus(); return; } float i; bool isNum = float.TryParse(txtGiaNhap.Text, out i); if (isNum) { mh.gianhap = i; } else { MessageBox.Show("Nhập sai giá nhập!"); txtGiaNhap.Focus(); return; } isNum = float.TryParse(txtGiaBan.Text, out i); if (isNum) { mh.giaban = i; } else { MessageBox.Show("Nhập sai giá bán!"); txtGiaBan.Focus(); return; } if (mh.giaban < mh.gianhap) { MessageBox.Show("Giá bán không được nhỏ hơn giá nhập!"); txtGiaBan.Focus(); return; } MatHangBLL bll = new MatHangBLL(); try { if (bll.add(mh)) { MessageBox.Show("Thêm thành công."); //load lại datagridview this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } // Danh mục else if (Fn == Function.DANH_MUC) { DanhMucBLL bll = new DanhMucBLL(); DanhMuc dm = new DanhMuc(); dm.name = txtNameDM.Text; dm.content = txtContentDM.Text; if (dm.name == "") { MessageBox.Show("Tên danh mục không được để trống."); txtNameDM.Focus(); return; } if (dm.content == "") { MessageBox.Show("Mô tả không được để trống"); txtContentDM.Focus(); return; } try { if (bll.add(dm)) { MessageBox.Show("Thêm danh mục thành công."); Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } // Khuyến mãi else if (Fn == Function.KHUYEN_MAI) { KhuyenMai km = new KhuyenMai(); // Kiểm tra mô tả km.content = txtContentKM.Text; if (km.content == "") { MessageBox.Show("Mô tả không được bỏ trống"); txtContentKM.Focus(); return; } // Kiểm tra giá float i; bool isNum = float.TryParse(txtGiaKM.Text, out i); if (isNum) { km.gia = i; if (km.gia < 0) { MessageBox.Show(" Giá không được nhỏ hơn 0"); txtGiaKM.Focus(); } } else { MessageBox.Show("Nhập giá không đúng"); txtGiaKM.Focus(); return; } // Thiết lập loại giá if (rdpKM.Checked == true) { km.typegia = 0; } else { km.typegia = 1; } if (km.typegia == 0) { if (100 < km.gia) { MessageBox.Show("Giá không được lớn hơn 100%"); } } //if (DateTime.Now > dtpStartKM.Value) //{ // MessageBox.Show("Thời gian bắt đầu nhỏ hơn hiện tại"); // return; //} if (DateTime.Now > dtpEndKM.Value) { MessageBox.Show("Thời gian kết thúc nhỏ hơn hiện tại"); return; } if (dtpStartKM.Value > dtpEndKM.Value) { MessageBox.Show("Thời gian bắt đầu lớn hơn thời gian kết thúc"); return; } km.starttime = dtpStartKM.Value.ToString("MM/dd/yyyy"); km.endtime = dtpEndKM.Value.ToString("MM/dd/yyyy"); KhuyenMaiBLL bll = new KhuyenMaiBLL(); try { if (bll.add(km)) { MessageBox.Show("Thêm Khuyến Mại thành công."); Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } // Tạo liên kết } // Nhà cung cấp else if (Fn == Function.NHA_CUNG_CAP) { NhaCungCap ncc = new NhaCungCap(); ncc.name = txtNameNCC.Text; if (ncc.name == "") { MessageBox.Show("Tên nhà cung cấp không được bỏ trống"); txtNameNCC.Focus(); return; } ncc.content = txtContentNCC.Text; if (ncc.content == "") { MessageBox.Show("Mô tả không được bỏ trống"); txtContentNCC.Focus(); return; } float i; bool isNum = float.TryParse(txtSdtNCC.Text, out i); if (isNum) { ncc.sdt = txtSdtNCC.Text; } else { MessageBox.Show("Không nhập đúng số điện thoại!"); txtSdtNCC.Focus(); return; } ncc.diachi = txtDiaChiNCC.Text; if (ncc.diachi == "") { MessageBox.Show("Địa chỉ không được bỏ trống"); txtDiaChiNCC.Focus(); return; } NhaCungCapBLL bll = new NhaCungCapBLL(); try { if (bll.add(ncc)) { MessageBox.Show("Thêm nhà cung cấp thành công."); Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } // Nhập hàng else if (Fn == Function.NHAP) { int i = 0; NhapHang nh = new NhapHang(); bool isNum = false; if (lisMHN.SelectedValue != null) { isNum = int.TryParse(lisMHN.SelectedValue.ToString(), out i); } else { MessageBox.Show("Mặt hàng không tồn tại"); return; } if (isNum) { nh.idMH = i; } if (cboNCCN.SelectedValue != null) { isNum = int.TryParse(cboNCCN.SelectedValue.ToString(), out i); } else { MessageBox.Show("Nhà cung cấp không tồn tại"); return; } if (isNum) { nh.idNCC = i; } isNum = int.TryParse(txtSoLuongN.Text, out i); if (isNum) { nh.soluong = i; if (nh.soluong <= 0) { MessageBox.Show("Số lượng phải lớn hơn 0"); txtSoLuongN.Focus(); return; } } else { MessageBox.Show("Nhập sai định dạng số lượng"); txtSoLuongN.Focus(); return; } if (txtThanhTienN.Text != "") { nh.thanhtien = float.Parse(txtThanhTienN.Text); } nh.idNV = idNV; string[] arr = new string[5]; //arr[0] = nh.id.ToString(); arr[0] = nh.idMH.ToString(); arr[1] = nh.idNCC.ToString(); arr[2] = nh.idNV.ToString(); arr[3] = nh.soluong.ToString(); arr[4] = nh.thanhtien.ToString(); ListViewItem item = new ListViewItem(arr); lvMHN.Items.Add(item); //try //{ // if (bll1.add(nh)) // { // bll.update(mh); // MessageBox.Show("Thêm mặt hàng thành công."); // } //} //catch (Exception ex) //{ // MessageBox.Show(ex.Message); //} } // Xuất hàng else if (Fn == Function.XUAT) { XuatHang xh = new XuatHang(); int i = 0; bool isNum = false; if (lisMHX.SelectedValue != null) { isNum = int.TryParse(lisMHX.SelectedValue.ToString(), out i); } else { MessageBox.Show("Mặt hàng không tồn tại"); return; } if (isNum) { xh.idMH = i; } xh.idNV = idNV; isNum = int.TryParse(txtSoLuongX.Text, out i); if (isNum) { xh.soluong = i; if (xh.soluong <= 0) { MessageBox.Show("Số lượng phải lớn hơn 0"); txtSoLuongX.Focus(); return; } } else { MessageBox.Show("Nhập sai định dạng số"); txtSoLuongX.Focus(); return; } MatHangBLL mhb = new MatHangBLL(); KhuyenMaiBLL kmb = new KhuyenMaiBLL(); MatHang mh = mhb.getDetailsById(xh.idMH); if (xh.soluong > mh.soluong) { MessageBox.Show("Số lượng xuất lớn hơn tồn kho"); txtSoLuongX.Focus(); return; } xh.thanhtien = float.Parse(txtThanhTienX.Text); KhuyenMai km = kmb.getDetailsByIdMH(xh.idMH); float gia; if (km != null) { if (km.typegia == 0) { gia = mh.giaban - mh.giaban / 100 * km.gia; } else { gia = mh.giaban - km.gia; } } else { gia = mh.giaban; } mh.soluong -= xh.soluong; xh.thanhtien = xh.soluong * gia; XuatHangBLL bll = new XuatHangBLL(); string[] arr = new string[4]; //arr[0] = nh.id.ToString(); arr[0] = xh.idMH.ToString(); arr[1] = xh.idNV.ToString(); arr[2] = xh.soluong.ToString(); arr[3] = xh.thanhtien.ToString(); ListViewItem item = new ListViewItem(arr); lvMHX.Items.Add(item); //try //{ // if (bll.add(xh)) // { // mhl.update(mh); // MessageBox.Show("Xuất Mặt Hàng thành công."); // } //} //catch (Exception ex) //{ // MessageBox.Show(ex.Message); //} } // Nhân viên else if (Fn == Function.NHAN_VIEN) { NhanVien nv = new NhanVien(); nv.username = txtUsernameNV.Text; if (nv.username == "") { MessageBox.Show("Tài khoản không được bỏ trống"); txtUsernameNV.Focus(); return; } nv.password = txtPasswordNV.Text; nv.password = MD5.md5(nv.password); if (nv.password == "") { MessageBox.Show("Mật khẩu không được bỏ trống"); txtPasswordNV.Focus(); return; } nv.name = txtNameNV.Text; if (nv.name == "") { MessageBox.Show("Tên nhân viên không được bỏ trống"); txtNameNV.Focus(); return; } if (rdNamNV.Checked == true) { nv.gioitinh = 1; } else { nv.gioitinh = 0; } nv.diachi = txtDiaChiNV.Text; if (nv.diachi == "") { MessageBox.Show("Địa chỉ không được bỏ trống"); txtDiaChiNV.Focus(); return; } float i; bool isNum = float.TryParse(txtSdtNV.Text, out i); if (!isNum) { MessageBox.Show("Nhập sai định dạng số điện thoại"); txtSdtNV.Focus(); return; } nv.sdt = txtSdtNV.Text; nv.chucvu = txtChucVuNV.Text; if (nv.chucvu == "") { MessageBox.Show("Chức vụ không được để trống"); txtChucVuNV.Focus(); return; } NhanVienBLL bll = new NhanVienBLL(); try { if (bll.add(nv)) { MessageBox.Show("Thêm nhân viên thành công."); Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
void Luu_Click(object sender, EventArgs e) { // Mặt hàng if (Fn == Function.MAT_HANG) { MatHangBLL bll = new MatHangBLL(); MatHang mh = bll.getDetailsById(id); mh.name = txtNameM.Text; if (mh.name == "") { MessageBox.Show("Tên mặt hàng không được bỏ trống"); txtNameM.Focus(); return; } float i; bool isNum = float.TryParse(txtGiaBanM.Text, out i); if (isNum) { mh.giaban = i; if (mh.giaban < 0) { MessageBox.Show("Giá bán không được nhỏ hơn 0"); txtGiaBanM.Focus(); return; } } else { MessageBox.Show("Nhập sai giá bán"); txtGiaBanM.Focus(); return; } isNum = float.TryParse(txtGiaNhapM.Text, out i); if (isNum) { mh.gianhap = i; if (mh.gianhap < 0) { MessageBox.Show("Giá nhập không được nhỏ hơn 0"); txtGiaNhapM.Focus(); return; } } else { MessageBox.Show("Nhập sai giá nhập"); txtGiaNhapM.Focus(); return; } if (mh.giaban < mh.gianhap) { MessageBox.Show("Giá bán phải lớn giá nhập."); txtGiaBanM.Focus(); return; } try { if (bll.update(mh)) { MessageBox.Show("Cập nhật thành công."); Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } // Danh mục else if (Fn == Function.DANH_MUC) { DanhMucBLL bll = new DanhMucBLL(); DanhMuc dm = bll.getDetailsById(id); dm.name = txtNameDM.Text; if (dm.name == "") { MessageBox.Show("Tên danh mục không được bỏ trống"); txtNameDM.Focus(); return; } dm.content = txtContentDM.Text; if (dm.content == "") { MessageBox.Show("Mô tả không được bỏ trống"); txtContentDM.Focus(); return; } try { if (bll.update(dm)) { MessageBox.Show("Cập nhật thành công."); Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } // Nhân viên else if (Fn == Function.NHAN_VIEN) { NhanVienBLL bll = new NhanVienBLL(); NhanVien nv = bll.getDetailsById(id); nv.name = txtNameNV.Text; if (nv.name == "") { MessageBox.Show("Tên nhân viên không được để trống"); txtNameNV.Focus(); return; } nv.diachi = txtDiaChiNV.Text; if (nv.diachi == "") { MessageBox.Show("Địa chỉ không được để trống"); txtDiaChiNV.Focus(); return; } nv.chucvu = txtChucVuNV.Text; if (nv.chucvu == "") { MessageBox.Show("Chức vụ không được để trống"); txtDiaChiNV.Focus(); return; } double i; bool isNum = double.TryParse(txtSdtNV.Text, out i); if (isNum) { nv.sdt = txtSdtNV.Text; } else { MessageBox.Show("Nhập không đúng số điện thoại!"); txtSdtNV.Focus(); return; } try { if (bll.update(nv)) { MessageBox.Show("Cập nhật thành công."); Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } // Nhà cung cấp else if (Fn == Function.NHA_CUNG_CAP) { NhaCungCapBLL bll = new NhaCungCapBLL(); NhaCungCap ncc = bll.getDetailsById(id); ncc.name = txtNameNCC.Text; if (ncc.name == "") { MessageBox.Show("Tên nhà cung cấp không được bỏ trống"); txtNameNCC.Focus(); return; } ncc.content = txtContentNCC.Text; if (ncc.content == "") { MessageBox.Show("Mô tả không được bỏ trống"); txtContentNCC.Focus(); return; } ncc.diachi = txtDiaChiNCC.Text; if (ncc.diachi == "") { MessageBox.Show("Địa chỉ không được bỏ trống"); txtDiaChiNCC.Focus(); return; } double i; bool isNum = double.TryParse(txtSdtNCC.Text, out i); if (isNum) { ncc.sdt = txtSdtNCC.Text; } else { MessageBox.Show("Nhập không đúng số điện thoại!"); txtSdtNCC.Focus(); return; } try { if (bll.update(ncc)) { MessageBox.Show("Cập nhật thành công."); Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } //Khuyến mãi else if (Fn == Function.KHUYEN_MAI) { KhuyenMaiBLL bll = new KhuyenMaiBLL(); KhuyenMai km = bll.getDetailsById(id); km.content = txtContentKM.Text; if (km.content == "") { MessageBox.Show("Mô tả không được bỏ trống"); txtContentKM.Focus(); return; } km.starttime = txtBatDauKM.Text; km.endtime = txtKetThucKM.Text; DateTime start = Convert.ToDateTime(txtBatDauKM.Text); DateTime end = Convert.ToDateTime(txtKetThucKM.Text); //if (DateTime.Now > start) //{ // MessageBox.Show("Ngày bắt đầu nhỏ hơn ngày hiện tại?"); // txtBatDauKM.Focus(); // return; //} if (end < start) { MessageBox.Show("Ngày bắt đầu lớn hơn ngày kết thúc?!"); txtKetThucKM.Focus(); return; } float i; bool isNum = float.TryParse(txtGiaKM.Text, out i); if (isNum) { km.gia = i; if (km.typegia == 0) { if (km.gia < 0 || km.gia > 100) { MessageBox.Show("Giới hạn % từ 0 đến 100!"); txtGiaKM.Focus(); return; } } } else { MessageBox.Show("Nhập không đúng định dạng số!"); txtGiaKM.Focus(); return; } try { if (bll.update(km)) { MessageBox.Show("Cập nhật thành công."); Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } // Nhập hàng else if (Fn == Function.NHAP) { NhapHangBLL bll = new NhapHangBLL(); NhapHang nh = bll.getDetailsById(id); MatHangBLL bll1 = new MatHangBLL(); MatHang mh = bll1.getDetailsById(nh.idMH); int i; bool isNum = int.TryParse(txtSoLuongNH.Text, out i); if (isNum) { mh.soluong -= nh.soluong; mh.soluong += i; nh.soluong = i; } else { MessageBox.Show("Nhập không đúng định dạng số"); txtSoLuongNH.Focus(); return; } try { if (bll.update(nh)) { bll1.update(mh); MessageBox.Show("Cập nhật thành công."); Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } // Xuất hàng else if (Fn == Function.XUAT) { XuatHangBLL bll = new XuatHangBLL(); XuatHang xh = bll.getDetailsById(id); MatHangBLL bll1 = new MatHangBLL(); MatHang mh = bll1.getDetailsById(xh.idMH); int i; bool isNum = int.TryParse(txtSoLuongXH.Text, out i); if (isNum) { if (mh.soluong < i) { MessageBox.Show("Số lượng bán không được lớn hơn tồn kho {" + mh.soluong + "}"); return; } mh.soluong += xh.soluong; mh.soluong -= i; xh.soluong = i; } else { MessageBox.Show("Nhập không đúng định dạng số!"); txtSoLuongXH.Focus(); return; } try { if (bll.update(xh)) { bll1.update(mh); MessageBox.Show("Cập nhật thành công."); Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
public int getIdAndInsert(XuatHang O) { return(dal.getIdAndInsert(O)); }
private void btnXuatHang_Click(object sender, EventArgs e) { XuatHang frm = new XuatHang(); frm.Show(); }
public JsonResult CreatePXK(string khach_hang, string sdt, string dia_chi, string ngay_xuat, string ma, string thu_kho, string nguoi_lap_phieu, string dien_giai, string tong_tien) { bool success = true; string message = "Kết quả: Tạo phiếu xuất kho thành công!"; //Thêm khách hàng var daoKH = new KhachHangDao(); KhachHang obj_kh = new KhachHang(); obj_kh.TenKH = khach_hang; obj_kh.SDT = sdt; obj_kh.DiaChi = dia_chi; obj_kh.CreatedDate = DateTime.Now; obj_kh.Status = true; obj_kh.CreateBy = Session["UserName"].ToString(); int ma_kh = -1; try { ma_kh = daoKH.Insert(obj_kh); } catch (Exception ex) { success = false; message = "Kết quả: " + ex.ToString() + "."; } if (ma_kh != -1) { //Thêm phiếu xuất hàng var dao = new XuatHangDao(); var daoID = new CauHinhIDDao(); XuatHang obj = new XuatHang(); obj.IDXuat = ma; obj.KhachHang = ma_kh; obj.NgayXuat = DateTime.ParseExact(ngay_xuat, "dd/MM/yyyy", null); obj.ThuKho = thu_kho; obj.NguoiLapPhieu = nguoi_lap_phieu; obj.DienGiai = dien_giai; obj.LoaiGiaoDichID = 1; obj.TongTien = decimal.Parse(tong_tien); obj.CreatedDate = DateTime.Now; obj.CreateBy = Session["UserName"].ToString(); obj.TrangThai = 1; try { dao.Insert(obj); daoID.Update("BH"); } catch (Exception ex) { success = false; message = "Kết quả: " + ex.ToString() + "."; } } return(Json(new { success = success, message = message })); }
public bool Insert(XuatHang entity) { db.XuatHangs.Add(entity); db.SaveChanges(); return(true); }
private void Details_Load(object sender, EventArgs e) { SuKien(); tbcUpdate.Controls.Clear(); // Mặt hàng if (Fn == Function.MAT_HANG) { tbcUpdate.Controls.Add(tpMH); MatHangBLL bll = new MatHangBLL(); MatHang mh = bll.getDetailsById(id); DanhMucBLL bll1 = new DanhMucBLL(); KhuyenMaiBLL kmb = new KhuyenMaiBLL(); KMInfo km = kmb.getKMInfo(mh.id); if (km == null) { btnXoaLK.Enabled = false; } txtIdM.Text = mh.id.ToString(); txtIdDMM.Text = bll1.getNameById(mh.idDM); txtNameM.Text = mh.name; txtSoLuongM.Text = mh.soluong.ToString(); txtGiaBanM.Text = mh.giaban.ToString(); txtGiaNhapM.Text = mh.gianhap.ToString(); txtGiaNhapM.ReadOnly = txtGiaBanM.ReadOnly = txtSoLuongM.ReadOnly = txtIdM.ReadOnly = txtIdDMM.ReadOnly = txtNameM.ReadOnly = true; Width = 609; Height = 421; } // Danh mục else if (Fn == Function.DANH_MUC) { tbcUpdate.Controls.Add(tpDM); DanhMucBLL bll = new DanhMucBLL(); DanhMuc dm = bll.getDetailsById(id); txtIdDM.Text = dm.id.ToString(); txtNameDM.Text = dm.name; txtContentDM.Text = dm.content; txtIdDM.ReadOnly = txtNameDM.ReadOnly = txtContentDM.ReadOnly = true; Width = 426; Height = 419; } // Nhân viên else if (Fn == Function.NHAN_VIEN) { tbcUpdate.Controls.Add(tpNV); NhanVienBLL bll = new NhanVienBLL(); NhanVien nv = bll.getDetailsById(id); txtIdNV.Text = nv.id.ToString(); txtUsernameNV.Text = nv.username; txtPasswordNV.Text = nv.password; txtNameNV.Text = nv.name; txtChucVuNV.Text = nv.chucvu; if (nv.gioitinh == 0) { txtGioiTinhNV.Text = "Nữ"; } else { txtGioiTinhNV.Text = "Nam"; } txtDiaChiNV.Text = nv.diachi; txtSdtNV.Text = nv.sdt; txtIdNV.ReadOnly = txtUsernameNV.ReadOnly = txtPasswordNV.ReadOnly = txtNameNV.ReadOnly = txtChucVuNV.ReadOnly = txtGioiTinhNV.ReadOnly = txtDiaChiNV.ReadOnly = txtSdtNV.ReadOnly = true; Width = 631; Height = 428; } // Nhà cung cấp else if (Fn == Function.NHA_CUNG_CAP) { tbcUpdate.Controls.Add(tpNCC); NhaCungCapBLL bll = new NhaCungCapBLL(); NhaCungCap ncc = bll.getDetailsById(id); txtIdNCC.Text = ncc.id.ToString(); txtNameNCC.Text = ncc.name; txtContentNCC.Text = ncc.content; txtSdtNCC.Text = ncc.sdt; txtDiaChiNCC.Text = ncc.diachi; txtIdNCC.ReadOnly = txtNameNCC.ReadOnly = txtContentNCC.ReadOnly = txtSdtNCC.ReadOnly = txtDiaChiNCC.ReadOnly = true; Width = 480; Height = 428; } // Khuyến mãi else if (Fn == Function.KHUYEN_MAI) { tbcUpdate.Controls.Add(tpKM); KhuyenMaiBLL bll = new KhuyenMaiBLL(); KhuyenMai km = bll.getDetailsById(id); txtIdKM.Text = km.id.ToString(); txtContentKM.Text = km.content; txtGiaKM.Text = km.gia.ToString(); if (km.typegia == 0) { txtTypeGiaKM.Text = "Phần trăm"; } else { txtTypeGiaKM.Text = "Nghìn đồng"; } txtBatDauKM.Text = km.starttime.Substring(0, km.starttime.LastIndexOf(" 12:00:00 AM")); txtKetThucKM.Text = km.endtime.Substring(0, km.endtime.LastIndexOf(" 12:00:00 AM")); txtTypeGiaKM.ReadOnly = txtIdKM.ReadOnly = txtContentKM.ReadOnly = txtGiaKM.ReadOnly = txtGiaKM.ReadOnly = txtBatDauKM.ReadOnly = txtKetThucKM.ReadOnly = true; Width = 580; Height = 421; } // Nhập hàng else if (Fn == Function.NHAP) { tbcUpdate.Controls.Add(tpNH); NhapHangBLL bll = new NhapHangBLL(); NhapHang nh = bll.getDetailsById(id); txtIdNH.Text = nh.id.ToString(); txtIdMHNH.Text = nh.idMH.ToString(); txtIdNVNH.Text = nh.idNV.ToString(); txtIdNCCNH.Text = nh.idNCC.ToString(); txtSoLuongNH.Text = nh.soluong.ToString(); txtThanhTienNH.Text = nh.thanhtien.ToString(); txtIdNH.ReadOnly = txtIdMHNH.ReadOnly = txtIdNVNH.ReadOnly = txtIdNCCNH.ReadOnly = txtSoLuongNH.ReadOnly = txtThanhTienNH.ReadOnly = true; Width = 613; Height = 421; } // Xuất hàng else if (Fn == Function.XUAT) { tbcUpdate.Controls.Add(tpXH); XuatHangBLL bll = new XuatHangBLL(); XuatHang xh = bll.getDetailsById(id); txtIdXH.Text = xh.id.ToString(); txtIdNVXH.Text = xh.idNV.ToString(); txtIdMHXH.Text = xh.idMH.ToString(); txtSoLuongXH.Text = xh.soluong.ToString(); txtThanhTienXH.Text = xh.thanhtien.ToString(); txtNgayXuat.Text = xh.ngayxuat; txtIdXH.ReadOnly = txtIdNVXH.ReadOnly = txtIdMHXH.ReadOnly = txtSoLuongXH.ReadOnly = txtThanhTienXH.ReadOnly = txtNgayXuat.ReadOnly = true; Width = 613; Height = 421; } }