private void button1_Click(object sender, EventArgs e)
        {
            if (txtName.Text == "" || txtPassword.Text == "" ||
                txtKeyword.Text == "")
            {
                errorProvider1.SetError(txtName, "Please enter a name");
                errorProvider2.SetError(txtPassword, "Please enter a password");
                errorProvider3.SetError(txtKeyword, "Please enter a keyword");
            }
            else
            {
                errorProvider1.Dispose();
                errorProvider2.Dispose();
                errorProvider3.Dispose();
                using (var budgetContext = new BudgetEntities())
                {
                    var user = budgetContext.Accounts.Where(acc => acc.Name.Equals(txtName.Text) &&
                                                            acc.KeyWord.Equals(txtKeyword.Text)).FirstOrDefault();

                    if (user != null)
                    {
                        user.Password = txtPassword.Text;
                        budgetContext.Entry(user).State = EntityState.Modified;
                        budgetContext.SaveChanges();
                        MessageBox.Show("Success!");
                    }
                    else
                    {
                        label4.Text = "Invalid keyword or name !";
                    }
                }
            }
        }
Example #2
0
        private void buttonUpdate_Click(object sender, EventArgs e)
        {
            if (this.dataGridUsers.SelectedRows.Count > 0)
            {
                using (var budgetContext = new BudgetEntities())
                {
                    foreach (DataGridViewRow item in this.dataGridUsers.SelectedRows)
                    {
                        var id   = Convert.ToInt32(item.Cells[0].Value);
                        var user = budgetContext.Accounts.Where(u => u.Id == id).FirstOrDefault();
                        user.Name     = Convert.ToString(item.Cells[1].Value);
                        user.Password = Convert.ToString(item.Cells[2].Value);
                        user.KeyWord  = Convert.ToString(item.Cells[3].Value);

                        budgetContext.Entry(user).State = EntityState.Modified;
                    }
                    budgetContext.SaveChanges();
                    MessageBox.Show("Users have been edited !");
                }
            }
            else
            {
                MessageBox.Show("Please select one row");
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (txtName.Text == "" || txtPassword.Text == "" ||
                txtKeyWord.Text == "")
            {
                errorProvider1.SetError(txtName, "Please enter a name");
                errorProvider2.SetError(txtPassword, "Please enter a password");
                errorProvider3.SetError(txtKeyWord, "Please enter a keyword");
            }
            else
            {
                errorProvider1.Dispose();
                errorProvider2.Dispose();
                errorProvider3.Dispose();
                using (var budgetContext = new BudgetEntities())
                {
                    var user = new Account();
                    user.Name     = txtName.Text;
                    user.Password = txtPassword.Text;
                    user.KeyWord  = txtKeyWord.Text;
                    user.Enabled  = true;

                    budgetContext.Accounts.Add(user);
                    budgetContext.SaveChanges();
                    EmptyFields();
                    MessageBox.Show("User successful registered !");
                }
            }
        }
Example #4
0
        private void UsersForm_Load(object sender, EventArgs e)
        {
            using (var budgetContext = new BudgetEntities())
            {
                var list = budgetContext.Accounts.ToList();
                usersList = (from usr in list
                             select new User
                {
                    Id = usr.Id,
                    Name = usr.Name,
                    Password = usr.Password,
                    KeyWord = usr.KeyWord
                }).ToList();

                dataGridUsers.DataSource = usersList;
            }
        }
Example #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            using (var budgetContext = new BudgetEntities())
            {
                var user = budgetContext.Accounts.Where(acc => acc.Name.Equals(textBox1.Text) &&
                                                        acc.Password.Equals(textBox2.Text) && acc.Enabled).FirstOrDefault();

                if (user != null)
                {
                    var form = new PersonalBudget(user.Id, user.Name);
                    form.Show();
                    this.Hide();
                }
                else
                {
                    label3.Text = "Invalid username or password !";
                }
            }
        }
        private async void button6_Click(object sender, EventArgs e)
        {
            decimal outValue    = 0;
            decimal inValue     = 0;
            decimal profitValue = 0;

            ClearCharts();

            using (var db = new BudgetEntities())
            {
                if (rbYears.Checked)
                {
                    var nrYears = dtProfitEnd.Value.Year - dtProfitStart.Value.Year;

                    for (int i = 0; i <= nrYears; i++)
                    {
                        decimal?outgoings = db.Outgoings.Where(o => o.StartDate.Year == dtProfitStart.Value.Year + i).Count() > 0 ?
                                            db.Outgoings.Where(o => o.StartDate.Year == dtProfitStart.Value.Year + i).Sum(a => a.Amount) : 0;
                        outValue += outgoings.Value;

                        decimal?incomes = db.Incomes.Where(o => o.StartDate.Year == dtProfitStart.Value.Year + i).Count() > 0
                            ? db.Incomes.Where(o => o.StartDate.Year == dtProfitStart.Value.Year + i).Sum(a => a.Amount) : 0;
                        inValue += incomes.Value;

                        decimal?profit = incomes - outgoings;
                        profitValue += profit.Value;

                        chart1.Series["Profit"].Points.AddXY(dtProfitStart.Value.Year + i, profit);
                        chart1.Series["Profit"].IsValueShownAsLabel = true;
                        chart2.Series["Income"].Points.AddXY(dtProfitStart.Value.Year + i, incomes);
                        chart2.Series["Income"].IsValueShownAsLabel = true;
                        chart3.Series["Outgoings"].Points.AddXY(dtProfitStart.Value.Year + i, outgoings);
                        chart3.Series["Outgoings"].IsValueShownAsLabel = true;
                    }
                }

                if (rbMonths.Checked)
                {
                    if (dtProfitEnd.Value.Year == dtProfitStart.Value.Year)
                    {
                        var nrMonths = dtProfitEnd.Value.Month - dtProfitStart.Value.Month;

                        for (int i = 0; i <= nrMonths; i++)
                        {
                            decimal?outgoings = db.Outgoings.Where(o => o.StartDate.Month == dtProfitStart.Value.Month + i).Count() > 0 ?
                                                db.Outgoings.Where(o => o.StartDate.Month == dtProfitStart.Value.Month + i).Sum(a => a.Amount) : 0;
                            outValue += outgoings.Value;

                            decimal?incomes = db.Incomes.Where(o => o.StartDate.Month == dtProfitStart.Value.Month + i).Count() > 0
                                ? db.Incomes.Where(o => o.StartDate.Month == dtProfitStart.Value.Month + i).Sum(a => a.Amount) : 0;
                            inValue += incomes.Value;

                            decimal?profit = incomes - outgoings;
                            profitValue += profit.Value;

                            chart1.Series["Profit"].Points.AddXY(dtProfitStart.Value.Month + i, profit);
                            chart1.Series["Profit"].IsValueShownAsLabel = true;
                            chart2.Series["Income"].Points.AddXY(dtProfitStart.Value.Month + i, incomes);
                            chart2.Series["Income"].IsValueShownAsLabel = true;
                            chart3.Series["Outgoings"].Points.AddXY(dtProfitStart.Value.Month + i, outgoings);
                            chart3.Series["Outgoings"].IsValueShownAsLabel = true;
                        }
                    }
                }

                labelOutgoing.Text = outValue.ToString();
                labelIncome.Text   = inValue.ToString();
                labelProfit.Text   = profitValue.ToString();
            }
        }