📄 addsch.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.Configuration;
using System.Data.SqlClient ;
namespace OfficeOnline
{
/// <summary>
/// AddSch 的摘要说明。
/// </summary>
public class AddSch : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox tbxcontent;
protected System.Web.UI.WebControls.TextBox tbxsubject;
protected System.Web.UI.WebControls.TextBox tbxplace;
protected System.Web.UI.WebControls.DropDownList dplschtype;
protected System.Web.UI.WebControls.TextBox tbxtime;
protected System.Web.UI.WebControls.Button btnadd;
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
//创建数据库连接和命令对象
SqlConnection objconn = new SqlConnection(ConfigurationSettings.AppSettings["connstr"]);
objconn.Open();
string objsql="Select SchTypeName from SchType";
SqlDataAdapter da = new SqlDataAdapter(objsql,objconn);
//创建并填充DataSet
DataSet ds = new DataSet();
da.Fill(ds,"SchType");
dplschtype.DataSource=ds;
dplschtype.DataMember="SchType";
dplschtype.DataTextField ="SchTypeName";
dplschtype.DataBind();
objconn.Close();
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnadd.Click += new System.EventHandler(this.btnadd_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnadd_Click(object sender, System.EventArgs e)
{
//创建数据库连接和命令对象
SqlConnection objconn = new SqlConnection(ConfigurationSettings.AppSettings["connstr"]);
SqlCommand objcmd = new SqlCommand("AddSch",objconn);
objcmd.CommandType=CommandType.StoredProcedure;
//添加参数
//员工编号
SqlParameter paramEmpID = new SqlParameter("@EmpID",SqlDbType.Int);
paramEmpID.Value =Convert.ToInt32(Session["EmpID"]);
//paramEmpID.Value =1;
objcmd.Parameters.Add(paramEmpID);
//日程类型编号
SqlParameter paramSchTypeID2 = new SqlParameter("@SchTypeID",SqlDbType.Int);
paramSchTypeID2.Value =Convert.ToInt32(dplschtype.SelectedIndex+1);
objcmd.Parameters.Add(paramSchTypeID2);
//日程主题
SqlParameter paramSubject=new SqlParameter("@Subject",SqlDbType.NVarChar,50);
paramSubject.Value=tbxsubject.Text;
objcmd.Parameters.Add(paramSubject);
//日程内容
SqlParameter paramContent = new SqlParameter("@Content",SqlDbType.NVarChar,4000);
paramContent.Value=tbxcontent.Text;
objcmd.Parameters.Add(paramContent);
//时间
SqlParameter paramDate = new SqlParameter("@Date",SqlDbType.DateTime);
paramDate.Value=Convert.ToDateTime(tbxtime.Text);
objcmd.Parameters.Add(paramDate);
//短时间
SqlParameter paramShortDate=new SqlParameter("@ShortDate",SqlDbType.DateTime);
paramShortDate.Value=Convert.ToDateTime(tbxtime.Text).ToShortDateString();
objcmd.Parameters.Add(paramShortDate);
//地点
SqlParameter paramPlace= new SqlParameter("@Place",SqlDbType.NVarChar,500);
paramPlace.Value=tbxplace.Text;
objcmd.Parameters.Add(paramPlace);
objcmd.Connection.Open();
objcmd.ExecuteNonQuery();
objcmd.Connection.Close();
Response.Redirect("Default.aspx");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -