📄 showhuo.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public partial class include_Showhuo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (Session["Leaveword"].ToString() != "pass")
{
Response.Redirect("../Default.aspx");
}
}
catch
{
Response.Redirect("../Default.aspx");
}
if (!Page.IsPostBack)
{
Bindgridview();
Tianchong();
}
}
//填充下拉菜单
private void Tianchong()
{
drpMonth.Items.Clear();
drpMonth1.Items.Clear();
drpDay.Items.Clear();
drpDay1.Items.Clear();
for (int i = 1; i < 13; i++)
{
drpMonth.Items.Add(new ListItem(i.ToString(), i.ToString()));
drpMonth1.Items.Add(new ListItem(i.ToString(), i.ToString()));
}
for (int i = 1; i < 32; i++)
{
drpDay.Items.Add(new ListItem(i.ToString(), i.ToString()));
drpDay1.Items.Add(new ListItem(i.ToString(), i.ToString()));
}
}
protected void HuoGridView_RowCommand(object sender, GridViewCommandEventArgs e)
{
switch (e.CommandName.ToString())
{
case "delete":
Delhuo(Int32.Parse(e.CommandArgument.ToString()));
Bindgridview();
break;
default:
break;
}
}
protected void HuoGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
}
protected void HuoGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
ImageButton deleteBtn = (ImageButton)e.Row.FindControl("delBtn");
if (deleteBtn != null)
{
deleteBtn.Attributes.Add("onclick", "return confirm('你确定要删除所选择信息?');");
}
}
protected void HuoGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
HuoGridView.PageIndex = e.NewPageIndex;
Bindgridview();
}
//绑定控件
private void Bindgridview()
{
DataSet ds = Gethuo();
HuoGridView.DataSource = ds.Tables["aa"].DefaultView;
HuoGridView.DataBind();
}
//删除信息
private void Delhuo(int nHuowuID)
{
string myConnectionString = ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING1"].ConnectionString + Server.MapPath("~") + ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING2"].ConnectionString;
OleDbConnection myConnection = new OleDbConnection(myConnectionString);
string cmdText = "DELETE FROM Huowu WHERE HuowuID=" + nHuowuID;
OleDbCommand myCommand = new OleDbCommand(cmdText, myConnection);
try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
}
catch (OleDbException ex)
{
throw new Exception(ex.Message, ex);
}
finally
{
myConnection.Close();
}
}
//取车辆信息
public DataSet Gethuo()
{
string myConnectionString = ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING1"].ConnectionString + Server.MapPath("~") + ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING2"].ConnectionString;
OleDbConnection myConnection = new OleDbConnection(myConnectionString);
string cmdText = "SELECT * FROM Huowu WHERE FaID=0 ORDER BY Createdate DESC";
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter(cmdText, myConnection);
try
{
myConnection.Open();
da.Fill(ds, "aa");
}
catch (OleDbException ex)
{
throw new Exception(ex.Message, ex);
}
finally
{
myConnection.Close();
}
return ds;
}
public DataSet Gethuobydate(string str1,string str2)
{
string myConnectionString = ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING1"].ConnectionString + Server.MapPath("~") + ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING2"].ConnectionString;
OleDbConnection myConnection = new OleDbConnection(myConnectionString);
string cmdText = "SELECT * FROM Huowu WHERE Createdate>=CDate('" + str1 + "')" + "AND Createdate<=CDate('" + str2 + "') AND FaID=0 ORDER BY Createdate DESC";
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter(cmdText, myConnection);
try
{
myConnection.Open();
da.Fill(ds, "aa");
}
catch (OleDbException ex)
{
throw new Exception(ex.Message, ex);
}
finally
{
myConnection.Close();
}
return ds;
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Write("<Script>window.open('Inputhuo.aspx','','width=540,height=240');</Script>");
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
Bindgridview();
}
protected void Button1_Click(object sender, EventArgs e)
{
string date01 = drpYear.SelectedValue.ToString() + "-" + drpMonth.SelectedValue.ToString() + "-" + drpDay.SelectedValue.ToString();
string date02 = drpYear1.SelectedValue.ToString() + "-" + drpMonth1.SelectedValue.ToString() + "-" + drpDay1.SelectedValue.ToString();
DataSet ds = Gethuobydate(date01, date02);
HuoGridView.DataSource = ds.Tables["aa"].DefaultView;
HuoGridView.DataBind();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -