发麻大家给看下我的错误在哪?
public partial class CRUDForm : Form{
AdminManager adminManager = new AdminManager();
Admin admin =new Admin();
public bool boolid = false;
public bool boolpwd = false;
public bool booltype = false;
public bool boolname = false;
public bool boolage = false;
public bool boolphone = false;
public CRUDForm()
{
InitializeComponent();
}
private void CRUDForm_Load(object sender, EventArgs e)
{
this.cbotxtloginType.Items.Add("超级管理员");
this.cbotxtloginType.Items.Add("管理员");
this.cbotxtloginType.SelectedIndex = 0;
LoadDgv();
}
public void LoadDgv()
{
dgvCRUD.DataSource = adminManager.GetAllAdmin();
}
private bool boolid_TextChanged(object sender, EventArgs e)
{
if ((string.IsNullOrEmpty(this.txtloginId.Text)))
{
MessageBox.Show("用户名不能为空");
boolid = false;
}
else if (!(Regex.IsMatch(this.txtloginId.Text, "[0-9][A-Za-z]")))
{
MessageBox.Show("用户名只能为英文和数字");
boolid = false;
}
else
{
return boolid = true;
}
return boolid;
}
private bool boolpwd_TextChanged(object sender, EventArgs e)
{
if ((string.IsNullOrEmpty(txtloginPwd.Text)))
{
MessageBox.Show("密码不能为空");
boolpwd = false;
}
else if ((Regex.IsMatch(this.txtloginPwd.Text, "[0-9][A-Za-z]") || Regex.IsMatch(this.txtloginPwd.Text, "[A-Za-z][0-9]")) && (this.txtloginPwd.Text.Length > 6))
{
boolpwd = true;
if ((this.txtloginPwd.Text.Length > 6) && (this.txtloginPwd.Text.Length < 10))
{
MessageBox.Show("密码强度低级");
}
else
{
MessageBox.Show("密码强度高级");
}
}
else
{
MessageBox.Show("长度要>=6,必须含有数字和字母");
boolpwd = false;
}
return boolpwd;
}
private bool booltype_TextChanged(object sender, EventArgs e)
{
if (this.cbotxtloginType.Text != "超级管理员" || this.cbotxtloginType.Text != "管理员")
{
MessageBox.Show("请选择真确的用户类型");
booltype = false;
}
else
{
booltype = true;
}
return booltype;
}
private bool boolname_TextChanged(object sender, EventArgs e)
{
if ((string.IsNullOrEmpty(this.txtadminName.Text)))
{
MessageBox.Show("用户名不能为空");
boolname = false;
}
else if (!(Regex.IsMatch(this.txtadminName.Text, "[A-Za-z]")) || !(Regex.IsMatch(this.txtadminName.Text, "/[^\u4E00-\u9FA5]/g")))
{
MessageBox.Show("用户名只能为英文或汉字");
boolname = false;
}
else
{
boolname = true;
}
return boolname;
}
private bool boolage_TextChanged(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txtadminAge.Text))
{
MessageBox.Show("年龄不能为空");
boolage = false;
}
else if (txtadminAge.Text != "^[0-9]*$")
{
MessageBox.Show("年龄只能为数字");
boolage = false;
}
else
{
boolage = true;
}
return boolage;
}
private bool boolphone_TextChanged(object sender, EventArgs e)
{
if ((string.IsNullOrEmpty(this.txtlbladminPhone.Text)))
{
MessageBox.Show("电话不能为空");
boolphone = false;
}
else if ((Regex.IsMatch(this.txtlbladminPhone.Text, "[0-9]") ||(this.txtlbladminPhone.Text.Length == 11)))
{
boolphone = true;
}
else
{
MessageBox.Show("请输入正确的电话格式,电话为数字长度为11位");
boolpwd = false;
}
return boolphone;
}
private void btnAddAdmin_Click(object sender, EventArgs e)
{
int id = Convert.ToInt32(dgvCRUD.SelectedRows[0].Cells["Id"].Value);
DialogResult result = MessageBox.Show("您确定要添加信息吗", "添加信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
if ((boolid = true) && (boolpwd = true) && (booltype = true) && (boolname = true) && (boolage = true) && (boolphone = true))
{
admin.LoginId = this.txtloginId.Text;
admin.LoginPwd = this.txtloginPwd.Text;
admin.LoginType = this.cbotxtloginType.Text;
admin.AdminName = this.txtadminName.Text;
admin.AdminAge = Convert.ToInt32(this.txtadminAge.Text);
admin.AdminPhone = this.txtlbladminPhone.Text;
adminManager.AddAdmin(admin);
MessageBox.Show("添加成功");
}
else
{
MessageBox.Show("添加失败");
}
LoadDgv();
}
private void brnUpdateAdmin_Click(object sender, EventArgs e)
{
int id = Convert.ToInt32(dgvCRUD.SelectedRows[0].Cells["Id"].Value);
DialogResult result = MessageBox.Show("您确定要修改信息吗", "修改信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
if ((boolid = true) && (boolpwd = true) &&(booltype = true) &&(boolname = true) &&(boolage = true) &&(boolphone = true))
{
admin.LoginId = this.txtloginId.Text;
admin.LoginPwd = this.txtloginPwd.Text;
admin.LoginType = this.cbotxtloginType.Text;
admin.AdminName = this.txtadminName.Text;
admin.AdminAge = Convert.ToInt32(this.txtadminAge.Text);
admin.AdminPhone = this.txtlbladminPhone.Text;
adminManager.UpdateAdmin(admin,id);
MessageBox.Show("保存成功");
}
LoadDgv();
}
private void dgvCRUD_CellClick(object sender, DataGridViewCellEventArgs e)
{
int id = Convert.ToInt32(dgvCRUD.SelectedRows[0].Cells["Id"].Value);
admin = adminManager.GetAdminByAdminID(id);
txtloginId.Text = admin.LoginId;
txtloginPwd.Text = admin.LoginPwd;
cbotxtloginType.Text = admin.LoginType;
txtadminName.Text = admin.AdminName;
txtadminAge.Text = admin.AdminAge.ToString();
txtlbladminPhone.Text = admin.AdminPhone;
}
private void btnExieAdmin_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void btnDelAdmin_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("您确定要删除信息吗", "删除信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
int id = Convert.ToInt32(dgvCRUD.SelectedRows[0].Cells["id"].Value);
adminManager.DeleteById(id);
MessageBox.Show("删除成功");
LoadDgv();
}
}
为什么我的添加 的 if 进不去 bool 的判断? --------------------编程问答-------------------- 请用代码模板功能,精简掉不必要的代码,这样的直接一个类贴上来怎么看。 --------------------编程问答-------------------- CTRL+C、CTRL+V 用得很high啊。 --------------------编程问答-------------------- VC好熟练 --------------------编程问答-------------------- 哪个if啊?
断点用F11調試一下。 --------------------编程问答-------------------- 这代码确实得整理下,,像考眼力的。 --------------------编程问答-------------------- 有些模糊啊 --------------------编程问答-------------------- 设断点自己先跟一下,看看在哪里报错。 --------------------编程问答-------------------- lz你是考我们眼力吗? --------------------编程问答--------------------
if ((boolid = true) && (boolpwd = true) &&(booltype = true) &&(boolname = true) &&(boolage = true) &&(boolphone = true))
你是做判断还是做赋值? --------------------编程问答-------------------- 第几行报错啊?大哥!你这里这么多 if!代码看的我头晕啊,你格式排一下啊!用“”
报错信息详细一点啊,接近崩溃的看完你的代码,结果问题简单的让我彻底崩溃。 --------------------编程问答-------------------- 额,太长了,自己调试吧… --------------------编程问答-------------------- 9楼应该是楼主需要找的问题吧,你是条件分支怎么都进步去了吧?给分吧。。。。。。 --------------------编程问答-------------------- 赋值?还是判断? --------------------编程问答--------------------
LZ大才啊,犯这种错误! --------------------编程问答-------------------- 路过路过、、、、、什么也没看见、、、、
补充:.NET技术 , C#