Esempio n. 1
0
        public void UpdateForm()
        {
            string month      = currMonthLabel.Text.Substring(0, (currMonthLabel.Text.Length - 5));
            string year       = currMonthLabel.Text.Substring(currMonthLabel.Text.Length - 4);
            int    a          = Array.IndexOf(_monthArray, month);
            int    monthQuery = a + 1;
            int    yearQuery  = int.Parse(year);

            using (var repo = new IncomeRepo())
            {
                incomeDataGridView.DataSource =
                    (repo.GetAll()).FindAll(
                        x =>
                        (x.Month == monthQuery && x.Year == yearQuery &&
                         x.Account_ID == _currentAccount));
            }
            using (var repo = new OutlayRepo())
            {
                outlayDataGridView.DataSource =
                    (repo.GetAll()).FindAll(
                        x =>
                        (x.Month == monthQuery && x.Year == yearQuery &&
                         x.Account_ID == _currentAccount));
            }
            toolStrip2.Items.Clear();
            using (var repo = new AccountRepo())
            {
                foreach (var item in repo.GetAll())
                {
                    var b = new ToolStripButton
                    {
                        Text       = item.Name + "\nБаланс: " + item.CurrentAmount,
                        Tag        = item.ID,
                        Image      = imageList1.Images[int.Parse(item.IconID.ToString())],
                        ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
                    };
                    b.Click += Butt_Click;
                    toolStrip2.Items.Add(b);
                }
            }
        }
Esempio n. 2
0
        public void PrevMonthButton_Click(object sender, EventArgs e)
        {
            string month = currMonthLabel.Text.Substring(0, (currMonthLabel.Text.Length - 5));
            string year  = currMonthLabel.Text.Substring(currMonthLabel.Text.Length - 4);
            int    a     = Array.IndexOf(_monthArray, month);

            if (a == 0)
            {
                currMonthLabel.Text = currMonthLabel.Text.Replace(_monthArray[a], _monthArray[11]);
                currMonthLabel.Text = currMonthLabel.Text.Replace(year, (int.Parse(year) - 1).ToString());
                a = 11;
            }
            else
            {
                currMonthLabel.Text = currMonthLabel.Text.Replace(_monthArray[a], _monthArray[a - 1]);
                a--;
            }
            year = currMonthLabel.Text.Substring(currMonthLabel.Text.Length - 4);
            using (var repo = new IncomeRepo())
            {
                int monthQuery = a + 1;
                int yearQuery  = int.Parse(year);
                incomeDataGridView.DataSource =
                    (repo.GetAll()).FindAll(
                        x =>
                        (x.Month == monthQuery && x.Year == yearQuery &&
                         x.Account_ID == _currentAccount));
            }
            using (var repo = new OutlayRepo())
            {
                int monthQuery = a + 1;
                int yearQuery  = int.Parse(year);
                outlayDataGridView.DataSource =
                    (repo.GetAll()).FindAll(
                        x =>
                        (x.Month == monthQuery && x.Year == yearQuery &&
                         x.Account_ID == _currentAccount));
            }
        }
Esempio n. 3
0
        public void UpdateForm()
        {
            string        month      = currMonthLabel.Text.Substring(0, (currMonthLabel.Text.Length - 5));
            string        year       = currMonthLabel.Text.Substring(currMonthLabel.Text.Length - 4);
            int           index      = Array.IndexOf(_monthArray, month);
            int           monthQuery = index + 1;
            int           yearQuery  = int.Parse(year);
            List <Person> personList;

            try
            {
                using (var repo = new PersonRepo())
                {
                    personList = repo.GetAll();
                }
                if (_typeOfData == 1)
                {
                    List <Income> incomeList;
                    using (var repo = new IncomeRepo())
                    {
                        incomeList = (repo.GetAll()).FindAll(x =>
                                                             (x.Month == monthQuery && x.Year == yearQuery));
                    }
                    var list = (from a in incomeList
                                from b in personList
                                where (a.Person_ID == b.ID)
                                select
                                new
                    {
                        Name = b.Name,
                        Sum = (from m in incomeList where m.Person_ID == b.ID select m.Value).Sum()
                    })
                               .Distinct().ToList();
                    chart1.DataSource = list;
                    chart2.DataSource = list;
                }
                else
                {
                    List <Outlay> outlayList;
                    using (var repo = new OutlayRepo())
                    {
                        outlayList = (repo.GetAll()).FindAll(x =>
                                                             (x.Month == monthQuery && x.Year == yearQuery));
                    }
                    var list = (from a in outlayList
                                from b in personList
                                where (a.Person_ID == b.ID)
                                select
                                new
                    {
                        Name = b.Name,
                        Sum = (from m in outlayList where m.Person_ID == b.ID select m.Value).Sum()
                    })
                               .Distinct().ToList();
                    chart1.DataSource = list;
                    chart2.DataSource = list;
                    chart1.Series["Series1"].Color = System.Drawing.Color.Red;
                    chart2.Series["Series1"].Color = System.Drawing.Color.Red;
                }

                chart1.Series["Series1"].XValueMember  = "Name";
                chart1.Series["Series1"].XValueType    = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Int32;
                chart1.Series["Series1"].YValueMembers = "Sum";
                chart1.Series["Series1"].YValueType    = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Int32;

                chart2.Series["Series1"].XValueMember  = "Name";
                chart2.Series["Series1"].XValueType    = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Int32;
                chart2.Series["Series1"].YValueMembers = "Sum";
                chart2.Series["Series1"].YValueType    = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Int32;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 4
0
        public void ExportDatabase(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            var path = folderBrowserDialog1.SelectedPath;

            using (var repo = new AccountRepo())
            {
                var xEle = new XElement("Accounts",
                                        repo.GetAll().Select(account => new XElement("Account",
                                                                                     new XAttribute("ID", account.ID),
                                                                                     new XElement("Name", account.Name),
                                                                                     new XElement("CurrentAmount", account.CurrentAmount)
                                                                                     )));
                xEle.Save($"{path}\\accounts.xml");
            }
            using (var repo = new TypeRepo())
            {
                var xEle = new XElement("Types",
                                        repo.GetAll().Select(type => new XElement("Type",
                                                                                  new XAttribute("ID", type.ID),
                                                                                  new XElement("Name", type.Name)
                                                                                  )));
                xEle.Save($"{path}\\types.xml");
            }
            using (var repo = new PersonRepo())
            {
                var xEle = new XElement("Persons",
                                        repo.GetAll().Select(account => new XElement("Person",
                                                                                     new XAttribute("ID", account.ID),
                                                                                     new XElement("Name", account.Name)
                                                                                     )));
                xEle.Save($"{path}\\persons.xml");
            }
            using (var repo = new IncomeRepo())
            {
                var xEle = new XElement("Incomes",
                                        repo.GetAll().Select(income => new XElement("Income",
                                                                                    new XAttribute("ID", income.ID),
                                                                                    new XElement("Account", income.Account),
                                                                                    new XElement("Day", income.Day),
                                                                                    new XElement("Month", income.Month),
                                                                                    new XElement("Year", income.Year),
                                                                                    new XElement("Person", income.Person),
                                                                                    new XElement("Type", income.Type),
                                                                                    new XElement("Account", income.Value),
                                                                                    new XElement("Comment", income.Comment)
                                                                                    )));
                xEle.Save($"{path}\\incomes.xml");
            }
            using (var repo = new OutlayRepo())
            {
                var xEle = new XElement("Outlays",
                                        repo.GetAll().Select(outlay => new XElement("Outlay",
                                                                                    new XAttribute("ID", outlay.ID),
                                                                                    new XElement("Account", outlay.Account),
                                                                                    new XElement("Day", outlay.Day),
                                                                                    new XElement("Month", outlay.Month),
                                                                                    new XElement("Year", outlay.Year),
                                                                                    new XElement("Person", outlay.Person),
                                                                                    new XElement("Type", outlay.Type),
                                                                                    new XElement("Account", outlay.Value),
                                                                                    new XElement("Comment", outlay.Comment)
                                                                                    )));
                xEle.Save($"{path}\\outlays.xml");
            }
        }