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();
         }
     }));
 }
 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();
         }
     }));
 }
        public void Update()
        {
            DateTime motnamtruoc = DateTime.Today.AddDays(-365);

            db = new Models.DBDataContext();

            var se = (from kh in db.KhachHangs
                      join qt in db.QuaTangs on kh.KhachHangID equals qt.KHID
                      join cn in db.ConNguois on kh.ConNguoiID equals cn.ConNguoiID
                      where qt.NgayGui.Value > motnamtruoc
                      group kh by new
            {
                ID = kh.KhachHangID,
                HoTen = cn.HoTen,
                GioiTinh = cn.GioiTinh,
                cn.Phone,
                cn.CMND,
                cn.Phone2,
                cn.DiaChi,
                TongGT = kh.QuaTangs.Sum(tt => tt.GiaTri)
            } into st
                      orderby st.Key.TongGT descending
                      select new { st.Key.DiaChi,
                                   st.Key.GioiTinh,
                                   st.Key.HoTen,
                                   st.Key.ID,
                                   st.Key.CMND,
                                   st.Key.Phone,
                                   st.Key.Phone2,
                                   st.Key.TongGT }).Take(10).ToList();

            SearchResult = new ObservableCollection <object>(se);
        }
 /// <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();
         }
     }));
 }
示例#5
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();
            }));
        }
示例#6
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));
         }
     }));
 }
示例#7
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();
         }
     }));
 }
 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();
         }
     }));
 }
 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();
         }
     }));
 }
示例#10
0
        public static void AppInitialize()
        {
            App.Log = new Lib.Logger(new DirectoryInfo(@"Log/"));
            Models.DBDataContext db = new Models.DBDataContext();
            if (!db.DatabaseExists())
            {
                db.CreateDatabase();
                Models.ChucVu ChucManager = new Models.ChucVu {
                    Quyen = new Models.Quyen {
                        PhanQuyen = false, HoTroGiaoTiepKH = true, XoaCuocGoi = true, QLTTCaNhanKH = true, SuaTTKH = true, XoaTTKH = true, QLTTNV = false, BaoCaoThongKe = true, QLTTQuaTang = true, XemTTQuaTang = true, XemTTNhanVien = true
                    }
                };
                Models.ChucVu ChucAdmin = new Models.ChucVu {
                    Quyen = new Models.Quyen {
                        PhanQuyen = true, HoTroGiaoTiepKH = false, XoaCuocGoi = false, QLTTCaNhanKH = false, SuaTTKH = false, XoaTTKH = false, QLTTNV = true, BaoCaoThongKe = false, QLTTQuaTang = false, XemTTQuaTang = false, XemTTNhanVien = true
                    }
                };
                Models.ChucVu ChucStaff = new Models.ChucVu {
                    Quyen = new Models.Quyen {
                        PhanQuyen = false, HoTroGiaoTiepKH = true, XoaCuocGoi = true, QLTTCaNhanKH = true, SuaTTKH = false, XoaTTKH = false, QLTTNV = false, BaoCaoThongKe = false, QLTTQuaTang = false, XemTTQuaTang = true, XemTTNhanVien = false
                    }
                };
                db.ChucVus.InsertAllOnSubmit(new List <Models.ChucVu>
                {
                    ChucManager, ChucAdmin, ChucStaff
                });

                db.LoaiQuanHes.InsertAllOnSubmit(new List <Models.LoaiQuanHe>
                {
                    new Models.LoaiQuanHe {
                        TenQuanHe = "Vợ"
                    },
                    new Models.LoaiQuanHe {
                        TenQuanHe = "Chồng"
                    },
                    new Models.LoaiQuanHe {
                        TenQuanHe = "Cha"
                    },
                    new Models.LoaiQuanHe {
                        TenQuanHe = "Mẹ"
                    },
                    new Models.LoaiQuanHe {
                        TenQuanHe = "Ông"
                    },
                    new Models.LoaiQuanHe {
                        TenQuanHe = "Bà"
                    },
                    new Models.LoaiQuanHe {
                        TenQuanHe = "Anh"
                    },
                    new Models.LoaiQuanHe {
                        TenQuanHe = "Chị"
                    },
                    new Models.LoaiQuanHe {
                        TenQuanHe = "Con"
                    },
                    new Models.LoaiQuanHe {
                        TenQuanHe = "Cháu"
                    },
                    new Models.LoaiQuanHe {
                        TenQuanHe = "Em"
                    },
                    new Models.LoaiQuanHe {
                        TenQuanHe = "Bạn"
                    },
                    new Models.LoaiQuanHe {
                        TenQuanHe = "Họ Hàng"
                    },
                    new Models.LoaiQuanHe {
                        TenQuanHe = "Người Quen"
                    }
                });

                db.LoaiCuocGois.InsertAllOnSubmit(new List <Models.LoaiCuocGoi>
                {
                    new Models.LoaiCuocGoi {
                        TenLoaiCuocGoi = "Yêu cầu"
                    },
                    new Models.LoaiCuocGoi {
                        TenLoaiCuocGoi = "Thắc mắc"
                    },
                    new Models.LoaiCuocGoi {
                        TenLoaiCuocGoi = "Phàn nàn"
                    },
                });

                Models.NhanVien Admin = new Models.NhanVien
                {
                    ConNguoi = new Models.ConNguoi {
                        HoTen = "Admin được khởi tạo tự động", MatKhau = "123"
                    },
                };

                Admin.DanhSachChucVus.Add(new Models.DanhSachChucVu {
                    ChucVu = ChucAdmin
                });

                db.NhanViens.InsertOnSubmit(Admin);

                db.SubmitChanges();
            }
        }