Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            string id    = this.textBox2.Text;
            string name  = this.textBox1.Text;
            string sy    = this.comboBox1.Text;
            string power = "";
            String cd    = null;

            if (name != null && !"".Equals(name))
            {
                if (name == "admin")
                {
                    MessageBox.Show("管理员账号不能被修改!");
                }
                else
                {
                    foreach (Control ctr in this.groupBox2.Controls)
                    {
                        //判断该控件是不是CheckBox
                        if (ctr is CheckBox)
                        {
                            //将ctr转换成CheckBox并赋值给ck
                            CheckBox ck = ctr as CheckBox;
                            if (ck.Checked)
                            {
                                power += "," + ck.Text;
                            }
                        }
                    }
                    for (int i = 0; i < checkedListBox1.Items.Count; i++)
                    {
                        if (checkedListBox1.GetItemChecked(i))
                        {
                            cd += "," + checkedListBox1.GetItemText(checkedListBox1.Items[i]);
                        }
                    }
                    if (power != null && !"".Equals(power))
                    {
                        power = power.Substring(1);
                        cd    = cd.Substring(1);
                        bean.UserInfo ui = new bean.UserInfo();
                        ui.Id       = id;
                        ui.UserName = name;
                        ui.Enable   = Int32.Parse(sy);
                        ui.Power    = power;
                        service.UserService us = new service.UserService();
                        bool istrue            = us.updateUser(ui, cd);
                        if (istrue)
                        {
                            this.Hide();
                            this.DialogResult = DialogResult.OK;
                        }
                        else
                        {
                            MessageBox.Show("用户名或密码为空,请重新输入!");
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            string name  = this.textBox1.Text;
            string pwd   = this.textBox2.Text;
            string pwd1  = this.textBox3.Text;
            string power = "";
            String cd    = null;

            if (name != null && !"".Equals(name) && pwd.Equals(pwd1))
            {
                foreach (Control ctr in this.groupBox2.Controls)
                {
                    //判断该控件是不是CheckBox
                    if (ctr is CheckBox)
                    {
                        //将ctr转换成CheckBox并赋值给ck
                        CheckBox ck = ctr as CheckBox;
                        if (ck.Checked)
                        {
                            power += "," + ck.Text;
                        }
                    }
                }

                for (int i = 0; i < checkedListBox1.Items.Count; i++)
                {
                    if (checkedListBox1.GetItemChecked(i))
                    {
                        cd += "," + checkedListBox1.GetItemText(checkedListBox1.Items[i]);
                    }
                }

                if (power != null && !"".Equals(power))
                {
                    power = power.Substring(1);
                    if (cd != null && cd != "")
                    {
                        cd = cd.Substring(1);
                    }
                    bean.UserInfo ui = new bean.UserInfo();
                    ui.UserName = name;
                    ui.Pwd      = MemoryPassword.MyEncrypt.EncryptDES(pwd);
                    ui.Power    = power;
                    ui.Enable   = 1;
                    service.UserService us = new service.UserService();
                    bool istrue            = us.addUser(ui, cd);
                    if (istrue)
                    {
                        this.Hide();
                        this.DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        MessageBox.Show("用户名已重复,请重新输入!");
                    }
                }
                else
                {
                    MessageBox.Show("未给新用户设置权限!");
                }
            }
            else
            {
                MessageBox.Show("用户名或密码不能为空或两次密码输入不一致!");
            }
        }