private void btnRegedit_Click(object sender, EventArgs e) { try { if (btnRegedit.Text == "注册") { btnRegedit.Text = "确定"; btnCancel.Enabled = true; ObjOpen(); } else if (txtUserName.Text.Trim() == "") { MessageBox.Show("用户名不能为空", "提示"); txtUserName.Focus(); } else if (txtPassword.Text.Trim() == "") { MessageBox.Show("密码不能为空", "提示"); txtPassword.Focus(); } else if (!UserNameExist(txtUserName.Text.Trim())) { MessageBox.Show("该用户已存在!", "提示"); txtUserName.Text = ""; txtPassword.Text = ""; ObjOpen(); btnRegedit.Text = "注册"; txtUserName.Focus(); } else { btnRegedit.Text = "注册"; string psw = CPublic.GetMd5Str(txtPassword.Text.Trim()); string sqlStr = "insert into tbl_User values('" + txtUserName.Text.Trim() + "','" + psw.Trim() + "','" + cmbPurview.Text.Trim() + "','是')"; string regType = cmbPurview.Text.Trim(); if (CDataBase.UpdateDB(sqlStr)) { MessageBox.Show(cmbPurview.Text + " " + txtUserName.Text + " 注册成功!\n" + "请进一步完善用户信息", "注册用户"); } CPublic.userName = txtUserName.Text.Trim(); if (regType == "普通管理员") { if (ob_FrmCompleteAdminInfo == null || ob_FrmCompleteAdminInfo.IsDisposed) { ob_FrmCompleteAdminInfo = new FrmCompleteAdminInfo(); ob_FrmCompleteAdminInfo.Show(); } else { ob_FrmCompleteAdminInfo.Activate(); } } else if (regType == "顾客") { if (ob_FrmCompleteCustomerInfo == null || ob_FrmCompleteCustomerInfo.IsDisposed) { ob_FrmCompleteCustomerInfo = new FrmCompleteCustomerInfo(); ob_FrmCompleteCustomerInfo.Show(); } else { ob_FrmCompleteCustomerInfo.Activate(); } } ClearAll(); ObjClose(); btnCancel.Enabled = false; } } catch (Exception ex) { CDataBase.conn.Close(); MessageBox.Show(ex.Message); ClearAll(); ObjClose(); btnCancel.Enabled = false; } }
private void btnRegedit_Click(object sender, EventArgs e) { try { if (btnRegedit.Text == "注册") { btnRegedit.Text = "确定"; btnCancel.Enabled = true; ObjOpen(); } else if (txtUserName.Text.Trim() == "") { MessageBox.Show("用户名不能为空", "提示"); txtUserName.Focus(); } else if (txtPassword.Text.Trim() == "") { MessageBox.Show("密码不能为空", "提示"); txtPassword.Focus(); } else if (!UserNameExist(txtUserName.Text.Trim())) { MessageBox.Show("该用户已存在!", "提示"); txtUserName.Text = ""; txtPassword.Text = ""; ObjOpen(); btnRegedit.Text = "注册"; txtUserName.Focus(); } else { btnRegedit.Text = "注册"; string psw = CPublic.GetMd5Str(txtPassword.Text.Trim()); string sqlStr = "insert into tbl_User values('" + txtUserName.Text.Trim() + "','" + psw.Trim() + "','" + cmbPurview.Text.Trim() + "','是')"; string regType = cmbPurview.Text.Trim(); if (CDataBase.UpdateDB(sqlStr)) MessageBox.Show(cmbPurview.Text + " " + txtUserName.Text + " 注册成功!\n" + "请进一步完善用户信息", "注册用户"); CPublic.userName = txtUserName.Text.Trim(); if (regType == "普通管理员") { if (ob_FrmCompleteAdminInfo == null || ob_FrmCompleteAdminInfo.IsDisposed) { ob_FrmCompleteAdminInfo = new FrmCompleteAdminInfo(); ob_FrmCompleteAdminInfo.Show(); } else { ob_FrmCompleteAdminInfo.Activate(); } } else if(regType == "顾客") { if (ob_FrmCompleteCustomerInfo == null || ob_FrmCompleteCustomerInfo.IsDisposed) { ob_FrmCompleteCustomerInfo = new FrmCompleteCustomerInfo(); ob_FrmCompleteCustomerInfo.Show(); } else { ob_FrmCompleteCustomerInfo.Activate(); } } ClearAll(); ObjClose(); btnCancel.Enabled = false; } } catch (Exception ex) { CDataBase.conn.Close(); MessageBox.Show(ex.Message); ClearAll(); ObjClose(); btnCancel.Enabled = false; } }