Example #1
0
        /// <summary>
        /// Listagem dos usuários.
        /// </summary>
        private void ListarUsuarios()
        {
            // limpa lista
            this.lstUsuarios.DataSource = null;

            try
            {
                // componente de negócio
                UsuarioBc usuarioBc = new UsuarioBc();

                // lista os usuários
                UsuarioDs usuarioDs = usuarioBc.ListarUsuarios();

                // data binding
                this.lstUsuarios.DataSource    = usuarioDs.Usuario;
                this.lstUsuarios.DisplayMember = "Nome";
                this.lstUsuarios.ValueMember   = "CodigoUsuario";
            }
            catch (Exception ex)
            {
                FrmErro frmErro = new FrmErro();
                frmErro.Mensagem = ex.Message;
                frmErro.ShowDialog(this);
                frmErro.Dispose();
            }
        }
Example #2
0
        public override global::System.Data.DataSet Clone()
        {
            UsuarioDs cln = ((UsuarioDs)(base.Clone()));

            cln.InitVars();
            cln.SchemaSerializationMode = this.SchemaSerializationMode;
            return(cln);
        }
Example #3
0
        public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(global::System.Xml.Schema.XmlSchemaSet xs)
        {
            UsuarioDs ds = new UsuarioDs();

            global::System.Xml.Schema.XmlSchemaComplexType type     = new global::System.Xml.Schema.XmlSchemaComplexType();
            global::System.Xml.Schema.XmlSchemaSequence    sequence = new global::System.Xml.Schema.XmlSchemaSequence();
            global::System.Xml.Schema.XmlSchemaAny         any      = new global::System.Xml.Schema.XmlSchemaAny();
            any.Namespace = ds.Namespace;
            sequence.Items.Add(any);
            type.Particle = sequence;
            global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable();
            if (xs.Contains(dsSchema.TargetNamespace))
            {
                global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream();
                global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream();
                try {
                    global::System.Xml.Schema.XmlSchema schema = null;
                    dsSchema.Write(s1);
                    for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();)
                    {
                        schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current));
                        s2.SetLength(0);
                        schema.Write(s2);
                        if ((s1.Length == s2.Length))
                        {
                            s1.Position = 0;
                            s2.Position = 0;
                            for (; ((s1.Position != s1.Length) &&
                                    (s1.ReadByte() == s2.ReadByte()));)
                            {
                                ;
                            }
                            if ((s1.Position == s1.Length))
                            {
                                return(type);
                            }
                        }
                    }
                }
                finally {
                    if ((s1 != null))
                    {
                        s1.Close();
                    }
                    if ((s2 != null))
                    {
                        s2.Close();
                    }
                }
            }
            xs.Add(dsSchema);
            return(type);
        }
Example #4
0
        /// <summary>
        /// Busca por um usuário.
        /// </summary>
        /// <param name="codigoUsuario">Código do usuário.</param>
        /// <returns>Um DataSet tipado contendo os dados do usuário.</returns>
        public UsuarioDs.UsuarioRow BuscarUsuario(int codigoUsuario)
        {
            SqlConnection conn = new SqlConnection(this.connectionStr);
            SqlCommand    cmd  = new SqlCommand("BuscarUsuario", conn);

            cmd.CommandType = CommandType.StoredProcedure;

            // cria usuário
            UsuarioDs usuarioDs = new UsuarioDs();

            UsuarioDs.UsuarioRow usuarioRow = usuarioDs.Usuario.NewUsuarioRow();

            // parâmetros
            cmd.Parameters.Add("@CodigoUsuario", SqlDbType.Int).Value      = codigoUsuario;
            cmd.Parameters.Add("@Nome", SqlDbType.NVarChar, 200).Direction = ParameterDirection.Output;
            cmd.Parameters.Add("@Login", SqlDbType.NVarChar, 20).Direction = ParameterDirection.Output;
            cmd.Parameters.Add("@Senha", SqlDbType.NVarChar, 80).Direction = ParameterDirection.Output;
            cmd.Parameters.Add("@Tipo", SqlDbType.SmallInt).Direction      = ParameterDirection.Output;

            try
            {
                // abre conexão
                conn.Open();

                // executa comando
                cmd.ExecuteNonQuery();

                // dados do usuário
                usuarioRow.CodigoUsuario = codigoUsuario;
                usuarioRow.Nome          = (string)cmd.Parameters["@Nome"].Value;
                usuarioRow.Login         = (string)cmd.Parameters["@Login"].Value;
                usuarioRow.Senha         = Criptografia.DesencriptarMD5((string)cmd.Parameters["@Senha"].Value);
                usuarioRow.Tipo          = Convert.ToByte(cmd.Parameters["@Tipo"].Value);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }

            return(usuarioRow);
        }
Example #5
0
        private void btnCriar_Click(object sender, EventArgs e)
        {
            // valida campos
            if (!ValidarCampos())
            {
                return;
            }

            Cursor.Current = Cursors.WaitCursor;

            try
            {
                // componente de negócio
                UsuarioBc usuarioBc = new UsuarioBc();

                // cria dataSet do usuário
                UsuarioDs usuarioDs = new UsuarioDs();
                this.usuarioRow = usuarioDs.Usuario.NewUsuarioRow();

                // dados
                this.usuarioRow.Nome  = this.txtNome.Text;
                this.usuarioRow.Login = this.txtLogin.Text;
                this.usuarioRow.Senha = this.txtSenha.Text;
                this.usuarioRow.Tipo  = (byte)this.cmbTipo.SelectedIndex;

                // cria o usuário
                this.usuarioRow.CodigoUsuario = usuarioBc.CriarUsuario(this.usuarioRow.Nome, this.usuarioRow.Login,
                                                                       this.usuarioRow.Senha, this.usuarioRow.Tipo);

                // código do usuário
                int codigoUsuario = this.usuarioRow.CodigoUsuario;

                // lista usuários
                ListarUsuarios();

                // seleciona o usuário criado
                this.lstUsuarios.SelectedValue = codigoUsuario;
            }
            catch (Exception ex)
            {
                FrmErro frmErro = new FrmErro();
                frmErro.Mensagem = ex.Message;
                frmErro.ShowDialog(this);
                frmErro.Dispose();
            }

            Cursor.Current = Cursors.Default;
        }
Example #6
0
        /// <summary>
        /// Lista todos os usuários.
        /// </summary>
        /// <returns>Um DataSet tipado contendo os dados dos usuários.</returns>
        public UsuarioDs ListarUsuarios()
        {
            SqlConnection conn      = new SqlConnection(this.connectionStr);
            UsuarioDs     usuarioDs = new UsuarioDs();

            try
            {
                SqlDataAdapter adapter = new SqlDataAdapter("ListarUsuarios", conn);
                adapter.SelectCommand.CommandType = CommandType.StoredProcedure;

                // preenche dataSet
                adapter.Fill(usuarioDs, usuarioDs.Usuario.TableName);

                // atualiza strings das senhas
                foreach (UsuarioDs.UsuarioRow usuarioRow in usuarioDs.Usuario)
                {
                    usuarioRow.Senha = Criptografia.DesencriptarMD5(usuarioRow.Senha);
                }

                // atualiza dataSet
                usuarioDs.AcceptChanges();
            }
            catch
            {
                throw;
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }

            return(usuarioDs);
        }
Example #7
0
            public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(global::System.Xml.Schema.XmlSchemaSet xs)
            {
                global::System.Xml.Schema.XmlSchemaComplexType type     = new global::System.Xml.Schema.XmlSchemaComplexType();
                global::System.Xml.Schema.XmlSchemaSequence    sequence = new global::System.Xml.Schema.XmlSchemaSequence();
                UsuarioDs ds = new UsuarioDs();

                global::System.Xml.Schema.XmlSchemaAny any1 = new global::System.Xml.Schema.XmlSchemaAny();
                any1.Namespace       = "http://www.w3.org/2001/XMLSchema";
                any1.MinOccurs       = new decimal(0);
                any1.MaxOccurs       = decimal.MaxValue;
                any1.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax;
                sequence.Items.Add(any1);
                global::System.Xml.Schema.XmlSchemaAny any2 = new global::System.Xml.Schema.XmlSchemaAny();
                any2.Namespace       = "urn:schemas-microsoft-com:xml-diffgram-v1";
                any2.MinOccurs       = new decimal(1);
                any2.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax;
                sequence.Items.Add(any2);
                global::System.Xml.Schema.XmlSchemaAttribute attribute1 = new global::System.Xml.Schema.XmlSchemaAttribute();
                attribute1.Name       = "namespace";
                attribute1.FixedValue = ds.Namespace;
                type.Attributes.Add(attribute1);
                global::System.Xml.Schema.XmlSchemaAttribute attribute2 = new global::System.Xml.Schema.XmlSchemaAttribute();
                attribute2.Name       = "tableTypeName";
                attribute2.FixedValue = "UsuarioDataTable";
                type.Attributes.Add(attribute2);
                type.Particle = sequence;
                global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable();
                if (xs.Contains(dsSchema.TargetNamespace))
                {
                    global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream();
                    global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream();
                    try {
                        global::System.Xml.Schema.XmlSchema schema = null;
                        dsSchema.Write(s1);
                        for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();)
                        {
                            schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current));
                            s2.SetLength(0);
                            schema.Write(s2);
                            if ((s1.Length == s2.Length))
                            {
                                s1.Position = 0;
                                s2.Position = 0;
                                for (; ((s1.Position != s1.Length) &&
                                        (s1.ReadByte() == s2.ReadByte()));)
                                {
                                    ;
                                }
                                if ((s1.Position == s1.Length))
                                {
                                    return(type);
                                }
                            }
                        }
                    }
                    finally {
                        if ((s1 != null))
                        {
                            s1.Close();
                        }
                        if ((s2 != null))
                        {
                            s2.Close();
                        }
                    }
                }
                xs.Add(dsSchema);
                return(type);
            }