예제 #1
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            string AddUserID = TB_UserID.Text.Trim().ToString();
            //string AddPassword = TB_Password.Text.ToString().Trim();

            string AddRoleID = "";

            //AddRoleID = GetRolesID();
            AddRoleID = Dr_SelRole.SelectedValue.ToString();
            try
            {
                if (TB_UserID.Text.Trim().ToString() == "") //如果不加.Trim()函数,那么输入空格也会成为合法输入,这样显然不符合逻辑。
                {
                    this.Lb_UserID.Text = "不能空";
                    return;
                }
                //if (TB_Password.Text == "")
                //{
                //    this.Lb_Password.Visible = true;
                //    return;
                //}
                else
                {
                    this.Lb_UserID.Text = " ";
                    //        this.Lb_Password.Visible = false;
                }
                if (users.Exists(AddUserID))        //此用账号已经存在
                {
                    this.Lb_UserID.Text = "此用账号已被使用";
                    this.TB_UserID.Text = "";
                    TB_UserID.Focus();

                    return;
                }
                else
                {
                    string temp_password = txtPwd.Text.Trim().ToString();
                    string pwd           = FormsAuthentication.HashPasswordForStoringInConfigFile(temp_password, "MD5");
                    bool   flag          = false;
                    flag = users.AddUser(AddUserID, pwd, AddRoleID);   //增加用户
                    if (flag == true)
                    {
                        this.Lb_UserID.Text = "添加成功";
                    }
                    bind();
                }
            }
            catch (Exception ee)
            {
                Response.Write("<script>alert('添加失败,系统错误')</script>");
            }
        }
예제 #2
0
        protected void Button2_Click(object sender, EventArgs e)
        {
            sr_User users = new sr_User();

            string UserID01 = TextBox1.Text.Trim().ToString();
            string UserID02 = TextBox2.Text.Trim().ToString();
            string UserID03 = TextBox3.Text.Trim().ToString();
            string UserID04 = TextBox4.Text.Trim().ToString();
            string UserID05 = TextBox5.Text.Trim().ToString();
            string UserID06 = TextBox6.Text.Trim().ToString();
            string UserID07 = TextBox7.Text.Trim().ToString();
            string UserID08 = TextBox8.Text.Trim().ToString();
            string UserID09 = TextBox9.Text.Trim().ToString();
            string UserID10 = TextBox10.Text.Trim().ToString();
            string UserID11 = TextBox11.Text.Trim().ToString();
            string UserID12 = TextBox12.Text.Trim().ToString();
            string UserID13 = TextBox13.Text.Trim().ToString();
            string UserID14 = TextBox14.Text.Trim().ToString();
            string UserID15 = TextBox15.Text.Trim().ToString();

            string AddRoleID = "";

            //AddRoleID = GetRolesID();
            AddRoleID = Dr_SelRole.SelectedValue.ToString();

            //   string temp_password = txtPwd.Text.Trim().ToString();
            string temp_Pwd      = txtPwd.Text.Trim().ToString();
            string temp_password = FormsAuthentication.HashPasswordForStoringInConfigFile(temp_Pwd, "MD5");

            int lenght = 15;

            string[] strUserIDs    = new String[lenght];
            string   WrongInputNum = "";
            int      count         = 0;
            int      emptyID       = 0;

            strUserIDs[0]      = UserID01;
            strUserIDs[1]      = UserID02;
            strUserIDs[2]      = UserID03;
            strUserIDs[3]      = UserID04;
            strUserIDs[4]      = UserID05;
            strUserIDs[5]      = UserID06;
            strUserIDs[6]      = UserID07;
            strUserIDs[7]      = UserID08;
            strUserIDs[8]      = UserID09;
            strUserIDs[9]      = UserID10;
            strUserIDs[10]     = UserID11;
            strUserIDs[11]     = UserID12;
            strUserIDs[12]     = UserID13;
            strUserIDs[13]     = UserID14;
            strUserIDs[14]     = UserID15;
            this.LbResult.Text = " ";
            for (int i = 0; i < lenght; i++)
            {
                if (strUserIDs[i] != "")
                {
                    if (!users.Exists(strUserIDs[i]))
                    {
                        users.AddUser(strUserIDs[i], temp_password, AddRoleID);   //增加用户
                        count++;
                    }
                    else
                    {
                        WrongInputNum += (i + 1).ToString() + ",";
                    }
                }
                else
                {
                    emptyID++;
                }

                //   this.LbResult.Text +=(i+1).ToString()+":"+ strUserIDs[i]+",";
            }

            if (emptyID == 15)  //输入全为空
            {
                this.LbResult.Text = " 抱歉,输入不能全为空";
                return;
            }
            if (count == 15) //输入不为空 且 输入账号不重复,即添加了全部数据
            {
                this.LbResult.Text = " 恭喜已成功添加全部数据";

                TextBox1.Focus();
                clearTextBox();
            }
            else //添加了少于15条的数据
            {
                this.LbResult.Text = " 总共添加" + count + "条数据";
                if (WrongInputNum != "")           //输入存在重复账号
                {
                    this.LbResult.Text += " 注意:账号" + WrongInputNum + "的数据已被使用,请重新输入";
                }
                else //有些输入为空,但输入不为空的都没有输入重复账号
                {
                    TextBox1.Focus();
                    clearTextBox();
                }
            }
            bind();
        }