Пример #1
0
        public Factura BuscarFactura(int id)
        {
            string        _cliente;
            DateTime      _alta;
            Factura       factura   = null;
            SqlConnection oConexion = new SqlConnection(Conexion.Cnn);
            SqlCommand    oComando  = new SqlCommand("EXEC BuscarFactura " + id, oConexion);

            SqlDataReader oReader;

            try
            {
                oConexion.Open();
                oReader = oComando.ExecuteReader();
                if (oReader.Read())
                {
                    _cliente = (string)oReader["FacCliente"];
                    _alta    = (DateTime)oReader["FacAlta"];

                    PersistenciaLineas pLineas = new PersistenciaLineas();

                    factura = new Factura(id, _cliente, _alta, pLineas.BuscarLineas(id));
                }
                oReader.Close();
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Problemas con la base de datos:" + ex.Message);
            }
            finally
            {
                oConexion.Close();
            }
            return(factura);
        }
Пример #2
0
        //Operaciones
        public void AltaFactura(Factura F)
        {
            SqlConnection oConexion = new SqlConnection(Conexion.Cnn);
            SqlCommand    oComando  = new SqlCommand("AltaFactura", oConexion);

            oComando.CommandType = CommandType.StoredProcedure;

            try
            {
                SqlParameter _id       = new SqlParameter("@IdFactura", F.Id);
                SqlParameter _fechaFac = new SqlParameter("Fecha", F.Fecha);
                SqlParameter _cliente  = new SqlParameter("@NombreCli", F.Cliente);

                oComando.Parameters.Add(_id);
                oComando.Parameters.Add(_fechaFac);
                oComando.Parameters.Add(_cliente);

                oConexion.Open();

                int resultado = oComando.ExecuteNonQuery();

                if (resultado == 1)
                {
                    PersistenciaLineas pLineas = new PersistenciaLineas();

                    foreach (Linea Lineaa in F.Lineas)
                    {
                        pLineas.AgregarLinea(Lineaa, F.Id);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                oConexion.Close();
            }
        }
Пример #3
0
        public Factura BuscarFactura(int IdFactura)
        {
            string   _idCliente;
            DateTime _fechaFac;
            Factura  Factura = null;//ponemos en null la factura para que asegurarnos que este vacia

            SqlConnection oConexion = new SqlConnection(Conexion.Cnn);
            SqlCommand    oComando  = new SqlCommand("BuscarFactura" + IdFactura, oConexion);

            SqlDataReader oReader;

            try
            {
                oConexion.Open();
                oReader = oComando.ExecuteReader();

                if (oReader.Read())
                {
                    _idCliente = (string)oReader["NombreCliente"];
                    _fechaFac  = (DateTime)oReader["Fecha"];

                    PersistenciaLineas pLineas = new PersistenciaLineas();

                    Factura = new Factura(IdFactura, _fechaFac, _idCliente, pLineas.BuscarLinea(IdFactura));
                }
                oReader.Close();
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Problemas con la base de datos:" + ex.Message);
            }
            finally
            {
                oConexion.Close();
            }

            return(Factura);
        }
Пример #4
0
        //Operaciones
        public void AltaFactura(Factura factura)
        {
            SqlConnection conn    = new SqlConnection(Conexion.Cnn);
            SqlCommand    command = new SqlCommand();

            try
            {
                command.Connection  = conn;
                command.CommandText = "AltaFactura";
                command.CommandType = CommandType.StoredProcedure;

                command.Parameters.Add(new SqlParameter("@FacID", factura.ID));
                command.Parameters.Add(new SqlParameter("@FacAlta", factura.FechaAlta.ToString("yyyy-MM-dd HH:mm:ss")));
                command.Parameters.Add(new SqlParameter("@FacCliente", factura.Cliente));

                conn.Open();

                int res = command.ExecuteNonQuery();

                if (res == 1)
                {
                    PersistenciaLineas pLines = new PersistenciaLineas();

                    foreach (LineaFactura lin in factura.Lineas)
                    {
                        pLines.AltaLineas(lin, factura.ID, conn);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
        }
Пример #5
0
        public void ModificarFactura(Factura factura)
        {
            SqlConnection conn    = new SqlConnection(Conexion.Cnn);
            SqlCommand    command = new SqlCommand();

            try
            {
                command.Connection  = conn;
                command.CommandText = "ModificarFactura";
                command.CommandType = CommandType.StoredProcedure;

                command.Parameters.Add(new SqlParameter("@FacID", factura.ID));
                command.Parameters.Add(new SqlParameter("@Cliente", factura.Cliente));

                conn.Open();

                command.ExecuteNonQuery();

                PersistenciaLineas pLineas = new PersistenciaLineas();

                //Eliminamos todas las lineas
                pLineas.EliminarLineas(factura.ID, conn);

                //Cargamos las lineas nuevamente
                foreach (LineaFactura lin in factura.Lineas)
                {
                    pLineas.AltaLineas(lin, factura.ID, conn);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
        }