private void buttonSearchEquipment_Click(object sender, EventArgs e) { try { if (!String.IsNullOrWhiteSpace(textBoxNameEquipmentSearch.Text)) { if (listBoxShops.SelectedItem == null) { throw new Exception("Не выбран цех"); } if (listBoxShops.SelectedItem != null) { StaticList list = (StaticList)listBoxShops.SelectedItem; string nameEquipment = textBoxNameEquipmentSearch.Text; Equipment result = list.Search(nameEquipment); if (result != null) { MessageBox.Show("Оборудование " + result.Name + " найдено количество " + result.Count.ToString()); } else { MessageBox.Show("Оборудование " + nameEquipment + " не найдено"); } textBoxNameEquipmentSearch.Text = ""; } } else { Update2(); } } catch (Exception err) { MessageBox.Show(err.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public void Add(StaticList nShop) { Node prev = Head; Node nNode = new Node(nShop); if (Head != null) { Node temp = Head; while (temp != null) { if (nNode.Shop.WorkshopName > temp.Shop.WorkshopName) { prev = temp; } if (temp.Next != Head) { temp = temp.Next; } else { break; } } temp = prev; if (temp == Head) { if (nNode.Shop.WorkshopName < temp.Shop.WorkshopName) { nNode.Next = temp; nNode.Previous = temp.Previous; temp.Previous.Next = nNode; temp.Previous = nNode; Head = nNode; } else { nNode.Previous = temp; nNode.Next = temp.Next; temp.Next.Previous = nNode; temp.Next = nNode; } } else { nNode.Previous = temp; nNode.Next = temp.Next; temp.Next.Previous = nNode; temp.Next = nNode; } } else { Head = nNode; Head.Next = Head; Head.Previous = Head; } }
private void buttonDeleteStatic_Click(object sender, EventArgs e) { try { if (listBoxShops.SelectedItem != null && dataGridViewStaticList.CurrentRow != null) { StaticList list = (StaticList)listBoxShops.SelectedItem; list.Remove(dataGridViewStaticList.CurrentRow.Cells["Name"].Value.ToString()); Update2(); } else { MessageBox.Show("Удаляемое оборудование не выбрано"); } } catch (Exception err) { MessageBox.Show(err.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void buttonAddStatic_Click(object sender, EventArgs e) { try { if (!String.IsNullOrWhiteSpace(textBoxNameEquipment.Text)) { if (listBoxShops.SelectedItem == null) { throw new Exception("Не выбран цех"); } if ((int)CountEquipment.Value != 0) { StaticList list = (StaticList)listBoxShops.SelectedItem; if (list.Search(textBoxNameEquipment.Text) == null) { Equipment nEquipment = new Equipment(textBoxNameEquipment.Text, (int)CountEquipment.Value); list.Add(nEquipment); } else { MessageBox.Show("Оборудование с таким наименованием уже существует"); } Update2(); textBoxNameEquipment.Text = ""; } else { MessageBox.Show("Количество единиц оборудования в цехе должно быть больше нуля"); } } else { MessageBox.Show("Заполните поле наименование оборудования"); } } catch (Exception err) { MessageBox.Show(err.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void buttonDelete_Click(object sender, EventArgs e) { try { StaticList list = (StaticList)listBoxShops.SelectedItem; ListShop.Remove(list); if (radioButton1.Checked) { Update1(); } if (radioButton2.Checked) { Update3(); } try { dataGridViewStaticList.DataSource = null; } catch { } } catch (Exception err) { MessageBox.Show(err.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void buttonAdd_Click(object sender, EventArgs e) { if (!String.IsNullOrWhiteSpace(textBoxNameShop.Text)) { if (ListShop.SearchForward(Int32.Parse(textBoxNameShop.Text)) == null) { if ((int)sizeList.Value != 0) { StaticList workshop = new StaticList((int)sizeList.Value); workshop.WorkshopName = Int32.Parse(textBoxNameShop.Text); ListShop.Add(workshop); textBoxNameShop.Text = ""; } else { MessageBox.Show("Количество оборудования в цехе должно быть больше нуля"); } } else { MessageBox.Show("Цех с таким номером уже существует"); } } else { MessageBox.Show("Заполните поле Номер цеха"); } if (radioButton1.Checked) { Update1(); } if (radioButton2.Checked) { Update3(); } }
public void Remove(StaticList nShop) { if (Head != null) { if (nShop == null) { throw new Exception("Не выбран удаляемый цех"); } Node nNode = Head; while (nNode != null) { if (nNode.Shop.Equals(nShop)) { break; } if (nNode.Next != Head) { nNode = nNode.Next; } else { break; } } if (nNode == Head) { nNode.Next.Previous = nNode.Previous; nNode.Previous.Next = nNode.Next; if (nNode.Next != Head) { Head = nNode.Next; } else { Head = null; } nNode.Shop.Dispose_(); nNode = null; GC.Collect(); } else { if (nNode.Next != Head) { nNode.Next.Previous = nNode.Previous; } else { Head.Previous = nNode.Previous; } nNode.Previous.Next = nNode.Next; nNode.Shop.Dispose_(); nNode = null; GC.Collect(); } } else { throw new Exception("Список пуст"); } }
public Node(StaticList shop) { Shop = shop; }
private void открытьToolStripMenuItem_Click(object sender, EventArgs e) { if (ListShop != null) { DialogResult result = MessageBox.Show("Все несохраненные данные будут утеряны после открытия нового файла. Продолжить?", "Открытие файла", MessageBoxButtons.OKCancel); if (result == DialogResult.OK) { ListShop.Dispose_(); } else { return; } } try { OpenFileDialog openFile = new OpenFileDialog(); openFile.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*"; if (openFile.ShowDialog() == DialogResult.OK) { XDocument doc = XDocument.Load(openFile.FileName); if (doc.Declaration.Encoding.Equals("utf-8") || doc.Declaration.Encoding.Equals("UTF-8")) { groupBox1.Enabled = true; сохранитьToolStripMenuItem.Enabled = true; XElement enterprise = doc.Root; ListShop = new DoubleLinkedList(); this.Text = enterprise.Attribute("Name").Value; if (enterprise.HasElements) { foreach (XElement xWorkShop in enterprise.Elements()) { if ((ListShop.SearchForward(Int32.Parse(xWorkShop.Attribute("Number").Value)) == null) && (!String.IsNullOrWhiteSpace(xWorkShop.Attribute("Number").Value)) && (!String.IsNullOrWhiteSpace(xWorkShop.Attribute("Size").Value)) && (Int32.Parse(xWorkShop.Attribute("Size").Value) != 0)) { StaticList workshop = new StaticList(Int32.Parse(xWorkShop.Attribute("Size").Value)); workshop.WorkshopName = Int32.Parse(xWorkShop.Attribute("Number").Value); if (xWorkShop.HasElements) { foreach (XElement xEquipment in xWorkShop.Elements()) { if ((workshop.Search(xEquipment.Attribute("NameEquipment").Value) == null) && (!String.IsNullOrWhiteSpace(xEquipment.Attribute("NameEquipment").Value.ToString())) && (!String.IsNullOrWhiteSpace(xEquipment.Attribute("CountEquipment").Value)) && (Int32.Parse(xEquipment.Attribute("CountEquipment").Value) != 0)) { Equipment equipment = new Equipment(xEquipment.Attribute("NameEquipment").Value, Int32.Parse(xEquipment.Attribute("CountEquipment").Value)); workshop.Add(equipment); } else { ListShop.Dispose_(); ListShop = null; GC.Collect(); groupBox1.Enabled = false; сохранитьToolStripMenuItem.Enabled = false; this.Text = ""; MessageBox.Show("Загружаемая база повреждена"); return; } } } ListShop.Add(workshop); } else { ListShop.Dispose_(); ListShop = null; GC.Collect(); groupBox1.Enabled = false; сохранитьToolStripMenuItem.Enabled = false; this.Text = ""; MessageBox.Show("Загружаемая база повреждена"); return; } } } if (radioButton1.Checked) { Update1(); } if (radioButton2.Checked) { Update3(); } try { dataGridViewStaticList.DataSource = null; } catch { } } else { MessageBox.Show("Загружаемая база повреждена"); } } } catch { groupBox1.Enabled = false; сохранитьToolStripMenuItem.Enabled = false; if (ListShop != null) { ListShop.Dispose_(); ListShop = null; GC.Collect(); } MessageBox.Show("Загружаемая база повреждена"); } }