📄 researchaddmodule.ascx.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>
/// ResearchAddModule 的摘要说明。
/// </summary>
public class ResearchAddModule : ModuleBase
{
protected System.Web.UI.WebControls.Label CreateLabel;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator4;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator7;
protected System.Web.UI.WebControls.ValidationSummary ValidationSummary1;
protected System.Web.UI.WebControls.Button SubmitButton;
protected System.Web.UI.WebControls.Button ReturnButton;
protected System.Web.UI.WebControls.Label RecordIdLabel;
protected System.Web.UI.WebControls.Label ClientNameLabel;
protected System.Web.UI.WebControls.Label CNameLabel;
protected System.Web.UI.WebControls.Label EngineerLabel;
protected System.Web.UI.WebControls.Label DealWithDateLabel;
protected System.Web.UI.WebControls.Label PhoneLabel;
protected System.Web.UI.WebControls.TextBox RDetailsTextBox;
protected System.Web.UI.WebControls.Label FinishDateLabel;
protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator2;
protected System.Web.UI.WebControls.TextBox RsDateTextBox;
protected System.Web.UI.WebControls.TextBox ResearcherTextBox;
protected System.Web.UI.WebControls.TextBox RsPersonTextBox;
protected System.Web.UI.WebControls.TextBox RsPhoneTextBox;
protected System.Web.UI.WebControls.TextBox EvaluationTextBox;
protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator3;
protected System.Web.UI.WebControls.Label CreateDateLabel;
protected System.Web.UI.WebControls.DropDownList RsIdeaList;
protected System.Web.UI.WebControls.Label ShowMsg;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
//显示记录序号信息
RecordIdLabel.Text=Request.QueryString ["RecordId"].ToString ();
//从文件Web.config中读取连接字符串
string sqldb= ConfigurationSettings.AppSettings["ConnectionString"];
//连接JdglSys数据库
SqlConnection Conn = new SqlConnection (sqldb);
Conn.Open ();
//利用Command对象调用存储过程sp_GetDispatchById
SqlCommand mycommand=new SqlCommand("sp_GetDispatchById",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();
CreateDateLabel.Text=dr["CreateDate"].ToString();
EngineerLabel.Text=dr["Engineer"].ToString();
DealWithDateLabel.Text=dr["DealWithDate"].ToString();
FinishDateLabel.Text=dr["FinishDate"].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.SubmitButton.Click += new System.EventHandler(this.SubmitButton_Click);
this.ReturnButton.Click += new System.EventHandler(this.ReturnButton_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void SubmitButton_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对象调用存储过程
SqlCommand mycommand=new SqlCommand ("sp_InsertResearch",Conn);
//将命令类型转为存储类型
mycommand.CommandType =CommandType.StoredProcedure ;
//往存储过程中添加参数
mycommand.Parameters .Add ("@RecordId",SqlDbType.NVarChar);
mycommand.Parameters .Add ("@RsPerson",SqlDbType.NVarChar);
mycommand.Parameters .Add ("@RsDate",SqlDbType.NVarChar);
mycommand.Parameters .Add ("@Researcher",SqlDbType.NVarChar);
mycommand.Parameters .Add ("@RsTel",SqlDbType.NVarChar);
mycommand.Parameters .Add ("@Evaluation",SqlDbType.NVarChar);
mycommand.Parameters .Add ("@RsIdea",SqlDbType.NVarChar);
//给存储过程的参数赋值
mycommand.Parameters ["@RecordId"].Value =RecordIdLabel.Text.Trim();
mycommand.Parameters ["@RsPerson"].Value = RsPersonTextBox.Text.Trim();
mycommand.Parameters ["@RsDate"].Value =RsDateTextBox.Text.Trim();
mycommand.Parameters ["@Researcher"].Value =ResearcherTextBox.Text.Trim();
mycommand.Parameters ["@RsTel"].Value =RsPhoneTextBox.Text.Trim();
mycommand.Parameters ["@Evaluation"].Value =EvaluationTextBox.Text.Trim();
mycommand.Parameters ["@RsIdea"].Value =RsIdeaList.SelectedIndex;
try
{
mycommand.ExecuteNonQuery();
ShowMsg.Text="服务调查添加成功";
ShowMsg.Style["color"]="green";}
catch(SqlException error)
{
ShowMsg.Text="添加未成功,请稍后再试。原因:"+error.Message;
ShowMsg.Style["color"]="red";
}
//关闭连接
Conn.Close();
}
}
private void ReturnButton_Click(object sender, System.EventArgs e)
{
Response.Redirect(PathPrefix+"/ResearchMan.aspx");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -