Esempio n. 1
0
        public Change_spend(Form1 F, One_spend spend, int pos)
        {
            F1         = F;
            this.spend = spend;
            this.pos   = pos;
            InitializeComponent();

            foreach (var item in F1.persons)
            {
                comboBox1.Items.Add(item.Name);
            }

            foreach (var item in F1.categories)
            {
                comboBox2.Items.Add(item.Name);
            }

            textBox1.Text         = spend.ID.ToString();
            textBox2.Text         = spend.Notion;
            textBox3.Text         = spend.Price.ToString();
            textBox4.Text         = spend.Name;
            comboBox1.Text        = spend.Person;
            comboBox2.Text        = spend.Categories;
            dateTimePicker1.Value = spend.Date;
        }
Esempio n. 2
0
        public void Add_spends(One_spend spend)
        {
            ListViewItem item = new ListViewItem(spend.ID.ToString());

            item.SubItems.Add(spend.Person);
            item.SubItems.Add(spend.Name);
            item.SubItems.Add(spend.Date.ToString());
            item.SubItems.Add(spend.Categories);
            item.SubItems.Add(spend.Price.ToString());
            listView1.Items.Add(item);
        }
Esempio n. 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            One_spend new_spend = new One_spend();

            new_spend.ID         = spend.ID;
            new_spend.Notion     = textBox2.Text;
            new_spend.Price      = int.Parse(textBox3.Text);
            new_spend.Name       = textBox4.Text;
            new_spend.Person     = comboBox1.Text;
            new_spend.Categories = comboBox2.Text;
            new_spend.Date       = dateTimePicker1.Value;

            F1.spends.RemoveAt(pos);
            F1.spends.Insert(pos, new_spend);
            F1.refresh();
        }
Esempio n. 4
0
        }//

        private void коррекцияToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ListView.SelectedIndexCollection sic = listView1.SelectedIndices; //колекция выбранных индесков

            foreach (int item in sic)
            {
                active_in = item; //определяет активный индекс клиента, важный элемент управления
            }
            if (sic.Count == 0)
            {
                textBox2.Text = "";
            }
            else
            {
                One_spend    to_change = spends[active_in];
                Change_spend spend     = new Change_spend(this, to_change, active_in);
                spend.Show(this);  //открыть окно с полями, передать в него объект этой формы
            }
        }
Esempio n. 5
0
        private void button3_Click(object sender, EventArgs e)
        {
            MatchCollection m         = Regex.Matches(textBox3.Text, "[0-9]+", RegexOptions.IgnoreCase);
            One_spend       new_spend = new One_spend();
            string          p         = "";

            foreach (Match match in m)
            {
                p += match;
            }

            if (p == "")
            {
                p = "0";
            }
            new_spend.Price      = int.Parse(p);
            new_spend.ID         = F1.new_id;
            new_spend.Name       = textBox2.Text;
            new_spend.Categories = comboBox1.Text;
            new_spend.Person     = comboBox2.Text;
            new_spend.Notion     = textBox1.Text;
            new_spend.Date       = dateTimePicker1.Value;

            if (new_spend.Name == "" || new_spend.Name == " ")
            {
                new_spend.Name = "No name";
            }
            if (new_spend.Categories == "" || new_spend.Categories == " ")
            {
                new_spend.Categories = "No name";
            }
            if (new_spend.Person == "" || new_spend.Person == " ")
            {
                new_spend.Person = "No name";
            }


            F1.spends.Add(new_spend);
            F1.Add_spends();
            this.Close();
        }
Esempio n. 6
0
        }//сохранение

        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();
        }