Пример #1
0
        public CurrentState_Record_Screen(int id)
        {
            InitializeComponent();
            index = id;
            string[] file = File.ReadAllLines(@"CurrentStateList.txt");
            Account.Text = file[0] + " руб.";
            Today.Text   = DateTime.Today.ToShortDateString();

            if (index != -1)
            {
                file = file[index + 2].Split(';');
                if (bool.Parse(file[1]))
                {
                    string[] categories = { "Стипендия", "Пенсия", "Долг", "Подарок", "Компенсация", "Подработка", "яя" };
                    Array.Sort(categories);
                    categories[categories.Length - 1] = "Другое";
                    Category.Items.AddRange(categories);
                }
                else
                {
                    string[] categories = { "Питание",    "Одежда", "Долг",          "Транспорт", "Интернет", "Телефон", "ЖКУ", "Подарки", "Техника",
                                            "Канцелярия", "Книги",  "Бытовая химия", "Ремонт",    "Лечение",  "яя" };
                    Array.Sort(categories);
                    categories[categories.Length - 1] = "Другое";
                    Category.Items.AddRange(categories);
                }
                EditRecord      = new CurrentState_Record(int.Parse(file[0]), file[3], float.Parse(file[4]), file[5], DateTime.Parse(file[2]), bool.Parse(file[1]));
                Category.Text   = EditRecord.GetCategory;
                Amount.Text     = EditRecord.GetAmount.ToString();
                Commentary.Text = EditRecord.GetComment;
                if (Commentary.Text == "0")
                {
                    Commentary.Text = "";
                }
            }
            else
            {
                string[] f = file[file.Length - 1].Split(';');
                if (bool.Parse(f[1]))
                {
                    string[] categories = { "Стипендия", "Пенсия", "Долг", "Подарок", "Компенсация", "Подработка", "яя" };
                    Array.Sort(categories);
                    categories[categories.Length - 1] = "Другое";
                    Category.Items.AddRange(categories);
                }
                else
                {
                    string[] categories = { "Питание",    "Одежда", "Долг",          "Транспорт", "Интернет", "Телефон", "ЖКУ", "Подарки", "Техника",
                                            "Канцелярия", "Книги",  "Бытовая химия", "Ремонт",    "Лечение",  "яя" };
                    Array.Sort(categories);
                    categories[categories.Length - 1] = "Другое";
                    Category.Items.AddRange(categories);
                }
            }
            category   = Category.Text;
            amount     = Amount.Text;
            commentary = Commentary.Text;
        }
Пример #2
0
        private void Save_Click(object sender, EventArgs e)
        {
            if (Category.Text == "")
            {
                MessageBox.Show("Укажите категорию", "Не заполнены обязательные поля", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                Category.DroppedDown = true;
                return;
            }
            if (Amount.Text == "")
            {
                MessageBox.Show("Укажите сумму", "Не заполнены обязательные поля", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                Amount.Focus();
                return;
            }
            if (!float.TryParse(Amount.Text, out float amount) || amount <= 0)
            {
                MessageBox.Show("Данные в поле \"Сумма\" введены неверно", "Не заполнены обязательные поля", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                Amount.Focus();
                Amount.Text = "";
                return;
            }
            if (amount > 1000000)
            {
                MessageBox.Show("Введено слишком большое значение!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                Amount.Focus();
                Amount.Text = "";
                return;
            }
            string category, commentary;

            category = Category.Text;
            if (Commentary.Text == "")
            {
                commentary = "0";
            }
            else
            {
                commentary = Commentary.Text;
            }
            if (index < 0)
            {
                CurrentState_Record NewRecord = new CurrentState_Record();
                NewRecord.Write(category, (float)Math.Round(amount, 2), commentary);
            }
            else
            {
                EditRecord.Edit(category, (float)Math.Round(amount, 2), commentary);
            }
            this.Close();
        }
Пример #3
0
        public CurrentState_Screen()
        {
            InitializeComponent();

            History_Record Transfer = new History_Record();

            Transfer.Write();

            StreamReader sr = new StreamReader(@"CurrentStateList.txt");

            account = float.Parse(sr.ReadLine());

            Today.Text   = DateTime.Today.ToShortDateString();
            Account.Text = Math.Round(account, 2).ToString() + " руб.";

            n = int.Parse(sr.ReadLine());

            CurrentState_Record[] CurrentStateRecord = new CurrentState_Record[n];
            for (int i = 0; i < n; i++)
            {
                CurrentStateRecord[i] = new CurrentState_Record();
                if (!CurrentStateRecord[i].Read(sr))
                {
                    MessageBox.Show("Произошла ошибка при загрузке данных. Текущее состояние счёта будет очищено, приложение перезагружено.",
                                    "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    sr.Close();

                    StreamWriter sw = new StreamWriter(@"CurrentStateList.txt", false);
                    sw.Write("");
                    sw.Close();
                    Application.Restart();
                }

                CurrentStateList.Columns[0].Text = DateTime.Today.ToLongDateString();

                CurrentStateList.Items.Add(CurrentStateRecord[i].GetCategory);
                CurrentStateList.Items[3 * i].Font = new Font("Century Gothic", 10, FontStyle.Bold);

                string amount = CurrentStateRecord[i].GetIncrease ? "+" : "-";
                amount += CurrentStateRecord[i].GetAmount + " руб.";
                CurrentStateList.Items.Add(amount);
                CurrentStateList.Items[3 * i + 1].Font      = new Font("Century Gothic", 15, FontStyle.Bold);
                CurrentStateList.Items[3 * i + 1].ForeColor = CurrentStateRecord[i].GetIncrease ? Color.FromArgb(0, 142, 63) : Color.FromArgb(144, 12, 10); //зеленый : красный

                CurrentStateList.Items.Add(CurrentStateRecord[i].GetComment);
                CurrentStateList.Items[3 * i + 2].Font = new Font("Century Gothic", 10);
            }
            sr.Close();
        }