private void button1_Click(object sender, EventArgs e) { if (textBox1.Text != "") { foreach (One_spend_categories item in F1.categories) { if (item.Name == textBox1.Text) { MessageBox.Show( "Такая категория уже существует", "Обратите внимание", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); return; } } One_spend_categories category = new One_spend_categories(); category.Name = textBox1.Text; category.Notion = textBox2.Text; comboBox1.Items.Add(textBox1.Text); F1.Add_category(category); } }
public Form1() { One_person first = new One_person(); One_spend_categories first_categories = new One_spend_categories(); first_categories.Name = "General"; first_categories.Notion = "Default categories spends"; first.Name = "Owner"; first.Notion = "Default Owner"; persons.Add(first); categories.Add(first_categories); InitializeComponent(); comboBox1.Items.Add(first.Name); comboBox2.Items.Add(first_categories.Name); }
private void button3_Click(object sender, EventArgs e) { if (comboBox1.Text != "") { foreach (One_spend_categories item in F1.categories) { //if (item.Name == comboBox1.Text) //{ // MessageBox.Show( // "Такая категория уже существует", // "Обратите внимание", // MessageBoxButtons.OK, // MessageBoxIcon.Information, // MessageBoxDefaultButton.Button1, // // return; //} } string chcaregor = F1.categories[last_selected_index].Name; F1.categories.RemoveAt(last_selected_index); F1.Dell_category(last_selected_index); comboBox1.Items.RemoveAt(last_selected_index); One_spend_categories categ = new One_spend_categories(); categ.Name = comboBox1.Text; categ.Notion = textBox2.Text; comboBox1.Items.Add(comboBox1.Text); F1.Add_category(categ); for (int i = 0; i < F1.spends.Count; i++) { if (F1.spends[i].Categories == chcaregor) { F1.spends[i].Categories = comboBox1.Text; } }//заменить ответственных на новых F1.refresh(); } }
public void search_categ() { bool flag = false; foreach (var item in spends) { flag = false; for (int i = 0; i < categories.Count; i++) { if (item.Categories == categories[i].Name) { flag = true; } } if (flag == false) { One_spend_categories newspc = new One_spend_categories(); newspc.Name = item.Categories; Add_category(newspc); } } }
}//сохранение private void загрузитьToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog open = new OpenFileDialog(); string path = ""; if (open.ShowDialog() == DialogResult.OK) { path = open.FileName; } else { return; } XmlReader reader; categories.Clear(); persons.Clear(); spends.Clear(); // открытие существующего файла reader = XmlReader.Create(path); { One_person pers = new One_person(); One_spend spend = new One_spend(); One_spend_categories categ = new One_spend_categories(); short pass = 0; int i = 0; while (reader.Read()) { pers = new One_person(); spend = new One_spend(); categ = new One_spend_categories(); if (reader.NodeType == XmlNodeType.Element && reader.Name == "Spend") { while (reader.Read() || pass == 0) { if (pass > 0) { break; } if (reader.NodeType == XmlNodeType.Element && reader.Name == "_person") { pass = 1; break; } if (i > 6) { i = 0; Add_spends(spend); spends.Add(spend); spend = new One_spend(); } if (reader.NodeType == XmlNodeType.Text) { if (reader.Value != "" && reader.Value != " ") { switch (i) { case 0: spend.ID = int.Parse(reader.Value); i++; break; case 1: spend.Name = reader.Value; i++; break; case 2: spend.Categories = reader.Value; i++; break; case 3: spend.Person = reader.Value; i++; break; case 4: DateTime dateTimeStart = DateTime.Parse(reader.Value); spend.Date = dateTimeStart; i++; break; case 5: spend.Notion = reader.Value; i++; break; case 6: spend.Price = int.Parse(reader.Value); i++; break; } } } } }//добавление спендов if (reader.NodeType == XmlNodeType.Element && reader.Name == "_person")// не читает первую { int count = 0; while (reader.Read() || pass == 1) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "_category") { pass = 2; break; } if (i > 1) { i = 0; Add_person(pers); pers = new One_person(); } if (reader.NodeType == XmlNodeType.Text) { if (reader.Value != "" && reader.Value != " ") { switch (i) { case 0: pers.Name = reader.Value; i++; break; case 1: pers.Notion = reader.Value; i++; count++; label5.Text = count.ToString(); break; } } } } ; }//добавление персон if (reader.NodeType == XmlNodeType.Element && reader.Name == "_category") { while (reader.Read() || pass == 2) { if (reader.Value == "1488_8841") { pass = 3; break; } if (i > 1) { i = 0; Add_category(categ); categ = new One_spend_categories(); } if (reader.NodeType == XmlNodeType.Text) { if (reader.Value != "" && reader.Value != " ") { switch (i) { case 0: categ.Name = reader.Value; i++; break; case 1: categ.Notion = reader.Value; i++; break; } } } } }//добавление категорий } } new_id = spends.Count(); reader.Close(); // search_categ(); refresh(); }
public void Add_category(One_spend_categories categ) { comboBox2.Items.Add(categ.Name); categories.Add(categ); }