?? addcjzykh.aspx.cs
字號:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;
namespace khgl
{
/// <summary>
/// addcjzykh 的摘要說明。
/// </summary>
public class addcjzykh : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList ddtcdw;
protected System.Web.UI.WebControls.DropDownList ddbkhdw;
protected System.Web.UI.WebControls.DropDownList ddbkhzy;
protected System.Web.UI.WebControls.TextBox tbwtms;
protected System.Web.UI.WebControls.TextBox tbkhyj;
protected System.Web.UI.WebControls.TextBox tbjkkhf;
protected System.Web.UI.WebControls.RangeValidator RangeValidator1;
protected System.Web.UI.WebControls.TextBox tbyf;
protected System.Web.UI.WebControls.RangeValidator Rangevalidator2;
protected System.Web.UI.WebControls.TextBox tblrr;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Label Labellrr;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label Labellrsj;
protected System.Web.UI.WebControls.Label ShowMsg;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此處放置用戶代碼以初始化頁面
// 在此處放置用戶代碼以初始化頁面
Labellrr.Text="球團廠專業考核錄入";
//顯示登記時間
Labellrsj.Text=DateTime.Now.ToString();
DateTime tnow=DateTime.Now;
tbyf.Text=(tnow.Month .ToString());
}
#region Web 窗體設計器生成的代碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 該調用是 ASP.NET Web 窗體設計器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
/// </summary>
private void InitializeComponent()
{
this.ddbkhdw.SelectedIndexChanged += new System.EventHandler(this.ddbkhdw_SelectedIndexChanged);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void ddbkhdw_SelectedIndexChanged(object sender, System.EventArgs e)
{
ArrayList values=new ArrayList();
//values.Add("所有");
ddbkhzy.DataSource=values;
ddbkhzy.DataBind();
//客戶信息下拉列表框綁定
string strconn= ConfigurationSettings.AppSettings["sqlConnectionString"];
//連接本地計算機的HMS數據庫
SqlConnection cn0= new SqlConnection (strconn);
cn0.Open ();
string mysql2="select distinct zy from dwzy where dw='" +ddbkhdw.SelectedItem.ToString() + "'";
SqlCommand cm2=new SqlCommand (mysql2,cn0);
SqlDataReader dr2=cm2.ExecuteReader ();
while(dr2.Read ())
{
ddbkhzy.Items .Add (new ListItem(dr2["zy"].ToString(),dr2["zy"].ToString()) );
}
cn0.Close ();
}
private void Button1_Click(object sender, System.EventArgs e)
{
if(Page.IsValid)
{
//從文件Web.config中讀取連接字符串
string sqldb= ConfigurationSettings.AppSettings["sqlConnectionString"];
//連接JdglSys數據庫
SqlConnection Conn= new SqlConnection (sqldb);
Conn.Open ();
//利用Command對象調用存儲過程
SqlCommand mycommand=new SqlCommand ("sp_Insertcjzykh",Conn);
//將命令類型轉為存儲類型
mycommand.CommandType =CommandType.StoredProcedure ;
//往存儲過程中添加參數
mycommand.Parameters .Add ("@tcdw",SqlDbType.NVarChar);
mycommand.Parameters .Add ("@bkhdw",SqlDbType.NVarChar);
mycommand.Parameters .Add ("@bkhzy",SqlDbType.NVarChar);
mycommand.Parameters .Add ("@wtms",SqlDbType.NVarChar);
mycommand.Parameters .Add ("@khyj",SqlDbType.NVarChar);
mycommand.Parameters .Add ("@jkkhf",SqlDbType.NVarChar);
mycommand.Parameters .Add ("@lrr",SqlDbType.NVarChar);
mycommand.Parameters .Add ("@yf",SqlDbType.Int);
mycommand.Parameters .Add ("@lrsj",SqlDbType.DateTime);
//給存儲過程的參數賦值
mycommand.Parameters ["@tcdw"].Value =ddtcdw.SelectedItem.Value;
mycommand.Parameters ["@bkhdw"].Value =ddbkhdw.SelectedItem.Value;
mycommand.Parameters ["@bkhzy"].Value =ddbkhzy.SelectedValue.ToString();
mycommand.Parameters ["@wtms"].Value =tbwtms.Text.Trim();
mycommand.Parameters ["@khyj"].Value =tbkhyj.Text.Trim();
mycommand.Parameters ["@jkkhf"].Value =tbjkkhf.Text.Trim();
mycommand.Parameters ["@lrr"].Value =tblrr.Text.Trim();
mycommand.Parameters ["@yf"].Value =tbyf.Text.Trim();
mycommand.Parameters ["@lrsj"].Value =Labellrsj.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 + -