📄 car_jilu.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace car1
{
/// <summary>
/// car_jilu 的摘要说明。
/// </summary>
public partial class car_jilu : System.Web.UI.Page
{
protected void Page_Load(object sender, System.EventArgs e)
{
if(Session["S_username"].ToString()=="")
{
Response.Redirect("index.aspx");
}
if(Session["S_userrule"].ToString()=="")
{
Response.Redirect("main1.aspx");
}
if(!Page.IsPostBack)
{
usecar_DataBind();
}
// 在此处放置用户代码以初始化页面
}
private void usecar_DataBind()
{
string SqlConn=System.Configuration.ConfigurationSettings.AppSettings["ConnString"];
SqlConnection Conn=new SqlConnection(SqlConn);
Conn.Open();
string SqlStr1="select id as '编号',carcode as '车牌号码',cartype as '车辆类型',caruser as '驾驶员',carcompany as '用车单位',carstate as '状态',carxingcheng as '车辆行程',carregtime as '用车日期',carmobile as '联系方式'from [beifen] order by id DESC";
SqlCommand Comm=new SqlCommand(SqlStr1,Conn);
DataSet ds=new DataSet();
SqlDataAdapter dr=new SqlDataAdapter(SqlStr1,Conn);
dr.Fill(ds,"beifen");
GridView1.DataSource=ds.Tables["beifen"].DefaultView;
GridView1.DataBind();
string SqlStr2="select * from [bumen]";
SqlDataAdapter de=new SqlDataAdapter(SqlStr2,Conn);
de.Fill(ds,"bumen");
this.DropDownList1.DataSource=ds.Tables["bumen"].DefaultView;
this.DropDownList1.DataTextField="type";
this.DropDownList1.DataValueField="type";
this.DropDownList1.DataBind();
string SqlStr3="select car_code from [car]";
SqlDataAdapter dw=new SqlDataAdapter(SqlStr3,Conn);
dw.Fill(ds,"carcode");
this.DropDownList2.DataSource=ds.Tables["carcode"].DefaultView;
this.DropDownList2.DataTextField="car_code";
this.DropDownList2.DataValueField="car_code";
this.DropDownList2.DataBind();
string SqlStr4="select name from [tb_user] where part='院办(车队)'";
SqlDataAdapter dq=new SqlDataAdapter(SqlStr4,Conn);
dq.Fill(ds,"user");
this.DropDownList3.DataSource=ds.Tables["user"].DefaultView;
this.DropDownList3.DataTextField="name";
this.DropDownList3.DataValueField="name";
this.DropDownList3.DataBind();
Conn.Close();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
}
#endregion
private void GridView1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
DataBind();
}
private void GridView1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if(GridView1.Rows.Count==1)
{
if(GridView1.PageIndex!=0)
{
GridView1.PageIndex=GridView1.PageIndex-1;
}
}
else
{
string SqlStr2="delete [beifen] where id="+e.Item.Cells[0].Text+"";
string SqlConn=System.Configuration.ConfigurationSettings.AppSettings["ConnString"];
SqlConnection Conn=new SqlConnection(SqlConn);
Conn.Open();
SqlCommand Comm=new SqlCommand(SqlStr2,Conn);
Comm.ExecuteReader();
Conn.Close();}
Response.Redirect("car_jilu.aspx");
}
private void GridView1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem||e.Item.ItemType==ListItemType.EditItem)
{
TableCell myTableCell;
myTableCell=e.Item.Cells[16];
LinkButton btnDel=(LinkButton)myTableCell.Controls[0];
btnDel.Attributes.Add("onclick","return confirm('您确定要删除这条车辆记录吗?');");
btnDel.Text="删除";
}
}
protected void Button3_Click(object sender, EventArgs e)
{
string SqlConn = System.Configuration.ConfigurationSettings.AppSettings["ConnString"];
SqlConnection Conn = new SqlConnection(SqlConn);
Conn.Open();
string SqlStr = "select id as '编号',carcode as '车牌号码',cartype as '车辆类型',caruser as '驾驶员',carcompany as '用车单位',carstate as '状态',carxingcheng as '车辆行程',carregtime as '用车日期',carmobile as '联系方式'from [beifen] where caruser='" + this.DropDownList3.SelectedValue + "' and carcompany like '%" + this.DropDownList1.SelectedValue + "%' and carcode='" + this.DropDownList2.SelectedValue + "' order by id DESC";
DataSet ds = new DataSet();
SqlDataAdapter dr = new SqlDataAdapter(SqlStr, Conn);
dr.Fill(ds, "beifen");
GridView1.DataSource = ds.Tables["beifen"].DefaultView;
GridView1.DataBind();
Conn.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -