-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
233 lines (207 loc) · 8.81 KB
/
Form1.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
using System;
using OfficeOpenXml;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
namespace Personal_Finance_Manger
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
static string FileIncome = @"K:\My backups\DataBase\AddIncome.txt";
static string FileExpenses = @"K:\My backups\DataBase\AddExpenses.txt";
static string FileSaving = @"K:\My backups\DataBase\AddSavings.txt";
clsFile file = new clsFile();
clsIncome income = new clsIncome(FileIncome);
clsExpense expense = new clsExpense(FileExpenses);
clsSaving saving = new clsSaving(FileSaving);
private void ExportToExcel(ListView listView)
{
// تعيين الترخيص المجاني باستخدام المسار الكامل
OfficeOpenXml.ExcelPackage.LicenseContext = OfficeOpenXml.LicenseContext.NonCommercial;
using (SaveFileDialog sfd = new SaveFileDialog() { Filter = "Excel Workbook|*.xlsx" })
{
if (sfd.ShowDialog() == DialogResult.OK)
{
using (ExcelPackage excelPackage = new ExcelPackage())
{
ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets.Add("Report");
// إضافة رؤوس الأعمدة
worksheet.Cells[1, 1].Value = "Month";
worksheet.Cells[1, 2].Value = "Year";
worksheet.Cells[1, 3].Value = "TotalIncome";
worksheet.Cells[1, 4].Value = "TotalExpenses";
// إضافة البيانات من ListView إلى ملف Excel
for (int i = 0; i < listView.Items.Count; i++)
{
worksheet.Cells[i + 2, 1].Value = listView.Items[i].SubItems[0].Text;
worksheet.Cells[i + 2, 2].Value = listView.Items[i].SubItems[1].Text;
worksheet.Cells[i + 2, 3].Value = listView.Items[i].SubItems[2].Text;
worksheet.Cells[i + 2, 4].Value = listView.Items[i].SubItems[3].Text;
}
// حفظ الملف
FileInfo excelFile = new FileInfo(sfd.FileName);
excelPackage.SaveAs(excelFile);
}
}
}
}
private void Form1_Resize(object sender, EventArgs e)
{
// base.OnResize(e);
tabControl1.ItemSize = new Size(tabControl1.Height / tabControl1.TabCount - 1, 40);
}
private void btnSave_Click(object sender, EventArgs e)
{
if (msktxtAmountI.Text != "" && !string.IsNullOrEmpty(cbxTypesI.Text))
{
clsFile.saveData(income.join(msktxtAmountI,dtpDateI,cbxTypesI,rtbNotesI),income.FileIncome);
MessageBox.Show("Successfully,Your Personal Financial Was Saved ", "Saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
cbxTypesI.Text = "";
msktxtAmountI.Clear();
}
else
{
MessageBox.Show("Error Your Fieldes are empty ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void msktxtAmountI_Validating(object sender, CancelEventArgs e)
{
if(msktxtAmountI.Text == "")
{
msktxtAmountI.Focus();
}
else
{
cbxTypesI.Focus();
}
}
private void cbxTypesI_Validating(object sender, CancelEventArgs e)
{
if (string.IsNullOrEmpty(cbxTypesI.Text))
{
cbxTypesI.Focus();
}
}
private void msktxtAmountE_Validating(object sender, CancelEventArgs e)
{
if (msktxtAmountE.Text == "")
{
msktxtAmountE.Focus();
}
else
{
cbxTypesE.Focus();
}
}
private void cbxTypesE_Validating(object sender, CancelEventArgs e)
{
if (string.IsNullOrEmpty(cbxTypesE.Text))
{
cbxTypesE.Focus();
}
}
private void btnSaveE_Click(object sender, EventArgs e)
{
if (msktxtAmountE.Text != "" && !string.IsNullOrEmpty(cbxTypesE.Text))
{
clsFile.saveData(expense.join(msktxtAmountE, dtpDateE, cbxTypesE, rtbNotesE), expense.FileExpense);
MessageBox.Show("Successfully,Your Personal Financial Was Saved ", "Saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
cbxTypesE.Text = "";
msktxtAmountE.Clear();
}
else
{
MessageBox.Show("Error Your Fieldes are empty ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
if (tabControl1.SelectedIndex == 1)
{
listView1.Items.Clear();
clsFile.readFromFile(FileIncome,listView1);
}
else if (tabControl1.SelectedIndex == 2)
{
listView2.Items.Clear();
clsFile.readFromFile(FileExpenses,listView2);
}
else if (tabControl1.SelectedIndex == 0)
{
tabControl1.TabPages[0].Controls.Clear();
file.CreateLiveChart(tabControl1,income.FileIncome,FileExpenses,FileSaving);
}
else if (tabControl1.SelectedIndex == 3)
{
listView3.Items.Clear();
clsFile.readFromSavingFile(FileSaving, listView3);
}
else if(tabControl1.SelectedIndex == 4)
{
clsDate.makeFromDateLessThanToDate(dtpDateFromR,dtpDateToR);
}
}
private void btnSaveS_Click(object sender, EventArgs e)
{
if(msktxtAmountS.Text != "" && msktxtDaysS.Text !="" || msktxtMonthsS.Text != "" || msktxtYearsS.Text != "")
{
clsFile.saveData(saving.join(msktxtAmountS, msktxtDaysS, msktxtMonthsS, msktxtYearsS,rtbNotesS),saving.FileSaving);
MessageBox.Show("Successfully,Your Saving Was Saved ", "Saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Error Your Fieldes are empty ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
ListViewItem createItem(DateTimePicker dateFrom,DateTimePicker dateTo)
{
ListViewItem Item = new ListViewItem();
Item.Text = clsDate.MonthFrom(dateFrom) + " - " + clsDate.MonthTo(dateTo);
Item.SubItems.Add(clsDate.YearFrom(dateFrom) + "-" + clsDate.YearTo(dateTo));
Array allIncome = clsFile.allFinancials(FileIncome);
Array allExpenses = clsFile.allFinancials(FileExpenses);
float totalIncome = 0.0f;
foreach (String item in allIncome)
{
String[] items = clsDate.shareMyDataToItem(item);
if (clsDate.isInMonth(items[1],clsDate.MonthFrom(dateFrom),clsDate.MonthTo(dateTo)) && clsDate.isInYear(items[2], clsDate.YearFrom(dateFrom), clsDate.YearTo(dateTo)))
{
totalIncome += float.Parse(items[0]);
}
}
Item.SubItems.Add(totalIncome.ToString());
float totalExpenses = 0.0f;
foreach (String item in allExpenses)
{
String[] items = clsDate.shareMyDataToItem(item);
if (clsDate.isInMonth(items[1], clsDate.MonthFrom(dateFrom), clsDate.MonthTo(dateTo)) && clsDate.isInYear(items[2], clsDate.YearFrom(dateFrom), clsDate.YearTo(dateTo)))
{
totalExpenses += float.Parse(items[0]);
}
}
Item.SubItems.Add(totalExpenses.ToString());
return Item;
}
private void btnShowR_Click(object sender, EventArgs e)
{
listView4.Items.Add(createItem(dtpDateFromR,dtpDateToR));
}
private void dtpDateToR_ValueChanged(object sender, EventArgs e)
{
clsDate.makeFromDateLessThanToDate(dtpDateFromR,dtpDateToR);
}
private void btnExportToExcel_Click(object sender, EventArgs e)
{
ExportToExcel(listView4);
}
private void Form1_Load(object sender, EventArgs e)
{
file.CreateLiveChart(tabControl1, income.FileIncome, FileExpenses, FileSaving);
}
}
}