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

📄 dispatchmodule.ascx.cs

📁 《C#数据库项目案例导航》一书的配套光盘
💻 CS
字号:
namespace KhfwWeb.Modules
{
	using System;
	using System.Data;
	using System.Data.SqlClient;
	using System.Configuration;
	using System.Drawing;
	using System.Web;
	using System.Web.UI.WebControls;
	using System.Web.UI.HtmlControls;

	/// <summary>
	///		DispatchModule 的摘要说明。
	/// </summary>
	public class DispatchModule : ModuleBase
	{
		protected System.Web.UI.WebControls.Label CreateLabel;
		protected System.Web.UI.WebControls.Label RecordIdLabel;
		protected System.Web.UI.WebControls.Label NowTimeLabel;
		protected System.Web.UI.WebControls.TextBox RDetailsTextBox;
		protected System.Web.UI.WebControls.ValidationSummary ValidationSummary1;
		protected System.Web.UI.WebControls.Button Submit;
		protected System.Web.UI.WebControls.HyperLink Return;
		protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator3;
		protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator4;
		protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator5;
		protected System.Web.UI.WebControls.Label ClientNameLabel;
		protected System.Web.UI.WebControls.Label CNameLabel;
		protected System.Web.UI.WebControls.Label PhoneLabel;
		protected System.Web.UI.WebControls.TextBox OpinionTextbox;
		protected System.Web.UI.WebControls.TextBox EngineerTextbox;
		protected System.Web.UI.WebControls.TextBox DealWithDateTextbox;
		protected System.Web.UI.WebControls.TextBox SubmitPersonTextbox;
		protected System.Web.UI.WebControls.Label SubmitDateLabel;
		protected System.Web.UI.WebControls.Label ShowMsg;
		protected System.Web.UI.WebControls.Label TitleLabel;

		protected string Type;

		private void Page_Load(object sender, System.EventArgs e)
		{
			if(!IsPostBack)
			{	
                //获取DispatchManModule传递的Type参数,Type=1表示记录分配,Type=2表示重新分配
				Type=Request.QueryString["Type"].ToString();
				if(Type=="1")
				{
					TitleLabel.Text="问题记录分配";
					Return.NavigateUrl=PathPrefix+"/ReDispatchMan.aspx?RStatus=1";
				}
				else if(Type=="2")
				{
					TitleLabel.Text="重新记录分配";
                    Return.NavigateUrl=PathPrefix+"/ReDispatchMan.aspx?RStatus=2";
				}
				//显示记录序号信息
				RecordIdLabel.Text=Request.QueryString ["RecordId"].ToString ();
				//显示提交时间
			    SubmitDateLabel.Text=DateTime.Now.ToString();
				//从文件Web.config中读取连接字符串
				string sqldb= ConfigurationSettings.AppSettings["ConnectionString"];
				//连接JdglSys数据库
				SqlConnection Conn = new SqlConnection (sqldb);
				Conn.Open ();
				//利用Command对象调用存储过程
				SqlCommand mycommand=new SqlCommand("sp_GetRecordById",Conn);
				//将命令类型转为存储类型
				mycommand.CommandType =CommandType.StoredProcedure ;
				mycommand.Parameters .Add ("@RecordId",SqlDbType.Int);
				mycommand.Parameters ["@RecordID"].Value = int.Parse(RecordIdLabel.Text);
				SqlDataReader dr=mycommand.ExecuteReader ();
				if(dr.Read ())
				{
					ClientNameLabel.Text=dr["ClientName"].ToString();
					CNameLabel.Text=dr["CPerson"].ToString();
					PhoneLabel.Text=dr["CTel"].ToString();
					RDetailsTextBox.Text=dr["RDetails"].ToString();
					NowTimeLabel.Text=dr["CreateDate"].ToString();
				}
				//关闭Conn
				Conn.Close();
			}
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		设计器支持所需的方法 - 不要使用代码编辑器
		///		修改此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.Submit.Click += new System.EventHandler(this.Submit_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void Submit_Click(object sender, System.EventArgs e)
		{
			if(Page.IsValid )
			{
				//从文件Web.config中读取连接字符串
				string sqldb = ConfigurationSettings.AppSettings["ConnectionString"];
				//连接JdglSys数据库
				SqlConnection Conn = new SqlConnection (sqldb);
				Conn.Open ();
				//利用Command对象调用updatesql
				SqlCommand mycommand=new SqlCommand ("sp_InsertDispatch",Conn);
				mycommand.CommandType=CommandType.StoredProcedure;
				//添加参数
				mycommand.Parameters .Add ("@RecordId",SqlDbType.Int);
				mycommand.Parameters .Add ("@Opinion",SqlDbType.NVarChar);
				mycommand.Parameters .Add ("@Engineer",SqlDbType.NVarChar);
				mycommand.Parameters .Add ("@DwDate",SqlDbType.DateTime);
				mycommand.Parameters .Add ("@SPerson",SqlDbType.NVarChar);
				mycommand.Parameters .Add ("@SDate",SqlDbType.DateTime );
				//给存储过程的参数赋值
				mycommand.Parameters ["@RecordId"].Value =RecordIdLabel.Text;
				mycommand.Parameters ["@Opinion"].Value =OpinionTextbox.Text.Trim();
				mycommand.Parameters ["@Engineer"].Value =EngineerTextbox.Text.Trim();
				mycommand.Parameters ["@DwDate"].Value =DealWithDateTextbox.Text.Trim();
				mycommand.Parameters ["@SPerson"].Value =SubmitPersonTextbox.Text.Trim();
				mycommand.Parameters ["@SDate"].Value =SubmitDateLabel.Text.Trim();
				try
				{
					mycommand.ExecuteNonQuery();
					ShowMsg.Text="分配提交成功";
					ShowMsg.Style["color"]="green";}
				catch(SqlException error)
				{
					ShowMsg.Text="提交未成功,请稍后再试。原因:"+error.Message;
					ShowMsg.Style["color"]="red";
				}
				//关闭连接
				Conn.Close();
			}
		}
	}
}

⌨️ 快捷键说明

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