Beispiel #1
0
        /// <summary>
        /// 添加或者修改按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            //接受用户输入

            //如果按钮的文本是 修改  就修改
            if (btnSave.Text == "修改")
            {
                ManagerInfo mi = new ManagerInfo();

                mi.userid = Convert.ToInt32(txtId.Text);
                if (Convert.ToInt32(txtId.Text) == -1)
                {
                    MessageBox.Show("请在编号处输入数字");
                    return;
                }
                mi.username = txtName.Text;
                if (rb1.Checked)
                {
                    mi.usertype = "经理";
                }
                else
                {
                    mi.usertype = "生化人";
                }
                //判断是否更改了密码  更改了就是true  反之false
                if (txtPwd.Text.Length != 0)
                {
                    mi.userpass = txtPwd.Text;
                    if (mib.UpdateToMysql(mi, true))
                    {
                        MessageBox.Show("修改成功");
                    }
                    else
                    {
                        MessageBox.Show("修改失败");
                    }
                }
                else
                {
                    if (mib.UpdateToMysql(mi, false))
                    {
                        MessageBox.Show("修改成功");
                    }
                    else
                    {
                        MessageBox.Show("修改失败");
                    }
                }
                txtId.ReadOnly = true;
                txtId.Text     = "添加时无编号";
                txtPwd.Text    = "";
                txtName.Text   = "";
            }
            //如果按钮的文本是 添加  添加
            else
            {
                ManagerInfo mi = new ManagerInfo();
                mi.username = txtName.Text;
                mi.userpass = txtPwd.Text;
                if (rb1.Checked)
                {
                    mi.usertype = "经理";
                }
                else
                {
                    mi.usertype = "生化人";
                }
                bool b = mib.AddToMySql(mi);

                if (b)
                {
                    MessageBox.Show("添加成功~");
                }
                else
                {
                    MessageBox.Show("操作失败");
                }
                txtPwd.Text  = "";
                txtName.Text = "";
            }
            LoadList();
            btnSave.Text = "添加";
        }