private void button1_Click(object sender, EventArgs e) { CategoryController catcon = new CategoryController(); string user_id = "7fa65ff0-4a3e-4cc5-b975-fae5c16b385e"; string date = DateTime.Now.Year.ToString() + '-' + DateTime.Now.Month.ToString(); CategorySummaryDto exp = new CategorySummaryDto(); CategorySummaryDto inc = new CategorySummaryDto(); exp = catcon.get_category_expense_summary(user_id, date); inc = catcon.get_category_income_summary(user_id, date); //int? value = categoryResponseDtoExp?.?.PropertyB?.PropertyC;.HasValue //CultureInfo usCulture = new CultureInfo("en-US"); double expense; double income; double balance; expense = exp.totalExpenes; income = inc.totalExpenes; balance = income - expense; SummaryView sumview = new SummaryView(); sumview.label6.Text = expense.ToString("C", CultureInfo.CreateSpecificCulture("en-LK")); sumview.label5.Text = income.ToString("C", CultureInfo.CreateSpecificCulture("en-LK")); if (balance > 0) { sumview.label7.Text = balance.ToString("C", CultureInfo.CreateSpecificCulture("en-LK")); } else { sumview.label7.Text = "-" + balance.ToString("C", CultureInfo.CreateSpecificCulture("en-LK")); } //sumview._initialmonth = DateTime.Now.Month.ToString(); var months = new Month[12]; months[0] = new Month("1", "January"); months[1] = new Month("2", "February"); months[2] = new Month("3", "March"); months[3] = new Month("4", "April"); months[4] = new Month("5", "May"); months[5] = new Month("6", "June"); months[6] = new Month("7", "July"); months[7] = new Month("8", "August"); months[8] = new Month("9", "September"); months[9] = new Month("10", "October"); months[10] = new Month("11", "November"); months[11] = new Month("12", "December"); foreach (var mo in months) { if (mo.id == DateTime.Now.Month.ToString()) { sumview.label4.Text = mo.name; } } sumview.Show(); }
public CategorySummaryDto getIncomeSummary(string user_id, string date) { CategorySummaryDto category_sum = new CategorySummaryDto(); using (MySqlConnection connection = new MySqlConnection(Helper.CnnVal("SampleDB"))) { bool MatchingRecordFound = false; try { connection.Open(); string sql = "SELECT * , SUM(amount) as totalAmount FROM transaction LEFT JOIN category ON transaction.categoryId = category.categoryId WHERE transaction.userId=@userId && CONCAT(YEAR(timestamp),'-',MONTH(timestamp)) =@date && category.type='income'"; //String query = "INSERT INTO dbo.SMS_PW (id,username,password,email) VALUES (@id,@username,@password, @email)"; using (MySqlCommand command = new MySqlCommand(sql, connection)) { command.CommandText = sql; command.Prepare(); command.Parameters.Add(new MySqlParameter("@userId", user_id)); command.Parameters.Add(new MySqlParameter("@date", date)); using (MySqlDataReader reader = command.ExecuteReader()) { MatchingRecordFound = reader.HasRows; while (reader.Read()) { category_sum.categoryId = reader["categoryId"].ToString(); category_sum.category = reader["category"].ToString(); category_sum.type = reader["type"].ToString(); category_sum.totalExpenes = (reader["totalAmount"] == DBNull.Value) ? 0.00 : Convert.ToDouble(reader["totalAmount"]); category_sum.userId = reader["userId"].ToString(); category_sum.exp_limit = reader["exp_limit"].ToString(); } } } } catch (Exception e) { MessageBox.Show(e.Message); } finally { connection.Close(); } // Check Error if (!MatchingRecordFound) { MessageBox.Show("Not found any income for this month"); } return(category_sum); } }
private void button1_Click(object sender, EventArgs e) { var type = comboBox1.SelectedValue.ToString(); var year = DateTime.Now.Year; var pre_year = year - 1; string user_id = "7fa65ff0-4a3e-4cc5-b975-fae5c16b385e"; CategoryController categoryController = new CategoryController(); CategorySummaryDto all_year_exp = new CategorySummaryDto(); all_year_exp = categoryController.get_category_expense_summary_for_year(user_id, pre_year); double prediction_value; if (type == "365") { prediction_value = all_year_exp.totalExpenes / 365; label2.Text = prediction_value.ToString("C", CultureInfo.CreateSpecificCulture("en-LK")); label3.Text = "Daily Expense Prediction"; label2.Visible = true; label3.Visible = true; } else if (type == "52") { prediction_value = all_year_exp.totalExpenes / 52; label2.Text = prediction_value.ToString("C", CultureInfo.CreateSpecificCulture("en-LK")); label3.Text = "Weekly Expense Prediction"; label2.Visible = true; label3.Visible = true; } else if (type == "12") { prediction_value = all_year_exp.totalExpenes / 12; label2.Text = prediction_value.ToString("C", CultureInfo.CreateSpecificCulture("en-LK")); label3.Text = "Monthly Expense Prediction"; label2.Visible = true; label3.Visible = true; } else { MessageBox.Show("Wrong type Retry please!"); } }