我有一个要提交的注册表单,它执行一些活动,例如将用户详细信息保存到数据库,将证明作为图像发送到数据库,并向用户发送电子邮件给出用户名和密码。单击提交按钮,控制转到新选项卡,然后只有控件转到CS文件。
我的代码是:
protected void sub2_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
incentiveClass.dbPerform dbc = new incentiveClass.dbPerform();
string custname = iname.Value;
custemail = iemail.Value;
string datebir = datepicker.Value;
string cadd1 = addr1.Value;
string cadd2 = add2.Value;
dt = dbc.conid(DropDownList1.SelectedValue);
string ctry = dt.Rows[0]["CountryID"].ToString();
string sta = state1.Value;
string city = icity.Value;
string pin = ipin.Value;
string pann = ipan.Value;
string cno = icno.Value;
string mobil = imobe.Value;
string faxx = ifx.Value;
pwd = PasswordCreation(10);
string filePath = addproof.PostedFile.FileName;
string filename = Path.GetFileName(filePath);
string ext = Path.GetExtension(filename);
string contenttype = String.Empty;
//Set the contenttype based on File Extension
switch (ext)
{
case ".doc":
contenttype = "application/vnd.ms-word";
break;
case ".docx":
contenttype = "application/vnd.ms-word";
break;
case ".xls":
contenttype = "application/vnd.ms-excel";
break;
case ".xlsx":
contenttype = "application/vnd.ms-excel";
break;
case ".jpg":
contenttype = "image/jpg";
break;
case ".png":
contenttype = "image/png";
break;
case ".gif":
contenttype = "image/gif";
break;
case ".pdf":
contenttype = "application/pdf";
break;
}
if (contenttype != String.Empty)
{
Stream fs = addproof.PostedFile.InputStream;
BinaryReader br = new BinaryReader(fs);
add1 = br.ReadBytes((Int32)fs.Length);
Label1.ForeColor = System.Drawing.Color.Green;
Label1.Text = "File Uploaded Successfully";
}
else
{
Label1.ForeColor = System.Drawing.Color.Red;
Label1.Text = "File format not recognised." +
" Upload Image/Word/PDF/Excel formats";
Response.Redirect("register.aspx");
}
string filePath1 = pancopy.PostedFile.FileName;
string filename1 = Path.GetFileName(filePath1);
string ext1 = Path.GetExtension(filename1);
string contenttype1 = String.Empty;
//Set the contenttype based on File Extension
switch (ext1)
{
case ".doc":
contenttype1 = "application/vnd.ms-word";
break;
case ".docx":
contenttype1 = "application/vnd.ms-word";
break;
case ".xls":
contenttype1 = "application/vnd.ms-excel";
break;
case ".xlsx":
contenttype1 = "application/vnd.ms-excel";
break;
case ".jpg":
contenttype1 = "image/jpg";
break;
case ".png":
contenttype1 = "image/png";
break;
case ".gif":
contenttype1 = "image/gif";
break;
case ".pdf":
contenttype1 = "application/pdf";
break;
}
if (contenttype1 != String.Empty)
{
Stream fs1 = pancopy.PostedFile.InputStream;
BinaryReader br1 = new BinaryReader(fs1);
pan = br1.ReadBytes((Int32)fs1.Length);
Label2.ForeColor = System.Drawing.Color.Green;
Label2.Text = "File Uploaded Successfully";
}
else
{
Label2.ForeColor = System.Drawing.Color.Red;
Label2.Text = "File format not recognised." +
" Upload Image/Word/PDF/Excel formats";
Response.Redirect("register.aspx");
}
Guid g = Guid.NewGuid();
string random = g.ToString();
dbc.Cuscode = random.Substring(0, 4);
dbc.Customer_name = custname;
dbc.Email = custemail;
dbc.Dateob = datebir;
dbc.Add1 = cadd1;
dbc.Add2 = cadd2;
dbc.Country = ctry;
dbc.State = sta;
dbc.Pin = pin;
dbc.Panno = pann;
dbc.Phone = cno;
dbc.Mobile1 = mobil;
dbc.Fax = faxx;
dbc.Pawd = pwd;
dbc.Bytes = add1;
dbc.Bytes1 = pan;
int flag = dbc.regstr(icity.Value);
if (flag == 1)
{
Page.ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "alert('Registration Successfull!!! Mail will be sent to your Email Id!!!');", true);
}
try
{
Response.Redirect("userhome.aspx",false);
SendMail();
}
catch(Exception ex)
{
ShowMessage(ex.Message);
}
}