-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMonthlyIncome.cs
141 lines (115 loc) · 4.18 KB
/
MonthlyIncome.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using System;
using System.Data;
using System.Data.SQLite;
using System.Windows.Forms;
namespace LabadaPOS
{
public partial class MonthlyIncome : Form
{
public MonthlyIncome()
{
InitializeComponent();
string month = DateTime.Now.ToString("MMMM");
string year = DateTime.Now.ToString("yyyy");
string day = DateTime.Now.ToString("dd");
month_txt.Text = month;
year_txt.Text = year;
day_txt.Text = day;
}
public void sqlite_aggregate(){
try
{
string myConnection = @"Data Source=sales.db;Version=3;";
SQLiteConnection con = new SQLiteConnection(myConnection, true);
string query;
if (day_txt.Text == "---")
{
query = "SELECT SUM(INCOME) FROM SALES WHERE MONTH=@MONTH AND YEAR=@YEAR;";
}
else if (month_txt.Text == "---") {
day_txt.Text = "---";
query = "SELECT SUM(INCOME) FROM SALES WHERE YEAR=@YEAR;";
}
else
{
query = "SELECT SUM(INCOME) FROM SALES WHERE MONTH=@MONTH AND DAY=@DAY AND YEAR=@YEAR;";
}
SQLiteCommand cmd = new SQLiteCommand(query, con);
cmd.Parameters.AddWithValue("@MONTH", month_txt.Text);
cmd.Parameters.AddWithValue("@YEAR", year_txt.Text);
cmd.Parameters.AddWithValue("@DAY", day_txt.Text);
SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
con.Open();
var total = string.Join(", ", dt.Rows[0].ItemArray);
if (total == "")
{
income_total.Text = "0.00";
}
else {
income_total.Text = total;
}
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public void sqlitequery() {
try
{
string myConnection = @"Data Source=sales.db;Version=3;";
SQLiteConnection con = new SQLiteConnection(myConnection, true);
string query;
if (day_txt.Text == "---")
{
query = "SELECT* FROM SALES WHERE MONTH=@MONTH AND YEAR=@YEAR;";
}
else if (month_txt.Text == "---")
{
day_txt.Text = "---";
query = "SELECT* FROM SALES WHERE YEAR=@YEAR;";
}
else
{
query = "SELECT* FROM SALES WHERE MONTH=@MONTH AND DAY=@DAY AND YEAR=@YEAR;";
}
SQLiteCommand cmd = new SQLiteCommand(query, con);
cmd.Parameters.AddWithValue("@MONTH", month_txt.Text);
cmd.Parameters.AddWithValue("@YEAR", year_txt.Text);
cmd.Parameters.AddWithValue("@DAY", day_txt.Text);
SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
con.Open();
dgv1.DataSource = dt;
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void timer1_Tick(object sender, EventArgs e)
{
date_time.Text = DateTime.Now.ToString("dddd , MMM dd yyyy,hh:mm:ss");
}
private void month_txt_TextChanged(object sender, EventArgs e)
{
sqlitequery();
sqlite_aggregate();
}
private void day_txt_TextChanged(object sender, EventArgs e)
{
sqlitequery();
sqlite_aggregate();
}
private void year_txt_TextChanged(object sender, EventArgs e)
{
sqlitequery();
sqlite_aggregate();
}
}
}