コード例 #1
0
        private void createFabricator_Click(object sender, RoutedEventArgs e)
        {
            if (nameFabricatorTextBox.Text != null)
            {
                try
                {
                    fabricator = new Fabricator();
                    fabricator.name_fabricator        = nameFabricatorTextBox.Text;
                    fabricator.tel_fabricator         = Convert.ToDecimal(telFabricatorTextBox.Text);
                    fabricator.inn_fabricator         = Convert.ToDecimal(innFabricatorTextBox.Text);
                    fabricator.description_fabricator = new TextRange(descriptionFabricatorTextBox.Document.ContentStart, descriptionFabricatorTextBox.Document.ContentEnd).Text;
                    fabricator.doing_fabricator       = sphereFabricatorTextBox.Text;
                    fabricator.contactName_fabricator = contacteFabricatorTextBox.Text;


                    if (create)
                    {
                        entities.Fabricators.Add(fabricator);
                    }
                    else
                    {
                        foreach (Fabricator f in listFabricators)
                        {
                            if (f.name_fabricator == name)
                            {
                                f.name_fabricator        = fabricator.name_fabricator;
                                f.inn_fabricator         = fabricator.inn_fabricator;
                                f.tel_fabricator         = fabricator.tel_fabricator;
                                f.description_fabricator = fabricator.description_fabricator;
                                f.doing_fabricator       = fabricator.doing_fabricator;
                                f.contactName_fabricator = fabricator.contactName_fabricator;
                            }
                        }
                    }
                    entities.SaveChanges();
                    this.DialogResult = true;
                }
                catch (Exception ex)
                {
                    this.ShowMessageAsync("Ошибка", ex.ToString());
                }
            }
            else
            {
                this.ShowMessageAsync("Ошибка", "Возможно, вы не заполнили некоторые обязательные поля");
            }
        }
コード例 #2
0
        public Fabricators(ObservableCollection <Fabricator> list, Fabricator fabr, Entities dataEntities)
        {
            InitializeComponent();

            this.entities        = dataEntities;
            this.listFabricators = list;
            if (fabr != null)
            {
                create = false;
                FabricatorTitle.Content  = "Изменение производителя";
                createFabricator.Content = "изменить";
                this.fabricator          = fabr;
                name = fabr.name_fabricator;
                nameFabricatorTextBox.Text = fabr.name_fabricator;
                telFabricatorTextBox.Text  = fabr.tel_fabricator.ToString();
                new TextRange(descriptionFabricatorTextBox.Document.ContentStart, descriptionFabricatorTextBox.Document.ContentEnd).Text = fabr.description_fabricator;
                innFabricatorTextBox.Text      = fabr.inn_fabricator.ToString();
                sphereFabricatorTextBox.Text   = fabr.doing_fabricator;
                contacteFabricatorTextBox.Text = fabr.contactName_fabricator;
            }
        }
コード例 #3
0
        public void Do()
        {
            try
            {
                equipment = new Equipment();
                equipment.code_equipment        = codeEquipmentTextBox.Text;
                equipment.name_equipment        = nameEquipmentTextBox.Text;
                equipment.description_equipment = new TextRange(descriptionEquipmentTextBox.Document.ContentStart, descriptionEquipmentTextBox.Document.ContentEnd).Text;
                Fabricator fabricator = fabricatorEquipmentComboBox.SelectedItem as Fabricator;
                equipment.fabricator_equipment = fabricator.id_fabricator;
                Сategories category = categoriesEquipmentComboBox.SelectedItem as Сategories;
                equipment.category_equipment = category.id_category;
                equipment.price_equipment    = Convert.ToDecimal(priceEquipmentTextBox.Text);

                WrapPanel[]      w     = attributesPanel.Children.OfType <WrapPanel>().ToArray();
                TextBox[]        t     = new TextBox[w.Count()];
                AttributeArray[] array = new AttributeArray[w.Count()];
                for (int i = 0; i < w.Count(); i++)
                {
                    t        = w[i].Children.OfType <TextBox>().ToArray();
                    array[i] = new AttributeArray(t[0].Name, t[0].Text);
                }

                foreach (Attribute item in ListAttributes)
                {
                    for (int i = 0; i < array.Count(); i++)
                    {
                        if (item.name_attribute == array[i].name)
                        {
                            Attributes_Values av = new Attributes_Values();
                            av.value_aValues     = array[i].value;
                            av.attribute_aValues = item.id_attribute;
                            if (id != 0)
                            {
                                av.equipment_aValues = id;
                            }
                            else
                            {
                                av.equipment_aValues = equipment.id_equipment;
                            }
                            equipment.Attributes_Values.Add(av);
                            item.Attributes_Values.Add(av);
                        }
                    }
                }

                if (create)
                {
                    equipment.col_equipment = 0;
                    entities.Equipments.Add(equipment);
                }
                else
                {
                    foreach (Equipment eq in ListEquipment)
                    {
                        if (eq.name_equipment == name)
                        {
                            eq.name_equipment        = equipment.name_equipment;
                            eq.code_equipment        = equipment.code_equipment;
                            eq.description_equipment = equipment.description_equipment;
                            eq.fabricator_equipment  = equipment.fabricator_equipment;
                            eq.category_equipment    = equipment.category_equipment;
                            eq.price_equipment       = equipment.price_equipment;
                            eq.Attributes_Values     = equipment.Attributes_Values;
                        }
                    }
                }
                entities.SaveChanges();
                this.DialogResult = true;
            }
            catch (Exception ex)
            {
                this.ShowMessageAsync("Ошибка", ex.ToString());
            }
        }