C#编程 家庭理财系统 代码追踪学习

chenjinglong 2013-09-20 05:31:20
登录实现 与SQL server链接
定义数据库连接类
class DBHelper
{
private static string strSql = string.Format(@"server=CHENJINGLONGPC\SQLEXPRESS;database=FamilyFinace;Integrated Security=True");
public static SqlConnection connect= new SqlConnection(strSql);
}
登录系统
try
{
DBHelper.connect.Open();
string sql = string.Format(@"select count(*) from FamilyUser where UserName='{0}' and UserPassword='{1}'", txtUserName.Text.Trim(), txtPassWord.Text);
SqlCommand conform = new SqlCommand(sql, DBHelper.connect);
int result = (int)conform.ExecuteScalar();
if (result > 0)
{
this.DialogResult = DialogResult.OK;
}
else
{
lblUPError.Visible = true;
}

// MessageBox.Show("success");
}

catch (SqlException ex)
{
MessageBox.Show("登录失败 原因如下" + ex.Message, "家庭理财管理系统");
}
finally
{
DBHelper.connect.Close();
}
...全文
216 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenjinglong 2013-09-20
  • 打赏
  • 举报
回复
确实 找其他的地方记录
  • 打赏
  • 举报
回复
你可以写在博客中。。
chenjinglong 2013-09-20
  • 打赏
  • 举报
回复
自己慢慢一点点写 纪录一下自己的进展状况 以后翻阅 可以作为以后加深回顾
threenewbee 2013-09-20
  • 打赏
  • 举报
回复
代码分享?你不如把完整的项目上传到download.csdn.net中,然后把链接贴出来。
chenjinglong 2013-09-20
  • 打赏
  • 举报
回复
注册代码实现:
       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();
                }
            }
chenjinglong 2013-09-20
  • 打赏
  • 举报
回复
用户名是否为空判断 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; }

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧