Exemplo n.º 1
0
        public bool Carregar_Config()
        {
            var file = string.Concat(AppDomain.CurrentDomain.BaseDirectory,
                                     "Configuracao\\Mysql.Xml");

            try
            {
                if (!File.Exists(file))
                {
                    return(false);
                }
                var xml = new XmlDocument();
                xml.Load(file);

                var list = xml.SelectNodes("/MYSQL");
                if (list == null)
                {
                    Console.WriteLine(@"Arquivo Local :[Configuracao\\Mysql.Xml]" + Environment.NewLine + @"Cod :1012");
                    return(false);
                }
                foreach (XmlNode n in list)
                {
                    var s = n.SelectSingleNode("SERVIDOR");
                    if (s != null)
                    {
                        Janela.CoreMySql.CoreMe.Servidor = HashEncryp.Decodifica(s.InnerText);
                    }
                    s = n.SelectSingleNode("PORTA");
                    if (s != null)
                    {
                        Janela.CoreMySql.CoreMe.Porta = HashEncryp.Decodifica(s.InnerText);
                    }
                    s = n.SelectSingleNode("USUARIO");
                    if (s != null)
                    {
                        Janela.CoreMySql.CoreMe.Usuario = HashEncryp.Decodifica(s.InnerText);
                    }
                    s = n.SelectSingleNode("SENHA");
                    if (s != null)
                    {
                        Janela.CoreMySql.CoreMe.Senha = HashEncryp.Decodifica(s.InnerText);
                    }
                    s = n.SelectSingleNode("BANCO");
                    if (s != null)
                    {
                        Janela.CoreMySql.CoreMe.Banco = HashEncryp.Decodifica(s.InnerText);
                    }
                }
                return(true);
            }
            catch (MySqlException e)
            {
                Erros.Output(e.ToString());
                return(false);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Simples log de usuario
        /// </summary>
        /// <param name="user">Usuario</param>
        /// <param name="servidor">Servidor</param>
        /// <param name="estacao"></param>
        /// <param name="funcao">Funcao</param>
        public static void LogUsuario(string user,
                                      string servidor,
                                      string estacao,
                                      TipoFuncaoUsuario funcao)
        {
            var path = @"%AppData%\Ose\Log\";

            path = Environment.ExpandEnvironmentVariables(path);
            if (!Directory.Exists(path))
            {
                // Criar a Pasta
                Directory.CreateDirectory(path);
            }
            // Continua :
            var          data = DateTime.Now.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture);
            var          time = DateTime.Now.ToString("HH:mm");
            string       file = string.Concat(path, HashEncryp.Codifica(user));
            StreamWriter sw;

            if (!File.Exists(file + @".txt"))
            {
                using (sw = File.CreateText(file + @".txt"))
                {
                    sw.WriteLine(@"- - - - - - - - - - - - - - - - - - - -");
                    sw.WriteLine(@"Data :" + data);
                    sw.WriteLine(@"Hora :" + time);
                    sw.WriteLine(@"Usuario :" + user);
                    sw.WriteLine(@"Servidor :" + servidor);
                    sw.WriteLine(@"Funcao :" + funcao.ToString());
                    sw.WriteLine(@"Estacao :" + estacao);
                    sw.WriteLine(@"- - - - - - - - - - - - - - - - - - - -");
                    sw.WriteLine();
                }
            }
            else
            {
                string s = @"- - - - - - - - - - - - - - - - - - - -" + Environment.NewLine +
                           @"Data :" + data + Environment.NewLine +
                           @"Hora :" + time + Environment.NewLine +
                           @"Usuario :" + user + Environment.NewLine +
                           @"Servidor :" + servidor + Environment.NewLine +
                           @"Funcao :" + funcao.ToString() + Environment.NewLine +
                           @"Estacao :" + estacao + Environment.NewLine +
                           @"- - - - - - - - - - - - - - - - - - - -" + Environment.NewLine;
                using (StreamWriter tw = File.AppendText(file + @".txt"))
                {
                    tw.WriteLine(s);
                    tw.Close();
                }
            }
            Output(@"Sucesso - LogUsuario");
        }
Exemplo n.º 3
0
        /// <summary>
        /// Entrada de usuario
        /// </summary>
        /// <param name="user">usuario</param>
        /// <param name="pw">senha</param>
        /// <returns></returns>
        public bool UserInput(string user,
                              string pw)
        {
            pw = HashEncryp.Codifica(pw);
            if (!IsConnectMySql())
            {
                return(false);
            }
            if (Connection.State != ConnectionState.Closed)
            {
                Connection.Close();
                Connection.Dispose();
            }

            try
            {
                Connection.Open();

                using (MySqlCommand s = new MySqlCommand(@"V101_ENTRADA_USUARIO", Connection))
                {
                    s.CommandType = CommandType.StoredProcedure;

                    s.Parameters.AddWithValue(@"p_USUARIO", user);
                    s.Parameters["@p_USUARIO"].Direction = ParameterDirection.Input;

                    s.Parameters.Add(new MySqlParameter(@"o_USUARIO", MySqlDbType.VarChar));
                    s.Parameters[@"o_USUARIO"].Direction = ParameterDirection.Output;

                    s.Parameters.Add(new MySqlParameter(@"o_PASSWORD", MySqlDbType.VarChar));
                    s.Parameters[@"o_PASSWORD"].Direction = ParameterDirection.Output;

                    s.Parameters.Add(new MySqlParameter(@"o_NOME", MySqlDbType.VarChar));
                    s.Parameters[@"o_NOME"].Direction = ParameterDirection.Output;

                    s.Parameters.Add(new MySqlParameter(@"o_PRIVILEGIO", MySqlDbType.VarChar));
                    s.Parameters[@"o_PRIVILEGIO"].Direction = ParameterDirection.Output;

                    s.Parameters.Add(new MySqlParameter(@"o_ESTADO", MySqlDbType.VarChar));
                    s.Parameters[@"o_ESTADO"].Direction = ParameterDirection.Output;

                    s.ExecuteNonQuery();

                    if (s.Parameters[@"p_USUARIO"].Value.ToString() != string.Empty)
                    {
                        // Comparacao - Senha
                        if (s.Parameters[@"o_PASSWORD"].Value.ToString() != pw)
                        {
                            //isConnect = false;
                            //myUser = null;
                            return(false);
                        }
                        // Verificar Usuario Bloqueado
                        if (s.Parameters[@"o_ESTADO"].Value.ToString() != "1")
                        {
                            //isConnect = false;
                            //myUser = @"BLOQUEADO";
                            return(false);
                        }

                        // Usuario- Validado com sucesso
                        //if (s.Parameters[@"p_USUARIO"].Value.ToString() == @"bloqueado")
                        //{
                        //    Janela.Usuario.MUsuario.Usuario = s.Parameters[@"p_USUARIO"].Value.ToString() +
                        //                                      user;
                        //}
                        //else
                        //{
                        Janela.Usuario.MUsuario.Usuario = s.Parameters[@"p_USUARIO"].Value.ToString();
                        //}
                        Janela.Usuario.MUsuario.Nome       = s.Parameters[@"o_NOME"].Value.ToString();
                        Janela.Usuario.MUsuario.Privilegio = s.Parameters[@"o_PRIVILEGIO"].Value.ToString();
                        Janela.Usuario.MUsuario.Estado     = s.Parameters[@"o_ESTADO"].Value.ToString();
                        return(true);
                    }
                }
            }
            catch (MySqlException e)
            {
                Erros.Output(e.ToString(),
                             @"public bool UserInput");
            }

            finally
            {
                if (Connection.State != ConnectionState.Closed)
                {
                    Connection.Close();
                    Connection.Dispose();
                }
            }
            return(false);
        }