private async void Totaux_Loaded(object sender, RoutedEventArgs e) { observableCollection = new ObservableCollection <Prod>(); DataHolder = new DataHolder(); await DataHolder.Init(); foreach (var data in DataHolder.Products) { observableCollection.Add(new Prod() { Product = data, Quant = 0, SlicedQuant = 0 }); } foreach (var client in DataHolder.Clients) { foreach (var pr in client.Products) { //https://stackoverflow.com/questions/6781192/how-do-i-update-a-single-item-in-an-observablecollection-class var prod = observableCollection.First(tmp => tmp.Product.Name == pr.Product.Name); var idx = observableCollection.IndexOf(prod); prod.Quant += pr.Quantity; if (pr.Sliced) { prod.SlicedQuant += pr.Quantity; } observableCollection[idx] = prod; } } Total.ItemsSource = observableCollection; }
private async void Ajouter_LoadedWithClient(object sender, RoutedEventArgs e) { ClientName.Text = LocalClient.Name; Phone.Text = LocalClient.Phone; Remarks.Text = LocalClient.Remarks; OrderedProducts = LocalClient.Products; ProductsList.ItemsSource = OrderedProducts; DataHolder = new DataHolder(); await DataHolder.Init(); foreach (var product in DataHolder.Products) { if (!Categories.Any(cat => cat.Category == product.Category)) { Categories.Add(new Product() { Category = product.Category, Name = product.Category, Price = 0, Slicable = null }); } } ProductsMenu.ItemsSource = Categories; }
private async Task UpdateCollection() { DataHolder = new DataHolder(); await DataHolder.Init(); if (DisplayAll.IsChecked == true) { ClientsList.ItemsSource = DataHolder.Clients.Where(cmd => cmd.Name.ToUpper().Contains(SearchBar.Text.ToUpper())); } else { ClientsList.ItemsSource = DataHolder.Clients.Where(tmp => tmp.State > 0).Where(tmp => tmp.Name.ToUpper().Contains(SearchBar.Text.ToUpper())); // Enlever le supérieur ou égal } TotalListe.Text = ClientsList.Items.Count.ToString() + "/" + DataHolder.Clients.Count.ToString(); }
private async void Ajouter_Loaded(object sender, RoutedEventArgs e) { ProductsList.ItemsSource = OrderedProducts; DataHolder = new DataHolder(); await DataHolder.Init(); foreach (var product in DataHolder.Products) { if (!Categories.Any(cat => cat.Category == product.Category)) { Categories.Add(new Product() { Category = product.Category, Name = product.Category, Price = 0, Slicable = null }); } } ProductsMenu.ItemsSource = Categories; }
private async void btnLogin_Click(object sender, EventArgs e) { if (Trigger) { Trigger = false; DataHolder.Init(); switch (cbLanguage.SelectedValue.ToString()) { case "Български": DataHolder.UserCulture = new CultureInfo("bg-BG"); break; case "English": DataHolder.UserCulture = new CultureInfo("en-US"); break; default: DataHolder.UserCulture = new CultureInfo("en-US"); break; } if (!string.IsNullOrEmpty(tbUsername.Text) && !string.IsNullOrEmpty(tbPassword.Text)) { DataHolder.ServerAddress = cbServer.Text; CommonUser user = await SAUsers.Login(tbUsername.Text, tbPassword.Text); if (user != null) { DataHolder.CurrnetUserId = user.UserId; DataHolder.OwnerId = user.OwnerId; DataHolder.Username = user.Username; DataHolder.UserType = user.Role; DataHolder.UserPermissions = user.Permissions; DataHolder.Settings = await SASettings.getUserSettings(); List <CommonMol> allMols = await SAOwner.getAllMols(user.OwnerId); foreach (var mol in allMols) { if (mol.IsPrimery) { DataHolder.PrimeryMol = mol; break; } } MainForm form = new MainForm(); Hide(); if (form.ShowDialog() == DialogResult.Cancel) { Trigger = true; labelError.Visible = false; Show(); tbPassword.Text = string.Empty; tbUsername.Text = DataHolder.Username; //clear previus data DataHolder.CurrnetUserId = Guid.Empty; DataHolder.OwnerId = Guid.Empty; DataHolder.ServerAddress = string.Empty; DataHolder.Username = string.Empty; DataHolder.UserType = 99; DataHolder.UserCulture = new CultureInfo("en-US"); DataHolder.PrimeryMol = null; DataHolder.UserPermissions = ""; DataHolder.Settings = new CommonSettings(); } } else { labelError.Visible = true; labelError.Text = DataHolder.GetString("invalid_username_or_password"); Trigger = true; } } else { labelError.Visible = true; labelError.Text = DataHolder.GetString("invalid_username_or_password"); Trigger = true; } } }