Пример #1
0
 private void Button_Click_2(object sender, RoutedEventArgs e)
 {
     if (addForm3 != null)
     {
         addForm3.Close();
     }
     addForm3 = new AddForm3();
     addForm3.Show();
     addForm3.Sumbit.Click += Sumbit_Click2;
 }
Пример #2
0
        public void Refresh()
        {
            TovarList.Children.Clear();
            SkladList.Children.Clear();
            PostavList.Children.Clear();
            ZakazList.Children.Clear();
            #region tovar
            foreach (Product product in config.list.AllProducts)
            {
                UserControl1 userControl1 = new UserControl1();
                userControl1.NameLabel.Content       = product.Name;
                userControl1.DescLabel.Text          = product.Desc;
                userControl1.Trash.PreviewMouseDown += delegate
                {
                    if (config.list.AllstroredProducts.Where(x => x.product == product).Count() > 0)
                    {
                        MessageBox.Show("На ваших полочках или в заказах престутсвует данный товар!");
                    }
                    else
                    {
                        config.list.AllProducts.Remove(product);
                        config.Save();
                        Refresh();
                    }
                };
                userControl1.Edit.PreviewMouseDown += delegate
                {
                    if (addForm != null)
                    {
                        addForm.Close();
                    }
                    addForm = new AddForm();
                    addForm.Show();
                    addForm.nametext.Text = product.Name; addForm.desctext.Text = product.Desc;
                    addForm.Sumbit.Click += delegate
                    {
                        product.Name = addForm.nametext.Text; product.Desc = addForm.desctext.Text;
                        if (addForm != null)
                        {
                            addForm.Close();
                        }
                        config.Save();
                        Refresh();
                    }
                    ;
                };
                TovarList.Children.Add(userControl1);
            }
            #endregion

            #region Postav
            foreach (Postavshick product in config.list.AllPostavshicks)
            {
                UserControl1 userControl1 = new UserControl1();
                userControl1.NameLabel.Content       = product.name;
                userControl1.DescLabel.Text          = product.tel + Environment.NewLine + product.adress;
                userControl1.Trash.PreviewMouseDown += delegate
                {
                    if (config.list.AllstroredProducts.Where(x => x.Postavshick == product).Count() > 0)
                    {
                        MessageBox.Show("Ваш товар привязан к данному поставщику!");
                    }
                    else
                    {
                        config.list.AllPostavshicks.Remove(product);
                        config.Save();
                        Refresh();
                    }
                };
                userControl1.Edit.PreviewMouseDown += delegate
                {
                    if (addForm3 != null)
                    {
                        addForm3.Close();
                    }
                    addForm3 = new AddForm3();
                    addForm3.Show();
                    addForm3.nameL.Text    = product.name;
                    addForm3.TelL.Text     = product.tel;
                    addForm3.adressT.Text  = product.adress;
                    addForm3.Sumbit.Click += delegate
                    {
                        product.adress = addForm3.adressT.Text; product.tel = addForm3.TelL.Text;
                        product.name   = addForm3.nameL.Text;
                        if (addForm3 != null)
                        {
                            addForm3.Close();
                        }
                        config.Save();
                        Refresh();
                    }
                    ;
                };
                PostavList.Children.Add(userControl1);
            }
            #endregion
            #region Store
            foreach (StroredProduct product in config.list.AllstroredProducts)
            {
                UserControl2 userControl1 = new UserControl2();
                userControl1.NameLabel.Content       = product.product.Name;
                userControl1.Kolichesvo.Content      = product.count;
                userControl1.Polochka.Content        = product.polka;
                userControl1.post.Content            = product.Postavshick.name;
                userControl1.Trash.PreviewMouseDown += delegate
                {
                    config.list.AllstroredProducts.Remove(product);
                    config.Save();
                    Refresh();
                };
                userControl1.Edit.PreviewMouseDown += delegate
                {
                    if (addForm2 != null)
                    {
                        addForm2.Close();
                    }
                    addForm2 = new AddForm2();
                    addForm2.Show();
                    addForm2.poltext.Text = product.polka.ToString();
                    addForm2.koltext.Text = product.count.ToString();
                    foreach (UserControl1 user in TovarList.Children.Cast <UserControl1>().ToArray())
                    {
                        addForm2.TovarList.Items.Add(new ListBoxItem()
                        {
                            Content = user.NameLabel.Content
                        });
                    }
                    foreach (UserControl1 user in PostavList.Children.Cast <UserControl1>().ToArray())
                    {
                        addForm2.PostavshickList.Items.Add(new ListBoxItem()
                        {
                            Content = user.NameLabel.Content
                        });
                    }
                    addForm2.TovarList.SelectedItem       = addForm2.TovarList.Items.Cast <ListBoxItem>().Where(x => x.Content.ToString() == product.product.Name).First();
                    addForm2.PostavshickList.SelectedItem = addForm2.PostavshickList.Items.Cast <ListBoxItem>().Where(x => x.Content.ToString() == product.Postavshick.name).First();
                    addForm2.Sumbit.Click += delegate
                    {
                        product.polka       = Convert.ToInt32(addForm2.poltext.Text);
                        product.count       = Convert.ToInt32(addForm2.koltext.Text);
                        product.product     = config.list.AllProducts.Where(x => x.Name == ((ListBoxItem)addForm2.TovarList.SelectedItem).Content.ToString()).First();
                        product.Postavshick = config.list.AllPostavshicks.Where(x => x.name == ((ListBoxItem)addForm2.PostavshickList.SelectedItem).Content.ToString()).First();
                        if (addForm2 != null)
                        {
                            addForm2.Close();
                        }
                        config.Save();
                        Refresh();
                    }
                    ;
                };
                SkladList.Children.Add(userControl1);
            }
            #endregion
            #region Zakaz
            foreach (Zakaz product in config.list.AllZakazs)
            {
                UserControl2 userControl1 = new UserControl2();
                userControl1.NameLabel.Content       = product.stroredProduct.Name;
                userControl1.Kolichesvo.Content      = product.Count;
                userControl1.PolPanel.Visibility     = Visibility.Collapsed;
                userControl1.post.Content            = product.postavshick.name;
                userControl1.Trash.PreviewMouseDown += delegate
                {
                    config.list.AllZakazs.Remove(product);
                    config.Save();
                    Refresh();
                };
                userControl1.Edit.PreviewMouseDown += delegate
                {
                    if (addForm4 != null)
                    {
                        addForm4.Close();
                    }
                    addForm4 = new AddForm4();
                    addForm4.Show();

                    addForm4.koltext.Text = product.Count.ToString();
                    foreach (UserControl1 user in TovarList.Children.Cast <UserControl1>().ToArray())
                    {
                        addForm4.TovarList.Items.Add(new ListBoxItem()
                        {
                            Content = user.NameLabel.Content
                        });
                    }
                    foreach (UserControl1 user in PostavList.Children.Cast <UserControl1>().ToArray())
                    {
                        addForm4.PostavshickList.Items.Add(new ListBoxItem()
                        {
                            Content = user.NameLabel.Content
                        });
                    }
                    addForm4.TovarList.SelectedItem       = addForm4.TovarList.Items.Cast <ListBoxItem>().Where(x => x.Content.ToString() == product.stroredProduct.Name).First();
                    addForm4.PostavshickList.SelectedItem = addForm4.PostavshickList.Items.Cast <ListBoxItem>().Where(x => x.Content.ToString() == product.postavshick.name).First();
                    addForm4.Sumbit.Click += delegate
                    {
                        product.Count = Convert.ToInt32(addForm2.koltext.Text);

                        product.stroredProduct = config.list.AllProducts.Where(x => x.Name == ((ListBoxItem)addForm4.TovarList.SelectedItem).Content.ToString()).First();
                        product.postavshick    = config.list.AllPostavshicks.Where(x => x.name == ((ListBoxItem)addForm4.PostavshickList.SelectedItem).Content.ToString()).First();
                        if (addForm4 != null)
                        {
                            addForm4.Close();
                        }
                        config.Save();
                        Refresh();
                    }
                    ;
                };
                ZakazList.Children.Add(userControl1);
            }
            #endregion
        }