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

📄 wldetailsmodule.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>
	///		WlDetailsModule 的摘要说明。
	/// </summary>
	public class WlDetailsModule : ModuleBase
	{
		protected System.Web.UI.WebControls.Label CreateLabel;
		protected System.Web.UI.WebControls.TextBox RmethodTextbox;
		protected System.Web.UI.WebControls.LinkButton Edit;
		protected System.Web.UI.WebControls.TextBox StartDateTextBox;
		protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator2;
		protected System.Web.UI.WebControls.TextBox EndDateTextbox;
		protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator3;
		protected System.Web.UI.WebControls.TextBox RwayTextBox;
		protected System.Web.UI.WebControls.TextBox RplaceTextbox;
		protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator1;
		protected System.Web.UI.WebControls.TextBox RLostTextBox;
		protected System.Web.UI.WebControls.Label ShowMsg;
		protected System.Web.UI.WebControls.ValidationSummary ValidationSummary1;
		protected System.Web.UI.WebControls.Label LogIdLabel;

		private void Page_Load(object sender, System.EventArgs e)
		{
			if(!IsPostBack)
			{	
				//显示记录序号信息
				LogIdLabel.Text=Request.QueryString ["LogId"].ToString ();
			
				//从文件Web.config中读取连接字符串
				string sqldb= ConfigurationSettings.AppSettings["ConnectionString"];
				//连接JdglSys数据库
				SqlConnection Conn = new SqlConnection (sqldb);
				Conn.Open ();
				string selsql="select * from WorkLogs where Logid='"+LogIdLabel.Text+"'";
				//利用Command对象调用selsql
				SqlCommand mycommand=new SqlCommand(selsql,Conn);
				SqlDataReader dr=mycommand.ExecuteReader ();
				if(dr.Read ())
				{
					StartDateTextBox.Text=dr["StartDate"].ToString();
					EndDateTextbox.Text=dr["EndDate"].ToString();
					RwayTextBox.Text=dr["Rway"].ToString();
					RplaceTextbox.Text=dr["Rplace"].ToString();
					RmethodTextbox.Text=dr["Rmethod"].ToString();
					RLostTextBox.Text=dr["Rlost"].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.Edit.Click += new System.EventHandler(this.Edit_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void Edit_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对象调用存储过程sp_UpdateWorkLog
				SqlCommand mycommand=new SqlCommand  ("sp_UpdateWorkLog",Conn);
				//将命令类型转为存储类型
				mycommand.CommandType =CommandType.StoredProcedure ;
				//往存储过程中添加参数
				mycommand.Parameters .Add ("@LogId",SqlDbType.Int);
				mycommand.Parameters .Add ("@StartDate",SqlDbType.DateTime);
				mycommand.Parameters .Add ("@EndDate",SqlDbType.DateTime);
				mycommand.Parameters .Add ("@Rway",SqlDbType.NVarChar);
				mycommand.Parameters .Add ("@Rplace",SqlDbType.NVarChar);
				mycommand.Parameters .Add ("@Rmethod",SqlDbType.NVarChar);
				mycommand.Parameters .Add ("@Rlost",SqlDbType.NVarChar);
				//给存储过程的参数赋值
				mycommand.Parameters ["@LogId"].Value =LogIdLabel.Text;
				mycommand.Parameters ["@StartDate"].Value = StartDateTextBox.Text;
				mycommand.Parameters ["@EndDate"].Value =EndDateTextbox.Text;
				mycommand.Parameters ["@Rway"].Value =RwayTextBox.Text.Trim();
				mycommand.Parameters ["@Rplace"].Value =RplaceTextbox.Text.Trim();
				mycommand.Parameters ["@Rmethod"].Value =RmethodTextbox.Text.Trim();
				mycommand.Parameters ["@Rlost"].Value =RLostTextBox.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 + -