public void ShowOrderEdit(int?id = null) { using (var context = new RestoranDbContext()) { if (id == null) { Order = new Order { AbonentId = Config.Abonents[0]?.Id, WaiterId = Config.WaiterId, FixedSource = FixSource.Kitchen, TimeOrder = DateTime.Now, Details = new List <Detail>() }; } else { Order = context.Order.Include("Details").SingleOrDefault(pk => pk.Id == id); } } cbAbonent.ItemsSource = Config.Abonents; cbAbonent.SelectedValue = Order.AbonentId; cbSource.ItemsSource = Enum.GetValues(typeof(FixSource)); cbSource.SelectedValue = Order.FixedSource; dpStart.Text = Order.TimeOrder.ToString("H.mm.ss"); dpEnd.Text = Order.EndOrder?.ToString("H.mm.ss") ?? "Активний"; //grid cbitem.ItemsSource = Config.FoodItems; dgOrder.ItemsSource = new ObservableCollection <Detail>(Order.Details); Visibility = Visibility.Visible; }
public static void Refresh() { using (var context = new RestoranDbContext()) { Abonents = context.Abonent.ToArray(); SourceItems = context.Sources.ToArray(); FoodItems = context.FoodItems.ToArray(); } }
private void RefreshGrid() { using (var context = new RestoranDbContext()) { var r = context.Order.Where(w => w.WaiterId == Config.WaiterId) .Join(context.Abonent, ws => ws.AbonentId, ab => ab.Id, (ws, ab) => new MainWindowViewModel { id = ws.Id, time_order = ws.TimeOrder.ToString("H:mm:ss"), abonent = ab.Name, Bill = ws.Bill }).ToArray(); dg.ItemsSource = new ObservableCollection <MainWindowViewModel>(r); } }
public RestaurantService( UserManager <Restoran> userManager, SignInManager <Restoran> signInManager, RoleManager <IdentityRole> roleManager, RestoranDbContext context ) { _userManager = userManager; _signInManager = signInManager; _roleManager = roleManager; _context = context; }
private void UserControl_Loaded(object sender, RoutedEventArgs e) { using (var context = new RestoranDbContext()) { var r = context.Waiters.Select(s => new { id = s.Id, name = s.Name }).ToArray(); waitersCB.ItemsSource = r; if (r.Length == 0) { throw new Exception("В базі відсутні офіціанти"); } waitersCB.SelectedValue = r[0].id; } }
private void orderEdit_OnSaveOrder(Order obj) { using (var context = new RestoranDbContext()) { //context.Order.Add(obj); // //obj.Details.Clear(); context.Order.Update(obj); //context.SaveChanges(); //obj.Details.Add(new Detail() { ItemsId = 1,Price = 10,Count = 2,Bill=20 //}); //context.Order.Add(obj); context.SaveChanges(); } RefreshGrid(); mainForm.Visibility = Visibility.Visible; orderEdit.Visibility = Visibility.Collapsed; }
private void CheckPassword() { using (var context = new RestoranDbContext()) { var r = context.Waiters.SingleOrDefault(s => s.Id == WaiterId); if (r?.Password == passwordPB.Password) { LoginResult?.Invoke(r.Id, r.Name); } else { passwordCounter--; if (passwordCounter == 0) { LoginResult?.Invoke(null, string.Empty); } errorBlock.Text = $"Пароль введено неправильно, спробуйте ще {passwordCounter} раз."; errorBlock.Visibility = Visibility.Visible; } } }
private void RefreshGrid() { using (var context = new RestoranDbContext()) { var r = context.Order.Where(w => w.WaiterId == Config.WaiterId) .Join(context.Abonent, ws => ws.AbonentId, ab => ab.Id, (ws, ab) => new MainWindowViewModel { id = ws.Id, time_order = ws.TimeOrder.ToString("H:mm:ss"), abonent = ab.Name, Bill = ws.Bill }).ToArray(); dg.ItemsSource = new ObservableCollection <MainWindowViewModel>(r); //var items = context.Order.ToArray(); //var s = new StringBuilder(); //foreach (var v in items) //{ // var str = "new Order { Id =" // + $" {v.Id}, WaiterId = {v.WaiterId}, AbonentId = {v.AbonentId}, TimeOrder"; // s.AppendLine("new FoodItem { Name ="+$" \"{v.Name}\",Price = {v.Price}M, Id = {v.Id}"+" },"); //} //var st = s.ToString(); //File.WriteAllText("sql.txt", st); } }
private void orderEdit_OnSaveOrder(Order obj) { using (var context = new RestoranDbContext()) { var connect = context.Database.GetDbConnection(); connect.BeginTransaction(); if (obj.Id == 0) { obj.Id = connect.ExecuteScalar <int>("SELECT IDENT_CURRENT('Order')"); connect.Execute("INSERT INTO [Order] (Id,[waiter_id],[abonent_id],[time_order],[Bill],[FixedSource]) VALUES(@Id, @waiter_id, @abonent_id, @time_order, @Bill, @FixedSource); ", new { Id = obj.Id, waiter_id = obj.WaiterId, abonent_id = obj.AbonentId, time_order = obj.TimeOrder, Bill = obj.Bill, FixedSource = obj.FixedSource }); } else { connect.Execute("UPDATE [Order] SET waiter_id = @waiter_id, abonent_id = @abonent_id, time_order = @time_order, Bill = @Bill, FixedSource = @FixedSource,end_order = @end_order,Paid = @Paid) WHERE Id=@Id; ", new { Id = obj.Id, waiter_id = obj.WaiterId, abonent_id = obj.AbonentId, time_order = obj.TimeOrder, Bill = obj.Bill, FixedSource = obj.FixedSource, end_order = obj.EndOrder, Paid = obj.Paid }); } foreach (var item in obj.Details) { if (item.Id == 0) { item.OrderId = obj.Id; } else { } } context.Order.Update(obj); //context.SaveChanges(); //obj.Details.Add(new Detail() { ItemsId = 1,Price = 10,Count = 2,Bill=20 //}); //context.Order.Add(obj); context.SaveChanges(); } RefreshGrid(); mainForm.Visibility = Visibility.Visible; orderEdit.Visibility = Visibility.Collapsed; }
public void ShowOrderEdit(int?id = null) { using (var context = new RestoranDbContext()) { var directionSQL = context.Abonent.FromSqlRaw("SELECT * FROM dbo.abonent").ToList(); if (id == null) { Order = new Order { AbonentId = Config.Abonents[0]?.Id, WaiterId = Config.WaiterId, SourceId = Config.SourceItems[0]?.Id, TimeOrder = DateTime.Now, Details = new List <Detail>() }; } else { Order = context.Order.Include("Details").SingleOrDefault(pk => pk.Id == id); } } cbAbonent.ItemsSource = Config.Abonents; cbAbonent.SelectedValue = Order.AbonentId; cbSource.ItemsSource = Config.SourceItems; cbSource.SelectedValue = Order.SourceId; dpStart.Text = Order.TimeOrder.ToString("H.mm.ss"); dpEnd.Text = Order.EndOrder?.ToString("H.mm.ss") ?? "Активний"; //grid cbitem.ItemsSource = Config.FoodItems; dgOrder.ItemsSource = new ObservableCollection <Detail>(Order.Details); Visibility = Visibility.Visible; }