-
Notifications
You must be signed in to change notification settings - Fork 0
/
customer.aspx.cs
318 lines (228 loc) · 12.1 KB
/
customer.aspx.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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using System.Data.SqlClient;
using System.Data;
namespace authwebpart
{
public partial class customer : System.Web.UI.Page
{
public static string cons = WebConfigurationManager.ConnectionStrings["v0scon"].ConnectionString;
SqlConnection myConnection = new SqlConnection(cons);
double totw = 0;
double tota = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["suser"] == null)
{
Response.Redirect("login.aspx");
}
if (!IsPostBack)
{
using (myConnection)
{
myConnection.Open();
string que = "SELECT IDENT_CURRENT('customer')+1; "; // to get next auto increment customer id c_id
SqlCommand ccmd = new SqlCommand(que, myConnection);
object totals = ccmd.ExecuteScalar();
int ncid = Convert.ToInt32(totals);
TextBox8.Text = ncid + "";
Session.Add("c_id", ncid);
}
}
}
static string cfpath="none";
static string mfpath ="none";
protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
{
using (myConnection)
{
myConnection.Open();
//insert into customer table
string cquery = "insert into customer ( c_fname,c_mname,c_lname,address,city,mobile_no,email_id,create_date,created_date,interest_rate,debit_limit,cphoto_path,mphoto_path)";
cquery += "values(@c_fname,@c_mname,@c_lname,@address,@city,@mobile_no,@email_id,@create_date,@created_date,@interest_rate,@debit_limit,@cphoto_path,@mphoto_path)";
SqlCommand ccmd = new SqlCommand(cquery, myConnection);
ccmd.Parameters.AddWithValue("@c_fname", TextBox1.Text.ToString());
ccmd.Parameters.AddWithValue("@c_mname", TextBox2.Text.ToString());
ccmd.Parameters.AddWithValue("@c_lname", TextBox3.Text.ToString());
if (string.IsNullOrWhiteSpace(this.TextBox4.Text))
{
ccmd.Parameters.AddWithValue("@address", "none");
}
else
{
ccmd.Parameters.AddWithValue("@address", TextBox4.Text.ToString());
}
ccmd.Parameters.AddWithValue("@city", DropDownList3.Text.ToString());
ccmd.Parameters.AddWithValue("@mobile_no", Decimal.Parse(TextBox7.Text.ToString()));
if (Calendar12.Text != "" && Calendar12.Text != null)
ccmd.Parameters.AddWithValue("@create_date", DateTime.Parse(Calendar12.Text));
else
ccmd.Parameters.AddWithValue("@create_date", System.DateTime.Now);
if (TextBox6.Text != "" && TextBox6.Text != null)
ccmd.Parameters.AddWithValue("@email_id", TextBox6.Text);
else
ccmd.Parameters.AddWithValue("@email_id", "none");
ccmd.Parameters.AddWithValue("@created_date", System.DateTime.Now);
ccmd.Parameters.AddWithValue("@interest_rate", Decimal.Parse(TextBox19.Text.ToString()));
ccmd.Parameters.AddWithValue("@debit_limit", Decimal.Parse(TextBox18.Text.ToString()));
ccmd.Parameters.AddWithValue("@cphoto_path", cfpath);
ccmd.Parameters.AddWithValue("@mphoto_path", mfpath);
ccmd.ExecuteNonQuery();
//insert mortgage items to c_id
string insq = "INSERT INTO cust_mor(c_id,item_type,item_name,gross_weight,rate,amount) SELECT @c_id,item_type,item_name,gross_weight,rate,amount FROM dumcust_mor ";
SqlCommand copcmd = new SqlCommand(insq, myConnection);
copcmd.Parameters.AddWithValue("@c_id", Int32.Parse(TextBox8.Text.ToString()));
copcmd.ExecuteNonQuery();
string dropquery = "TRUNCATE TABLE dumcust_mor ";
//flush buffer table
SqlCommand drcmd = new SqlCommand(dropquery, myConnection);
drcmd.ExecuteNonQuery();
// Response.Write("drop succesfully");
string tquery = "insert into transection (c_id,t_type,t_date,t_amount)";
tquery += "values (@c_id,@t_type,@t_date,@t_amount)";
SqlCommand tcmd = new SqlCommand(tquery, myConnection);
tcmd.Parameters.AddWithValue("@c_id", Int32.Parse(TextBox8.Text.ToString()));
tcmd.Parameters.AddWithValue("@t_type", "d");
tcmd.Parameters.AddWithValue("@t_date", DateTime.Parse(Calendar12.Text));
tcmd.Parameters.AddWithValue("@t_amount", Decimal.Parse(TextBox20.Text.ToString()));
tcmd.ExecuteNonQuery();
myConnection.Close();
Response.Redirect("cust_list.aspx");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string filext = System.IO.Path.GetExtension(FileUpload1.FileName);
Response.Write(filext);
if(filext==".jpeg" || filext == ".png" || filext == ".jpg")
{
try
{
string filename = Path.GetFileName(FileUpload1.FileName);
FileUpload1.SaveAs(Server.MapPath("~/photos/") + "c"+Session["c_id"].ToString()+ filext);
cfpath = "~/photos/"+ "c"+Session["c_id"].ToString()+ filext;
Label22.Text = "Upload status: File uploaded!";
}
catch (Exception ex)
{
Label22.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
}
}
else
Label22.Text = "Upload status: Only Image files are accepted!";
}
}
protected void Button2_Click(object sender, EventArgs e)
{
if (FileUpload2.HasFile)
{
string filext = System.IO.Path.GetExtension(FileUpload2.FileName);
if (filext == ".jpeg" || filext == ".png" || filext == ".jpg")
{
try
{
string filename = Path.GetFileName(FileUpload2.FileName);
FileUpload2.SaveAs(Server.MapPath("~/photos/") +"m"+ Session["c_id"].ToString()+filext);
mfpath = "~/photos/" +"m"+ Session["c_id"].ToString()+ filext;
Label23.Text = "Upload status: File uploaded!";
}
catch (Exception ex)
{
Label23.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
}
}
else
Label23.Text = "Upload status: Only Image files are accepted!";
}
}
protected void Wizard1_NextButtonClick(object sender, WizardNavigationEventArgs e)
{
if (e.NextStepIndex == 2)
{
lblName.Text = TextBox1.Text + " " + TextBox2.Text + " " + TextBox3.Text;
lblCity.Text = DropDownList3.SelectedValue;
lblMobile.Text = TextBox7.Text;
lblEmail.Text = TextBox6.Text;
lblAdd.Text = TextBox4.Text;
lblId.Text = TextBox8.Text;
GridView2.DataBind();
System.Text.RegularExpressions.Regex mobile = new System.Text.RegularExpressions.Regex("^[789]\\d{9}$");
System.Text.RegularExpressions.Regex email = new System.Text.RegularExpressions.Regex("^\\w+([\\.-]?\\w+)*@\\w+([\\.-]?\\w+)*(\\.\\w{2,3})+$");
if (string.IsNullOrWhiteSpace(this.TextBox1.Text) || string.IsNullOrWhiteSpace(this.TextBox2.Text) || string.IsNullOrWhiteSpace(this.TextBox3.Text) || !email.IsMatch(TextBox6.Text)|| !mobile.IsMatch(TextBox7.Text) || DropDownList3.SelectedValue=="--SELECT--")
{
erlbl.Visible = true;
erlbl.Text = "Step1-Invalid Credential";
}else
{
Button b = (Button)Wizard1.FindControl("FinishNavigationTemplateContainerID").FindControl("FinishButton");
b.Enabled = true;
}
}
if (e.NextStepIndex == 1)
{
TextBox9.Text = TextBox1.Text + " " + TextBox2.Text + " " + TextBox3.Text;
}
}
protected void linkInsert_Click(object sender, EventArgs e)
{
SqlDataSource3.InsertParameters["item_name"].DefaultValue = txtItem.Text;
SqlDataSource3.InsertParameters["rate"].DefaultValue = txtRate.Text;
SqlDataSource3.InsertParameters["item_type"].DefaultValue = dropItem.SelectedValue.ToString();
SqlDataSource3.InsertParameters["gross_weight"].DefaultValue = txtGross.Text;
SqlDataSource3.InsertParameters["amount"].DefaultValue = txtAmount.Text;
SqlDataSource3.Insert();
// Response.Write("inserter");
txtAmount.Text = "";
txtGross.Text = "";
txtItem.Text = "";
txtRate.Text = "";
}
protected void GridView3_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
//header portion
}
else if (e.Row.RowType == DataControlRowType.DataRow)
{
double dtw = Double.Parse((e.Row.DataItem as DataRowView).Row["gross_weight"].ToString());
double dta = Double.Parse((e.Row.DataItem as DataRowView).Row["amount"].ToString());
//retrive gridview Coloumn
tota = dta + tota;
totw = dtw + totw;
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
//lbl total mortgage amount and total weight
Label albl = (Label)e.Row.FindControl("lbltota");
Label wlbl = (Label)e.Row.FindControl("lbltotw");
string famt = string.Format(new System.Globalization.CultureInfo("en-IN"), "{0:c}", tota);
wlbl.Text =(totw/1000) + "/-kg";
albl.Text = famt;
Label12.Text = (totw/1000) + "/-kg";
Label13.Text = famt;
}
}
protected void Page_PreRender(object sender, EventArgs e)
{
if (Wizard1.ActiveStepIndex == 0)
TextBox1.Focus();//set focus
else if (Wizard1.ActiveStepIndex == 1)
{
/* Button btn = (Button)Wizard1.FindControl("StepNavigationTemplateContainerID").FindControl("StepNextButton");
btn.OnClientClick = "return confirm('Are You Sure Want to go to Next Step?')";
btn.CausesValidation = true;
btn.ValidationGroup = "nbtn";*/
Calendar12.Focus();
}
}
}
}