Example #1
0
        public List <Marca> Listar()
        {
            List <Marca>  Marcas = new List <Marca>();
            SqlDataReader Lector;
            SqlCommand    Comando  = new SqlCommand();
            SqlConnection Conexion = new SqlConnection();
            Marca         Aux;


            try
            {
                Conexion.ConnectionString = "data source=NBBASAR605\\SQLEXPRESS; initial catalog=Negocio; integrated security=sspi";
                Comando.CommandType       = System.Data.CommandType.Text;

                Comando.CommandText = "select ID, Descripcion from [Negocio].[dbo].Marca";
                Comando.Connection  = Conexion;

                Conexion.Open();
                Lector = Comando.ExecuteReader();

                while (Lector.Read())
                {
                    Aux = new Marca((int)Lector["ID"], (string)Lector["Descripcion"]);


                    Marcas.Add(Aux);
                }

                return(Marcas);
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }
Example #2
0
        public List <Categoria> Lista()
        {
            SqlConnection    conexion = new SqlConnection();
            SqlCommand       comando  = new SqlCommand();
            SqlDataReader    Lector;
            List <Categoria> Lista = new List <Categoria>();

            conexion.ConnectionString = "data source=.\\SQLEXPRESS; initial catalog = CATALOGO_DB; integrated security = sspi";
            comando.CommandType       = System.Data.CommandType.Text;
            comando.CommandText       = "select Id,Descripcion from CATEGORIAS";
            comando.Connection        = conexion;
            conexion.Open();
            Lector = comando.ExecuteReader();
            while (Lector.Read())
            {
                Categoria aux = new Categoria();
                aux.ID          = (int)Lector["Id"];
                aux.Descripcion = (string)Lector["Descripcion"];

                Lista.Add(aux);
            }
            Lector.Close();
            conexion.Close();
            return(Lista);
        }
Example #3
0
        public List <Articulos> Listar()
        {
            ///Declarar la shit necesaria para poder conectarse
            SqlConnection    Conexion = new SqlConnection();
            SqlCommand       Comando  = new SqlCommand();
            SqlDataReader    Lector;
            List <Articulos> lista = new List <Articulos>();

            //Configurando conexion
            Conexion.ConnectionString = "data source = .\\SQLEXPRESS; initial catalog = CATALOGO_DB; integrated security = sspi";
            Comando.CommandType       = System.Data.CommandType.Text;
            Comando.CommandText       = "select a.id as IdArt, a.Codigo, a.nombre, a.descripcion, a.imagenurl, a.precio, c.id as IdCategoria, c.Descripcion as Categoria,m.id as IdMarca, m.Descripcion as Marca from ARTICULOS as a join CATEGORIAS c on a.IdCategoria = c.id join MARCAS as m on m.Id = a.IdMarca";
            //se ejecuta la conexion
            Comando.Connection = Conexion;
            try
            {
                Conexion.Open();
                //se manda la query a seleccionar registros
                Lector = Comando.ExecuteReader();


                //Logica una vez conectado, ¿qué tenemos que hacer?
                while (Lector.Read())
                {
                    Articulos Aux = new Articulos();
                    ///Tenemos que Instanciar un objeto auxiliar al que asignarle los valores
                    ///leidos y de ahí sumarlo a la lista
                    Aux.Id          = (int)Lector["IdArt"];
                    Aux.Codigo      = Lector.GetString(1);
                    Aux.Nombre      = Lector.GetString(2);
                    Aux.Descripcion = Lector.GetString(3);
                    Aux.Imagen      = (string)Lector["ImagenUrl"];
                    Aux.Precio      = Lector.GetSqlMoney(5);

                    Aux.categoria             = new Categoria();
                    Aux.categoria.Id          = (int)Lector["IdCategoria"];
                    Aux.categoria.Descripcion = (string)Lector["Categoria"];

                    Aux.Marca             = new Marca();
                    Aux.Marca.Descripcion = (string)Lector["marca"];
                    Aux.Marca.Id          = (int)Lector["IdMarca"];


                    lista.Add(Aux);
                }
                Conexion.Close();
                return(lista);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #4
0
        public List <Articulo> listar()
        {
            SqlConnection   conexion = new SqlConnection();
            SqlCommand      comando  = new SqlCommand();
            SqlDataReader   Lector;
            List <Articulo> Lista = new List <Articulo>();

            conexion.ConnectionString = "data source=.\\SQLEXPRESS; initial catalog = CATALOGO_DB; integrated security = sspi";
            comando.CommandType       = System.Data.CommandType.Text;
            comando.CommandText       = "Select  A.Id,A.Codigo,A.Nombre,A.Descripcion,A.ImagenUrl,A.Precio,M.Descripcion Marca,M.Id IDMarca, C.Descripcion Categoria,C.Id IDCategoria " +
                                        "From ARTICULOS A, MARCAS M, CATEGORIAS C where A.IdMarca = M.Id and A.IdCategoria = C.Id";
            comando.Connection = conexion;
            conexion.Open();
            Lector = comando.ExecuteReader();
            while (Lector.Read())
            {
                Articulo aux = new Articulo();
                aux.ID          = (int)Lector["Id"];
                aux.Codigo      = (String)Lector["Codigo"];
                aux.Nombre      = (String)Lector["Nombre"];
                aux.Descripcion = (String)Lector["Descripcion"];
                aux.Precio      = Convert.ToDouble(Lector["Precio"]);
                aux.ImagenUrl   = (String)Lector["ImagenUrl"];

                aux.Marca             = new Marca();
                aux.Marca.ID          = (int)Lector["IDMarca"];
                aux.Marca.Descripcion = (String)Lector["Marca"];

                aux.Categoria             = new Categoria();
                aux.Categoria.ID          = (int)Lector["IDCategoria"];
                aux.Categoria.Descripcion = (String)Lector["Categoria"];

                Lista.Add(aux);
            }
            Lector.Close();
            conexion.Close();
            return(Lista);
        }
Example #5
0
        private void btnAbrirArchivo_Click(object sender, EventArgs e)
        {
            Lector      Bussines = new Negocio.Lector();
            TiempoExtra objExtra = new Modal.TiempoExtra();

            var fileContent = string.Empty;
            var filePath    = string.Empty;

            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                openFileDialog.InitialDirectory = "c:\\";
                openFileDialog.Filter           = "txt files (*.txt)|*.txt*";
                openFileDialog.FilterIndex      = 2;
                openFileDialog.RestoreDirectory = true;

                List <string>      desa    = new List <string>();
                List <TiempoExtra> objetos = new List <TiempoExtra>();

                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    //Get the path of specified file
                    filePath = openFileDialog.FileName;


                    //Read the contents of the file into a stream
                    var fileStream = openFileDialog.OpenFile();



                    desa = new List <string>(File.ReadLines(filePath));


                    objExtra = new TiempoExtra();
                    string[] temp;
                    foreach (string item in desa)
                    {
                        if (string.IsNullOrEmpty(objExtra.Obra) && item.ToUpper().Contains("OBRA:"))
                        {
                            temp          = item.Split(':');
                            objExtra.Obra = temp[1];
                        }
                        //if (item.ToUpper().Contains("FECHA:"))
                        //{
                        //    temp = item.Split(':');
                        //    objExtra.Fecha = DateTime.Parse(temp[1]);
                        //}
                        //if (item.ToUpper().Contains("MOTIVO:"))
                        //{
                        //    temp = item.Split(':');
                        //    objExtra.Motivo = temp[1];
                        //}
                        //if (item.ToUpper().Contains("INICIO:"))
                        //{
                        //    temp = item.Split(':');
                        //    objExtra.horaInicio = DateTime.Parse(temp[1]);
                        //}
                        //if (item.ToUpper().Contains("FIN:"))
                        //{
                        //    objExtra.horaFin = DateTime.Parse(item);
                        //}
                        //if (item.ToUpper().Contains("EXTRA:"))
                        //{
                        //    temp = item.Split(':');
                        //    objExtra.tiempoExtraReal = int.Parse(temp[1]);
                        //}
                        //if (item.ToUpper().Contains("EMPLEADO:"))
                        //{
                        //      objExtra .Nombre = item;
                        //}
                        if (!string.IsNullOrEmpty(objExtra.Obra) && !string.IsNullOrEmpty(objExtra.Fecha.ToString()) && !string.IsNullOrEmpty(objExtra.Motivo) &&
                            !string.IsNullOrEmpty(objExtra.horaInicio.ToString()) && !string.IsNullOrEmpty(objExtra.horaFin.ToString()) && !string.IsNullOrEmpty(objExtra.tiempoExtraReal.ToString()) &&
                            !string.IsNullOrEmpty(objExtra.Nombre))
                        {
                            objetos.Add(objExtra);
                            objExtra = new TiempoExtra();
                        }

                        if (!string.IsNullOrEmpty(objExtra.Obra))
                        {
                            objetos.Add(objExtra);
                            objExtra = new TiempoExtra();
                        }
                    }


                    tiempoExtraBindingSource.DataSource = objetos;



                    //using (StreamReader reader = new StreamReader(fileStream))
                    //{
                    //    fileContent = reader.ReadToEnd();


                    //}
                }
            }
        }