⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 homesunhaiinfo.aspx.cs

📁 学生寝室管理系统
💻 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 homesunhaiinfo : System.Web.UI.Page
{
   SqlCommand  cmd,cmd1,cmd2,cmd3;
   SqlConnection  cn;
    SqlDataReader  dr;
    string strcon, strsql,strsql1,strsql2;
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!this .IsPostBack )
        {
            if ( Convert .ToString (Session["shenfen"]) == "室员")
            {
                Response.Write("<script language='javascript'>alert('非常抱歉!您不是"寝室长",不能进入该页面!^_^');window.location.href='userindex.aspx'</script>");
            }
            else
            {
                Response.Write("<script language='javascript'>alert('您的身份是"寝室长",欢迎进入该页面!^_^');</script>");
            }
            this.txtusername .Text = Convert.ToString(Session["username"]);
            this.txtuserid .Text = Convert.ToString(Session["userid"]);
            cn = sqldata.createcon();
            cn.Open();
            strsql1 = "select home from homedetail ";
            cmd1 = new SqlCommand (strsql1, cn);
            dr = cmd1.ExecuteReader();
            this.ddlhomeflood.DataSource = dr;
            this.ddlhomeflood.DataTextField = "home";
            this.ddlhomeflood.DataBind();

            this.ddlhomeflood .Items.Add("请选择");
            this.ddlhomeflood .SelectedIndex = this.ddlhomeflood .Items.Count - 1;
          
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (this.IsValid)
        {
            cn = sqldata.createcon();
            cn.Open();
            strsql = "insert into homebad(userid,username,homeflood,homesex,homecount,homehao,homephone,content)values('" + this.txtuserid.Text.ToString() + "','" + this.txtusername.Text.ToString() + "','" + this.ddlhomeflood .SelectedItem .Value .ToString() + "','"+this.ddlhomesex .SelectedItem .Value .ToString ()+"','"+this.ddlhomecount .SelectedItem .Value .ToString ()+"','" + this.txthomehao.Text.ToString() + "','"+this.txthomephone .Text .ToString ()+"','" + this.txtcontent.Text.ToString() + "')";
            cmd= new SqlCommand (strsql, cn);
            cmd.ExecuteNonQuery();
            this.Label3.Text = "添加成功";
            cn.Close();
        }
    }
    protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        string content = args.Value;
        cn = sqldata.createcon();
        cn.Open();
        strsql2 = "select count(*)from homebad where content='" + content + "'";
        cmd2 = new SqlCommand (strsql2, cn);
        int count = Convert.ToInt32(cmd2.ExecuteScalar());
        if (count > 0)
        {
            args.IsValid = false;
        }
        else
        {
            args.IsValid = true;
        }
        cn.Close();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        this.txthomehao.Text = "";
        this.txtcontent.Text = "";
        this.txthomehao.Focus();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -