コード例 #1
0
        public void outlayAddButton_Click(object sender, EventArgs e)
        {
            var      a  = outlayAccountComboBox.SelectedItem as Account;
            var      p  = outlayPersonComboBox.SelectedItem as Person;
            var      t  = outlayTypeComboBox.SelectedItem as Type;
            DateTime dt = outlayDatePicker.Value;

            try
            {
                if (o == null)
                {
                    using (var repo = new OutlayRepo())
                    {
                        repo.Add(new Outlay()
                        {
                            Account_ID = a.ID,
                            Day        = dt.Day,
                            Month      = dt.Month,
                            Year       = dt.Year,
                            Person_ID  = p.ID,
                            Type_ID    = t.ID,
                            Value      = double.Parse(outlayValueBox.Text),
                            Comment    = outlayCommentBox.Text
                        });
                    }
                    using (var repo = new AccountRepo())
                    {
                        a.CurrentAmount -= double.Parse(outlayValueBox.Text);
                        repo.Save(a);
                    }
                }
                else
                {
                    using (var repo = new AccountRepo())
                    {
                        a.CurrentAmount += o.Value;
                        a.CurrentAmount -= double.Parse(outlayValueBox.Text);
                        repo.Save(a);
                    }
                    using (var repo = new OutlayRepo())
                    {
                        o.Account_ID = a.ID;
                        o.Day        = dt.Day;
                        o.Month      = dt.Month;
                        o.Year       = dt.Year;
                        o.Person_ID  = p.ID;
                        o.Type_ID    = t.ID;
                        o.Value      = double.Parse(outlayValueBox.Text);
                        o.Comment    = outlayCommentBox.Text;
                        repo.Save(o);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #2
0
 public void DeleteOperation(object sender, EventArgs e)
 {
     if (_currentGridView == 0)
     {
         return;
     }
     if (_currentGridView == 1)
     {
         var i = incomeDataGridView.CurrentRow?.DataBoundItem as Income;
         if (i == null)
         {
             return;
         }
         if (MessageBox.Show(@"Видалити обране поле?", @"Видалення", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) ==
             DialogResult.OK)
         {
             using (var repo = new AccountRepo())
             {
                 var a = repo.GetOne(_currentAccount);
                 a.CurrentAmount -= i.Value;
                 repo.Save(a);
             }
             using (var repo = new IncomeRepo())
             {
                 repo.Delete(i);
             }
         }
     }
     else
     {
         var o = outlayDataGridView.CurrentRow?.DataBoundItem as Outlay;
         if (o == null)
         {
             return;
         }
         if (MessageBox.Show(@"Видалити обране поле?", @"Видалення", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) ==
             DialogResult.OK)
         {
             using (var repo = new AccountRepo())
             {
                 var a = repo.GetOne(_currentAccount);
                 a.CurrentAmount -= o.Value;
                 repo.Save(a);
             }
             using (var repo = new OutlayRepo())
             {
                 repo.Delete(o);
             }
         }
     }
     UpdateForm();
 }
コード例 #3
0
 public void DetInfoForm_Load(object sender, EventArgs e)
 {
     try
     {
         if (_typeOfData == 1)
         {
             Text = "Дохід";
             using (var repo = new IncomeRepo())
             {
                 var i = repo.GetOne(_id);
                 dayBox.Text     = i.Day.ToString();
                 monthBox.Text   = i.Month.ToString();
                 yearBox.Text    = i.Year.ToString();
                 personBox.Text  = i.Person.Name;
                 accountBox.Text = i.Account.Name;
                 typeBox.Text    = i.Type.Name;
                 valieBox.Text   = i.Value.ToString();
                 commentBox.Text = i.Comment;
             }
         }
         else
         {
             Text = "Витрата";
             using (var repo = new OutlayRepo())
             {
                 var o = repo.GetOne(_id);
                 dayBox.Text     = o.Day.ToString();
                 monthBox.Text   = o.Month.ToString();
                 yearBox.Text    = o.Year.ToString();
                 personBox.Text  = o.Person.Name;
                 accountBox.Text = o.Account.Name;
                 typeBox.Text    = o.Type.Name;
                 valieBox.Text   = o.Value.ToString();
                 commentBox.Text = o.Comment;
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
コード例 #4
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);
                }
            }
        }
コード例 #5
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));
            }
        }
コード例 #6
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);
            }
        }
コード例 #7
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");
            }
        }