private void LoadData(string strsearch) { try { NhanVienClient client = new NhanVienClient(); DataTable dtb = client.NhanVien_GetNhanVien(new NhanVien(), strsearch).Tables[0]; dgv_DsNhanVien.DataSource = dtb; FormatGrid(); } catch (Exception ex) { throw ex; } }
private void btn_Xoa_Click(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { try { NhanVienClient client = new NhanVienClient(); if (MessageBox.Show("Bạn chắc chắn muốn xoá nhân viên '" + grid_DsNhanVien.GetRowCellValue(grid_DsNhanVien.FocusedRowHandle, "TenNhanVien").ToString() + "' không?", "Thông báo", MessageBoxButtons.YesNo) == DialogResult.Yes) { if (client.NhanVien_Delete(grid_DsNhanVien.GetRowCellValue(grid_DsNhanVien.FocusedRowHandle, "MaNhanVien").ToString())) { MessageBox.Show("Xoá sách thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Xoá thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } LoadData(""); } pic_Avatar.Image = Properties.Resources.userdefault; imagedefault = true; txt_MaNhanVien.Text = ""; txt_MaNhanVien.ReadOnly = true; txt_TenNhanVien.Text = ""; txt_TenNhanVien.ReadOnly = true; txt_NgaySinh.Text = ""; txt_NgaySinh.ReadOnly = true; txt_GioiTinh.Text = ""; txt_GioiTinh.ReadOnly = true; txt_CMND.Text = ""; txt_CMND.ReadOnly = true; txt_DiaChi.Text = ""; txt_DiaChi.ReadOnly = true; txt_SoDienThoai.Text = ""; txt_SoDienThoai.ReadOnly = true; btn_Browse.Visible = false; btn_CapNhat.Visible = false; lb_Search.Visible = true; txt_Search.Visible = true; pic_Them.Visible = true; } catch (Exception ex) { MessageBox.Show(ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void LoadMaNhanVien() { try { NhanVienClient nvclient = new NhanVienClient(); NhanVien nv = new NhanVien(); DataTable dtb = nvclient.NhanVien_GetNhanVien(nv, "").Tables[0]; AutoCompleteStringCollection DsNhanVien = new AutoCompleteStringCollection(); foreach (DataRow row in dtb.Rows) { DsNhanVien.Add(row["MaNhanVien"].ToString()); } txt_NhanVien.AutoCompleteMode = AutoCompleteMode.SuggestAppend; txt_NhanVien.AutoCompleteSource = AutoCompleteSource.CustomSource; txt_NhanVien.AutoCompleteCustomSource = DsNhanVien; } catch (Exception ex) { throw ex; } }
//Load thông tin thống kê private void LoadTotalReport() { try { #region Thống kê phiếu nhập PhieuNhapClient phieunhap_client = new PhieuNhapClient(); PhieuNhap pn = new PhieuNhap(); pn.NgayNhap = DateTime.Today; DataTable dt = phieunhap_client.PhieuNhap_GetPhieuNhap(pn, "").Tables[0]; lb_PhieuNhap1_SoPhieu_value.Text = dt.Rows.Count.ToString(); decimal Tongtiennhap = 0; if (dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { Tongtiennhap += Convert.ToDecimal(row["TongTien"]); } } if (Tongtiennhap != 0) { lb_PhieuNhap1_Tien_value.Text = Tongtiennhap.ToString("#,##"); } else { lb_PhieuNhap1_Tien_value.Text = "0"; } pn = new PhieuNhap(); dt = phieunhap_client.PhieuNhap_GetPhieuNhap(pn, " and Year(pns.NgayNhap) = " + DateTime.Today.Year + " and Month(pns.NgayNhap) = " + DateTime.Today.Month).Tables[0]; lb_PhieuNhap2_SoPhieu_value.Text = dt.Rows.Count.ToString(); Tongtiennhap = 0; if (dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { Tongtiennhap += Convert.ToDecimal(row["TongTien"]); } } if (Tongtiennhap != 0) { lb_PhieuNhap2_Tien_value.Text = Tongtiennhap.ToString("#,##"); } else { lb_PhieuNhap2_Tien_value.Text = "0"; } #endregion #region Thống kê phiếu xuất PhieuXuatClient phieuxuat_client = new PhieuXuatClient(); PhieuXuat px = new PhieuXuat(); px.NgayXuat = DateTime.Today; dt = phieuxuat_client.PhieuXuat_GetPhieuXuat(px, "").Tables[0]; lb_PhieuXuat1_SoPhieu_value.Text = dt.Rows.Count.ToString(); decimal Tongtienxuat = 0; if (dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { Tongtienxuat += Convert.ToDecimal(row["TongTien"]); } } if (Tongtienxuat != 0) { lb_PhieuXuat1_Tien_value.Text = Tongtienxuat.ToString("#,##"); } else { lb_PhieuXuat1_Tien_value.Text = "0"; } px = new PhieuXuat(); dt = phieuxuat_client.PhieuXuat_GetPhieuXuat(px, " and Year(pxs.NgayXuat) = " + DateTime.Today.Year + " and Month(pxs.NgayXuat) = " + DateTime.Today.Month).Tables[0]; lb_PhieuXuat2_SoPhieu_value.Text = dt.Rows.Count.ToString(); Tongtienxuat = 0; if (dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { Tongtienxuat += Convert.ToDecimal(row["TongTien"]); } } if (Tongtienxuat != 0) { lb_PhieuXuat2_Tien_value.Text = Tongtienxuat.ToString("#,##"); } else { lb_PhieuXuat2_Tien_value.Text = "0"; } #endregion #region Thống kê hoá đơn - ghi nợ HoaDonClient hoadon_client = new HoaDonClient(); HoaDon hd = new HoaDon(); hd.NgayXuat = DateTime.Today; dt = hoadon_client.HoaDon_GetHoaDon(hd, "").Tables[0]; lb_HoaDon1_SoHD_value.Text = dt.Rows.Count.ToString(); Tongtienxuat = 0; decimal Tongtienno = 0; if (dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { Tongtienxuat += Convert.ToDecimal(row["TongTien"]); Tongtienno += Convert.ToDecimal(row["ConLai"]); } } if (Tongtienxuat != 0) { lb_HoaDon1_DoanhThu_value.Text = Tongtienxuat.ToString("#,##"); } else { lb_HoaDon1_DoanhThu_value.Text = "0"; } if (Tongtienno != 0) { lb_SoNo_value.Text = Tongtienno.ToString("#,##"); } else { lb_SoNo_value.Text = "0"; } hd = new HoaDon(); dt = hoadon_client.HoaDon_GetHoaDon(hd, " and Year(NgayXuat) = " + DateTime.Today.Year + " and Month(NgayXuat) = " + DateTime.Today.Month).Tables[0]; lb_HoaDon2_SoHD_value.Text = dt.Rows.Count.ToString(); Tongtienxuat = 0; Tongtienno = 0; if (dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { Tongtienxuat += Convert.ToDecimal(row["TongTien"]); Tongtienno += Convert.ToDecimal(row["ConLai"]); } } if (Tongtienxuat != 0) { lb_HoaDon2_DoanhThu_value.Text = Tongtienxuat.ToString("#,##"); } else { lb_HoaDon2_DoanhThu_value.Text = "0"; } if (Tongtienno != 0) { lb_SoNo_Thang_value.Text = Tongtienno.ToString("#,##"); } else { lb_SoNo_Thang_value.Text = "0"; } #endregion #region Thống kê khách hàng KhachHangClient khachhang_client = new KhachHangClient(); KhachHang kh = new KhachHang(); //Đếm tổng số khách hàng dt = khachhang_client.KhachHang_GetKhachHang(kh, "").Tables[0]; lb_KhachHang_Tong_value.Text = dt.Rows.Count.ToString(); //Đếm số khách hàng còn nợ dt = khachhang_client.KhachHang_GetKhachHang(kh, " and SoNo > 0").Tables[0]; lb_KhachHang_ConNo_value.Text = dt.Rows.Count.ToString(); #endregion #region Thống kê nhân viên NhanVienClient nhanvien_client = new NhanVienClient(); //Đếm số nv nam NhanVien nv = new NhanVien(); nv.GioiTinh = "Nam"; dt = nhanvien_client.NhanVien_GetNhanVien(nv, "").Tables[0]; lb_NhanVien_Nam_value.Text = dt.Rows.Count.ToString(); //Đếm số nv nữ nv = new NhanVien(); nv.GioiTinh = "Nu"; dt = nhanvien_client.NhanVien_GetNhanVien(nv, "").Tables[0]; lb_NhanVien_Nu_value.Text = dt.Rows.Count.ToString(); #endregion #region Thống kê phiếu thu - thanh toán nợ PhieuThuClient phieuthu_client = new PhieuThuClient(); PhieuThu pt = new PhieuThu(); pt.NgayThu = DateTime.Today; dt = phieuthu_client.PhieuThu_GetPhieuThu(pt, "").Tables[0]; decimal TongTienThu = 0; if (dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { TongTienThu += Convert.ToDecimal(row["SoTienThu"]); } } if (TongTienThu != 0) { lb_TienThu_value.Text = TongTienThu.ToString("#,##"); } else { lb_TienThu_value.Text = "0"; } pt = new PhieuThu(); dt = phieuthu_client.PhieuThu_GetPhieuThu(pt, " and Year(NgayThu) = " + DateTime.Today.Year + " and Month(NgayThu) = " + DateTime.Today.Month).Tables[0]; TongTienThu = 0; if (dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { TongTienThu += Convert.ToDecimal(row["SoTienThu"]); } } if (TongTienThu != 0) { lb_TienThu_Thang_value.Text = TongTienThu.ToString("#,##"); } else { lb_TienThu_Thang_value.Text = "0"; } #endregion #region Thống kê sản phẩm SanPhamClient sanpham_client = new SanPhamClient(); SanPham sp = new SanPham(); SanPham[] dssp = sanpham_client.SanPham_GetSanPham(sp, ""); lb_MaSanPham_value.Text = dssp.Length.ToString(); decimal tongsotonkho = 0; if (dssp.Length > 0) { foreach (SanPham sanpham in dssp) { tongsotonkho += Convert.ToDecimal(sanpham.LuongTon); } } lb_TongTon_value.Text = tongsotonkho.ToString(); dssp = sanpham_client.SanPham_GetSanPham(sp, " and SoLuongTon > 0"); lb_ConHang_value.Text = dssp.Length.ToString(); dssp = sanpham_client.SanPham_GetSanPham(sp, " and SoLuongTon = 0"); lb_HetHang_value.Text = dssp.Length.ToString(); #endregion } catch (Exception ex) { MessageBox.Show(ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btn_CapNhat_Click(object sender, EventArgs e) { try { if (!checknull()) { NhanVien nv = new NhanVien(); nv.MaNhanVien = txt_MaNhanVien.Text; nv.TenNhanVien = txt_TenNhanVien.Text; nv.GioiTinh = txt_GioiTinh.Text; nv.NgaySinh = Convert.ToDateTime(txt_NgaySinh.Text); nv.DiaChi = txt_DiaChi.Text; nv.SoDienThoai = txt_SoDienThoai.Text; nv.CMND = txt_CMND.Text; if (!imagedefault) { if (!string.IsNullOrEmpty(pic_Avatar.ImageLocation)) { FileStream fs = new FileStream(pic_Avatar.ImageLocation, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); nv.HinhAnh = br.ReadBytes((int)fs.Length); } else { MemoryStream ms = new MemoryStream(); pic_Avatar.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Png); nv.HinhAnh = ms.ToArray(); } } else { nv.HinhAnh = null; } NhanVienClient client = new NhanVienClient(); if (txt_MaNhanVien.ReadOnly) { if (client.NhanVien_Update(nv)) { MessageBox.Show("Cập nhật nhân viên thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadData(""); } else { MessageBox.Show("Cập nhật nhân viên thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { if (client.NhanVien_Insert(nv)) { MessageBox.Show("Thêm nhân viên thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadData(""); } else { MessageBox.Show("Thêm nhân viên thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } pic_Avatar.Image = Properties.Resources.userdefault; imagedefault = true; txt_MaNhanVien.Text = ""; txt_MaNhanVien.ReadOnly = true; txt_TenNhanVien.Text = ""; txt_TenNhanVien.ReadOnly = true; txt_NgaySinh.Text = ""; txt_NgaySinh.ReadOnly = true; txt_GioiTinh.Text = ""; txt_GioiTinh.ReadOnly = true; txt_CMND.Text = ""; txt_CMND.ReadOnly = true; txt_DiaChi.Text = ""; txt_DiaChi.ReadOnly = true; txt_SoDienThoai.Text = ""; txt_SoDienThoai.ReadOnly = true; btn_Browse.Visible = false; btn_CapNhat.Visible = false; lb_Search.Visible = true; txt_Search.Visible = true; pic_Them.Visible = true; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }