-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
206 lines (168 loc) · 7.19 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
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
namespace Billie
{
public partial class Form1 : Form
{
List<PersonItemMap> PersonItemMaps;
public Form1()
{
InitializeComponent();
PersonItemMaps = new List<PersonItemMap>();
}
private void NextButton_Click(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(TaxRateText.Text) || !double.TryParse(TaxRateText.Text, out _))
{
MessageBox.Show("Enter a Valid Tax Percentage.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (string.IsNullOrWhiteSpace(ShopNameBox.Text))
{
MessageBox.Show("Enter a Shop Name.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
PersonItemMaps.Clear();
for (int i = 0; i < NameGrid.Rows.Count; i++)
{
MapForm mapForm = new MapForm(NameGrid.Rows, i, ItemGrid.Rows);
mapForm.ShowDialog();
PersonItemMaps.Add(mapForm.GetPersonItemMap());
}
//NextButton.Enabled = false;
BreakdownButton.Enabled = true;
}
private void AddNameButton_Click(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(NameText.Text))
{
MessageBox.Show("Enter A Name.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
for (int i = 0; i < NameGrid.Rows.Count; i++)
if (NameGrid.Rows[i].Cells[0].Value as string == NameText.Text.Trim())
{
MessageBox.Show("Name already exists. Enter a different name.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
NameGrid.Rows.Add(NameText.Text.Trim(), "Remove");
NameText.Text = "";
}
private void TrustedFacesList_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
var senderGrid = (DataGridView)sender;
if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0)
senderGrid.Rows.RemoveAt(e.RowIndex);
}
private void AddItemButton_Click(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(ItemTextBox.Text))
{
MessageBox.Show("Enter an Item Name.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (string.IsNullOrWhiteSpace(PriceTextBox.Text) || !double.TryParse(PriceTextBox.Text, out _))
{
MessageBox.Show("Enter a Valid Price.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
ItemGrid.Rows.Add(ItemTextBox.Text.Trim(), PriceTextBox.Text.Trim(), TaxExcludeCheckBox.Checked, "Remove");
ItemTextBox.Text = "";
PriceTextBox.Text = "";
TaxExcludeCheckBox.Checked = false;
}
private void BreakdownButton_Click(object sender, EventArgs e)
{
BillieData billieData = new BillieData();
for (int i = 0; i < NameGrid.Rows.Count; i++)
billieData.PeopleNames.Add(NameGrid.Rows[i].Cells[0].Value.ToString());
for (int i = 0; i < ItemGrid.Rows.Count; i++)
{
ItemDetails itemDetails = new ItemDetails
{
Name = ItemGrid.Rows[i].Cells[0].Value.ToString(),
Price = double.Parse(ItemGrid.Rows[i].Cells[1].Value.ToString()),
TaxExcempted = Convert.ToBoolean(ItemGrid.Rows[i].Cells[2].Value)
};
billieData.Items.Add(itemDetails);
}
billieData.Maps = PersonItemMaps;
billieData.TaxPercentage = double.Parse(TaxRateText.Text.Trim());
billieData.ShopName = ShopNameBox.Text.Trim();
billieData.PurchaseDate = DateTime.Now;
billieData.Currency = "Rs.";
//string json = JsonConvert.SerializeObject(billieData);
//File.WriteAllText("json.txt", json);
//MessageBox.Show(json);
//BillieData readData = JsonConvert.DeserializeObject<BillieData>(File.ReadAllText("json.txt"));
//Billie billie = new Billie(readData);
Billie billie = new Billie(billieData);
string path = billie.GenerateBreakdown();
if (MessageBox.Show("Breakdown generated Successfully!\n\nOpen now?", "Success", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
Process.Start(path);
}
private void Fire_Click(object sender, EventArgs e)
{
string json = File.ReadAllText("json.txt");
BillieData billieDataL = JsonConvert.DeserializeObject<BillieData>(json);
Billie billie = new Billie(billieDataL);
string path = billie.GenerateBreakdown();
if (MessageBox.Show("Breakdown generated Successfully!\n\nOpen now?", "Success", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
Process.Start(path);
}
private void TaxRateText_TextChanged(object sender, EventArgs e)
{
if (double.TryParse(TaxRateText.Text, out double p))
TaxExcludeCheckBox.Enabled = p > 0;
if (p <= 0)
for (int i = 0; i < ItemGrid.Rows.Count; i++)
(ItemGrid.Rows[i].Cells[2] as DataGridViewCheckBoxCell).Value = false;
}
private void ResetButton_Click(object sender, EventArgs e)
{
ItemGrid.Rows.Clear();
NameGrid.Rows.Clear();
PersonItemMaps.Clear();
TaxRateText.Text = "";
ShopNameBox.Text = "";
NextButton.Enabled = true;
BreakdownButton.Enabled = false;
}
private void ResetNamesButton_Click(object sender, EventArgs e)
{
NameGrid.Rows.Clear();
PersonItemMaps.Clear();
NextButton.Enabled = true;
BreakdownButton.Enabled = false;
}
private void ResetItemsButton_Click(object sender, EventArgs e)
{
ItemGrid.Rows.Clear();
PersonItemMaps.Clear();
NextButton.Enabled = true;
BreakdownButton.Enabled = false;
}
private void NameText_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
AddNameButton_Click(null, null);
}
private void ItemTextBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
ActiveControl = PriceTextBox;
}
private void PriceTextBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
AddItemButton_Click(null, null);
ActiveControl = ItemTextBox;
}
}
}
}