Esempio n. 1
0
        public List <IncomeDomain> GetIncomes(int fromMonthIndex, int toMonthIndex, int year)
        {
            SQLiteCommand command = new SQLiteCommand("select * from income where (month >= @frommonthindex and month <= @tomonthindex) and year=@year ", DatabaseManager.SQLiteConnection);

            command.Parameters.Add(new SQLiteParameter("frommonthindex", fromMonthIndex));
            command.Parameters.Add(new SQLiteParameter("tomonthindex", toMonthIndex));
            command.Parameters.Add(new SQLiteParameter("year", year));
            SQLiteDataReader reader = command.ExecuteReader();

            List <IncomeDomain> incomes = new List <IncomeDomain>();

            while (reader.Read())
            {
                IncomeDomain income = new IncomeDomain();
                income.Id             = Convert.ToInt32(reader["id"]);
                income.IncomeSourceId = reader["income_source_id"] != null?Convert.ToInt32(reader["income_source_id"]) : 0;

                income.Amount = Convert.ToDouble(reader["amount"]);
                income.Month  = reader["month"] != null?Convert.ToInt32(reader["month"]) : 0;

                income.Year = reader["year"] != null?Convert.ToInt32(reader["year"]) : 0;

                incomes.Add(income);
            }

            return(incomes);
        }
Esempio n. 2
0
        private void incomeDataGridView_SelectionChanged(object sender, EventArgs e)
        {
            if ((_setSelectedIncome && (incomeDataGridView.SelectedRows == null || incomeDataGridView.SelectedRows.Count == 0)) ||
                (!_setSelectedIncome && _selectedIncome == null))
            {
                return;
            }

            if (_setSelectedIncome)
            {
                _selectedIncome = incomeDataGridView.SelectedRows[0].DataBoundItem as IncomeDomain;
            }

            IncomeSourceDomain incomeSource = _incomeSources.Find(p => p.Id == _selectedIncome.IncomeSourceId);

            incomeSourceComboBox.SelectedItem = incomeSource;

            Month month = _months.Find(p => p.Index == _selectedIncome.Month);

            monthComboBox.SelectedItem = month;

            yearTextBox.Text   = _selectedIncome.Year.ToString();
            amountTextBox.Text = _selectedIncome.Amount.ToString();

            _setSelectedIncome = true;
        }
Esempio n. 3
0
        public void Delete(IncomeDomain income)
        {
            SQLiteCommand command = new SQLiteCommand("delete from income where id=@incomeid", DatabaseManager.SQLiteConnection);

            command.Parameters.Add(new SQLiteParameter("incomeid", income.Id));

            command.ExecuteNonQuery();
        }
Esempio n. 4
0
        public IncomeDomain AddIncome(IncomeSourceDomain incomeSource, int month, int year, double amount)
        {
            IncomeDomain income = new IncomeDomain();

            income.IncomeSourceId = incomeSource.Id;
            income.Month          = month;
            income.Year           = year;
            income.Amount         = amount;

            return(DaoFactory.IncomeDao.Save(income));
        }
Esempio n. 5
0
        public IncomeDomain Update(IncomeDomain income)
        {
            SQLiteCommand command = new SQLiteCommand("update income set income_source_id=@incomesourceid, month=@month, year=@year, amount=@amount where id=@incomeid", DatabaseManager.SQLiteConnection);

            command.Parameters.Add(new SQLiteParameter("incomeid", income.Id));
            command.Parameters.Add(new SQLiteParameter("incomesourceid", income.IncomeSourceId));
            command.Parameters.Add(new SQLiteParameter("amount", income.Amount));
            command.Parameters.Add(new SQLiteParameter("month", income.Month));
            command.Parameters.Add(new SQLiteParameter("year", income.Year));

            command.ExecuteNonQuery();

            return(income);
        }
Esempio n. 6
0
        private void deleteToolStripButton_Click(object sender, EventArgs e)
        {
            if (_selectedIncome == null)
            {
                return;
            }

            LogicFactory.IncomeLogic.DeleteIncome(_selectedIncome);

            _incomes.Remove(_selectedIncome);

            _filterActive      = false;
            _selectedIncome    = null;
            _setSelectedIncome = true;
            RefreshGrid();
        }
Esempio n. 7
0
        public IncomeDomain Save(IncomeDomain income)
        {
            SQLiteCommand command = new SQLiteCommand("insert into income (income_source_id, amount, month, year) values " +
                                                      "(@incomesourceid, @amount, @month, @year)", DatabaseManager.SQLiteConnection);

            command.Parameters.Add(new SQLiteParameter("incomesourceid", income.IncomeSourceId));
            command.Parameters.Add(new SQLiteParameter("amount", income.Amount));
            command.Parameters.Add(new SQLiteParameter("month", income.Month));
            command.Parameters.Add(new SQLiteParameter("year", income.Year));
            command.ExecuteNonQuery();

            command = new SQLiteCommand("select last_insert_rowid()", DatabaseManager.SQLiteConnection);
            Int64 id = (Int64)command.ExecuteScalar();

            income.Id = (int)id;

            return(income);
        }
Esempio n. 8
0
        private void SelectIncomeOnTheGrid(int incomeId)
        {
            int index = 0;

            foreach (DataGridViewRow row in incomeDataGridView.Rows)
            {
                IncomeDomain income = row.DataBoundItem as IncomeDomain;
                if (income.Id == incomeId)
                {
                    _selectedIncome = income;
                    break;
                }

                index++;
            }

            incomeDataGridView.Rows[index].Selected = true;
        }
Esempio n. 9
0
        public List <IncomeDomain> GetAllIncomes()
        {
            SQLiteCommand    command = new SQLiteCommand("select * from income", DatabaseManager.SQLiteConnection);
            SQLiteDataReader reader  = command.ExecuteReader();

            List <IncomeDomain> incomes = new List <IncomeDomain>();

            while (reader.Read())
            {
                IncomeDomain income = new IncomeDomain();
                income.Id             = Convert.ToInt32(reader["id"]);
                income.IncomeSourceId = reader["income_source_id"] != null?Convert.ToInt32(reader["income_source_id"]) : 0;

                income.Amount = Convert.ToDouble(reader["amount"]);
                income.Month  = reader["month"] != null?Convert.ToInt32(reader["month"]) : 0;

                income.Year = reader["year"] != null?Convert.ToInt32(reader["year"]) : 0;

                incomes.Add(income);
            }

            return(incomes);
        }
Esempio n. 10
0
 public void DeleteIncome(IncomeDomain income)
 {
     DaoFactory.IncomeDao.Delete(income);
 }
Esempio n. 11
0
 public IncomeDomain UpdateIncome(IncomeDomain income)
 {
     return(DaoFactory.IncomeDao.Update(income));
 }
Esempio n. 12
0
        private void saveToolStripButton_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(yearTextBox.Text) || !_numericRegex.IsMatch(yearTextBox.Text))
            {
                MessageBox.Show("Tahun tidak boleh kosong dah harus diisi dengan angka!", null, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (!String.IsNullOrEmpty(amountTextBox.Text) && !_numericRegex.IsMatch(amountTextBox.Text))
            {
                MessageBox.Show("Nominal harus diisi dengan angka!", null, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            IncomeSourceDomain incomeSource = incomeSourceComboBox.SelectedItem as IncomeSourceDomain;
            Month  month  = monthComboBox.SelectedValue as Month;
            int    year   = Convert.ToInt32(yearTextBox.Text);
            double amount = 0;

            if (!String.IsNullOrEmpty(amountTextBox.Text))
            {
                amount = Convert.ToDouble(amountTextBox.Text);
            }

            if (_uiMode == UserInterfaceModes.Adding)
            {
                IncomeDomain income = LogicFactory.IncomeLogic.AddIncome(incomeSource, month.Index, year, amount);

                income.DisplayedMonth          = month.Name;
                income.DisplayedAmount         = amount.ToString("#,##0");
                income.IncomeSourceDescription = incomeSource.Description;

                _incomes.Add(income);

                _selectedIncome = income;
            }
            else if (_uiMode == UserInterfaceModes.Editing)
            {
                _selectedIncome.IncomeSourceId = incomeSource.Id;
                _selectedIncome.Month          = month.Index;
                _selectedIncome.Year           = year;
                _selectedIncome.Amount         = amount;

                IncomeDomain income = LogicFactory.IncomeLogic.UpdateIncome(_selectedIncome);
                income.DisplayedMonth  = month.Name;
                income.DisplayedAmount = amount.ToString("#,##0");

                int index = _incomes.IndexOf(_selectedIncome);
                _incomes.Remove(_selectedIncome);
                _incomes.Insert(index, income);

                _selectedIncome = income;
            }

            _uiMode = UserInterfaceModes.Viewing;
            SetUIControlsAvailability();

            _filterActive      = false;
            _setSelectedIncome = false;
            RefreshGrid();
        }