Esempio n. 1
0
        public void LoadItem(string name)
        {
            _groupName = name;
            DataAccess  da = new DataAccess();
            spare_group b  = da.GetSpareGroup(name);

            edtName.Text  = b.name;
            edtDescr.Text = b.description;
        }
Esempio n. 2
0
        private spare_group CreateItem()
        {
            DataAccess  da = new DataAccess();
            spare_group i  = new spare_group();

            i.name        = edtName.Text;
            i.description = edtDescr.Text;
            i.ParentGroup = da.GetSpareGroups().FirstOrDefault(g => g.name == _parentName);
            return(da.SpareGroupCreate(i));
        }
Esempio n. 3
0
        private int EditItem()
        {
            DataAccess  da   = new DataAccess();
            spare_group item = new spare_group();

            item.id          = da.GetSpareGroups().FirstOrDefault(g => g.name == _groupName).id;
            item.name        = edtName.Text;
            item.description = edtDescr.Text;
            return(da.SpareGroupEdit(item));
        }
Esempio n. 4
0
        public void Update(spare_group item) // обновление без удаления
        {
            spare_group ind = items.Where(x => x != null).FirstOrDefault(x => x.id == item.id);

            if (ind != null)
            {
                int i = items.IndexOf(ind);
                items[i] = item;
            }
            else
            {
                items.Add(item);
            }
        }
Esempio n. 5
0
 // удалить группу
 private void GroupDelete()
 {
     if (treeSpareGroups.SelectedItem != null)
     {
         TreeViewItem     tvi  = (TreeViewItem)treeSpareGroups.SelectedItem;
         string           name = tvi.Header.ToString();
         spare_group      g    = da.GetSpareGroups().FirstOrDefault(sg => sg.name == name);
         MessageBoxResult res  = MessageBox.Show("Вы действительно хотите удалить выделенную группу и все её подгруппы?", "Удаление группы", MessageBoxButton.YesNo);
         if (res == MessageBoxResult.Yes)
         {
             da.SpareGroupDelete(g);
             LoadGroups(true);
         }
     }
 }
Esempio n. 6
0
        // редактировать группу
        private void GroupEdit()
        {
            SpareGroupEditView v = new SpareGroupEditView();

            if (treeSpareGroups.SelectedItem != null)
            {
                TreeViewItem tvi  = (TreeViewItem)treeSpareGroups.SelectedItem;
                string       name = tvi.Header.ToString();
                spare_group  g    = da.GetSpareGroups().FirstOrDefault(sg => sg.name == name);
                v._groupName    = name;
                v.edtName.Text  = name;
                v.edtDescr.Text = g.description;
                v.ShowDialog();
                LoadGroups(true);
            }
        }
Esempio n. 7
0
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            int         res   = 0;
            spare_group group = null;

            if (this._groupName != null)
            {
                res = EditItem();
            }
            else
            {
                group = CreateItem();
            }
            if (res == 0 && group == null)
            {
                this.Close();
            }
            else
            {
                MessageBox.Show("Группа с таким названием уже существует!");
            }
        }
Esempio n. 8
0
        private void GroupsTreeViewSelectionChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            spare_group group = e.NewValue as spare_group;
            DataAccess  da    = new DataAccess();

            // Если выбрана не группа, а брэнд, отобразить список групп с двумя наложенными фильтрами:
            //  1. Выбранный брэнд
            //  2. Родительская для выранного брэнда группа
            if (group.IsBrand)
            {
                string brandName = group.name;
                int    groupID   = group.ParentGroup.id;
                _GroupIDBrandName(groupID, brandName);
            }
            else
            {
                int GroupID = group.id;
                _GroupIDBrandName(GroupID, "");
            }

            dgSpares.SelectedIndex = 0;
        }
Esempio n. 9
0
        public static List <spare_group> getGroups(string FilePath)
        {
            List <spare_group> items = new List <spare_group>();

            // Объявляем и забиваем файл в документ
            XmlDocument xd = new XmlDocument();
            FileStream  fs = new FileStream(FilePath, FileMode.Open);

            xd.Load(fs);

            XmlNodeList list = xd.GetElementsByTagName("Row"); // Создаем и заполняем лист по тегу "row"

            for (int i = 0; i < list.Count; i++)
            {
                spare_group b = new spare_group();
                b.code1C = list[i].FirstChild.InnerText;
                b.name   = list[i].LastChild.InnerText;
                items.Add(b);
            }
            MessageBox.Show("Сформирован список из " + items.Count.ToString() + " элементов.");
            DataAccess da = new DataAccess();
            int        xc = 0;

            foreach (spare_group i in items)
            {
                da.SpareGroupCreate(i);
                xc++;
            }
            MessageBox.Show("Добавлено  " + xc.ToString() + " элементов.");
            FixGroupsParents(list);

            // Закрываем поток
            fs.Close();

            return(items);
        }
Esempio n. 10
0
        public void Remove(int id)
        {
            spare_group sv = items.FirstOrDefault(x => x.id == id);

            items.Remove(sv);
        }
Esempio n. 11
0
 // обновление без удаления
 public void Update(spare_group item)
 {
     spare_group ind = items.Where(x => x != null).FirstOrDefault(x => x.id == item.id);
     if (ind != null)
     {
         int i = items.IndexOf(ind);
         items[i] = item;
     }
     else
     {
         items.Add(item);
     }
 }