⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 showcustom.aspx.cs

📁 asp.net 的某物流管理系统 MIS 系统
💻 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_Showcustom : 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();
        }
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Response.Write("<Script>window.open('Inputcustom.aspx','','width=560,height=220');</Script>");
    }
    //绑定控件
    private void Bindgridview()
    {
        DataSet ds = Getcustom();
        CustomGridView.DataSource = ds.Tables["aa"].DefaultView;
        CustomGridView.DataBind();
    }
    //取客户信息
    public DataSet Getcustom()
    {
        string myConnectionString = ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING1"].ConnectionString + Server.MapPath("~") + ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING2"].ConnectionString;
        OleDbConnection myConnection = new OleDbConnection(myConnectionString);
        DataSet ds = new DataSet();
        string cmdText = "SELECT * FROM Custom ORDER BY Createdate DESC";
        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;
    }
    //删除客户信息
    private void Delcustom(int nCustomID)
    {
        string myConnectionString = ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING1"].ConnectionString + Server.MapPath("~") + ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING2"].ConnectionString;
        OleDbConnection myConnection = new OleDbConnection(myConnectionString);
        string cmdText = "DELETE FROM Custom WHERE CustomID=" + nCustomID;
        OleDbCommand myCommand = new OleDbCommand(cmdText, myConnection);
        try
        {
            myConnection.Open();
            myCommand.ExecuteNonQuery();
        }
        catch 
        {
            
        }
        finally
        {
            myConnection.Close();
        }
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        Bindgridview();
    }
    protected void CustomGridView_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "delete")
        {
            
            try
            {
                Delcustom(Int32.Parse(e.CommandArgument.ToString()));
                
                Bindgridview();
                
            }
            catch(Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }
    }
    protected void CustomGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        CustomGridView.PageIndex = e.NewPageIndex;
        Bindgridview();
    }

    protected void CustomGridView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        ImageButton deleteBtn = (ImageButton)e.Row.FindControl("delBtn");
        if (deleteBtn != null)
        {
            deleteBtn.Attributes.Add("onclick", "return confirm('你确定要删除所选择客户信息?');");
        }
        
    }
    protected void CustomGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

    }
}

⌨️ 快捷键说明

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