예제 #1
0
        public static void SetDishItems(List <DishItem> dishItems, List <int> li)
        {
            try
            {
                using (KindergartenContext db = new KindergartenContext())
                {
                    //var dishItemsDict = dishItems.ToDictionary(x => x.Id);

                    var dishItemsDict = dishItems.Select(x => x.Id).ToList();
                    li.ForEach(x =>
                    {
                        if (!dishItemsDict.Contains(x))    //!dishItemsDict.ContainsKey(x)
                        {
                            db.Entry(db.DishItems.Where(y => y.Id == x).FirstOrDefault()).State = EntityState.Deleted;
                        }
                    });

                    dishItems.ForEach(x =>
                    {
                        db.Entry(x).State = x.Id == 0 ? EntityState.Added : EntityState.Modified;
                    });

                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка! " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
예제 #2
0
        public static void SetDocument(Document document, List <Party> parties)
        {
            try
            {
                using (KindergartenContext db = new KindergartenContext())
                {
                    db.Entry(document).State = document.Id == 0 ? EntityState.Added : EntityState.Modified;
                    db.SaveChanges();

                    if (parties != null)
                    {
                        parties.ForEach(x =>
                        {
                            x.DocumentId = db.Documents.Local.First().Id;
                        });

                        PartyModel.SetParty(parties);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка! " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
예제 #3
0
        public static void SetMenus(List <Menu> menus, List <int> li)
        {
            try
            {
                using (KindergartenContext db = new KindergartenContext())
                {
                    var menuDict = menus.ToDictionary(x => x.Id);
                    li.ForEach(x =>
                    {
                        if (!menuDict.ContainsKey(x))
                        {
                            db.Entry(db.Users.Where(y => y.Id == x).FirstOrDefault()).State = EntityState.Deleted;
                        }
                    });

                    menus.ForEach(x =>
                    {
                        db.Entry(x).State = x.Id == 0 ? EntityState.Added : EntityState.Modified;
                    });

                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка! " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
예제 #4
0
        public static bool CheckLogin(string login, string password)
        {
            try
            {
                using (KindergartenContext db = new KindergartenContext())
                {
                    List <User> user = db.Users.Where(p => p.Login == login).ToList();

                    if (user == null || user.Count() != 1)
                    {
                        return(false);
                    }
                    else if (user[0].Password == password)
                    {
                        return(true);
                    }

                    return(false);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);//Вывод в лог текст исключения
                MessageBox.Show("Ошибка создания контекста", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
        }
예제 #5
0
        public static void DecreaseParty(ICollection <DocumentData> documentDatas)
        {
            try
            {
                using (KindergartenContext db = new KindergartenContext())
                {
                    var ids = documentDatas.Select(x => x.PartyId).ToList();
                    var nc  = db.Parties.Where(x => ids.Contains(x.Id)).ToList();

                    nc.ForEach(x =>
                    {
                        foreach (var item in documentDatas)
                        {
                            if (x.Id == item.PartyId)
                            {
                                x.Quantity -= item.Quantity;
                                if (x.Quantity <= 0)
                                {
                                    x.IsClosed   = true;
                                    x.DateClosed = DateTime.Now;
                                }
                            }
                        }
                    });

                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка! " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
예제 #6
0
        public static void SetPartyFromInvoice(List <Party> parties)
        {
            try
            {
                using (KindergartenContext db = new KindergartenContext())
                {
                    db.Parties.AddRange(parties);
                    db.SaveChanges();

                    List <DocumentData> dd = new List <DocumentData>();

                    var lp = db.Parties.Local.ToList();
                    lp.ForEach(x =>
                               dd.Add(
                                   new DocumentData()
                    {
                        Quantity    = x.Quantity,
                        DateCreated = DateTime.Now,
                        DocumentId  = x.DocumentId,
                        ProductId   = x.ProductId,
                        PartyId     = x.Id
                    }
                                   )
                               );

                    DocumentDataModel.SetDocumentData(dd);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка! " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
예제 #7
0
        public static void SetEmployee(List <Employee> data, List <int> ids)
        {
            try
            {
                using (KindergartenContext db = new KindergartenContext())
                {
                    var dates = data.Select(x => x.Id).ToList();
                    var nc    = db.Employees.Where(x => dates.Contains(x.Id)).ToList();

                    ids = ids.Except(dates).ToList();
                    var deletedObjects = db.Employees.Where(x => ids.Contains(x.Id)).ToList();

                    for (int i = 0; i < deletedObjects.Count(); i++)
                    {
                        db.Employees.Remove(deletedObjects[i]);
                    }

                    for (int i = 0; i < data.Count(); i++)
                    {
                        bool isNew = true;

                        for (int j = 0; j < nc.Count(); j++)
                        {
                            if (nc[j].Id == data[i].Id)
                            {
                                nc[j].Name       = data[i].Name;
                                nc[j].Lastname   = data[i].Lastname;
                                nc[j].Patronymic = data[i].Patronymic;
                                nc[j].Phone      = data[i].Phone;
                                nc[j].Position   = data[i].Position;

                                isNew = false;
                            }
                        }

                        if (isNew)
                        {
                            var newEmployees = new Employee()
                            {
                                Name       = data[i].Name,
                                Lastname   = data[i].Lastname,
                                Patronymic = data[i].Patronymic,
                                Phone      = data[i].Phone,
                                Position   = data[i].Position
                            };

                            db.Employees.Add(newEmployees);
                        }
                    }

                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка! " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
예제 #8
0
        public static void SetSupplier(List <Supplier> supplier, List <int> li)
        {
            try
            {
                using (KindergartenContext db = new KindergartenContext())
                {
                    var dates = supplier.Select(x => x.Id).ToList();
                    var u     = db.Suppliers.Where(x => dates.Contains(x.Id)).ToList();

                    li = li.Except(dates).ToList();
                    var deletedObjects = db.Suppliers.Where(x => li.Contains(x.Id)).ToList();

                    for (int i = 0; i < deletedObjects.Count(); i++)
                    {
                        db.Suppliers.Remove(deletedObjects[i]);
                    }

                    for (int i = 0; i < supplier.Count(); i++)
                    {
                        bool isNew = true;

                        for (int j = 0; j < u.Count(); j++)
                        {
                            if (u[j].Id == supplier[i].Id)
                            {
                                u[j].Name  = supplier[i].Name;
                                u[j].Phone = supplier[i].Phone;

                                isNew = false;
                            }
                        }

                        if (isNew)
                        {
                            var newSupplier = new Supplier()
                            {
                                Name  = supplier[i].Name,
                                Phone = supplier[i].Phone
                            };

                            db.Suppliers.Add(newSupplier);
                        }
                    }

                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка! " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
예제 #9
0
        public static void SetProducts(List <Product> products, List <int> ids)
        {
            try
            {
                using (KindergartenContext db = new KindergartenContext())
                {
                    var dates = products.Select(x => x.Id).ToList();
                    var nc    = db.Products.Where(x => dates.Contains(x.Id)).ToList();

                    ids = ids.Except(dates).ToList();
                    var deletedObjects = db.Products.Where(x => ids.Contains(x.Id)).ToList();

                    for (int i = 0; i < deletedObjects.Count(); i++)
                    {
                        db.Products.Remove(deletedObjects[i]);
                    }

                    for (int i = 0; i < products.Count(); i++)
                    {
                        bool isNew = true;

                        for (int j = 0; j < nc.Count(); j++)
                        {
                            if (nc[j].Id == products[i].Id)
                            {
                                nc[j].Name = products[i].Name;

                                isNew = false;
                            }
                        }

                        if (isNew)
                        {
                            var newProducts = new Product()
                            {
                                Name = products[i].Name
                            };

                            db.Products.Add(newProducts);
                        }
                    }

                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка! " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
예제 #10
0
 public static void SetDishItemFacts(ICollection <DishItemFact> dishItemFacts)
 {
     try
     {
         using (KindergartenContext db = new KindergartenContext())
         {
             db.DishItemFacts.AddRange(dishItemFacts);
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Ошибка! " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
예제 #11
0
 public static void SetMenuFact(MenuFact menu)
 {
     try
     {
         using (KindergartenContext db = new KindergartenContext())
         {
             db.MenuFacts.Add(menu);
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Ошибка! " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
예제 #12
0
 public static void SetParty(List <Party> parties)
 {
     try
     {
         using (KindergartenContext db = new KindergartenContext())
         {
             db.Parties.AddRange(parties);
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Ошибка! " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
예제 #13
0
 public static void DeletedInvoice(int id)
 {
     try
     {
         using (KindergartenContext db = new KindergartenContext())
         {
             var i = db.Invoices.Where(x => x.ID == id).ToList();
             i.RemoveAt(0);
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Ошибка! " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
예제 #14
0
        public static void SetDocumentExpenseForNutrition(Document document)
        {
            try
            {
                using (KindergartenContext db = new KindergartenContext())
                {
                    db.Documents.Add(document);
                    db.SaveChanges();

                    PartyModel.DecreaseParty(document.DocumentDatas);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка! " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
예제 #15
0
        /// <summary>
        /// Возвращает все шаблоны меню
        /// </summary>
        /// <returns></returns>
        public static List <Menu> GetMenus()
        {
            List <Menu> menus = new List <Menu>();

            try
            {
                using (KindergartenContext db = new KindergartenContext())
                {
                    menus = db.Menus.ToList();
                    return(menus);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка! " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(menus);
            }
        }
예제 #16
0
        public static List <DocumentData> GetDocumentData(Document document)
        {
            List <DocumentData> documentData = new List <DocumentData>();

            try
            {
                using (KindergartenContext db = new KindergartenContext())
                {
                    documentData = db.DocumentData.Where(x => x.DocumentId == document.Id).ToList();
                    return(documentData);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка! " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(documentData);
            }
        }
예제 #17
0
        ///<summary>
        ///Возвращает все документы за указанный интервал
        ///</summary>
        public static List <Document> GetDocument(DateTime startDate, DateTime endDate)
        {
            List <Document> documents = new List <Document>();

            try
            {
                using (KindergartenContext db = new KindergartenContext())
                {
                    documents = db.Documents.Where(x => x.Date >= startDate).Where(x => x.Date <= endDate).Include(x => x.Invoice).Include(x => x.DocumentType).ToList();
                    return(documents);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка! " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(documents);
            }
        }
예제 #18
0
        /// <summary>
        /// Возвращает определенное меню со связными сущностями
        /// </summary>
        /// <param name="MenuId"></param>
        /// <returns></returns>
        public static List <Menu> GetMenus(int MenuId)
        {
            List <Menu> menus = new List <Menu>();

            try
            {
                using (KindergartenContext db = new KindergartenContext())
                {
                    menus = db.Menus.Where(x => x.Id == MenuId).Include(x => x.Dishes).ThenInclude(y => y.DishItems).ToList();
                    return(menus);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка! " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(menus);
            }
        }
예제 #19
0
        ///<summary>
        ///Возвращает все документы указанног типа
        ///</summary>
        public static List <Document> GetDocument(DocumentType documentType)
        {
            List <Document> documents = new List <Document>();

            try
            {
                using (KindergartenContext db = new KindergartenContext())
                {
                    documents = db.Documents.Where(x => x.DocumentType == documentType).ToList();
                    return(documents);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка! " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(documents);
            }
        }
예제 #20
0
        public static List <DishFact> GetDishFact(int DishFact)
        {
            List <DishFact> dishes = new List <DishFact>();

            try
            {
                using (KindergartenContext db = new KindergartenContext())
                {
                    dishes = db.DishFacts.Where(x => x.Id == DishFact).ToList();
                    return(dishes);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка! " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(dishes);
            }
        }
예제 #21
0
        public static List <MenuFact> GetMenuFacts(int MenuFactId)
        {
            List <MenuFact> menus = new List <MenuFact>();

            try
            {
                using (KindergartenContext db = new KindergartenContext())
                {
                    menus = db.MenuFacts.Where(x => x.Id == MenuFactId).ToList();
                    return(menus);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка! " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(menus);
            }
        }
예제 #22
0
        public static List <Invoice> GetInvoice(DateTime startDate, DateTime endDate)
        {
            List <Invoice> invoices = new List <Invoice>();

            try
            {
                using (KindergartenContext db = new KindergartenContext())
                {
                    invoices = db.Invoices.Where(x => x.DateOfInvoice >= startDate).Where(x => x.DateOfInvoice <= endDate).Include(x => x.Supplier).ToList();

                    return(invoices);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка! " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(invoices);
            }
        }
예제 #23
0
        public static List <Supplier> GetSupplier()
        {
            List <Supplier> lstSupplier = new List <Supplier>();

            try
            {
                using (KindergartenContext db = new KindergartenContext())
                {
                    lstSupplier = db.Suppliers.ToList();

                    return(lstSupplier);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка! " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(lstSupplier);
            }
        }
예제 #24
0
        public static List <Product> GetProducts()
        {
            List <Product> lstProducts = new List <Product>();

            try
            {
                using (KindergartenContext db = new KindergartenContext())
                {
                    lstProducts = db.Products.ToList();

                    return(lstProducts);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка! " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(lstProducts);
            }
        }
예제 #25
0
        /// <summary>
        /// Возвращается список дат с количеством детей каждой категории
        /// </summary>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <returns></returns>
        public static List <NumberChildren> GetChildrenData(DateTime startDate, DateTime endDate)
        {
            List <NumberChildren> lstChildren = new List <NumberChildren>();

            try
            {
                using (KindergartenContext db = new KindergartenContext())
                {
                    lstChildren = db.NumberChildrens.Where(x => x.Date >= startDate).Where(x => x.Date <= endDate).ToList();

                    return(lstChildren);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка! " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(lstChildren);
            }
        }
예제 #26
0
        public static void SetInvoice(Invoice invoice, List <Party> parties)
        {
            try
            {
                using (KindergartenContext db = new KindergartenContext())
                {
                    foreach (var item in parties)
                    {
                        if (item.ProductId == 0)
                        {
                            parties.Remove(item);
                        }
                    }

                    if (parties.Count() > 0)
                    {
                        db.Entry(invoice).State = invoice.ID == 0 ? EntityState.Added : EntityState.Modified;
                        db.SaveChanges();

                        var dt = db.DocumentTypes.Where(x => x.Name == "Приход от поставщика").FirstOrDefault();

                        var document = new Document()
                        {
                            Date           = DateTime.Now,
                            InvoiceId      = db.Invoices.Local.First().ID,
                            DocumentTypeId = dt.Id
                        };

                        DocumentModel.SetDocumentFromInvoice(document, parties);
                        MessageBox.Show("Накладная добавлена в систему!", "Успех", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        MessageBox.Show("Накладная не содержит товары!", "Пустая накладная", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка! " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
예제 #27
0
        public static List <User> GetUser()
        {
            List <User> lstUser = new List <User>();

            try
            {
                using (KindergartenContext db = new KindergartenContext())
                {
                    lstUser = db.Users.Include(x => x.Employee).ToList();
                    //Where(x => x.Date >= startDate).Where(x => x.Date <= endDate).ToList();

                    return(lstUser);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка! " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(lstUser);
            }
        }
예제 #28
0
        public static int GetAccessLevel(string login)
        {
            try
            {
                using (KindergartenContext db = new KindergartenContext())
                {
                    List <User> user = db.Users.Include(p => p.Employee).Where(p => p.Login == login).ToList();

                    if (user.FirstOrDefault() != null && user.Count() == 1)
                    {
                        return(user[0].LevelAccess);
                    }
                    return(-1);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка! " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(-1);
            }
        }
예제 #29
0
        /// <summary>
        /// Возвращает все партии, которые не закрыты
        /// </summary>
        /// <returns></returns>
        public static List <Party> GetParty()
        {
            List <Party> parties = new List <Party>();

            try
            {
                using (KindergartenContext db = new KindergartenContext())
                {
                    parties = db.Parties.Where(x => x.IsClosed == false)
                              .Include(x => x.Document).ThenInclude(x => x.Invoice).ThenInclude(y => y.Supplier)
                              .Include(x => x.Product)
                              .ToList();
                    return(parties);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка! " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(parties);
            }
        }
예제 #30
0
        public static int SetOneDish(Dish dish, int MenuId)
        {
            try
            {
                using (KindergartenContext db = new KindergartenContext())
                {
                    if (dish.Id == 0)
                    {
                        dish.MenuId = MenuId;
                        db.Dishes.Add(dish);
                        db.SaveChanges();
                    }

                    return(dish.Id);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка! " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(0);
            }
        }