public void SearchCustomer(String Key)
 {
     System.Threading.ThreadPool.QueueUserWorkItem(((o) =>
     {
         if (!smp.WaitOne(0))
         {
             return;
         }
         try
         {
             SearchProgresBarVisibility = Visibility.Visible;
             db = new Models.DBDataContext();
             double temp = 0;
             if (double.TryParse(Key, out temp))
             { // key vào là số thì có thể họ đang tìm kiếm bằng ID hoặc số CMND
                 SearchResult = new ObservableCollection <Models.KhachHang>(db.KhachHangs.Where(kh => kh.KhachHangID == temp || kh.ConNguoi.CMND.Contains(Key) || kh.ConNguoi.Phone.Contains(Key) || kh.ConNguoi.Phone2.Contains(Key)));
                 SearchProgresBarVisibility = Visibility.Hidden;
                 return;
             }
             Key = Key.ToLower();
             // nếu họ tìm bằng chuỗi thông thường thì có thể họ đang tìm kiếm bằng địa chỉ hoặc họ tên
             SearchResult = new ObservableCollection <Models.KhachHang>(db.KhachHangs.Where(kh => kh.ConNguoi.DiaChi.ToLower().Contains(Key) || kh.ConNguoi.HoTen.ToLower().Contains(Key)));
             SearchProgresBarVisibility = Visibility.Hidden;
         }
         catch (Exception ex)
         {
             FireHandledExeptionAndLogErorrAsync(ErrorTemplates.GetDBInteractionError(ex));
         }
         finally
         {
             smp.Release();
         }
     }));
 }
예제 #2
0
 public void Refresh()
 {
     System.Threading.ThreadPool.QueueUserWorkItem(((o) =>
     {
         if (!_Smp.WaitOne(0))
         {
             return;
         }
         try
         {
             Models.SinhNhat.renewBirthDay();
             db = new Models.DBDataContext();
             KhachHangs = from sn in db.SinhNhats
                          select new
             {
                 sn.KhachHang.ConNguoi.HoTen,
                 sn.KhachHang.ConNguoi.Phone,
                 sn.KhachHang.ConNguoi.Phone2,
                 sn
             };
         }
         catch (Exception ex)
         {
             FireHandledExeptionAndLogErorrAsync(ErrorTemplates.GetDBInteractionError(ex));
         }
         finally
         {
             _Smp.Release();
         }
     }));
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="notsendyet"></param>
 /// <param name="from"></param>
 /// <param name="to"></param>
 public void Search(bool notsendyet, DateTime from, DateTime to)
 {
     ThreadPool.QueueUserWorkItem(((o) =>
     {
         if (!_Smp.WaitOne(0))
         {
             return;
         }
         try
         {
             db = new Models.DBDataContext();
             SearchProgresBarVisibility = Visibility.Visible;
             var SearchResult = db.QuaTangs.Where(qt => notsendyet ? !qt.DaGui : true && qt.NgayLenKeHoach <= to && qt.NgayLenKeHoach >= from);
             QuaTangs = new ObservableCollection <Models.QuaTang>(SearchResult);
             SearchProgresBarVisibility = Visibility.Hidden;
         }
         catch (Exception ex)
         {
             FireHandledExeptionAndLogErorrAsync(ErrorTemplates.GetDBInteractionError(ex));
         }
         finally
         {
             _Smp.Release();
         }
     }));
 }
예제 #4
0
 public void SaveCG()
 {
     try
     {
         dbcg.SubmitChanges();
     }catch (Exception ex)
     {
         FireHandledExeptionAndLogErorrAsync(ErrorTemplates.GetDBInteractionError(ex));
     }
 }
 public CustomerAddViewModel()
 {
     try
     {
         LoaiQuanHes = db.LoaiQuanHes;
     }
     catch (Exception ex)
     {
         FireHandledExeptionAndLogErorrAsync(ErrorTemplates.GetDBInteractionError(ex));
     }
 }
 public AddEmployeeViewModel()
 {
     try
     {
         ChucVus = db.ChucVus;
     }
     catch (Exception ex)
     {
         FireHandledExeptionAndLogErorrAsync(ErrorTemplates.GetDBInteractionError(ex));
     }
 }
예제 #7
0
        public void Update()
        {
            System.Threading.ThreadPool.QueueUserWorkItem(((o) =>
            {
                if (!_Smp.WaitOne(0))
                {
                    return;
                }
                try
                {
                    DateTime motnamtruoc = DateTime.Today.AddDays(-365);
                    db = new Models.DBDataContext();

                    var se = (from kh in db.KhachHangs
                              join cg in db.CuocGois on kh.KhachHangID equals cg.KhachHangID
                              join cn in db.ConNguois on kh.ConNguoiID equals cn.ConNguoiID
                              where cg.ThoiDiemGoi > motnamtruoc
                              group kh by new
                    {
                        ID = kh.KhachHangID,
                        cn.HoTen,
                        cn.GioiTinh,
                        cn.CMND,
                        cn.Phone,
                        cn.Phone2,
                        cn.DiaChi,
                        TongGT = kh.CuocGois.Count
                    } into st
                              orderby st.Key.TongGT descending
                              select new
                    {
                        st.Key.DiaChi,
                        st.Key.GioiTinh,
                        st.Key.HoTen,
                        st.Key.CMND,
                        st.Key.ID,
                        st.Key.Phone,
                        st.Key.Phone2,
                        st.Key.TongGT
                    }).Take(10).ToList();

                    SearchResult = new ObservableCollection <object>(se);
                }
                catch (Exception ex)
                {
                    FireHandledExeptionAndLogErorrAsync(ErrorTemplates.GetDBInteractionError(ex));
                }
                _Smp.Release();
            }));
        }
예제 #8
0
 public void AddCall(int LoaiCGoiID, int TThaiKH, String Note)
 {
     try
     {
         // Nhân viên ID chưa sửa, cần sửa lại
         db.CuocGois.InsertOnSubmit(new Models.CuocGoi {
             KhachHangID = Customer.KhachHangID, ThoiDiemGoi = StartTime, ThoiDiemKetThuc = DateTime.Now, LoaiCuocGoiID = LoaiCGoiID, TragThaiKH = TThaiKH, GhiChu = Note, NhanVienID = 2
         });
         db.SubmitChanges();
     }
     catch (Exception ex)
     {
         FireHandledExeptionAndLogErorrAsync(ErrorTemplates.GetDBInteractionError(ex));
     }
 }
예제 #9
0
 public MakeCallViewModel(Models.KhachHang kh)
 {
     System.Threading.ThreadPool.QueueUserWorkItem(((o) =>
     {
         try
         {
             Customer = kh;
             LoaiCuocGois = db.LoaiCuocGois;
         }
         catch (Exception ex)
         {
             FireHandledExeptionAndLogErorrAsync(ErrorTemplates.GetDBInteractionError(ex));
         }
     }));
 }
예제 #10
0
 public void RefreshAsync()
 {
     System.Threading.ThreadPool.QueueUserWorkItem(((o) =>
     {
         try
         {
             db = new Models.DBDataContext();
             DSChucVu = new ObservableCollection <Models.DanhSachChucVu>(db.DanhSachChucVus.Where(cv => cv.NhanVienID == _Employee.NhanVienID));
         }
         catch (Exception ex)
         {
             FireHandledExeptionAndLogErorrAsync(ErrorTemplates.GetDBInteractionError(ex));
         }
     }));
 }
예제 #11
0
 public ExpandViewModel(Models.KhachHang kh)
 {
     Customer = kh;
     try
     {
         LoaiQuanHes        = dbcg.LoaiQuanHes;
         WindowTitle        = Customer.ConNguoi.HoTen;
         CbbLQHData         = dbcg.LoaiQuanHes;
         CbbLoaiCuocGoiData = dbcg.LoaiCuocGois;
     }
     catch (Exception ex)
     {
         FireHandledExeptionAndLogErorrAsync(ErrorTemplates.GetDBInteractionError(ex));
     }
     RefreshNTAsync();
     RefreshCGAsync();
 }
예제 #12
0
 public ExpandEmployeeViewModel(Models.NhanVien nv)
 {
     _Employee = nv;
     System.Threading.ThreadPool.QueueUserWorkItem(((o) =>
     {
         try
         {
             _Employee = db.NhanViens.Single(em => em.NhanVienID == nv.NhanVienID);
             ChucVu = new ObservableCollection <Models.ChucVu>(db.ChucVus);
         }
         catch (Exception ex)
         {
             FireHandledExeptionAndLogErorrAsync(ErrorTemplates.GetDBInteractionError(ex));
         }
         RefreshAsync();
     }));
 }
 public void AddCustomer(string name, string address, bool?gioitinh, DateTime?ngaysinh,
                         string phone1, string phone2, string CMND, string email)
 {
     KhachHang.ConNguoi = new Models.ConNguoi {
         HoTen    = name, DiaChi = address, GioiTinh = gioitinh,
         NgaySinh = ngaysinh, Phone = phone1, Phone2 = phone2, CMND = CMND, Email = email
     };
     db.KhachHangs.InsertOnSubmit(KhachHang);
     try
     {
         db.SubmitChanges();
         KhachHang  = new Models.KhachHang();
         NguoiThans = new ObservableCollection <Models.NguoiThan>();
     }
     catch (Exception ex)
     {
         FireHandledExeptionAndLogErorrAsync(ErrorTemplates.GetDBInteractionError(ex));
     }
 }
예제 #14
0
 public void AddGift(int giatri, Models.NhanVien Emp)
 {
     foreach (var item in KhachHangs)
     {
         db.QuaTangs.InsertOnSubmit(new Models.QuaTang {
             DaNhan = false, GiaTri = giatri, KHID = item.KhachHangID, NhanVienID = Emp.NhanVienID
         });
     }
     ThreadPool.QueueUserWorkItem(new WaitCallback((o) =>
     {
         try
         {
             db.SubmitChanges();
         }
         catch (Exception ex)
         {
             FireHandledExeptionAndLogErorrAsync(ErrorTemplates.GetDBInteractionError(ex));
         }
     }));
 }
 public void AddEmployee(string Hoten, string Diachi, bool Gioitinh, DateTime?NgaySinh, String Phone1, String Phone2, String CMND, String Email, Models.ChucVu chucvu, string password)
 {
     Models.NhanVien nv = new Models.NhanVien {
         ConNguoi = new Models.ConNguoi {
             HoTen = Hoten, DiaChi = Diachi, GioiTinh = Gioitinh, NgaySinh = NgaySinh, Phone = Phone1, Phone2 = Phone2, CMND = CMND, Email = Email, MatKhau = password
         }
     };
     nv.DanhSachChucVus.Add(new Models.DanhSachChucVu {
         NhanVien = nv, ChucVu = chucvu
     });
     db.NhanViens.InsertOnSubmit(nv);
     try
     {
         db.SubmitChanges();
     }
     catch (Exception ex)
     {
         FireHandledExeptionAndLogErorrAsync(ErrorTemplates.GetDBInteractionError(ex));
     }
 }
예제 #16
0
 public void RefreshAsync()
 {
     System.Threading.ThreadPool.QueueUserWorkItem(((o) =>
     {
         if (!_Smp.WaitOne(0))
         {
             return;
         }
         try
         {
             db = new Models.DBDataContext();
             Result = new ObservableCollection <Models.QuaTang>(db.QuaTangs.Where(qt => qt.DaGui == false && qt.NhanVienID == App.CurentEmployee.NhanVienID));
         }
         catch (Exception ex)
         {
             FireHandledExeptionAndLogErorrAsync(ErrorTemplates.GetDBInteractionError(ex));
         }
         finally
         {
             _Smp.Release();
         }
     }));
 }
예제 #17
0
 public void Refresh()
 {
     System.Threading.ThreadPool.QueueUserWorkItem(((o) =>
     {
         if (!_Smp.WaitOne(0))
         {
             return;
         }
         try
         {
             Models.SinhNhat.renewBirthDay();
             Num = db.SinhNhats.Where(sn => sn.DaGoi == false).Count().ToString();
         }
         catch (Exception ex)
         {
             FireHandledExeptionAndLogErorrAsync(ErrorTemplates.GetDBInteractionError(ex));
         }
         finally
         {
             _Smp.Release();
         }
     }));
 }
예제 #18
0
 public void RefreshCGAsync()
 {
     // tạo một thread chạy ngầm cho đỡ phải đợi
     ThreadPool.QueueUserWorkItem(((o) =>
     {
         if (!smp2.WaitOne(0))
         {
             return;
         }
         try
         {
             dbcg = new Models.DBDataContext();
             CuocGois = dbcg.CuocGois.Where(cg => cg.KhachHangID == Customer.KhachHangID);
         }
         catch (Exception ex)
         {
             FireHandledExeptionAndLogErorrAsync(ErrorTemplates.GetDBInteractionError(ex));
         }
         finally
         {
             smp2.Release();
         }
     }));
 }
예제 #19
0
 public void RefreshNTAsync()
 {
     // tạo một thread chạy ngầm cho đỡ phải đợi
     ThreadPool.QueueUserWorkItem(((o) =>
     {
         if (!smp1.WaitOne(0))
         {
             return;
         }
         try
         {
             db = new Models.DBDataContext();
             NguoiThans = new ObservableCollection <Models.NguoiThan>(db.NguoiThans.Where(nt => nt.KhachHangID == Customer.KhachHangID));
         }
         catch (Exception ex)
         {
             FireHandledExeptionAndLogErorrAsync(ErrorTemplates.GetDBInteractionError(ex));
         }
         finally
         {
             smp1.Release();
         }
     }));
 }
예제 #20
0
        public void Login(string UserName, string Password)
        {
            try
            {
                nv = db.NhanViens.Single(tt => tt.NhanVienID.ToString() == UserName && tt.ConNguoi.MatKhau == Password);

                // Tạo một đối tượng quyền mà tất cả các quyền của nó đều bằng false
                Models.Quyen VTquyen = new Models.Quyen
                {
                    BaoCaoThongKe   = false,
                    HoTroGiaoTiepKH = false,
                    PhanQuyen       = false,
                    QLTTCaNhanKH    = false,
                    QLTTNV          = false,
                    QLTTQuaTang     = false,
                    SuaTTKH         = false,
                    XemTTNhanVien   = false,
                    XemTTQuaTang    = false,
                    XoaCuocGoi      = false,
                    XoaTTKH         = false,
                };

                // chạy trong danh sách các quyền mà người này có để lấ ra một đối tượng quyền là sự kết hợp của các quyền khác
                var quyens = from cvs in db.DanhSachChucVus
                             join cv in db.ChucVus on cvs.ChucVuID equals cv.ChucVuID
                             join q in db.Quyens on cv.QuyenID equals q.QuyenID
                             where cvs.NhanVienID == nv.NhanVienID
                             select q;
                foreach (var q in quyens)
                {
                    if (q.BaoCaoThongKe == true)
                    {
                        VTquyen.BaoCaoThongKe = true;
                    }
                    if (q.HoTroGiaoTiepKH == true)
                    {
                        VTquyen.HoTroGiaoTiepKH = true;
                    }
                    if (q.PhanQuyen == true)
                    {
                        VTquyen.PhanQuyen = true;
                    }
                    if (q.QLTTCaNhanKH == true)
                    {
                        VTquyen.QLTTCaNhanKH = true;
                    }
                    if (q.QLTTNV == true)
                    {
                        VTquyen.QLTTNV = true;
                    }
                    if (q.QLTTQuaTang == true)
                    {
                        VTquyen.QLTTQuaTang = true;
                    }
                    if (q.SuaTTKH == true)
                    {
                        VTquyen.SuaTTKH = true;
                    }
                    if (q.XemTTNhanVien == true)
                    {
                        VTquyen.XemTTNhanVien = true;
                    }
                    if (q.XemTTQuaTang == true)
                    {
                        VTquyen.XemTTQuaTang = true;
                    }
                    if (q.XoaCuocGoi == true)
                    {
                        VTquyen.XoaCuocGoi = true;
                    }
                    if (q.XoaTTKH == true)
                    {
                        VTquyen.XoaTTKH = true;
                    }
                }
                App.CurrentPermissions = VTquyen;
                App.CurentHuman        = nv.ConNguoi;
                App.CurentEmployee     = nv;

                LoginResultEvent(this, true);
            }
            catch (Exception ex)
            {
                if (ex is InvalidOperationException)
                {
                    LoginResultEvent(this, false);
                }
                else if (ex is System.Data.SqlClient.SqlException)
                {
                    FireHandledExeptionAndLogErorrAsync(ErrorTemplates.GetDBInteractionError(ex));
                }
            }
        }