Пример #1
0
        public MainCRMViewModel()
        {
            Messenger.Default.Register<NotificationMessage>(this, (message) =>
            {
                switch (message.Notification)
                {
                    case "CloseMainCRMWindow":
                        App.Current.Shutdown();
                        break;
                }
            });

            int userId = ApplicationState.GetValue<Int32>("EmployeeID");
            Employee u = null;
            using (dbContext db = new dbContext())
            {
                u = db.Employee.SingleOrDefault(item => item.EmployeeId == userId);
                this.employeer = u;
                u.LastLog = DateTime.Now;
                if (u.NumberOfLogs == null)
                {
                    u.NumberOfLogs = 1;
                }
                else
                {
                    u.NumberOfLogs += 1;
                }
                db.SaveChanges();
            }
        }
Пример #2
0
 public LogBookListViewModel()
 {
     int userId = ApplicationState.GetValue<Int32>("EmployeeID");
     using (dbContext db = new dbContext())
     {
         Employeer = db.Employee.Find(userId);
     }
     GetEmployeers();
     GetLogs();
 }
Пример #3
0
 public CustomerListViewModel()
 {
     using (dbContext db = new dbContext())
     {
         //Employeer = db.Employee.Find(ApplicationState.GetValue<Int32>("EmployeeID"));
         Employeer = db.Employee.Find(2);
         db.CustomerGroup.OrderBy(item => item.Name).ToList();
         CustomerGroupList = db.CustomerGroup.Local;
     }
        GetCustomers();
 }
Пример #4
0
 private void AddNewCustomerGroupItem()
 {
     using (var db = new dbContext())
     {
         var cg = new CustomerGroup();
         cg.Name = this.customerGroupName;
         db.CustomerGroup.Add(cg);
         db.SaveChanges();
     }
     Messenger.Default.Send(new NotificationMessage("CloseWindowGroup"));
 }
Пример #5
0
        public LogBookViewModel(int CustomerId)
        {
            this.ContactDate = DateTime.Now;
            int userId = ApplicationState.GetValue<Int32>("EmployeeID");

            using (dbContext db = new dbContext())
            {
                Employeer = db.Employee.Find(userId);
                Customer = db.Customer.Find(CustomerId);

                db.CustomerContactType.ToList().OrderBy(item => item.Name);
                this.CustomerContactTypeList = db.CustomerContactType.Local;
            }
        }
Пример #6
0
        public bool CanAddNewCustomerGroupItem()
        {
            int userId = ApplicationState.GetValue<Int32>("EmployeeID");
            if (this.customerGroupName == null)
            {
                return false;
            }

            using (var db = new dbContext())
            {
                db.CustomerGroup.ToList();
                CustomerGroup tmp = db.CustomerGroup.SingleOrDefault(item => item.Name.ToLower().Equals(this.customerGroupName.ToLower()));
                if (tmp != null)
                {
                    return false;
                }
            }
            return true;
        }
Пример #7
0
        private void AddLogBookItem()
        {
            var lbvm = new LogBookViewModel(SelectedCustomer.CustomerId);
            var lbv = new LogBookView();
            Messenger.Default.Register<MessangerLogBook>(this, (message) =>
            {
                switch (message.id)
                {
                    case 1:
                        using (dbContext db = new dbContext())
                        {
                            LogBook x = new LogBook();
                            x.Customer = db.Customer.Find(message.CustomerId);
                            x.CustomerContactType = db.CustomerContactType.Find(message.CustomerContactTypeId);
                            x.Information = message.Information;
                            x.Employeer = db.Employee.Find(message.EmployeerId);
                            x.ContactDate = message.ContactDate;
                            db.LogBook.Add(x);
                            db.SaveChanges();
                            //RaisePropertyChanged("SelectedCustomer");
                        }
                        break;
                }
            });
            lbv.DataContext = lbvm;
            lbv.ShowDialog();
            SearchCustomers();

        }
Пример #8
0
        private void DeleteCustomer()
        {
            using (dbContext dba = new dbContext())
            {
                if (SelectedCustomer != null)
                {
                    Customer cst;

                    cst = dba.Customer.Include("LogBook").SingleOrDefault(item => item.CustomerId == this.SelectedCustomer.CustomerId);
                    this.CustomerListCollection.Remove(CustomerListCollection.FirstOrDefault(item => item.CustomerId == SelectedCustomer.CustomerId));
                    
                    foreach (LogBook child in cst.LogBook.ToList())
                        dba.LogBook.Remove(child);

                        if (cst != null)
                    {
                        
                        dba.Customer.Remove(cst);
                        dba.Entry(cst).State = EntityState.Deleted;
                        dba.SaveChanges();
                        
                    }
                }
            }
            //GetCustomers();
        }
Пример #9
0
 internal void GetCustomersInGroup()
 {
     using (dbContext db = new dbContext())
     {
         if (String.IsNullOrWhiteSpace(SearchText))
         {
             db.Customer.Where(p => p.CustomerGroup.Any(c => c.CustomerGroupId == SelectedCustomerGroup.CustomerGroupId)).Include("State").Include("CustomerGroup").Include("Category").Include("Status").Include("AccountManager").Include("LogBook").Include("LogBook.CustomerContactType").Include("LogBook.Employeer").ToList();
             this.CustomerListCollection = db.Customer.Local;
         } else {
             db.Customer.Where(p => p.CustomerGroup.Any(c => c.CustomerGroupId == SelectedCustomerGroup.CustomerGroupId))
                 .Include("State")
                 .Include("CustomerGroup")
                 .Include("Category")
                 .Include("Status")
                 .Include("AccountManager")
                 .Include("LogBook")
                 .Include("LogBook.CustomerContactType")
                 .Include("LogBook.Employeer")
                 .Where(pa => pa.CustomerFullName.Contains(SearchText) || pa.Street.Contains(SearchText) || pa.City.Contains(SearchText))
                 .ToList();
             this.CustomerListCollection = db.Customer.Local;
         }
     }
 }
Пример #10
0
 private void ChangeUserPassword()
 {
     using (var db = new dbContext())
     {
         Employee emp = db.Employee.SingleOrDefault(item => item.EmployeeId == this._userId);
         emp.Password = this.NewPassword1;
         db.SaveChanges();
     }
     Messenger.Default.Send(new NotificationMessage("CloseWindow"));
 }
Пример #11
0
        public CustomerViewModel(int CustomerID = 0, CustomerTemp ct = null )
        {
            int userId = ApplicationState.GetValue<Int32>("EmployeeID");
            this.ShowView2Command = new RelayCommand(this.ShowView2CommandExecute);  // ??
            this.db = new dbContext();
            this.Items = new Dictionary<string, object>();
            employeer = this.db.Employee.SingleOrDefault(item => item.EmployeeId == userId);

            this.SelectedItems = new Dictionary<string, object>();

            if (CustomerID == 0)
            {

                this.isNew = true;
                this.customer = new Customer();
                if (ct != null)
                {
                    this.ct = ct;
                    this.customer.AccountMarketer = db.Employee.SingleOrDefault(item => item.EmployeeId == userId);
                }
                this.customer.CreateDate = DateTime.Now;
                this.SelectedItems = new Dictionary<string, object>();

            }
            else
            {
                this.isNew = false;
                this.customer = this.db.Customer.Where(s => s.CustomerId == CustomerID).FirstOrDefault<Customer>();
                if (ct != null)
                {
                    this.ct = ct;
                    this.customer.AccountMarketer = db.Employee.SingleOrDefault(item => item.EmployeeId == userId);
                }
            }

            if (this.CustomerContact == null)
            {
                this.CustomerContactList = new ObservableCollection<CustomerContact>();
            }
            else
            {
                this.CustomerContactList = new ObservableCollection<oneCRM.Model.CustomerContact>(this.CustomerContact);
            }

            if (this.LogBook == null)
            {
                this.LogBookList = new ObservableCollection<Model.LogBook>();
            }
            else
            {
                this.LogBookList = new ObservableCollection<Model.LogBook>(this.LogBook);
            }

            if (this.CustomerAktywa == null)
            {
                this.CustomerAktywaList = new ObservableCollection<CustomerAktywa>();
            }
            else
            {
                this.CustomerAktywaList = new ObservableCollection<CustomerAktywa>(this.CustomerAktywa);
            }

            if (this.CustomerZatrudnienie == null)
            {
                this.CustomerZatrudnienieList = new ObservableCollection<CustomerZatrudnienie>();
            }
            else
            {
                this.CustomerZatrudnienieList = new ObservableCollection<CustomerZatrudnienie>(this.CustomerZatrudnienie);
            }

            if (this.CustomerPrzychody == null)
            {
                this.CustomerPrzychodyList = new ObservableCollection<CustomerPrzychody>();
            }
            else
            {
                this.CustomerPrzychodyList = new ObservableCollection<CustomerPrzychody>(this.CustomerPrzychody);
            }

            GetLists();
            Items.Clear();
            foreach (var item in CustomerGroupList)
            {
                Items.Add(item.Name, item);
            }
            SelectedItems.Clear();
            if(this.CustomerGroup != null)
            {
                foreach (CustomerGroup a in this.CustomerGroup.Where(item => item.isSelected == true))
                {
                    this.SelectedItems.Add(a.Name, a);
                }
            }
            db.SaveChanges();
        }
Пример #12
0
        internal void GetLogs(int i = 0)
        {
            using (dbContext db = new dbContext())
            {
                ileDni = i;
                if (i == 100) // Wszystkie
                {
                    if (AccountManager == null)
                    {
                        IQueryable<LogBook> clc = (from p in db.LogBook
                                                  orderby p.ContactDate descending
                                                  select p).Include(item => item.Customer).Include(item => item.Employeer).Include(item => item.CustomerContactType);
                        this.LogBookCollection = new ObservableCollection<LogBook>(clc);
                    }
                    else
                    {
                    IQueryable<LogBook> clc = (from p in db.LogBook
                                                  where (p.Employeer.EmployeeId == AccountManager.EmployeeId)
                                                  orderby p.ContactDate descending
                                                  select p).Include(item => item.Customer).Include(item => item.Employeer).Include(item => item.CustomerContactType); ;
                        this.LogBookCollection = new ObservableCollection<LogBook>(clc);
                    }
                }
                else if (i == 200) // Specyfic client
                {
                    IQueryable<LogBook> clc = (from p in db.LogBook
                                              where (p.Customer.CustomerId == SelectedLogBook.Customer.CustomerId)
                                              orderby p.ContactDate descending
                                              select p).Include(item => item.Customer).Include(item => item.Employeer).Include(item => item.CustomerContactType);
                    this.LogBookCollection = new ObservableCollection<LogBook>(clc);
                }
                else
                {
                    DateTime now = DateTime.Now.Date.AddDays(-i);
                    DateTime today = DateTime.Now.Date;
                    if (i == 1)
                    {
                        if (AccountManager == null)
                        {
                            IQueryable<LogBook> clc = (from p in db.LogBook
                                                      where (p.ContactDate >= now && p.ContactDate < today)
                                                      orderby p.ContactDate descending
                                                      select p).Include(item => item.Customer).Include(item => item.Employeer).Include(item => item.CustomerContactType);
                            this.LogBookCollection = new ObservableCollection<LogBook>(clc);
                        }
                        else
                        {
                            IQueryable<LogBook> clc = (from p in db.LogBook
                                                      where (p.ContactDate >= now && p.ContactDate < today && p.Employeer.EmployeeId == AccountManager.EmployeeId)
                                                      orderby p.ContactDate descending
                                                      select p).Include(item => item.Customer).Include(item => item.Employeer).Include(item => item.CustomerContactType);

                            this.LogBookCollection = new ObservableCollection<LogBook>(clc);
                        }
                    }
                    else
                    {
                        if (AccountManager == null)
                        {
                            var clc = (from p in db.LogBook
                                        where (p.ContactDate >= now)
                                        orderby p.ContactDate descending
                                       select p).Include(item => item.Customer).Include(item => item.Employeer).Include(item => item.CustomerContactType);
                            this.LogBookCollection = new ObservableCollection<LogBook>(clc);
                        }
                        else
                        {
                            IQueryable<LogBook> clc = (from p in db.LogBook
                                                      where (p.ContactDate >= now && p.Employeer.EmployeeId == AccountManager.EmployeeId)
                                                      orderby p.ContactDate descending
                                                       select p).Include(item => item.Customer).Include(item => item.Employeer).Include(item => item.CustomerContactType);

                            this.LogBookCollection = new ObservableCollection<LogBook>(clc);
                        }
                    }

                }
            }
            RaisePropertyChanged("LogBookCollection");
        }
Пример #13
0
 internal void GetEmployeesList()
 {
     using (dbContext db = new dbContext())
     {
         db.Employee.OrderBy(item => item.EmployeeFullName).ToList();
         this.AccountManagerList = db.Employee.Local;
     }
 }
Пример #14
0
 internal void GetEmployeers()
 {
     using (dbContext db = new dbContext())
     {
         db.Employee.ToList();
         EmployeeCollection = db.Employee.Local;
     }
 }
Пример #15
0
 private void MergeSelectedCustomer()
 {
     CustomerView cv = new CustomerView();
     cv.DataContext = new CustomerViewModel(SelectedCustomer.CustomerId, CustomerTemp);
     cv.Show();
     using (dbContext db = new dbContext())
     {
         var temp = db.CustomerTemp.SingleOrDefault(item => item.CustomerTempId == CustomerTemp.CustomerTempId);
         db.CustomerTemp.Remove(temp);
         db.SaveChanges();
     }
     Messenger.Default.Send(new NotificationMessage("CloseSimilarCustomerListViewWindow"));
 }
Пример #16
0
        private void AddNewLogBook()
        {
            using (dbContext db = new dbContext())
            {
                try
                {
                    var lb = new LogBook();
                    lb.Employeer = db.Employee.Find(this.Employeer.EmployeeId);
                    lb.Information = this.Information;
                    lb.ContactDate = ContactDate;
                    lb.Customer = db.Customer.Find(this.Customer.CustomerId);
                    lb.CustomerContactType = db.CustomerContactType.Find(this.CustomerContactType.CustomerContactTypeId);
                    db.LogBook.Add(lb);
                    db.SaveChanges();
                }
                catch (Exception ex)
                {

                    Messenger.Default.Send(new NotificationMessage(ex.ToString()));
                }

            }
            Messenger.Default.Send(new NotificationMessage("CloseWindowLogBookItem"));
        }
Пример #17
0
 public async Task<List<Customer>> GetCustomerByNamePaged(string sortExpression, string nameSearchString, int startRowIndex, int maximumRows)
 {
     if (String.IsNullOrWhiteSpace(sortExpression))
     {
         sortExpression = "CustomerFullName";
     }
     if (String.IsNullOrWhiteSpace(nameSearchString))
     {
         nameSearchString = "";
     }
     using (dbContext db = new dbContext())
     {
         db.Configuration.ProxyCreationEnabled = false;
         return await db.Customer.Include("State").Include("CustomerGroup").Include("Category").Include("Status").Include("AccountManager").Include("LogBook").Include("LogBook.CustomerContactType").Include("LogBook.Employeer")
         .OrderBy(o => o.CustomerFullName)
         .Where(d => d.CustomerFullName.Contains(nameSearchString))
         .ToListAsync();
     }
 }
Пример #18
0
        private void AddNewPrzychody()
        {
            var lb = new CustomerPrzychody();
            lb.Rok = rok;
            lb.Wartosc = wartosc;
            lb.Uwagi = uwagi;

            using (dbContext db = new dbContext())
            {
                Customer = db.Customer.Find(CustomerId);
                lb.Customers.Add(Customer);

                try
                {
                    db.CustomerPrzychody.Add(lb);
                    db.SaveChanges();
                }
                catch (Exception)
                {
                    Messenger.Default.Send(new NotificationMessage("ERROR"));
                }
            }

            Messenger.Default.Send(new MessangerCustomerPrzychody(lb.Rok, lb.Wartosc, lb.Uwagi));
            Messenger.Default.Send(new NotificationMessage("CloseWindowCustomerPrzychody"));
        }
Пример #19
0
        private void LoginExcute()
        {
            Employee emp = null;
                try
                {

                    using (var db = new dbContext())
                    {
                    db.Configuration.ProxyCreationEnabled = false;
                    var x = from d in db.Employee
                            where d.Login == this.login && d.Password == this.Password && d.Status == true
                            select d;
                    emp = x.FirstOrDefault<Employee>();
                    }
                }
                catch (Exception)
                {

                    emp = null;
                }

            if (emp != null)
            {
                if (isChecked)
                {
                    hkcu = Registry.CurrentUser.OpenSubKey(@"Software\oneCRM\", true);
                    if ((string)hkcu.GetValue("Login") == null)
                    {
                        hkcu.SetValue("Login", login, RegistryValueKind.String);
                    } else if ((string)hkcu.GetValue("Login") != login)
                    {
                        hkcu.SetValue("Login", login, RegistryValueKind.String);
                    }

                    if ((string)hkcu.GetValue("Password") == null)
                    {
                        hkcu.SetValue("Password", Password, RegistryValueKind.String);

                    }
                    else if ((string)hkcu.GetValue("Password") != Password)
                    {
                        hkcu.SetValue("Password", Password, RegistryValueKind.String);
                    }
                    hkcu.Close();

                }
                ApplicationState.SetValue("EmployeeID", emp.EmployeeId);
                this.employeer = emp.EmployeeId;

                MainCRMView mCRM = new MainCRMView();
                mCRM.Show();
                Messenger.Default.Send(new NotificationMessage("CloseLoginWindow"));

            }
            else
            {
                this.Password = null;
            }
        }
Пример #20
0
        public bool CanChangeUserPassword()
        {
            if (this.NewPassword1 == null || this.NewPassword2 == null)
            {
                return false;
            }

            if (this.NewPassword1 != this.NewPassword2)
            {
                return false;
            }

            using (var db = new dbContext())
            {
                IQueryable<Employee> x = db.Employee.Where(item => item.EmployeeId == this._userId && item.Password == this.ActualPassword);

                if (x == null)
                {
                    return false;
                }
            }

            return true;
        }