private void LoadExpense(int index) { Income.Visibility = Visibility.Hidden; LabelIncome.Visibility = Visibility.Hidden; Expenses.Visibility = Visibility.Visible; LabelExpenses.Visibility = Visibility.Visible; pageExpense = new ExpenseChart(dictionary[index]); Frame.Navigate(pageExpense); using (var context = new MSSQLContext()) { var list = context.PurchaseIngredients.ToList(); if (index != 0) { Expenses.Text = list.Where(l => DateTime.Now .Subtract(l.DateOfPurchase.Date).TotalDays <= dictionary[index]) .Sum(l => l.Price * l.Count).ToString(); } else { Expenses.Text = list.Sum(l => l.Price * l.Count).ToString(); } } }
private void LoadOrders(List <ValueTuple <string, decimal> > income, int days) { var listId = new List <int>(); using (var context = new MSSQLContext()) { var orders = context.Orders .Include(o => o.Food) .Include(o => o.OrderList) .ToList(); foreach (var item in orders) { if (!listId.Contains(item.FoodId)) { listId.Add(item.FoodId); if (days == 0) { income.Add((item.Food.Name, orders.Where(o => o.FoodId == item.FoodId) .Sum(o => o.PriceBoughtFor * o.Count))); } else { income.Add((item.Food.Name, orders.Where(o => o.FoodId == item.FoodId && DateTime.Now .Subtract(o.OrderList.DateOrder.Date).TotalDays <= days) .Sum(o => o.PriceBoughtFor * o.Count))); } } } } }
private void LoadIncome(int index) { Income.Visibility = Visibility.Visible; LabelIncome.Visibility = Visibility.Visible; Expenses.Visibility = Visibility.Hidden; LabelExpenses.Visibility = Visibility.Hidden; pageIncome = new DiagramIncome(dictionary[index]); Frame.Navigate(pageIncome); using (var context = new MSSQLContext()) { var list = context.Orders .Include(o => o.OrderList) .ToList(); if (index != 0) { Income.Text = list.Where(l => DateTime.Now .Subtract(l.OrderList.DateOrder.Date).TotalDays <= dictionary[index]) .Sum(l => l.PriceBoughtFor * l.Count).ToString(); } else { Income.Text = list.Sum(l => l.PriceBoughtFor * l.Count).ToString(); } } }
private void SaveChanges() { using (var context = new MSSQLContext()) { string telepnone = currentUser.Telephone; currentUser = context.Users.Find(currentUser.Id); if (currentUser.Telephone != telepnone) { if (null != context.Users.FirstOrDefault(u => u.Telephone == telepnone)) { MessageBox.Show("Этот теефон недоступен для повторной регистрации. Укажите другой", "Внимание", MessageBoxButton.OK, MessageBoxImage.Error); return; } } currentUser.LastName = LastName.Text; currentUser.FirstName = FirstName.Text; currentUser.MiddleName = MiddleName.Text; currentUser.Telephone = telepnone; context.SaveChanges(); } success.Invoke(currentUser); MessageBox.Show("Изменения прошли успешно.", "Внимание", MessageBoxButton.OK, MessageBoxImage.Information); isDataDirty = false; Close(); }
private void LoadAllFood() { using (var context = new MSSQLContext()) { foods = context.Foods.ToList(); } }
private System.Data.DataTable ChefReport(int a = 0) { var table = new System.Data.DataTable(); using (var context = new MSSQLContext()) { var list = context.Inquiries.ToList(); table.Columns.Add(new DataColumn("Название", typeof(string))); table.Columns.Add(new DataColumn("Количество", typeof(decimal))); table.Columns.Add(new DataColumn("Дата заказа", typeof(DateTime))); foreach (var item in list) { DataRow newRow = table.NewRow(); newRow[0] = context.Ingredients.Find(item.IngredientId).Name; newRow[1] = item.ExpectedQuantity; newRow[2] = item.Date; table.Rows.Add(newRow); } } margCellsEnd = "C1"; reportName = "Отчёт Шеф-Повара"; return(table); }
private System.Data.DataTable ManagerReportIngredient(int a = 0) { var table = new System.Data.DataTable(); using (var context = new MSSQLContext()) { var list = context.Ingredients.ToList(); table.Columns.Add(new DataColumn("Название", typeof(string))); table.Columns.Add(new DataColumn("Количество", typeof(decimal))); table.Columns.Add(new DataColumn("Текущая цена за 1 ед.", typeof(decimal))); foreach (var item in list) { DataRow newRow = table.NewRow(); newRow[0] = item.Name; newRow[1] = item.Count; newRow[2] = item.Price; table.Rows.Add(newRow); } } margCellsEnd = "C1"; reportName = "Отчёт Менеджера по Ингредиентам"; return(table); }
private System.Data.DataTable ManagerReportFood(int a = 0) { var table = new System.Data.DataTable(); using (var context = new MSSQLContext()) { var list = context.Foods .Include(f => f.Structures) .ToList(); table.Columns.Add(new DataColumn("Название", typeof(string))); table.Columns.Add(new DataColumn("Есть в меню?", typeof(bool))); table.Columns.Add(new DataColumn("Текущая цена", typeof(decimal))); foreach (var item in list) { DataRow newRow = table.NewRow(); newRow[0] = item.Name; newRow[1] = item.InMenu; newRow[2] = item.CurrentPrice; table.Rows.Add(newRow); } reportName = "Отчёт Менеджера по Блюдам"; margCellsEnd = "C1"; } return(table); }
private void LoadOrders(List <ValueTuple <string, decimal> > expense, int days) { List <int> listId = new List <int>(); using (var context = new MSSQLContext()) { var purchaseList = context.PurchaseIngredients .Include(p => p.Ingredient) .ToList(); foreach (var item in purchaseList) { if (!listId.Contains(item.IngredientId)) { listId.Add(item.IngredientId); if (days == 0) { expense.Add((item.Ingredient.Name, purchaseList.Where(l => l.IngredientId == item.IngredientId) .Sum(l => l.Price * l.Count))); } else { expense.Add((item.Ingredient.Name, purchaseList.Where(l => l.IngredientId == item.IngredientId && DateTime.Now.Subtract(l.DateOfPurchase.Date).Days <= days) .Sum(l => l.Price * l.Count))); } } } } }
private bool ChangePasswordValidation() { if (!Validation.TelephoneValidation(Telephone.Text)) { return(false); } if (!Validation.PasswordValidation(Password.Password)) { return(false); } if (Password.Password != PasswordCheck.Password) { MessageBox.Show("Пароли не совпадают", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } using (var context = new MSSQLContext()) { if (null == context.Users.FirstOrDefault(u => u.Telephone == Telephone.Text && u.IsBlock == false)) { MessageBox.Show("Такого теефона мы не знаем или он заблокирован", "Ошабка", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } } return(true); }
public ManagerViewFood(Food food) { InitializeComponent(); var context = new MSSQLContext(); FoodImage.Source = WorkWithImage.ConvertArrayByteToImage(food.Image); NameFood.Text = food.Name; Category.Text = context.Categories.Find(food.CategoryId).Name; Price.Text = food.CurrentPrice.ToString(); InMenu.IsChecked = food.InMenu; Description.Text = food.Description; this.food = food; var structures = context.Structures.Where(s => s.FoodId == food.Id).ToList(); foreach (var currentStructure in structures) { if (structures.IndexOf(currentStructure) == structures.Count) { Ingredients.Text += context.Ingredients.First(i => i.Id == currentStructure.IngredientId).Name + "."; } else { Ingredients.Text += context.Ingredients.First(i => i.Id == currentStructure.IngredientId).Name + " ,"; } } context.Database.Connection.Close(); }
private void LoadFoodWithOutDescription() { using (var context = new MSSQLContext()) { foods = context.Foods.Where(f => f.Description == "").ToList(); } }
private void InquiryExecute_Click(object sender, RoutedEventArgs e) { using (var context = new MSSQLContext()) { var listInquiry = new List <Inquiry>(); foreach (var item in list) { if (item.AdditionalAmount == 0) { continue; } listInquiry.Add(new Inquiry() { IngredientId = item.Id, ExpectedQuantity = item.AdditionalAmount, Date = DateTime.Now }); } list.Clear(); if (listInquiry.Count != 0) { context.Inquiries.AddRange(listInquiry); context.SaveChanges(); } } }
private void LoadWoodWithOutPrice() { using (var context = new MSSQLContext()) { foods = context.Foods.Where(f => f.CurrentPrice == 0).ToList(); } }
private void LoadFoodNotInMenu() { using (var context = new MSSQLContext()) { foods = context.Foods.Where(f => f.InMenu == false).ToList(); } }
internal static bool CanUserBuy(List <FoodInBasket> foods, Food currentFood) { using (var context = new MSSQLContext()) { var listIngredients = context.Ingredients.ToList(); foreach (var food in foods) { foreach (var structure in context.Structures.Where(s => s.FoodId == food.Id)) { listIngredients.First(i => i.Id == structure.IngredientId).Count -= structure.Quantity; } } if (listIngredients.FirstOrDefault(i => i.Count < 0) != null) { MessageBox.Show("Приносим свои извенения, но у нас не хватает ингредиентов на все ваши " + "заказы!!", "Внимание", MessageBoxButton.OK, MessageBoxImage.Information); return(false); } } return(true); }
public UserViewFood(Food currentFood, List <FoodInBasket> basket, Button basketButton) { InitializeComponent(); Price.Text = currentFood.CurrentPrice.ToString(); FoodDescription.Text = currentFood.Description; AddToBasket.IsEnabled = Validation.CanUserBuy(basket, currentFood); foodImage.Source = WorkWithImage.ConvertArrayByteToImage(currentFood.Image); using (var context = new MSSQLContext()) { var structures = context.Structures.Where(s => s.FoodId == currentFood.Id) .Include(s => s.Ingredient) .ToList(); foreach (var currentStructure in structures) { if (structures.IndexOf(currentStructure) == structures.Count) { FoodStruct.Text += context.Ingredients.First(i => i.Id == currentStructure.IngredientId).Name + $" {currentStructure.Quantity} {currentStructure.Ingredient.Unit}."; } else { FoodStruct.Text += context.Ingredients.First(i => i.Id == currentStructure.IngredientId).Name + $" {currentStructure.Quantity} {currentStructure.Ingredient.Unit},"; } } } this.basket = basket; this.currentFood = currentFood; this.basketButton = basketButton; }
private void LoadIngredientsWithCountNull() { using (var context = new MSSQLContext()) { ingredients = context.Ingredients.Where(i => i.Count == 0).ToList(); } LoadIngredients(); }
private void LoadFood(string str) { using (var context = new MSSQLContext()) { foods = context.Foods.Where(f => f.Name.StartsWith(str) == true).ToList(); } CreateButtons(); }
private void LoadIngredients(string str) { using (var context = new MSSQLContext()) { var list = context.Ingredients.Where(i => i.Name.StartsWith(str) == true).ToList(); LoadModel(list); } }
private void LoadAllIngredients() { using (var context = new MSSQLContext()) { ingredients = context.Ingredients.ToList(); } LoadIngredients(); }
private void LoadInquiryListBox() { IngredientControlVisibility(2); inquiryDictionary = new Dictionary <int, TextBox>(); var context = new MSSQLContext(); listInquiry = context.Inquiries .Include(i => i.Ingredient) .ToList(); foreach (var item in listInquiry) { var panel = new StackPanel(); var label = new Label() { Foreground = Brushes.White, HorizontalAlignment = HorizontalAlignment.Center, Content = item.Ingredient.Name + "\t\t" + item.ExpectedQuantity + "\t\t" + item.Date.ToString("d", CultureInfo.CreateSpecificCulture("de-DE")) }; var textBox = new TextBox() { Text = "Введите стоймость 1 единицы ингредиента", Foreground = Brushes.PaleGoldenrod, HorizontalAlignment = HorizontalAlignment.Center }; textBox.GotKeyboardFocus += new KeyboardFocusChangedEventHandler(GotKeyboardFocus); textBox.LostKeyboardFocus += new KeyboardFocusChangedEventHandler(LostKeyboardFocus); var button = new Button() { Name = "Name" + item.Id, Content = "Купить", Foreground = Brushes.White, HorizontalAlignment = HorizontalAlignment.Right }; button.Click += EventForButton; panel.Children.Add(label); panel.Children.Add(textBox); panel.Children.Add(button); InquiryListBox.Items.Add(panel); inquiryDictionary.Add(item.Id, textBox); } context.Database.Connection.Close(); }
private void Save_Click(object sender, RoutedEventArgs e) { using (var context = new MSSQLContext()) { int id = Convert.ToInt32(Id.Text); var user = context.Users.FirstOrDefault(u => u.Id == id); user.LvlAccess = Role.SelectedIndex; user.IsBlock = IsBlock.IsChecked == true; context.SaveChanges(); } }
private void Load() { using (var context = new MSSQLContext()) { listCategories = context.Database.SqlQuery <Category>("select * from Categories").ToList(); listFood = context.Database.SqlQuery <Food>("select * from Foods where InMenu = 1 and CurrentPrice > 0").ToList(); listIngredients = context.Database.SqlQuery <Ingredient>("select * from Ingredients where Count > 0").ToList(); } LoadCategories(); LoadFood(0); }
private System.Data.DataTable EconomistReportIncome(int days) { var table = new System.Data.DataTable(); var listId = new List <int>(); using (var context = new MSSQLContext()) { var list = context.Orders .Include(o => o.Food) .Include(o => o.OrderList) .ToList(); table.Columns.Add(new DataColumn("Название", typeof(string))); table.Columns.Add(new DataColumn("Общий доход", typeof(decimal))); table.Columns.Add(new DataColumn("Проданное количество", typeof(decimal))); foreach (var item in list) { if (!listId.Contains(item.FoodId)) { DataRow newRow = table.NewRow(); newRow[0] = item.Food.Name; if (days == 0) { newRow[1] = list.Where(l => l.FoodId == item.FoodId).Sum(i => i.PriceBoughtFor * i.Count); newRow[2] = list.Where(l => l.FoodId == item.FoodId).Sum(i => i.Count); } else { newRow[1] = list.Where(l => l.FoodId == item.FoodId && DateTime.Now.Subtract(l.OrderList.DateOrder.Date).TotalDays <= days) .Sum(i => i.PriceBoughtFor * i.Count); newRow[2] = list.Where(l => l.FoodId == item.FoodId && DateTime.Now.Subtract(l.OrderList.DateOrder.Date).TotalDays <= days) .Sum(i => i.Count); } listId.Add(item.FoodId); table.Rows.Add(newRow); } } margCellsEnd = "C1"; reportName = "Отчёт Экономита по продажам за" + (days == 0 ? "всё время" : $"последние {days} дней"); } return(table); }
private System.Data.DataTable EconomistReportExpense(int days) { var table = new System.Data.DataTable(); var listId = new List <int>(); using (var context = new MSSQLContext()) { var list = context.PurchaseIngredients .Include(o => o.Ingredient) .ToList(); table.Columns.Add(new DataColumn("Название", typeof(string))); table.Columns.Add(new DataColumn("Общий расход", typeof(decimal))); table.Columns.Add(new DataColumn("Приобретённое количество", typeof(decimal))); foreach (var item in list) { if (!listId.Contains(item.IngredientId)) { DataRow newRow = table.NewRow(); newRow[0] = item.Ingredient.Name; if (days == 0) { newRow[1] = list.Where(l => l.IngredientId == item.IngredientId).Sum(i => i.Price * i.Count); newRow[2] = list.Where(l => l.IngredientId == item.IngredientId).Sum(i => i.Count); } else { newRow[1] = list.Where(l => l.IngredientId == item.IngredientId && DateTime.Now.Subtract(item.DateOfPurchase.Date).Days <= days) .Sum(i => i.Price * i.Count); newRow[2] = list.Where(l => l.IngredientId == item.IngredientId && DateTime.Now.Subtract(item.DateOfPurchase.Date).Days <= days) .Sum(i => i.Count); } listId.Add(item.Id); table.Rows.Add(newRow); } } margCellsEnd = "C1"; reportName = "Отчёт Экономита по расходам за " + (days == 0 ? "всё время" : $"последние {days} дней");; } return(table); }
private void SaveNewPassword() { using (var context = new MSSQLContext()) { currentUser = context.Users.FirstOrDefault(u => u.Telephone == Telephone.Text); currentUser.Password = Password.Password; context.SaveChanges(); } MessageBox.Show("Изменения прошли успешно.", "Внимание", MessageBoxButton.OK, MessageBoxImage.Information); isDataDirty = false; Close();; }
internal static bool CheckUser(string str) { using (var context = new MSSQLContext()) { if (null != context.Users.FirstOrDefault(u => u.Login == str)) { MessageBox.Show("Такой логин уже есть, придумайте другой", "Внимание", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } } return(true); }
internal static bool CheckTelephone(string str) { using (var context = new MSSQLContext()) { if (null != context.Users.FirstOrDefault(u => u.Telephone == str)) { MessageBox.Show("Такой телефон уже есть, воспользуйтесь другим", "Внимание", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } } return(true); }
private void RequestReport_Click(object sender, RoutedEventArgs e) { var flag = true; using (var context = new MSSQLContext()) { flag = context.Inquiries.ToList().Count != 0; } if (flag) { Report report = new Report(); report.CommonPart(0); } }