Exemplo n.º 1
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");
     }
 }
Exemplo n.º 2
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("新用户添加成功!");
        }