?? recordeditmodule.ascx.cs
字號(hào):
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>
/// RecordEditModule 的摘要說明。
/// </summary>
public class RecordEditModule : ModuleBase
{
protected System.Web.UI.WebControls.Label CreateLabel;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
protected System.Web.UI.WebControls.Label NowTimeLabel;
protected System.Web.UI.WebControls.TextBox ClientIdTextbox;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.TextBox CNameTextBox;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator4;
protected System.Web.UI.WebControls.TextBox PhoneTextBox;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator7;
protected System.Web.UI.WebControls.DropDownList LevelList;
protected System.Web.UI.WebControls.CustomValidator LevelCustomvalidator;
protected System.Web.UI.WebControls.TextBox RDetailsTextBox;
protected System.Web.UI.WebControls.DropDownList StatusList;
protected System.Web.UI.WebControls.CustomValidator StatusCustomvalidator;
protected System.Web.UI.WebControls.TextBox FinishDateTextbox;
protected System.Web.UI.WebControls.TextBox RemarksTextBox;
protected System.Web.UI.WebControls.RadioButtonList ResearchList;
protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator2;
protected System.Web.UI.WebControls.TextBox LogPersonTextbox;
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.Label ShowMsg;
protected System.Web.UI.WebControls.Label RecordIdLabel;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
//顯示記錄序號(hào)信息
RecordIdLabel.Text=Request.QueryString ["RecordId"].ToString ();
//從文件Web.config中讀取連接字符串
string sqldb= ConfigurationSettings.AppSettings["ConnectionString"];
//連接JdglSys數(shù)據(jù)庫(kù)
SqlConnection Conn = new SqlConnection (sqldb);
Conn.Open ();
//利用Command對(duì)象調(diào)用存儲(chǔ)過程
SqlCommand mycommand=new SqlCommand("sp_GetRecordById",Conn);
//將命令類型轉(zhuǎn)為存儲(chǔ)類型
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 ())
{
ClientIdTextbox.Text=dr["ClientName"].ToString();
CNameTextBox.Text=dr["CPerson"].ToString();
PhoneTextBox.Text=dr["CTel"].ToString();
LevelList.SelectedIndex=int.Parse(dr["RLevel"].ToString());
RDetailsTextBox.Text=dr["RDetails"].ToString();
StatusList.SelectedIndex=int.Parse(dr["RStatus"].ToString());
LogPersonTextbox.Text=dr["LogPerson"].ToString();
NowTimeLabel.Text=dr["CreateDate"].ToString();
FinishDateTextbox.Text=dr["FinishDate"].ToString();
RemarksTextBox.Text =dr["Remarks"].ToString();
ResearchList.SelectedIndex=int.Parse(dr["IsResearch"].ToString());
}
//關(guān)閉Conn
Conn.Close();
}
}
//檢驗(yàn)嚴(yán)重級(jí)別列表框是否填寫
public void LevelNotNullValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
{
if(LevelList.SelectedIndex==0)
{
args.IsValid =false;//未填寫
}
else
{
args.IsValid =true;//已填寫
}
}
//檢驗(yàn)狀態(tài)列表框是否填寫
public void StatusNotNullValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
{
if(StatusList.SelectedIndex==0)
{
args.IsValid =false;//未填寫
}
else
{
args.IsValid =true;//已填寫
}
}
#region Web 窗體設(shè)計(jì)器生成的代碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 該調(diào)用是 ASP.NET Web 窗體設(shè)計(jì)器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 設(shè)計(jì)器支持所需的方法 - 不要使用代碼編輯器
/// 修改此方法的內(nèi)容。
/// </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數(shù)據(jù)庫(kù)
SqlConnection Conn = new SqlConnection (sqldb);
Conn.Open ();
//定義sql語(yǔ)句
String updatesql="update Records set RDetails=@RDetails,RLevel=@RLevel,RStatus=@RStatus,"+
" ClientName=@ClientName,CPerson=@CPerson,CTel=@CTel,LogPerson=@LogPerson,"+
" FinishDate=@FinishDate,IsResearch=@IsResearch,"+
" Remarks=@Remarks where RecordId = @RecordId";
//利用Command對(duì)象調(diào)用updatesql
SqlCommand mycommand=new SqlCommand (updatesql,Conn);
//往存儲(chǔ)過程中添加參數(shù)
mycommand.Parameters .Add ("@RecordId",SqlDbType.Int);
mycommand.Parameters .Add ("@ClientName",SqlDbType.NVarChar);
mycommand.Parameters .Add ("@CPerson",SqlDbType.NVarChar);
mycommand.Parameters .Add ("@CTel",SqlDbType.NVarChar);
mycommand.Parameters .Add ("@RLevel",SqlDbType.NVarChar);
mycommand.Parameters .Add ("@RDetails",SqlDbType.NVarChar);
mycommand.Parameters .Add ("@RStatus",SqlDbType.NVarChar);
mycommand.Parameters .Add ("@LogPerson",SqlDbType.NVarChar);
mycommand.Parameters .Add ("@FinishDate",SqlDbType.DateTime);
mycommand.Parameters .Add ("@Remarks",SqlDbType.NVarChar);
mycommand.Parameters .Add ("@IsResearch",SqlDbType.Int);
//給存儲(chǔ)過程的參數(shù)賦值
mycommand.Parameters ["@RecordId"].Value =RecordIdLabel.Text.Trim();
mycommand.Parameters ["@ClientName"].Value =ClientIdTextbox.Text.Trim();
mycommand.Parameters ["@CPerson"].Value = CNameTextBox.Text.Trim();
mycommand.Parameters ["@CTel"].Value =PhoneTextBox.Text.Trim();
mycommand.Parameters ["@RLevel"].Value =LevelList.SelectedIndex;
mycommand.Parameters ["@RDetails"].Value =RDetailsTextBox.Text.Trim();
mycommand.Parameters ["@RStatus"].Value =StatusList.SelectedIndex;
mycommand.Parameters ["@LogPerson"].Value =LogPersonTextbox.Text.Trim();
mycommand.Parameters ["@FinishDate"].Value =FinishDateTextbox.Text;
mycommand.Parameters ["@Remarks"].Value =RemarksTextBox.Text.Trim();
mycommand.Parameters ["@IsResearch"].Value =ResearchList.SelectedIndex;
try
{
mycommand.ExecuteNonQuery();
ShowMsg.Text="客戶記錄修改成功";
ShowMsg.Style["color"]="green";}
catch(SqlException error)
{
ShowMsg.Text="修改未成功,請(qǐng)稍后再試。原因:"+error.Message;
ShowMsg.Style["color"]="red";
}
//關(guān)閉連接
Conn.Close();
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -