showche.aspx.cs

来自「asp.net 的某物流管理系统 MIS 系统」· CS 代码 · 共 132 行

CS
132
字号
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_Showche : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            try
            {
                if (Session["Leaveword"] != "pass")
                {
                    Response.Redirect("../Default.aspx");
                }
            }
            catch
            {
                Response.Redirect("../Default.aspx");
            }
            Bindgridview();
        }
    }
    //绑定控件
    private void Bindgridview()
    {
        DataSet ds = Getche();
        CheGridView.DataSource = ds.Tables["aa"].DefaultView;
        CheGridView.DataBind();
    }
    //取车辆信息
    public DataSet Getche()
    {
        string myConnectionString = ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING1"].ConnectionString + Server.MapPath("~") + ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING2"].ConnectionString;
        OleDbConnection myConnection = new OleDbConnection(myConnectionString);
        string cmdText = "SELECT * FROM Che WHERE ShowID=1 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 LinkButton2_Click(object sender, EventArgs e)
    {
        Bindgridview();
    }
    protected void LinkButton3_Click(object sender, EventArgs e)
    {
        Response.Write("<Script>window.open('Inputche.aspx','','width=430,height=220');</Script>");
    }
    protected void LinkButton4_Click(object sender, EventArgs e)
    {
        Response.Redirect("../Default.aspx");
    }
    protected void CheGridView_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "delete")
        {

            try
            {
                Delche(Int32.Parse(e.CommandArgument.ToString()));
                Bindgridview();
            }
            catch
            {
            }
        }
        
    }
    //删除车辆
    private void Delche(int nCheID)
    {
        string myConnectionString = ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING1"].ConnectionString + Server.MapPath("~") + ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING2"].ConnectionString;
        OleDbConnection myConnection = new OleDbConnection(myConnectionString);
        string cmdText = "DELETE FROM Che WHERE CheID=" + nCheID;
        OleDbCommand myCommand = new OleDbCommand(cmdText, myConnection);
        try
        {
            myConnection.Open();
            myCommand.ExecuteNonQuery();
        }
        catch (OleDbException ex)
        {
            throw new Exception(ex.Message, ex);
        }
        finally
        {
            myConnection.Close();
        }
    }
    protected void CheGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

    }
   
    protected void CheGridView_RowDateBound(object sender, GridViewRowEventArgs e)
    {
        ImageButton deleteBtn = (ImageButton)e.Row.FindControl("delBtn");
        if (deleteBtn != null)
        {
            deleteBtn.Attributes.Add("onclick", "return confirm('你确定要删除所选择车辆?');");
        }
    }
    //翻页
    protected void CheGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        CheGridView.PageIndex = e.NewPageIndex;
        Bindgridview();
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?