-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddListing.cs
229 lines (212 loc) · 10.1 KB
/
addListing.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
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Project_Mockup
{
public partial class addListing : Form
{
string username = "";
public addListing(string a)
{
// Get length/size of carList from file - keep all cars in list even after sale/de-listing (keep them stored for reference)
// Use the length/size value to give each carListing a unique "ID" number that can be used as reference throughout the program
InitializeComponent();
username = a;
}
private int checkFlags()
{
int ctr = 0;
if (cbMake.Text == "")
{
errorProvider1.SetError(cbMake, "Please select a Make from the drop down list");
ctr++;
}
if (txtModel.Text == ""||txtModel.Text.Contains('/'))
{
errorProvider1.SetError(txtModel, "Please enter a car Model that does not have '/' in it");
ctr++;
}
if (cbYear.Text == "")
{
errorProvider1.SetError(cbYear, "Please choose a year from the drop down list");
ctr++;
}
if (cbColour.Text == "")
{
errorProvider1.SetError(cbColour, "Please choose a colour from the drop down list");
ctr++;
}
if (txtMileage.Text == "")
{
ctr++;
errorProvider1.SetError(txtMileage, "Please enter odometer reading in kilometers");
}
else
{
foreach (char c in txtMileage.Text)
{
if (char.IsNumber(c) != true)
{
ctr++;
errorProvider1.SetError(txtMileage, "Please enter a number for the mileage");
}
}
}
if (cbTransmission.Text == "")
{
errorProvider1.SetError(cbTransmission, "Please choose a transmission type from the drop down menu");
ctr++;
}
if (txtPrice.Text == "")
{
ctr++;
errorProvider1.SetError(txtPrice, "Please enter a price");
}
else
{
foreach (char c in txtPrice.Text)
{
if (char.IsNumber(c) != true)
{
ctr++;
errorProvider1.SetError(txtPrice, "Please enter a number for the price");
}
}
}
return ctr;
}
private void btnSubmit_Click(object sender, EventArgs e)
{
string listDate = DateTime.Now.ToString("h:mm:ss tt");
errorProvider1.Clear();
int ctr=checkFlags();
if (ctr==0)
{
SaveCar(listDate);
}
}
private void SaveCar(string a)
{
string listDate = a;
string newCar = "";
//Send this form the username of the main page so we can append it to the listing if they create one
if (string.IsNullOrWhiteSpace(imgBox1.Text)) // No user uploaded image
{
newCar = cbMake.Text + "/" + txtModel.Text + "/" + cbYear.Text + "/" + txtMileage.Text + "/" + cbColour.Text + "/" + cbTransmission.Text + "/" + txtPrice.Text + "/" + username + "/" + listDate + "/" + @"images\default.png" + "/" + @"images\default.png" + "/" + @"images\default.png" + "/" + @"images\default.png" + "/" + @"images\default.png" + "/" + "Listed";
}
else if (string.IsNullOrWhiteSpace(imgBox2.Text))
{
newCar = cbMake.Text + "/" + txtModel.Text + "/" + cbYear.Text + "/" + txtMileage.Text + "/" + cbColour.Text + "/" + cbTransmission.Text + "/" + txtPrice.Text + "/" + username + "/" + listDate + "/" + @"images\" + imgBox1.Text + "/" + @"images\default.png" + "/" + @"images\default.png" + "/" + @"images\default.png" + "/" + @"images\default.png" + "/" + "Listed";
}
else if (string.IsNullOrWhiteSpace(imgBox3.Text))
{
newCar = cbMake.Text + "/" + txtModel.Text + "/" + cbYear.Text + "/" + txtMileage.Text + "/" + cbColour.Text + "/" + cbTransmission.Text + "/" + txtPrice.Text + "/" + username + "/" + listDate + "/" + @"images\" + imgBox1.Text + "/" + @"images\" + imgBox2.Text + "/" + @"images\default.png" + "/" + @"images\default.png" + "/" + @"images\default.png" + "/" + "Listed";
}
else if (string.IsNullOrWhiteSpace(imgBox4.Text))
{
newCar = cbMake.Text + "/" + txtModel.Text + "/" + cbYear.Text + "/" + txtMileage.Text + "/" + cbColour.Text + "/" + cbTransmission.Text + "/" + txtPrice.Text + "/" + username + "/" + listDate + "/" + @"images\" + imgBox1.Text + "/" + @"images\" + imgBox2.Text + "/" + @"images\" + imgBox3.Text + "/" + @"images\default.png" + "/" + @"images\default.png" + "/" + "Listed";
}
else if (string.IsNullOrWhiteSpace(imgBox5.Text))
{
newCar = cbMake.Text + "/" + txtModel.Text + "/" + cbYear.Text + "/" + txtMileage.Text + "/" + cbColour.Text + "/" + cbTransmission.Text + "/" + txtPrice.Text + "/" + username + "/" + listDate + "/" + @"images\" + imgBox1.Text + "/" + @"images\" + imgBox2.Text + "/" + @"images\" + imgBox3.Text + "/" + @"images\" + imgBox4.Text + "/" + @"images\default.png" + "/" + "Listed";
}
else
{
newCar = cbMake.Text + "/" + txtModel.Text + "/" + cbYear.Text + "/" + txtMileage.Text + "/" + cbColour.Text + "/" + cbTransmission.Text + "/" + txtPrice.Text + "/" + username + "/" + listDate + "/" + @"images\" + imgBox1.Text + "/" + @"images\" + imgBox2.Text + "/" + @"images\" + imgBox3.Text + "/" + @"images\" + imgBox4.Text + "/" + @"images\" + imgBox5.Text + "/" + "Listed";
}
File.AppendAllText(@"Listings.txt", newCar + Environment.NewLine);
this.DialogResult = DialogResult.OK;
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
}
private void btnSavePrivate_Click(object sender, EventArgs e)
{
string listDate = DateTime.Now.ToString("h:mm:ss tt");
errorProvider1.Clear();
int ctr = checkFlags();
if (ctr == 0)
{
SaveCar(listDate);
}
}
private void btnAdd1_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "Image files (*.jpg, *.jpeg, *.jpe, *.jfif, *.png) | *.jpg; *.jpeg; *.jpe; *.jfif; *.png";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string fileName = "";
fileName = openFileDialog1.FileName;
imgBox1.Text = Path.GetFileName(fileName);
if (!File.Exists(@"images\" + imgBox1.Text))
{
File.Copy(openFileDialog1.FileName, @"images\" + imgBox1.Text, true);
}
}
}
private void btnAdd2_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "Image files (*.jpg, *.jpeg, *.jpe, *.jfif, *.png) | *.jpg; *.jpeg; *.jpe; *.jfif; *.png";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string fileName = "";
fileName = openFileDialog1.FileName;
imgBox2.Text = Path.GetFileName(fileName);
if (!File.Exists(@"images\" + imgBox2.Text))
{
File.Copy(openFileDialog1.FileName, @"images\" + imgBox2.Text, true);
}
}
}
private void btnAdd3_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "Image files (*.jpg, *.jpeg, *.jpe, *.jfif, *.png) | *.jpg; *.jpeg; *.jpe; *.jfif; *.png";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string fileName = "";
fileName = openFileDialog1.FileName;
imgBox3.Text = Path.GetFileName(fileName);
if (!File.Exists(@"images\" + imgBox3.Text))
{
File.Copy(openFileDialog1.FileName, @"images\" + imgBox3.Text, true);
}
}
}
private void btnAdd4_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "Image files (*.jpg, *.jpeg, *.jpe, *.jfif, *.png) | *.jpg; *.jpeg; *.jpe; *.jfif; *.png";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string fileName = "";
fileName = openFileDialog1.FileName;
imgBox4.Text = Path.GetFileName(fileName);
if (!File.Exists(@"images\" + imgBox4.Text))
{
File.Copy(openFileDialog1.FileName, @"images\" + imgBox4.Text, true);
}
}
}
private void btnAdd5_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "Image files (*.jpg, *.jpeg, *.jpe, *.jfif, *.png) | *.jpg; *.jpeg; *.jpe; *.jfif; *.png";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string fileName = "";
fileName = openFileDialog1.FileName;
imgBox5.Text = Path.GetFileName(fileName);
if (!File.Exists(@"images\" + imgBox5.Text))
{
File.Copy(openFileDialog1.FileName, @"images\" + imgBox5.Text, true);
}
}
}
}
}