Пример #1
0
        private void HandleEmpEdit()
        {
            MySqlConnection conn = null;

            try
            {
                conn = MySqlConnHelper.GetMySqlConn(Properties.Settings.Default.DbConn);
                MySqlCommand cmd = conn.CreateCommand();
                cmd.CommandType = CommandType.Text;
                #region
                string pwd = string.Empty;
                if (checkBoxEmpPwd.Checked == true)
                {
                    pwd = textBoxEmpPwd.Text;
                }
                else
                {
                    pwd = listViewEmpInfo.SelectedItems[0].SubItems[3].Text;
                }
                pwd             = PswdHelper.EncryptString(pwd); // 加密
                cmd.CommandText = "update employee set password=?pwd, acl= ?acl where id=?id;";
                cmd.Parameters.Clear();
                cmd.Parameters.AddWithValue("?pwd", pwd);
                string acl = GetEmpAcl();
                cmd.Parameters.AddWithValue("?acl", acl);
                string id = listViewEmpInfo.SelectedItems[0].SubItems[0].Text;
                cmd.Parameters.AddWithValue("?id", id);
                conn.Open();
                cmd.ExecuteNonQuery();

                // 更新列表
                ResetEmp();
                RefreshEmpList();
                #region 记录操作日志
                StringBuilder sb = new StringBuilder(512);
                sb.AppendFormat("U employee {0}=[{1}], ", "name", PswdHelper.EncryptString(textBoxEmpName.Text));
                sb.AppendFormat("{0}=[{1}], ", "pwd", PswdHelper.EncryptString(textBoxEmpPwd.Text));
                sb.AppendFormat("{0}=[{1}], ", "acl", acl);
                sb.AppendFormat("{0}=[{1}], ", "id", id);
                WriteLog(sb.ToString());
                #endregion


                #endregion
            }
            catch (Exception ex)
            {
                WriteLog(ex.ToString());
                NotifyHelper.NotifyUser(ex.Message);
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
        }
Пример #2
0
        private void HandleEmpAdd()
        {
            MySqlConnection conn = null;

            try
            {
                conn = MySqlConnHelper.GetMySqlConn(Properties.Settings.Default.DbConn);
                MySqlCommand cmd = conn.CreateCommand();
                cmd.CommandType = CommandType.Text;
                #region
                // 不检查是否已经有相同的姓名
                //cmd.CommandText = "select id, name, acl from employee where name=?name;";
                //cmd.Parameters.Clear();
                //cmd.Parameters.AddWithValue("?name", textBoxEmpName.text);
                //conn.Open();
                //MySqlDataReader dr = cmd.ExecuteReader();
                //if(dr.Read())
                //{
                //    dr.Close();
                //    conn.Close();
                //    NotifyHelper.NotifyUser("该姓名已存在");
                //    return;
                //}
                cmd.CommandText = "insert into employee(name, password, acl) values(?name, ?pwd, ?acl);";
                cmd.Parameters.Clear();
                cmd.Parameters.AddWithValue("?name", textBoxEmpName.Text);
                cmd.Parameters.AddWithValue("?pwd", PswdHelper.EncryptString(textBoxEmpPwd.Text));
                string acl = GetEmpAcl();
                cmd.Parameters.AddWithValue("?acl", acl);
                conn.Open();
                #region log
                StringBuilder sb = new StringBuilder(512);
                sb.AppendFormat("C employee {0}=[{1}], ", "name", PswdHelper.EncryptString(textBoxEmpName.Text));
                sb.AppendFormat("{0}=[{1}], ", "pwd", PswdHelper.EncryptString(textBoxEmpPwd.Text));
                sb.AppendFormat("{0}=[{1}], ", "acl", acl);
                WriteLog(sb.ToString());
                #endregion
                cmd.ExecuteNonQuery();

                // 更新列表
                ResetEmp();
                RefreshEmpList();
                #endregion
            }
            catch (Exception ex)
            {
                WriteLog(ex.ToString());
                NotifyHelper.NotifyUser("操作失败: " + ex.Message);
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
        }