private void xml_ChangedChek(object sender, EventArgs p1, string filename) { if (comboBox1.SelectedIndex != -1 && comboBox3.SelectedIndex != -1 && listBox1.Items.Count != 0) { XmlTextWriter check = null; try { check = new XmlTextWriter(filename, System.Text.Encoding.Unicode); check.Formatting = Formatting.Indented; check.WriteStartDocument(); check.WriteStartElement("CheckList"); check.WriteStartElement($"date"); check.WriteElementString($"date", Convert.ToString(DateTime.Now)); check.WriteEndElement(); b = (buyer)comboBox3.Items[comboBox3.SelectedIndex]; //buyer b2 = new buyer(b); check.WriteStartElement($"buyer"); check.WriteElementString($"buyer", Convert.ToString(b)); check.WriteEndElement(); u = (user)comboBox1.Items[comboBox1.SelectedIndex]; check.WriteStartElement($"user"); check.WriteElementString($"user", Convert.ToString(u)); check.WriteEndElement(); for (var i = 0; i < listBox1.Items.Count; i++) { t = (Tovar)listBox1.Items[i]; check.WriteStartElement($"tovar"); check.WriteElementString($"tovar{i}", t.ToString()); check.WriteEndElement(); } check.WriteEndElement(); } finally { if (check != null) { check.Close(); } MessageBox.Show("Данные внесены в файл", "Инфо", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { if (listBox1.Items.Count == 0) { MessageBox.Show("список покупок пуст, чек не оформлен", "Инфо", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("combobox продавца или покупателя пуст, чек не оформлен", "Инфо", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
private void button2_Click(object sender, EventArgs e) { t = new Tovar(); Form2 addform = new Form2(t, true); if (addform.ShowDialog() == DialogResult.OK) { comboBox2.Items.Add(t); } }
private void button9_Click(object sender, EventArgs e) { if (comboBox2.SelectedIndex == -1) { MessageBox.Show("Вы не выбрали товар"); return; } t = (Tovar)comboBox2.Items[comboBox2.SelectedIndex]; Tovar t2 = new Tovar(t); listBox1.Items.Add(t2); }
private void button2_Click(object sender, EventArgs e) { if (textBox1.Text == "") { MessageBox.Show("Заполните поле"); return; } if (t == null) { t = new Tovar(); } t.Name = textBox1.Text; this.DialogResult = DialogResult.OK; }
public Form2(Tovar t, bool addnew) { InitializeComponent(); this.addnew = addnew; this.t = t; if (addnew == false) { textBox1.Text = t.Name; this.Text = "Редактирование товара"; this.button2.Text = "Обновить"; } else { this.Text = "Добавление товара"; } }
private void button7_Click(object sender, EventArgs e) { if (comboBox2.SelectedIndex == -1) { MessageBox.Show("Вы не выбрали товар"); return; } int n = comboBox2.SelectedIndex; t = (Tovar)comboBox2.Items[n]; Form2 editform = new Form2(t, false); editform.ShowDialog(); comboBox2.Items.RemoveAt(n); comboBox2.Items.Insert(n, t); comboBox2.SelectedIndex = n; }
private void button4_Click(object sender, EventArgs e) { comboBox1.Items.Clear(); comboBox2.Items.Clear(); comboBox3.Items.Clear(); if (!File.Exists(TovarFileXml)) { MessageBox.Show("Файла товаров не существует", "Инфо", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { using (StreamReader sr = File.OpenText(TovarFileXml)) { var i = 0; var fi = new FileInfo(TovarFileXml); if (fi.Length == 0) { MessageBox.Show("Файл товаров пуст.", "Инфо", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { XPathDocument doc = new XPathDocument(TovarFileXml); XPathNavigator nav = doc.CreateNavigator(); XPathNodeIterator iterator = nav.Select("/tovarList/tovar"); int x = iterator.Count; while (iterator.MoveNext()) { XPathNodeIterator it = iterator.Current.Select($"tovar{i}"); i++; it.MoveNext(); t = new Tovar(); t.Name = it.Current.Value; comboBox2.Items.Add(t); } } } } if (!File.Exists(userFileXml)) { MessageBox.Show("Файла продавцов не существует", "Инфо", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { using (StreamReader sr = File.OpenText(userFileXml)) { var i = 0; var fi = new FileInfo(userFileXml); if (fi.Length == 0) { MessageBox.Show("Файл продавцов пуст.", "Инфо", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { XPathDocument doc = new XPathDocument(userFileXml); XPathNavigator nav = doc.CreateNavigator(); XPathNodeIterator iterator = nav.Select("/userList/user"); int x = iterator.Count; while (iterator.MoveNext()) { XPathNodeIterator it = iterator.Current.Select($"user{i}"); i++; it.MoveNext(); u = new user(); u.Name = it.Current.Value; comboBox1.Items.Add(u); } } } } if (!File.Exists(buyerFileXml)) { MessageBox.Show("Файла покупателей не существует", "Инфо", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { using (StreamReader sr = File.OpenText(buyerFileXml)) { var i = 0; var fi = new FileInfo(buyerFileXml); if (fi.Length == 0) { MessageBox.Show("Файл покупателей пуст.", "Инфо", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { XPathDocument doc = new XPathDocument(buyerFileXml); XPathNavigator nav = doc.CreateNavigator(); XPathNodeIterator iterator = nav.Select("/buyerList/buyer"); int x = iterator.Count; while (iterator.MoveNext()) { XPathNodeIterator it = iterator.Current.Select($"buyer{i}"); i++; it.MoveNext(); b = new buyer(); b.Name = it.Current.Value; comboBox3.Items.Add(b); } } } } }
public Tovar(Tovar t) { Name = t.Name; }