-
Notifications
You must be signed in to change notification settings - Fork 0
/
SearchPage.cs
105 lines (89 loc) · 3.56 KB
/
SearchPage.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace courseWork02
{
public partial class SearchPage : Form
{
public SearchPage()
{
InitializeComponent();
}
public static class ExpenseDetails
{
public static int ExpenseId { get; set; }
public static int IncomeId { get; set; }
}
private void button1_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(dtpFromDate.Text) || string.IsNullOrEmpty(dtpToDate.Text))
{
MessageBox.Show("You must select Date range!");
return;
}
else if (chkExpense.Checked)
{
using (MoneyPred db = new MoneyPred())
{
var expenseDetails = from expenses in db.Expenses
where dtpFromDate.Value < expenses.Date
&& dtpToDate.Value > expenses.Date
select new
{Description = expenses.Description, Amount = expenses.Amount, Date = expenses.Date, Id = expenses.ExpensseId};
expenseDataGrid.DataSource = expenseDetails.ToList();
}
expenseDataGrid.Visible = true;
lblExpGrid.Visible = true;
}
else if (chkIncome.Checked)
{
using (MoneyPred db = new MoneyPred())
{
var incomeDetails = from incomes in db.Incomes
where dtpFromDate.Value < incomes.Date
&& dtpToDate.Value > incomes.Date
select new
{ Description = incomes.Description, Amount = incomes.Amount, Date = incomes.Date, Id = incomes.IncomeId };
incomeDataGrid.DataSource = incomeDetails.ToList();
}
incomeDataGrid.Visible = true;
lblIncGrid.Visible = true;
}
}
private void dataGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
var senderGrid = (DataGridView)sender;
if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn &&
e.RowIndex >= 0)
{
var expId = expenseDataGrid.Rows[e.RowIndex].Cells[4].Value.ToString();
ExpenseDetails.ExpenseId = Convert.ToInt32(expId);
this.Hide();
var expensePage = new ExpensePage();
expensePage.Activate();
expensePage.Show();
}
}
private void incomeDataGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
var senderGrid = (DataGridView)sender;
if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn &&
e.RowIndex >= 0)
{
var incId = incomeDataGrid.Rows[e.RowIndex].Cells[4].Value.ToString();
ExpenseDetails.IncomeId = Convert.ToInt32(incId);
this.Hide();
var incomePage = new IncomePage();
incomePage.Activate();
incomePage.Show();
}
}
}
}