C#编程 家庭理财系统 代码追踪学习 本帖最后由 chenjinglong 于 2013-09-20 18:36:47 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用户名是否为空判断 private bool checkEmpty() { bool result = true; //定义默认返回结果为true if (txtUserName.Text.Trim() == string.Empty) { lblUserEmpty.Visible = true; result = false; } else { lblUserEmpty.Visible = false; } if (txtPassWord.Text == string.Empty) { lblPassEmpty.Visible = true; result = false; } else { lblPassEmpty.Visible = false; } return result; } 注册代码实现: private bool checkEmpty() { bool result = true; if (txtUserName.Text.Trim() == string.Empty) { lblUserError.Visible = true; result = false; } else { lblUserError.Visible = false; } if (txtPassWord.Text == string.Empty) { lblPassError.Visible = true; result = false; } else { lblPassError.Visible = false; } if (txtCPass.Text == string.Empty) { lblCoformError.Visible = true; result = false; } else if (txtPassWord.Text != txtCPass.Text) { lblPassError.Visible = false; lblCoformError.Visible = false; MessageBox.Show("密码不匹配请重新输入,请重新输入"); txtPassWord.Clear(); txtCPass.Clear(); result = false; } return result; } private void btnRegist_Click(object sender, EventArgs e) { // SqlCommand ins = null; bool isEmpty = checkEmpty(); if (isEmpty == true) { try { DBHelper.connect.Open(); string sql = string.Format(@"insert into [FamilyUser] values('{0}','{1}')", txtUserName.Text.Trim(), txtPassWord.Text); SqlCommand ins = new SqlCommand(sql, DBHelper.connect); int count = ins.ExecuteNonQuery(); if (count == 1) { MessageBox.Show("你已经成功注册"); this.Close(); } } catch (SqlException ex) { MessageBox.Show("注册失败 原因如下" + ex.Message); } finally { DBHelper.connect.Close(); } } 代码分享?你不如把完整的项目上传到download.csdn.net中,然后把链接贴出来。 C# WindowsForm 的 ComboBox 的一个问题! 每隔5分钟执行结束QQ.exe任务管理器进程(马上给分) 代码中怎么让文本框失去焦点 求正则表达式 C#2005能写标准的Dll动态库吗 事件和委托的关系及应用 大学疑问??? ( winform )点datagrid里面一行,弹出窗口提示下载,下载后,本行数据进入状态N(不能再下了),现在怎么刷新datagrid? 请问服务器端的执行代码怎么样输出到客户端最快? toolbarbutton 图像问题 user32.dll调用问题 C# 谁能提供一个新闻上一篇、下一篇的代码,谢谢
private bool checkEmpty()
{
bool result = true; //定义默认返回结果为true if (txtUserName.Text.Trim() == string.Empty)
{
lblUserEmpty.Visible = true;
result = false;
}
else
{
lblUserEmpty.Visible = false; } if (txtPassWord.Text == string.Empty)
{
lblPassEmpty.Visible = true;
result = false;
}
else
{
lblPassEmpty.Visible = false;
}
return result;
}
private bool checkEmpty()
{
bool result = true;
if (txtUserName.Text.Trim() == string.Empty)
{
lblUserError.Visible = true;
result = false;
}
else
{
lblUserError.Visible = false;
}
if (txtPassWord.Text == string.Empty)
{
lblPassError.Visible = true;
result = false;
}
else
{
lblPassError.Visible = false;
}
if (txtCPass.Text == string.Empty)
{
lblCoformError.Visible = true;
result = false;
}
else if (txtPassWord.Text != txtCPass.Text)
{
lblPassError.Visible = false;
lblCoformError.Visible = false;
MessageBox.Show("密码不匹配请重新输入,请重新输入");
txtPassWord.Clear();
txtCPass.Clear();
result = false;
} return result;
} private void btnRegist_Click(object sender, EventArgs e)
{
// SqlCommand ins = null;
bool isEmpty = checkEmpty();
if (isEmpty == true)
{
try
{
DBHelper.connect.Open();
string sql = string.Format(@"insert into [FamilyUser] values('{0}','{1}')", txtUserName.Text.Trim(), txtPassWord.Text);
SqlCommand ins = new SqlCommand(sql, DBHelper.connect);
int count = ins.ExecuteNonQuery();
if (count == 1)
{ MessageBox.Show("你已经成功注册");
this.Close(); }
}
catch (SqlException ex)
{
MessageBox.Show("注册失败 原因如下" + ex.Message);
}
finally
{
DBHelper.connect.Close();
}
}