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

📄 addhomehold.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 admin_Default2 : System.Web.UI.Page
{
    BaseClass bc = new BaseClass();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Convert.ToString(Session["UID"]) == "")
        {
            Response.Redirect("login.aspx");

        }
        if (!IsPostBack)
        {
            bind();
        }
       

    }

    protected void bind() 
    {
       
        bc.ExecDropDownList(pav, "select * from pavilion", "Name", "paID");//楼宇
        bc.ExecDropDownList(cell, "select * from type where type='DY'", "name", "code");//单元
        string pavcell = pav.SelectedItem.Value.ToString() + cell.SelectedItem.Value.ToString();
        int pavcelllength = pavcell.Length;
        string sql = "select Code,ownerID from room where left(Code," + pavcelllength + ")=" + pavcell + "";
        // Response.Write(sql);
        //  Response.End();
        bc.ExecDropDownList(ddlownerID, sql, "ownerID", "Code");
    }


   




    protected void Button2_Click(object sender, EventArgs e)
    {
      
        string name=txtname.Text.Trim();
        string tel=txttel.Text.Trim();
        string roomID=txtroomID.Text.Trim();
        string cardid=txtcardid.Text.Trim();
        string contact=txtcontact.Text.Trim();
        string mobile=txtmobile.Text.Trim();
        string email=txtemail.Text.Trim();
        string unit=txtunit.Text.Trim();
        string meme=txtmemo.Text.Trim();
        string uid,pwd;
        if(txtuid.Text=="")
        {
            uid=txtcardid.Text.Trim();
        }
        else
        {
            uid=txtuid.Text.Trim();
        }
        
        if(txtpwd.Text=="")
        {
            pwd = txtcardid.Text.Trim();

        }
        else
        {
            pwd=txtpwd.Text.Trim();
        }

       
        string varuser = "select Count(*) from homehold where uid='" + uid + "'";
        int count = (int)bc.ExecCscalar(varuser);
        if (count > 0)
        {
            Response.Write("<script>alert('登录用户名重复,请选择其它用户名!');</script>");

            return;
        }

        
            string strsql = "select count(*) from homehold where Code='" + ddlownerID.SelectedItem.Value + "'";
           
             count = (int)bc.ExecCscalar(strsql);

            if (count > 0)  
            {
                Response.Write("<script>alert('已有住户,添加失败,请重试!');</script>");
                //Response.Write("qq");
                Response.End();
                return;

            }
            else            //表明数据库中没有相关信息,执行插入记录
            {
                ArrayList arraySQl=new ArrayList();
                string sql = "insert into homehold(code,Name,tel,contact,mobile,Email,cardID,roomID,unit,password,uid,memo)values('";
                sql = sql + ddlownerID.SelectedItem.Value.ToString() + "','" + name + "','" + tel + "','" + contact + "','" + mobile + "','" + email + "','" + cardid + "','" + roomID + "','"+unit;
                sql = sql + "','" + pwd + "','" + uid + "','" + meme + "')";
               // Response.Write(sql);
                //Response.End();
                arraySQl.Add(sql);
                string sql1 = "update room set state=1 where Code='" + ddlownerID.SelectedItem.Value + "'";
                arraySQl.Add(sql1);
                if (bc.ExecSQLTrans(arraySQl))
                {
                    Response.Write("<script>alert('数据保存成功!');location='homehold.aspx'</script>");

                }
                else
                {
                    Response.Write("<script>alert('数据保存失败!');</script>");

                    return;

                }

            }

           






        }
      
       

        
    protected void  cell_SelectedIndexChanged(object sender, EventArgs e)
    {
         string pavcell = pav.SelectedItem.Value.ToString() + cell.SelectedItem.Value.ToString();
        int pavcelllength = pavcell.Length;
        string sql = "select Code,ownerID from room where left(Code," + pavcelllength + ")=" + pavcell + "";
        // Response.Write(sql);
        //  Response.End();
        bc.ExecDropDownList(ddlownerID, sql, "ownerID", "Code");
     }

    //根据文本档中的单元名称查找相应的房间业主信息绑定到相应的地方
    #region 根据文本档中的单元名称查找相应的房间业主信息绑定到相应的地方
    /// <summary>
    /// 
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Button1_Click(object sender, EventArgs e)
    {
        //string sql = "select count(code) from room where ownerID='" + codeName.Text.Trim() + "'";
        //int count = (int)bc.ExecCscalar(sql);
        //if (count > 0)
        //{
        //    string strsql = "select * from homehold where Code in(select Code from room where ownerID='" + codeName.Text.Trim() + "')";

        //    //Response.Write(strsql);
        //    //Response.End();
        //    SqlDataReader sdr = bc.ExecRead(strsql);
        //    if (sdr.Read())
        //    {
        //        txtname.Text = sdr["Name"].ToString();//姓名
        //        txttel.Text = sdr["tel"].ToString();//电话
        //        txtroomID.Text = sdr["roomID"].ToString();
        //        txtcardid.Text = sdr["cardID"].ToString();//身份证
        //        txtcontact.Text = sdr["contact"].ToString();//联系地址
        //        txtmobile.Text = sdr["mobile"].ToString();//手机
        //        txtemail.Text = sdr["Email"].ToString();//电子邮件
        //        txtunit.Text = sdr["unit"].ToString();//单位
        //        txtuid.Text = sdr["uid"].ToString();//用户名
        //        txtpwd.Text = sdr["password"].ToString();//密码
        //        txtmemo.Text = sdr["memo"].ToString();//备注
        //    }
        //    else
        //    {

        //        txtname.Text = "";
        //        txttel.Text = "";
        //        txtroomID.Text = "";
        //        txtcardid.Text = "";
        //        txtcontact.Text = "";
        //        txtmobile.Text = "";
        //        txtemail.Text = "";
        //        txtunit.Text = "";
        //        txtuid.Text = "";
        //        txtpwd.Text = "";
        //        txtmemo.Text = "";
        //        Response.Write("<script>alert('该单元还没有住户!');</script>");



        //    }


        //}
        //else
        //{
        //    Response.Write("<script>alert('该单元不存在!');</script>");
        //}
    }
    #endregion
}

⌨️ 快捷键说明

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