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

📄 editcustom.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_Inputcustom : 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)
        {
            OleDbDataReader dr = Getcustom(Int32.Parse(Request.Params["ShowID"].ToString()));
            if (dr.Read())
            {
                txtName.Text = dr["Xingming"].ToString();
                txtPhone.Text = dr["Dianhua"].ToString();
                txtDanwei.Text = dr["Danwei"].ToString();
                txtBeizhu.Text = dr["Beizhu"].ToString();
            }
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Write("<Script>window.close()</Script>");
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string name = txtName.Text.ToString().Trim();
        string phone = txtPhone.Text.ToString().Trim();
        string danwei = txtDanwei.Text.ToString().Trim();
        string beizhu = txtBeizhu.Text.ToString().Trim();
        if (name.Length < 1)
        {
            return;
        }
        Updateinfo(name, phone, danwei, beizhu,Int32.Parse(Request.Params["ShowID"].ToString()));
        Response.Write("<Script>alert('修改成功!')</Script>");        
    }
   
    //更表客户信息到数据库
    private void Updateinfo(string sName, string sPhone, string sDanwei, string sBeizhu,int nCustomID)
    {
        string myConnectionString = ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING1"].ConnectionString + Server.MapPath("~") + ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING2"].ConnectionString;
        OleDbConnection myConnection = new OleDbConnection(myConnectionString);
        string cmdText = "UPDATE Custom SET " +
            "Xingming='" + sName + "'," +
            "Dianhua='" + sPhone + "'," +
            "Danwei='" + sDanwei + "'," +
            "Beizhu='" + sBeizhu + "' WHERE CustomID=" + nCustomID;
        OleDbCommand myCommand = new OleDbCommand(cmdText, myConnection);
        try
        {
            myConnection.Open();
            myCommand.ExecuteNonQuery();
        }
        catch (OleDbException ex)
        {
            throw new Exception(ex.Message, ex);
        }
        finally
        {
            myConnection.Close();
        }
    }
   
    //取客户信息
    public OleDbDataReader Getcustom(int nCustomID)
    {
        string myConnectionString = ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING1"].ConnectionString + Server.MapPath("~") + ConfigurationManager.ConnectionStrings["OLEDBCONNECTIONSTRING2"].ConnectionString;
        OleDbConnection myConnection = new OleDbConnection(myConnectionString);
        string cmdText = "SELECT * FROM Custom WHERE CustomID=" + nCustomID;
        OleDbCommand myCommand = new OleDbCommand(cmdText, myConnection);
        OleDbDataReader dr = null;
        try
        {
            myConnection.Open();
            dr=myCommand.ExecuteReader(CommandBehavior.CloseConnection);
            
        }
        catch (OleDbException ex)
        {
            throw new Exception(ex.Message, ex);
        }

        return dr;
    }
}

⌨️ 快捷键说明

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