Example #1
0
        private void ChangePasswordButton_Click(object sender, EventArgs e)
        {
            if (ChangePasswordTextbox.Text == "")
            {
                MessageBox.Show("密码只能由字母、数字、点、下划线组成,且不能为空!");
            }
            ShowPasswordTextbox.Enabled = true;
            DataTable dt = new DataTable();
            CTMySql   cm = new CTMySql();

            dt = cm.GetTableValue("Account");
            int    pkvalue = -1;
            string pkname  = dt.Columns[0].ColumnName;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (UserNameTextbox.Text == dt.Rows[i]["Account"].ToString())
                {
                    pkvalue = Convert.ToInt32(dt.Rows[i][0]);
                    break;
                }
            }
            cm.UpdataDatabass("account", ChangePasswordTextbox.Text, "Password", pkname, pkvalue);
            MessageBox.Show("密码修改成功!");
            ShowPasswordTextbox.Text = ChangePasswordTextbox.Text;
        }
Example #2
0
 //登陆页面  首次出现
 private void FormSignIn_Shown(object sender, EventArgs e)
 {
     cTMySql          = new CTMySql("localhost", "root", "震动监测系统", "000000", "3306"); //设置连接参数
     CTMySql.isSignIn = false;
     if (cTMySql.ConnectDatabass())                                                   //打开连接,判断连接是否成功
     {
         //MessageBox.Show("Success To Connect MySQL");
     }
     else
     {
         MessageBox.Show("Fail To Connect MySQL");
     }
 }
Example #3
0
        private void ShowPasswordButton_Click(object sender, EventArgs e)
        {
            ShowPasswordTextbox.Enabled = true;
            DataTable dt = new DataTable();
            CTMySql   cm = new CTMySql();

            dt = cm.GetTableValue("Account");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (UserNameTextbox.Text == dt.Rows[i]["Account"].ToString())
                {
                    ShowPasswordTextbox.Text = dt.Rows[i]["Password"].ToString();
                    break;
                }
            }
        }
Example #4
0
        private void ChangeAdminYesRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            CTMySql   cm = new CTMySql();

            dt = cm.GetTableValue("Account");
            int    pkvalue = -1;
            string pkname  = dt.Columns[0].ColumnName;

            if (dt.Rows[0]["Account"].ToString() == UserNameTextbox.Text)
            {
                MessageBox.Show("此默认账户不能被修改!");
                return;
            }
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (UserNameTextbox.Text == dt.Rows[i]["Account"].ToString())
                {
                    pkvalue = Convert.ToInt32(dt.Rows[i][0]);
                    break;
                }
            }
            if (ChangeAdminYesRadioButton.Checked)
            {
                cm.UpdataDatabass("Account", "1", "Level", pkname, pkvalue);
            }
            else
            {
                cm.UpdataDatabass("Account", "0", "Level", pkname, pkvalue);
            }
            cm.IsUserAdmin();
            this.Refresh();
            #region 获取所有用户信息
            //获取所有用户信息
            UserListView.BeginUpdate();

            UserListView.View = View.Details;
            UserListView.Clear();
            UserListView.Columns.Add("用户名(双击选择用户)", 200, HorizontalAlignment.Right);
            UserListView.Columns.Add("管理员", 50, HorizontalAlignment.Center);
            UserListView.FullRowSelect = true;

            dt = cm.GetTableValue("Account");

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string name;
                ulong  admin;
                name  = (string)dt.Rows[i]["Account"];
                admin = (ulong)dt.Rows[i]["Level"];

                ListViewItem lvi = new ListViewItem();
                lvi.Text = name;
                if (admin == 1)
                {
                    lvi.SubItems.Add("是");
                }
                else
                {
                    lvi.SubItems.Add("否");
                }
                UserListView.Items.Add(lvi);
            }
            UserListView.EndUpdate();
            #endregion
        }
Example #5
0
        // 删除用户按钮   点击
        private void DeletUserButton_Click(object sender, EventArgs e)
        {
            DialogResult dr = new DialogResult();

            dr = MessageBox.Show("确认删除用户 " + UserNameTextbox.Text + "?", "", MessageBoxButtons.YesNo);
            if (dr == DialogResult.No)
            {
                return;
            }
            DataTable dt = new DataTable("Account");
            CTMySql   cm = new CTMySql();

            dt = cm.GetTableValue("Account");
            int    pkvalue = -1;
            string pkname  = dt.Columns[0].ColumnName;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (UserNameTextbox.Text == dt.Rows[i]["Account"].ToString())
                {
                    pkvalue = Convert.ToInt32(dt.Rows[i][0]);
                    break;
                }
            }
            cm.DeletRowfromDatabass("Account", pkname, pkvalue);
            MessageBox.Show("删除用户成功!");

            #region 获取所有用户信息
            //获取所有用户信息
            UserListView.BeginUpdate();

            UserListView.View = View.Details;
            UserListView.Clear();
            UserListView.Columns.Add("用户名(双击选择用户)", 200, HorizontalAlignment.Right);
            UserListView.Columns.Add("管理员", 50, HorizontalAlignment.Center);
            UserListView.FullRowSelect = true;

            dt = cm.GetTableValue("Account");

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string name;
                ulong  admin;
                name  = (string)dt.Rows[i]["Account"];
                admin = (ulong)dt.Rows[i]["Level"];

                ListViewItem lvi = new ListViewItem();
                lvi.Text = name;
                if (admin == 1)
                {
                    lvi.SubItems.Add("是");
                }
                else
                {
                    lvi.SubItems.Add("否");
                }
                UserListView.Items.Add(lvi);
            }
            UserListView.EndUpdate();
            #endregion
        }
Example #6
0
        // 添加用户按钮
        private void NewUserAddButton_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable("Account");
            CTMySql   cm = new CTMySql();

            cm.ConnectDatabass();
            dt = cm.GetTableValue("Account");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (NewUserNameTextbox.Text == (string)dt.Rows[i]["Account"])
                {
                    MessageBox.Show("用户已经存在,请更改用户名");
                    return;
                }
            }
            if (NewUserPasswordTextbox.Text == "")
            {
                MessageBox.Show("密码不能为空,请重试");
                return;
            }
            DialogResult dr = DialogResult.Yes;

            if (NewUserAdminYesRadioButton.Checked)
            {
                dr = MessageBox.Show("确定添加的新用户为管理员用户?", "", MessageBoxButtons.YesNo);
            }
            if (dr == DialogResult.No)
            {
                return;
            }
            int level = 0;

            if (NewUserAdminYesRadioButton.Checked)
            {
                level = 1;
            }
            if (NewUserAdminNoRadioButton.Checked)
            {
                level = 0;
            }
            string[] data = new string[3];
            data[0] = NewUserPasswordTextbox.Text;
            data[1] = NewUserNameTextbox.Text;
            data[2] = level.ToString();
            cm.AddRowtoDatabass(data, "Account");

            #region 获取所有用户信息
            //获取所有用户信息
            UserListView.BeginUpdate();

            UserListView.View = View.Details;
            UserListView.Clear();
            UserListView.Columns.Add("用户名(双击选择用户)", 200, HorizontalAlignment.Right);
            UserListView.Columns.Add("管理员", 50, HorizontalAlignment.Center);
            UserListView.FullRowSelect = true;

            dt = cm.GetTableValue("Account");

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string name;
                ulong  admin;
                name  = (string)dt.Rows[i]["Account"];
                admin = (ulong)dt.Rows[i]["Level"];

                ListViewItem lvi = new ListViewItem();
                lvi.Text = name;
                if (admin == 1)
                {
                    lvi.SubItems.Add("是");
                }
                else
                {
                    lvi.SubItems.Add("否");
                }
                UserListView.Items.Add(lvi);
            }
            UserListView.EndUpdate();
            #endregion

            MessageBox.Show("新用户添加成功!");
        }
Example #7
0
        void InitForm()
        {
            #region 初始锁定控件
            //初始锁定控件
            NewUserNameTextbox.Enabled         = false;
            NewUserPasswordTextbox.Enabled     = false;
            NewUserAdminNoRadioButton.Enabled  = false;
            NewUserAdminYesRadioButton.Enabled = false;

            NewUserAddButton.Enabled = false;

            UserNameTextbox.Enabled           = false;
            ChangeAdminNoRadioButton.Enabled  = false;
            ChangeAdminYesRadioButton.Enabled = false;
            DeletUserButton.Enabled           = false;
            ShowPasswordButton.Enabled        = false;
            ShowPasswordTextbox.Enabled       = false;
            ChangePasswordButton.Enabled      = false;
            ChangePasswordTextbox.Enabled     = false;
            #endregion

            #region 获取所有用户信息
            //获取所有用户信息
            UserListView.BeginUpdate();

            UserListView.View = View.Details;
            UserListView.Clear();
            UserListView.Columns.Add("用户名(双击选择用户)", 200, HorizontalAlignment.Right);
            UserListView.Columns.Add("管理员", 50, HorizontalAlignment.Center);
            UserListView.FullRowSelect = true;

            DataTable dt = new DataTable("Account");
            CTMySql   cm = new CTMySql();

            dt = cm.GetTableValue("Account");

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string name;
                ulong  admin;
                name  = (string)dt.Rows[i]["Account"];
                admin = (ulong)dt.Rows[i]["Level"];

                ListViewItem lvi = new ListViewItem();
                lvi.Text = name;
                if (admin == 1)
                {
                    lvi.SubItems.Add("是");
                }
                else
                {
                    lvi.SubItems.Add("否");
                }
                UserListView.Items.Add(lvi);
            }
            UserListView.EndUpdate();
            #endregion

            #region 检测管理员权限
            if (!CTMySql.isUserAdmin)
            {
                UserListView.Enabled  = false;
                NewUserButton.Enabled = false;
            }
            #endregion
        }