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

📄 st_roomaddmodule.ascx.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 Context_ST_RoomAddModule : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            this.lblInfo.Visible = false;

            SqlConnection ST_myCon = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
            SqlCommand ST_mycommand = new SqlCommand();
            ST_mycommand.Connection = ST_myCon;
            ST_mycommand.CommandText = "select ST_RCategoryId,ST_Name from ST_RoomCategory";
            ST_myCon.Open();
            SqlDataReader dl = ST_mycommand.ExecuteReader();
            while (dl.Read())
            {
                ListItem li = new ListItem(dl["ST_Name"].ToString(), dl["ST_RCategoryId"].ToString());
                this.ddlCategory.Items.Add(li);
            }
            dl.Close();
            ST_myCon.Close();

        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            SqlConnection ST_myCon = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
            SqlCommand ST_mycommand = new SqlCommand();
            ST_mycommand.Connection = ST_myCon;
            ST_mycommand.CommandText = "ST_InsertRoom";
            ST_mycommand.CommandType = CommandType.StoredProcedure;
            ST_mycommand.Parameters.Add("@RoomId", SqlDbType.Int);
            ST_mycommand.Parameters.Add("@RCategoryId", SqlDbType.Int);
            ST_mycommand.Parameters.Add("@RPosition", SqlDbType.VarChar, 50);
            ST_mycommand.Parameters.Add("@Description", SqlDbType.VarChar, 50);


            ST_mycommand.Parameters["@RoomId"].Value = int.Parse(this.txtRoomId.Text);
            ST_mycommand.Parameters["@RCategoryId"].Value = System.Convert.ToInt32(this.ddlCategory.SelectedValue);
            ST_mycommand.Parameters["@RPosition"].Value = this.txtPosition.Text;
            ST_mycommand.Parameters["@Description"].Value = this.txtDesc.Text;
            try
            {
                ST_myCon.Open();
                ST_mycommand.ExecuteNonQuery();
                this.lblInfo.Visible = true;
                this.lblInfo.Text = "添加成功";
            }
            catch (SqlException exx)
            {
                this.lblInfo.Visible = true;
                this.lblInfo.Text = "出错:" + exx.Message;
            }
            finally
            {
                ST_myCon.Close();
            }
        }
    }
    protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        SqlConnection ST_myCon = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
        SqlCommand ST_mycommand = new SqlCommand();
        ST_mycommand.Connection=ST_myCon;
        int RoomId=int.Parse(this.txtRoomId.Text);
        ST_mycommand.CommandText = "select * from ST_RoomsInfo where ST_RoomId=" + RoomId + "";
        ST_myCon.Open();
        SqlDataReader dl = ST_mycommand.ExecuteReader();
        if (dl.Read())
        {
            args.IsValid = false;
        }
        else
        {
            args.IsValid = true;
        }
        dl.Close();
        ST_myCon.Close();
    }
}

⌨️ 快捷键说明

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