📄 addmeeting.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class addmeeting : System.Web.UI.Page
{
ArrayList year, month, day,hour,m;
int i;
SqlConnection cn;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
cn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["cn"]);
cn.Open();
SqlCommand cmd = new SqlCommand("select * from userinfo",cn);
SqlDataReader dr = cmd.ExecuteReader();
this.CheckBoxList1.DataSource = dr;
this.CheckBoxList1.DataTextField = "username";
this.CheckBoxList1.DataBind();
dr.Close();
cn.Close();
year = new ArrayList();
month = new ArrayList();
day = new ArrayList();
hour = new ArrayList();
m=new ArrayList ();
for (i =2000; i <=2100; i++)
year.Add(i.ToString());
for (i = 1; i <= 12; i++)
month.Add(i.ToString());
for (i = 1; i <= 31; i++)
day.Add(i.ToString());
for (i = 1; i <= 24; i++)
hour.Add(i.ToString ());
for (i = 00; i <= 59; i++)
m.Add(i.ToString());
ddlyear.DataSource = year;
ddlyear.DataBind();
ddlyear.Text = System.DateTime.Now.Year.ToString ();
DropDownList1 . Text = System.DateTime.Now.Year.ToString();
ddlmonth.DataSource = month;
ddlmonth.DataBind();
ddlmonth.Text = System.DateTime.Now.Month.ToString();
DropDownList2 . Text = System.DateTime.Now.Month.ToString();
ddlday.DataSource = day;
ddlday.DataBind();
ddlday.Text = System.DateTime.Now.Day.ToString();
DropDownList3 .Text = System.DateTime.Now.Day.ToString();
ddlhour.DataSource = hour;
ddlhour.DataBind();
ddlhour.Text = System.DateTime.Now.Hour.ToString();
DropDownList4.Text = System.DateTime.Now.Hour.ToString();
ddlm.DataSource = m;
ddlm.DataBind();
ddlm.Text = System.DateTime.Now.Minute.ToString();
this.DropDownList1.DataSource = year;
this.DropDownList1.DataBind();
this.DropDownList2.DataSource = month;
this.DropDownList2.DataBind();
this.DropDownList3.DataSource = day;
this.DropDownList3.DataBind();
this.DropDownList4.DataSource =hour ;
this.DropDownList4.DataBind();
this.DropDownList5.DataSource =m;
this.DropDownList5.DataBind();
DropDownList5.Text = System.DateTime.Now.Minute.ToString();
}
}
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
string adminname = args.Value;
cn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["cn"]);
cn.Open();
SqlCommand cmd = new SqlCommand("select count(*)from meeting where name='" + adminname + "'", cn);
int count = Convert.ToInt32(cmd.ExecuteScalar());
if (count > 0)
{
args.IsValid = false;
this.Labmessage.Text = "";
}
else
{
args.IsValid = true;
}
cn.Close();
}
protected void ddlmonth_SelectedIndexChanged(object sender, EventArgs e)
{
int[] numbers = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if ((Convert.ToInt32(ddlyear.SelectedItem.Text.ToString()) % 4) == 0)
numbers[1] = 29;
day = new ArrayList();
for (i = 1; i <= numbers[Convert.ToInt32(ddlmonth.SelectedItem.Text.ToString()) - 1]; i++)
day.Add(i.ToString());
ddlday.DataSource = day;
ddlday.DataBind();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button2_Click(object sender, EventArgs e)
{
this.Label1.Text = "";
if (Page.IsValid)
{
//循环显示信息
for (int i = 0; i <= CheckBoxList1.Items.Count - 1; i++)
{
if (this.CheckBoxList1.Items[i].Selected)
{
this.Label1.Text += this.CheckBoxList1.Items[i].Text.ToString() + ",";
}
}
try
{
//添加会议功能
cn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["cn"]);
//打开数据库连接
cn.Open();
SqlCommand cmd = new SqlCommand("insert into meeting(name,addr,begintime,endtime,person,builder,content)values('" + this.txtname.Text.ToString().Trim() + "','" + this.ddlroompos.SelectedItem.Value.ToString() + "','" + this.ddlyear.SelectedItem.Value.ToString() + "-" + this.ddlmonth.SelectedItem.Value.ToString() + "-" + this.ddlday.SelectedItem.Value + " " + this.ddlhour.SelectedItem.Value.ToString() + ":" + this.ddlm.SelectedItem.Value.ToString() + "','" + this.DropDownList1.SelectedItem.Value.ToString() + "-" + this.DropDownList2.SelectedItem.Value.ToString() + "-" + this.DropDownList3.SelectedItem.Value.ToString() + " " + this.DropDownList4.SelectedItem.Value.ToString() + ":" + this.DropDownList5.SelectedItem.Value.ToString() + "','" + this.Label1.Text.Trim() + "','" + Convert.ToString(Session["username"]) + "','" + this.txtnote.Text.Trim() + "')", cn);
cmd.ExecuteNonQuery();
this.HyperLink1.Visible = true;
this.Labmessage.Text = "添加会议成功";
}
catch
{
this.Labmessage.Text = "服务器忙,请一会在试!";
}
finally
{
cn.Close();
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
this.txtname.Text = "";
this.txtnote.Text = "";
this.txtname.Focus();
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
int[] numbers = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if ((Convert.ToInt32(this.DropDownList1 .SelectedItem.Text.ToString()) % 4) == 0)
numbers[1] = 29;
day = new ArrayList();
for (i = 1; i <= numbers[Convert.ToInt32(this.DropDownList2 .SelectedItem.Text.ToString()) - 1]; i++)
day.Add(i.ToString());
this.DropDownList3 .DataSource = day;
this.DropDownList3 .DataBind();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -