Пример #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
        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();

        }
Пример #3
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"));
 }
Пример #4
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();
        }
Пример #5
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"));
        }
 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"));
 }
Пример #7
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"));
        }
Пример #8
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"));
 }
Пример #9
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();
        }