Example #1
0
        /// <summary>
        /// 获得用户的详细信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public T_Jb_Login_Pass getUserById(string id)
        {
            T_Jb_Login_Pass user = null;
            string          sql  = "select C_LOGID,C_PASSWORD,C_CHINESENAME,C_JIAOSE,I_STATE from T_JB_LOGIN_PASS where c_logid = '" + id + "'";

            try
            {
                DataTable dt = dbHelper.GetDataSet(sql);
                if (dt != null && dt.Rows.Count > 0)
                {
                    user               = new T_Jb_Login_Pass();
                    user.C_loginID     = dt.Rows[0]["C_LOGID"].ToString();
                    user.C_password    = dt.Rows[0]["C_PASSWORD"].ToString();
                    user.C_chinesename = dt.Rows[0]["C_CHINESENAME"].ToString();
                    user.C_jiaose      = dt.Rows[0]["C_JIAOSE"].ToString();
                    user.I_state       = Convert.ToInt32(dt.Rows[0]["I_STATE"]);
                }
            }
            catch (Exception ex)
            {
                Log.write(ex.Message + "\r\n" + ex.StackTrace);
                throw ex;
            }
            finally
            {
                dbHelper.getConnection().Close();
            }
            return(user);
        }
Example #2
0
        /// <summary>
        /// 更改用户密码
        /// </summary>
        /// <param name="newPassword"></param>
        /// <param name="c_id"></param>
        /// <returns></returns>
        public bool updateUser(T_Jb_Login_Pass user)
        {
            try
            {
                int       count = 0;
                string    sql   = "update T_JB_LOGIN_PASS set c_password = @newPassword ,C_CHINESENAME = @name,C_JIAOSE = @C_JIAOSE  where C_LOGID = @c_id ";
                Hashtable table = new Hashtable();
                table.Add("newPassword", user.C_password);
                table.Add("name", user.C_chinesename);
                table.Add("c_id", user.C_loginID);
                table.Add("C_JIAOSE", user.C_jiaose);
                DbParameter[] parms = dbHelper.getParams(table);

                count = dbHelper.ExecuteCommand(sql, parms);

                if (count > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Log.write(ex.Message + "\r\n" + ex.StackTrace);
                throw ex;
            }
            finally
            {
                dbHelper.getConnection().Close();
            }
        }
Example #3
0
        private void ModPassword_Load(object sender, EventArgs e)
        {
            this.Left = (Global.baseWidth) / 2;
            this.Top  = Global.baseHeight / 4;


            this.comboBox1.DataSource    = layoutBLL.getAllRols(Global.role);
            this.comboBox1.DisplayMember = "C_JIAOSE";
            this.comboBox1.ValueMember   = "C_JIAOSE";

            if ("超级管理员".Equals(Global.role))
            {
                comboBox1.Visible = true;
            }
            else
            {
                comboBox1.Visible = false;
            }

            user = layoutBLL.getUserById(id);
            if (user == null)
            {
                MessageBox.Show("获取用户信息失败!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                this.Close();
            }
            else
            {
                this.label2.Text    = user.C_loginID;
                this.textBox4.Text  = user.C_chinesename;
                this.comboBox1.Text = user.C_jiaose;
            }

            //
        }
Example #4
0
 /// <summary>
 /// 是否为合法用户
 /// </summary>
 /// <param name="user">用户信息的数据封装对象</param>
 /// <returns>是否合法</returns>
 public bool login(T_Jb_Login_Pass user)
 {
     try
     {
         return(dal.login(user));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #5
0
 /// <summary>
 /// 更改用户密码
 /// </summary>
 /// <param name="newPassword"></param>
 /// <param name="c_id"></param>
 /// <returns></returns>
 public bool updateUser(T_Jb_Login_Pass user)
 {
     try
     {
         return(dal.updateUser(user));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #6
0
        /// <summary>
        /// 是否为合法用户
        /// </summary>
        /// <param name="user">用户信息的数据封装对象</param>
        /// <returns>是否合法</returns>
        public bool login(T_Jb_Login_Pass user)
        {
            bool   flag = false;
            string sql  = "select * from T_JB_LOGIN_PASS where C_LOGID=@useruid and C_PASSWORD=@userpass ";

            try
            {
                Hashtable table = new Hashtable();
                table.Add("useruid", user.C_loginID);
                table.Add("userpass", user.C_password);

                DbParameter[] parms = dbHelper.getParams(table);

                DataTable ds = dbHelper.GetDataSet(sql, parms);
                if (ds.Rows.Count > 0)
                {
                    flag           = true;
                    user.C_loginID = ds.Rows[0][0].ToString();


                    user.C_password    = ds.Rows[0][3].ToString();
                    user.C_chinesename = ds.Rows[0][4].ToString();
                    user.C_jiaose      = ds.Rows[0][5].ToString();

                    user.I_state = Convert.ToInt32(ds.Rows[0][7]);
                }
                dbHelper.getConnection().Close();
            }
            catch (Exception ex)
            {
                Log.write(ex.Message + "\r\n" + ex.StackTrace);
                throw ex;
            }
            finally
            {
                dbHelper.getConnection().Close();
            }
            return(flag);
        }
Example #7
0
        /// <summary>
        /// 保存用户信息
        /// </summary>
        /// <param name="user">系统用户</param>
        /// <returns></returns>
        public bool save(T_Jb_Login_Pass user)
        {
            try
            {
                int    count = 0;
                string sql   = "INSERT INTO  T_JB_LOGIN_PASS  ( C_LOGID ,    C_PASSWORD ,    C_CHINESENAME ,  C_JIAOSE ,   I_STATE ) " +
                               " VALUES(@C_LOGID,@C_PASSWORD,@C_CHINESENAME,@C_JIAOSE,@I_STATE )";
                Hashtable table = new Hashtable();
                table.Add("C_LOGID", user.C_loginID);

                table.Add("C_PASSWORD", user.C_password);
                table.Add("C_CHINESENAME", user.C_chinesename);
                table.Add("C_JIAOSE", user.C_jiaose);
                table.Add("I_STATE", user.I_state);

                DbParameter[] parms = dbHelper.getParams(table);

                count = dbHelper.ExecuteCommand(sql, parms);
                if (count > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Log.write(ex.Message + "\r\n" + ex.StackTrace);
                throw ex;
            }
            finally
            {
                dbHelper.getConnection().Close();
            }
        }
Example #8
0
        private void btnsave_Click(object sender, EventArgs e)
        {
            bool flag = true;

            #region 验证输入
            if (this.txtId.Text == null || string.Empty.Equals(this.txtId.Text.Trim()))
            {
                this.lblID.Visible = true;
                flag = false;
            }
            else
            {
                this.lblID.Visible = false;
            }
            if (this.txtPassword.Text == null || string.Empty.Equals(this.txtPassword.Text.Trim()))
            {
                this.lblPassword.Visible = true;
                flag = false;
            }
            else
            {
                this.lblPassword.Visible = false;
            }
            if (this.txtName.Text == null || string.Empty.Equals(this.txtName.Text.Trim()))
            {
                this.lblName.Visible = true;
                flag = false;
            }
            else
            {
                this.lblName.Visible = false;
            }
            if (this.comboBox1.Text == null || string.Empty.Equals(this.comboBox1.Text.Trim()))
            {
                this.label19.Visible = true;
                flag = false;
            }
            else
            {
                this.label19.Visible = false;
            }
            #endregion

            if (flag) //输入正确
            {
                try
                {
                    string pwd = layoutBLL.getPasswordByName(txtId.Text.Trim());
                    if (pwd == null)
                    {
                        T_Jb_Login_Pass user = new T_Jb_Login_Pass();
                        user.C_loginID     = txtId.Text.Trim();
                        user.C_password    = txtPassword.Text.Trim();
                        user.C_chinesename = txtName.Text.Trim();
                        user.C_jiaose      = comboBox1.Text;
                        user.I_state       = 0;
                        if (layoutBLL.save(user))
                        {
                            MessageBox.Show("用户信息保存成功!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);

                            Log.saveLog(string.Format("添加用户{0}成功!", user.C_loginID));

                            setUserList(null, null);
                            txtId.Text       = string.Empty;
                            txtName.Text     = string.Empty;
                            txtPassword.Text = string.Empty;
                        }
                        else
                        {
                            MessageBox.Show("用户信息保存失败!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    else
                    {
                        MessageBox.Show("用户:" + txtId.Text + " 已经存在!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("与数据库连接失败,请查看网络连接是否正常。如不能解决请与网络管理员联系!", "严重错误:", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                    return;
                }
            }
        }
Example #9
0
 /// <summary>
 /// 保存用户信息
 /// </summary>
 /// <param name="user">系统用户</param>
 /// <returns></returns>
 public bool save(T_Jb_Login_Pass user)
 {
     return(dal.save(user));
 }
Example #10
0
        //确定按钮
        private void btnLogin_Click(object sender, EventArgs e)
        {
            Log.saveLog(txtUserName.Text.Trim() + " 登陆");

            if (validate())//验证成功
            {
                //封装数据对象
                T_Jb_Login_Pass user = new T_Jb_Login_Pass();
                user.C_loginID  = txtUserName.Text;
                user.C_password = txtPassword.Text;
                //  user.C_jiaose = "管理员";

                bool flag = false;
                try
                {
                    flag = layoutBLL.login(user);
                }
                catch (Exception)
                {
                    MessageBox.Show("与数据库连接失败,请查看网络连接是否正常。如不能解决请与网络管理员联系!", "严重错误:", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                //如果登录成功
                if (flag)
                {
                    Global.userName = user.C_chinesename; //保存用户的中文名
                    Global.role     = user.C_jiaose;      //保存用户角色
                    Global.longid   = user.C_loginID;
                    Global.login    = user;

                    Log.saveLog(txtUserName.Text.Trim() + " 登陆成功!");

                    try
                    {
                        //设置主窗体标题
                        mainform.Text = "点创科技——" + Global.Corporation + "   当前用户:" + Global.userName + "  当前时间:" + DateTime.Now.ToLongDateString()
                                        + " ";
                        //mainform.MainToolBar.BackColor = pnlPlaceholder.BackColor;
                        mainform.initDictionary();
                        mainform.initToolBar();

                        Utility.writeConfig("UserName", Global.longid);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("与数据库连接失败,请查看网络连接是否正常。如不能解决请与网络管理员联系!", "严重错误:", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    this.Close();
                    this.Dispose();
                    mainform.login = null;
                }
                else //登录失败 如果3次失败则退出 否则提示还有多少次
                {
                    if (loginTimes == Global.loginTime)
                    {
                        Log.saveLog(txtUserName.Text.Trim() + " 超出登陆失败次数,系统自动退出!");
                        Application.Exit();
                    }
                    else
                    {
                        MessageBox.Show("你第[" + (loginTimes + 1) + "]次登录没有成功,请核对用户名称、登录密码!", "提示:你有" + (Global.loginTime - loginTimes) + "次机会", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        loginTimes++;

                        Log.saveLog(txtUserName.Text.Trim() + " 第" + loginTimes + "登陆失败!");
                    }
                }
            }
        }