private void ThisFormLoading(object sender, EventArgs e) { MonthlyInfo.Fetch(); BarChart.Series["Earning"].Color = Color.YellowGreen; BarChart.Series["Expense"].Color = Color.DarkOrange; for (int year = 2018; year <= _selectedYear + 3; year++) { YearComboBox.Items.Add(year.ToString()); } YearComboBox.SelectedIndex = 0; _isFirstCall = false; }
private void DeleteDailyInfo(bool manuallyRemoveRow = false) { string message = "Selected information will be permanently deleted. " + "Are you sure you want to delete the selected information?"; DialogResult userResponse = MessageBox.Show(message, "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (userResponse == DialogResult.No) { return; } foreach (DataGridViewRow row in MonthlyReportDataGridView.SelectedRows) { string[] date = row.Cells[0].Value.ToString().Split(' '); int day = Convert.ToInt32(date[0]); int month = _monthList.IndexOf(date[1].Replace(",", "")) + 1; int year = Convert.ToInt32(date[2]); string result = WebHandler.DeleteDailyInfo(day, month, year); if (result == "SUCCESS") { if (manuallyRemoveRow) { //when we delete a row on click of delete button //that doesn't automatically remove that row from dataGridView //so we need to manually remove it MonthlyReportDataGridView.Rows.RemoveAt(row.Index); } GlobalSpace.DailyInfoList.RemoveAll( d => d.Day == day && d.Month == month && d.Year == year); } else { //if the deleting doesn't succeed, the error info is returned MessageBox.Show("Something went wrong! Please check your internet connection and try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } //monthly info should change accordingly since daily info has been modified MonthlyInfo.Fetch(); UpdateTotalEarningAndExpenseLabel(); }
private void ShowOverview(MonthlyInfo monthly, int row) { //add an overview for that month on the last column of dataGridView if (monthly.Earning < monthly.Expense) { HomeDataGridView.Rows[row].Cells[4].Style.ForeColor = Color.Red; HomeDataGridView.Rows[row].Cells[4].Value = "Negative"; } else if (monthly.Earning > monthly.Expense) { HomeDataGridView.Rows[row].Cells[4].Style.ForeColor = Color.Green; HomeDataGridView.Rows[row].Cells[4].Value = "Positive"; } else { HomeDataGridView.Rows[row].Cells[4].Style.ForeColor = Color.OrangeRed; HomeDataGridView.Rows[row].Cells[4].Value = "Neutral"; } }
private void PlotGeneralYearlyExpenseDataOnChart(List <MonthlyInfo> monthlyInfo) { YearlyReportChart.Series["expense"].Points.Clear(); for (int month = 1; month <= 12; month++) { MonthlyInfo monthly = monthlyInfo.Find(m => m.Month == month); DataPoint point = new DataPoint(); if (monthly != null) { point.SetValueXY(_monthNames[month - 1], monthly.Expense); point.ToolTip = monthly.Expense.ToString(); YearlyReportChart.Series["expense"].Points.Add(point); } else { point.SetValueXY(_monthNames[month - 1], 0); point.ToolTip = "0.00"; YearlyReportChart.Series["expense"].Points.Add(point); } } }
private string SaveDailyInfo() { if (!_hasUnsavedChanges) { return("No changes to save."); } DailyInfo daily = new DailyInfo(); daily.Note = NoteTextBox.ForeColor == Color.Black ? NoteTextBox.Text : "No note"; daily.Day = _selectedDay; daily.Month = _selectedMonth; daily.Year = _selectedYear; daily.TotalEarning = Convert.ToDouble(TotalEarningLabel.Text); daily.TotalExpense = Convert.ToDouble(TotalExpenseLabel.Text); string source; string reason; string category; string comment; double amount; foreach (DataGridViewRow row in ExpenseDataGridView.Rows) { if (IsLastEmptyRow(ExpenseDataGridView, row.Index)) { break; } try { reason = ExpenseDataGridView.Rows[row.Index].Cells[0].Value.ToString(); reason = FilterString(reason); } catch { reason = ""; } try { if (!double.TryParse(ExpenseDataGridView.Rows[row.Index].Cells[1].Value.ToString(), out amount)) { string message = "The value for amount is not correct on row"; message += (row.Index + 1) + " in the expense table. Please correct" + " the amount in order to save."; MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return("Invalid value entered"); } } catch (NullReferenceException) { string message; message = "Looks like you forgot to enter amount on row "; message += (row.Index + 1) + " in the expense table. "; message += "Do you want to save without changing the amount?"; DialogResult dlgResult = MessageBox.Show(message, "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dlgResult == DialogResult.Yes) { amount = 0; } else { return("Terminated by user"); } } try { category = ExpenseDataGridView.Rows[row.Index].Cells[2].Value.ToString(); category = FilterString(category); } catch { category = "Other"; } try { comment = ExpenseDataGridView.Rows[row.Index].Cells[3].Value.ToString(); comment = FilterString(comment); } catch { comment = ""; } ExpenseInfo expense = new ExpenseInfo { Reason = reason, Amount = amount, Category = category, Comment = comment }; daily.ExpenseList.Add(expense); } foreach (DataGridViewRow row in EarningDataGridView.Rows) { if (IsLastEmptyRow(EarningDataGridView, row.Index)) { break; } try { source = EarningDataGridView.Rows[row.Index].Cells[0].Value.ToString(); source = FilterString(source); } catch { source = ""; } try { if (!double.TryParse(EarningDataGridView.Rows[row.Index].Cells[1].Value.ToString(), out amount)) { string message = "The value for amount is not correct on row" + (row.Index + 1) + " in the earning table. Please correct the amount in order to save."; MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return("Invalid value entered"); } } catch (NullReferenceException) { string message = "Looks like you forgot to enter amount on row " + (row.Index + 1) + " in the earning table. Do you want to save without changing the amount?"; DialogResult dlgResult = MessageBox.Show(message, "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dlgResult == DialogResult.Yes) { amount = 0; } else { return("Terminated by user"); } } try { category = EarningDataGridView.Rows[row.Index].Cells[2].Value.ToString(); category = FilterString(category); } catch { category = "Other"; } try { comment = EarningDataGridView.Rows[row.Index].Cells[3].Value.ToString(); comment = FilterString(comment); } catch { comment = ""; } EarningInfo earning = new EarningInfo { Source = source, Amount = amount, Category = category, Comment = comment, }; daily.EarningList.Add(earning); } string result = WebHandler.SaveDailyInfo(daily); if (result == "SUCCESS") { //if any info on the same date already exists, overwrite that info //otherwise, add this info as new info int index = GlobalSpace.DailyInfoList.FindIndex( d => d.Day == daily.Day && d.Month == daily.Month && d.Year == daily.Year); if (index != -1) { GlobalSpace.DailyInfoList[index] = daily; } else { GlobalSpace.DailyInfoList.Add(daily); } //monthly info should change accordingly since daily info has been modified MonthlyInfo.Fetch(); //MessageBox.Show("The data has been successfully saved!", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information); _hasUnsavedChanges = false; } return(result); }