Вы находитесь на странице: 1из 13

SqlHelper.

cs
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Data;
/// <summary>
/// Summary description for database
/// </summary>
public class database
{
Sql Connection con =new
SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionSt
ring);
public int nonquery(string s)
{
int n = 0;
try
{
con.Open();

ONLINE RTO MANAGEMENT SYSTEM 38


.
SqlCommand com = new SqlCommand(s, con);
n = com.ExecuteNonQuery();
}
catch
{
}
finally
{
con.Close();
}
return n;
}
public string scalar(string s)
{
string n = "";
try
{
con.Open();
SqlCommand com = new SqlCommand(s, con);
n = com.ExecuteScalar().ToString();
}
catch
{
}
finally
{
con.Close();
}
return n;
}
public DataTable table(String s)
{

ONLINE RTO MANAGEMENT SYSTEM 39


.
DataTable n = new DataTable();
try
{
con.Open();
SqlCommand cmd = new SqlCommand(s, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(n);
}
catch
{
}
finally
{
con.Close();
}
return n;
}
}
/*License Application*/
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
ONLINE RTO MANAGEMENT SYSTEM 40
.
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
public partial class usercontrol_License : System.Web.UI.UserControl
{
database db=new database();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
int i=0;
string cnt = "";
try
{
cnt = db.scalar("select max(id) from LicensePhoto");
}
catch { }
int id = 0;
if (cnt != "")
{
id = int.Parse(cnt) + 1;
}
else
{
id = 1;
}
string ft = FileUpload1.PostedFile.FileName;
string fname = Path.GetFileName(ft);
string str = (id.ToString()) + fname;

ONLINE RTO MANAGEMENT SYSTEM 41


.
i = db.nonquery("insert into License values('" + TextBox1.Text + "','" + TextBox2.Text + "','"
+ DropDownList1.SelectedItem.ToString() + "','" + TextBox4.Text + "','" + TextBox5.Text +
"','" + TextBox6.Text + "','" + TextBox7.Text + "','" + TextBox8.Text +
"','"+TextBox12.Text+"','" + TextBox9.Text + "','" + TextBox10.Text + "','" + TextBox11.Text
+ "','" + TextBox13.Text + "','"+TextBox14.Text+"','1')");
if (i > 0)
{
Label1.Text = "Saved";
TextBox1.Text = "";
TextBox2.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
TextBox6.Text = "";
TextBox7.Text = "";
TextBox8.Text = "";
TextBox9.Text = "";
TextBox10.Text = "";
TextBox11.Text = "";
TextBox12.Text = "";
TextBox13.Text = "";
string str1 = "";
try
{
str1 = db.scalar("select Licenseno from LicensePhoto where Licenseno='" + TextBox14.Text
+ "'");
}
catch { }
if (str1 != "")
{
}
else
{
int g = 0;

ONLINE RTO MANAGEMENT SYSTEM 42


.
g = db.nonquery("insert into LicensePhoto values('" + TextBox14.Text + "','" + str + "')");
if (g > 0)
{
FileUpload1.SaveAs(Server.MapPath("~") + @"\\License\" + str);
Label1.Text = "success";
}
else
{
Label1.Text = "Not success";
}
}
}
else
{
Label1.Text = "Not Saved";
}
}
}
Use: To apply for a licence for registered users.
/*Vehicle Registration*/
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;

ONLINE RTO MANAGEMENT SYSTEM 43


.
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class usercontrol_VehicleReg : System.Web.UI.UserControl
{
database db = new database();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void TextBox8_TextChanged(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
int i = 0;
i = db.nonquery("insert into VehicleReg values('" + TextBox1.Text + "','" + TextBox2.Text +
"','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "','" + TextBox6.Text
+ "','" + TextBox7.Text + "','" + TextBox8.Text + "','" + TextBox9.Text + "','" +
TextBox10.Text + "','" + TextBox11.Text + "','" + TextBox12.Text + "','" + TextBox13.Text +
"','" + TextBox14.Text + "','" + TextBox15.Text + "','" + TextBox16.Text + "','" +
TextBox17.Text + "','" + TextBox18.Text + "','" + TextBox19.Text + "','" + TextBox20.Text +
"')");
if (i > 0)
{
Label1.Text = "Saved";
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";

ONLINE RTO MANAGEMENT SYSTEM 44


.
TextBox5.Text = "";
TextBox6.Text = "";
TextBox7.Text = "";
TextBox8.Text = "";
TextBox9.Text = "";
TextBox10.Text = "";
TextBox11.Text = "";
TextBox12.Text = "";
TextBox13.Text = "";
TextBox14.Text = "";
TextBox15.Text = "";
TextBox16.Text = "";
TextBox17.Text = "";
TextBox18.Text = "";
TextBox19.Text = "";
TextBox20.Text = "";
}
else
{
Label1.Text = "Not Saved";
}
}
}
Use: To apply for vehicle registration.
/*Complaint Module*/
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;

ONLINE RTO MANAGEMENT SYSTEM 45


.
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class usercontrol_Complaint : System.Web.UI.UserControl
{
database db = new database();
public static string uid = "";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
uid = Session["UID"].ToString();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
int i = 0;
i = db.nonquery("insert into Complaint
values('"+uid+"','"+TextBox1.Text+"','"+TextBox2.Text+"','"+DateTime.Now.ToString()
+"','1')");
if (i > 0)
{
Label1.Text = "Complaint Send Succesfully";
TextBox1.Text = "";
TextBox2.Text = "";
}
else
{

ONLINE RTO MANAGEMENT SYSTEM 46


.
Label1.Text = "Not Send";
}
}
}
Use: For registering a complaint.
/*Fancy Number Selection*/
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class usercontrol_FancyNumber : System.Web.UI.UserControl
{
database db = new database();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string str = "";
try
{

ONLINE RTO MANAGEMENT SYSTEM 47


.
str = db.scalar("select FancyNumber from FancyNumber where
FancyNumber='"+TextBox1.Text+"'");
if (str != "")
{
Label2.Text = "FancyNumber Already used";
TextBox1.Text = "";
}
else
{
int i = 0;
i = db.nonquery("insert into FancyNumber values('" + TextBox1.Text + "','1')");
if (i > 0)
{
Label2.Text = "Success";
TextBox1.Text = "";
}
else
{
Label2.Text = "Not Saved";
//TextBox1.Text = "";
}
}
}
catch { }
}
}
Use: To select a fancy number from the available list.
/*Vehicle Search*/
using System;
using System.Collections;

ONLINE RTO MANAGEMENT SYSTEM 48


using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class usercontrol_VehicleSearch : System.Web.UI.UserControl
{
database db = new database();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
CheckBox3.Visible = false;
CheckBox4.Visible = false;
}
protected void CheckBox3_CheckedChanged(object sender, EventArgs e)
{
RadioButtonList1.Visible = false;
}
protected void CheckBox4_CheckedChanged(object sender, EventArgs e)
{
RadioButtonList1.Visible = false;
}
int r = 0;
public static int cnt = 0;

ONLINE RTO MANAGEMENT SYSTEM 49


S.N.ARTS AND SCIENCE COLLEGE KEDAMANGALAM
protected void Button1_Click(object sender, EventArgs e)
{
if (RadioButtonList1.SelectedIndex == 1)
{
Label3.Visible = true;
TextBox2.Visible = true;
Label2.Visible = false;
TextBox1.Visible = false;
Button2.Visible = true;
cnt = 1;
}
else if (RadioButtonList1.SelectedIndex == 0)
{
Label2.Visible = true;
TextBox1.Visible = true;
Label3.Visible = false;
TextBox2.Visible =false;
Button2.Visible = true;
cnt = 2;
}
else if (CheckBox3.Checked == true && CheckBox4.Checked == true)
{
r = 1;
Label4.Visible = true;
Button2.Visible = true;
TextBox3.Visible = true;
RadioButtonList1.Visible = false;
Label5.Visible = true;
TextBox4.Visible = true;
Label2.Visible = false;
TextBox1.Visible = false;
Label3.Visible = false;

ONLINE RTO MANAGEMENT SYSTEM 50


TextBox2.Visible = false;
cnt = 3;
}
if (CheckBox3.Checked == true)
{
if (r == 0)
{
Button2.Visible = true;
Label4.Visible = true;
TextBox3.Visible = true;
RadioButtonList1.Visible = false;
Label5.Visible = false;
TextBox4.Visible = false;
Label2.Visible = false;
TextBox1.Visible = false;
Label3.Visible = false;
TextBox2.Visible = false;
cnt = 4;
}
}
if (CheckBox4.Checked == true)
{
if (r == 0)
{
Button2.Visible = true;
Label5.Visible = true;
TextBox4.Visible = true;
RadioButtonList1.Visible = false;
Label4.Visible = false;
TextBox3.Visible = false;
Label2.Visible = false;
TextBox1.Visible = false;

ONLINE RTO MANAGEMENT SYSTEM 51


Label3.Visible = false;
TextBox2.Visible = false;
cnt = 5;
}
}
}
protected void Button2_Click(object sender, EventArgs e)
{
if (cnt == 1)
{
DataTable dt = new DataTable();
dt = db.table("SELECT name AS NAMEOFOWNER,age AS AGE,caddress AS
CONTADDRESS,dealer AS DEALERNAME,class AS CLASS, body AS BODY,vehicle AS
VEHICLENAME, manuname AS MANUNAME, dateofmanu AS DATEOFMANU, hp AS
HP, chassisno AS CHASSISNO, engno AS ENGNO,capacity AS CAPACITY, fuel AS FUEL,
color AS COLOUR, length AS LENGTH, width AS WIDTH, height AS HEIGHT, regno AS
REGNO FROM VehicleReg where chassisno like '%"+TextBox2.Text+"%'");
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
else
{
Label6.Text = "No Records";
}
}
else if (cnt == 2)
{
DataTable dt = new DataTable();

ONLINE RTO MANAGEMENT SYSTEM 52


dt = db.table("SELECT name AS NAMEOFOWNER,age AS AGE,caddress AS
CONTADDRESS,dealer AS DEALERNAME,class AS CLASS, body AS BODY,vehicle AS
VEHICLENAME, manuname AS MANUNAME, dateofmanu AS DATEOFMANU, hp AS
HP, chassisno AS CHASSISNO, engno AS ENGNO,capacity AS CAPACITY, fuel AS FUEL,
color AS COLOUR, length AS LENGTH, width AS WIDTH, height AS HEIGHT, regno AS
REGNO FROM VehicleReg where regno like '%" + TextBox1.Text + "%'");
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
else
{
Label6.Text = "No Records";
}
}
else if (cnt == 3)
{
DataTable dt = new DataTable();
dt = db.table("SELECT name AS NAMEOFOWNER,age AS AGE,caddress AS
CONTADDRESS,dealer AS DEALERNAME,class AS CLASS, body AS BODY,vehicle AS
VEHICLENAME, manuname AS MANUNAME, dateofmanu AS DATEOFMANU, hp AS
HP, chassisno AS CHASSISNO, engno AS ENGNO,capacity AS CAPACITY, fuel AS FUEL,
color AS COLOUR, length AS LENGTH, width AS WIDTH, height AS HEIGHT, regno AS
REGNO FROM VehicleReg where vehicle like '%" + TextBox3.Text + "%' and color
like'%"+TextBox4.Text+"%'");
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
else

ONLINE RTO MANAGEMENT SYSTEM 53


.
{
Label6.Text = "No Records";
}
}
else if (cnt == 4)
{
DataTable dt = new DataTable();
dt = db.table("SELECT name AS NAMEOFOWNER,age AS AGE,caddress AS
CONTADDRESS,dealer AS DEALERNAME,class AS CLASS, body AS BODY,vehicle AS
VEHICLENAME, manuname AS MANUNAME, dateofmanu AS DATEOFMANU, hp AS
HP, chassisno AS CHASSISNO, engno AS ENGNO,capacity AS CAPACITY, fuel AS FUEL,
color AS COLOUR, length AS LENGTH, width AS WIDTH, height AS HEIGHT, regno AS
REGNO FROM VehicleReg where vehicle like '%" + TextBox3.Text + "%'");
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
else
{
Label6.Text = "No Records";
}
}
else if (cnt == 5)
{
DataTable dt = new DataTable();
dt = db.table("SELECT name AS NAMEOFOWNER,age AS AGE,caddress AS
CONTADDRESS,dealer AS DEALERNAME,class AS CLASS, body AS BODY,vehicle AS
VEHICLENAME, manuname AS MANUNAME, dateofmanu AS DATEOFMANU, hp AS
HP, chassisno AS CHASSISNO, engno AS ENGNO,capacity AS CAPACITY, fuel AS FUEL,
color AS COLOUR, length AS LENGTH, width AS WIDTH, height AS

ONLINE RTO MANAGEMENT SYSTEM 54


.
HEIGHT, regno AS REGNO FROM VehicleReg where color like '%" + TextBox4.Text +
"%'");
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
else
{
Label6.Text = "No Records";
}
}
}
}
Use: To search for a vehicle using some key.
/*Message*/
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class usercontrol_Messages : System.Web.UI.UserControl
{

ONLINE RTO MANAGEMENT SYSTEM 55


.
database db = new database();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
string id="";
id=Session["UID"].ToString();
dt = db.table("select id,From1,Subject from Mail where Status='1' and To1='" + id + "' order
by dte desc");
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs
e)
{
int d = e.NewSelectedIndex;
Session["inbox"] = GridView1.Rows[d].Cells[1].Text;
Response.Redirect("InboxRead.aspx");
}
}
Use: To send informative mails to registered users.

Вам также может понравиться