protected void btnGuardar_Click(object sender, EventArgs e)
    {
        Reparacion r = new Reparacion();
        Vehiculo v = new Vehiculo();
        EstadoReparacion er = new EstadoReparacion();
        er.idEstado = 1;
        //f.numeroFactura = GestorFacturas.ObtenerNumeroMaximo() + 1;
        //f.fechaFactura = DateTime.Now;

        int idVehiculo = (int)ViewState["idVehiculo"];

        //if (ViewState["reparacion"] != null) r = (Reparacion)ViewState["reparacion"];
        v.idVehiculo = idVehiculo;
        r.vehiculo = v;
        r.estadoReparacion = er;
        r.fechaFin = (DateTime) ViewState["fechaFin"];
        r.totalMO = (decimal)ViewState["totalReparacion"];

        List<DetalleReparacion> listaDetalles;
        if (ViewState["detallesReparacion"] == null) ViewState["detallesReparacion"] = new List<DetalleFactura>();
        listaDetalles = (List<DetalleReparacion>)ViewState["detallesReparacion"];
        GestorReparaciones.InsertarReparacion(r, listaDetalles);
        alertaExito.Visible = true;
        Inicio();
    }
Example #2
0
        public static void InsertarReparacion(Reparacion r, List<DetalleReparacion> listaDetalles)
        {
            SqlConnection con = new SqlConnection(cadena);

            con.Open();
            SqlTransaction tran = con.BeginTransaction();
            //Insertamos la factura primero
            string sql = "INSERT INTO Reparaciones (fechaFin, idVehiculo, idEstado, totalMO) VALUES (@fechaFin, @idVehiculo, @idEstado, @totalMO); SELECT @@Identity";

            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = sql;
            cmd.Connection = con;
            cmd.Transaction = tran;

            cmd.Parameters.AddWithValue("@fechaFin", r.fechaFin);
            cmd.Parameters.AddWithValue("@idVehiculo", r.vehiculo.idVehiculo);
            cmd.Parameters.AddWithValue("@idEstado", r.estadoReparacion.idEstado);
            cmd.Parameters.AddWithValue("@totalMO", r.totalMO);

            try
            {
                int idReparacion = Convert.ToInt32(cmd.ExecuteScalar());
                r.idReparacion = idReparacion;

                //Insertamos los detalles luego
                foreach (var dr in listaDetalles)
                {
                    dr.reparacion= r;
                    DetalleReparacionDAO.InsertarDetalleReparacion(dr, tran, con);
                }

                ////Marcar como facturada la reparacion
                //ReparacionDAO.Facturar(f.reparacion.idReparacion, con, tran);

                tran.Commit();
            }
            catch (Exception e)
            {
                tran.Rollback();
                throw new ApplicationException("Error al insertar factura: " + e.Message);
            }

            finally
            {
                con.Close();
            }
        }
Example #3
0
    protected void btnGuardar_Click(object sender, EventArgs e)
    {
        Factura f = new Factura();
        Reparacion r = new Reparacion();

        f.numeroFactura = GestorFacturas.ObtenerNumeroMaximo() + 1;
        f.fechaFactura = DateTime.Now;

        int idReparacion = (int)ViewState["idReparacion"];

        //if (ViewState["reparacion"] != null) r = (Reparacion)ViewState["reparacion"];
        r.idReparacion = idReparacion;
        f.reparacion = r;

        f.total = (decimal)ViewState["totalFactura"];

        List<DetalleFactura> listaDetalles;
        if (ViewState["detallesFactura"] == null) ViewState["detallesFactura"] = new List<DetalleFactura>();
        listaDetalles = (List<DetalleFactura>)ViewState["detallesFactura"];

        GestorFacturas.InsertarFactura(f, listaDetalles);
        alertaExito.Visible = true;
        Inicio();
    }
Example #4
0
        public static List<Reparacion> Obtener(int idVehiculo, int idEstado, decimal totalDesde, decimal totalHasta, string orden)
        {
            List<Reparacion> listaReparaciones = new List<Reparacion>();
            SqlConnection con = new SqlConnection(cadena);
            try
            {
                con.Open();
                SqlCommand cmd = new SqlCommand();
                string sql = "SELECT Reparaciones.idReparacion, Vehiculos.dominio, Clientes.apellido, Clientes.nombre, EstadosReparacion.nombreEstado, Reparaciones.fechaFin, Reparaciones.totalMO";
                //Facturas.numeroFactura, Facturas.fechaFactura, Vehiculos.dominio, Clientes.apellido, Clientes.nombre, Clientes.numeroDocumento, Reparaciones.totalMO, Facturas.total";
                sql += " FROM Reparaciones JOIN Vehiculos ON Reparaciones.idVehiculo = Vehiculos.idVehiculo JOIN Clientes ON Vehiculos.idCliente = Clientes.idCliente ";
                sql += "JOIN EstadosReparacion ON Reparaciones.idEstado = EstadosReparacion.idEstado";

                string where = "";

                if (idVehiculo != 0)
                {
                    where += " AND (Vehiculos.idVehiculo = @idVehiculo)";
                    cmd.Parameters.AddWithValue("@idVehiculo", idVehiculo);
                }
                if (idEstado != 0)
                {
                    where += " AND (EstadosReparacion.idEstado = @idEstado)";
                    cmd.Parameters.AddWithValue("@idEstado", idEstado);
                }

                if (totalDesde > -1 && totalHasta > -1)
                {
                    where += " AND (Reparaciones.totalMO BETWEEN @totalDesde AND @totalHasta)";
                    cmd.Parameters.AddWithValue("@totalDesde", totalDesde);
                    cmd.Parameters.AddWithValue("@totalHasta", totalHasta);
                }
                else
                {
                    if (totalDesde > -1)
                    {
                        where += " AND (Reparaciones.totalMO > @totalDesde)";
                        cmd.Parameters.AddWithValue("@totalDesde", totalDesde);
                    }
                    else
                    {
                        if (totalHasta > -1)
                        {
                            where += " AND (Reparaciones.totalMO < @totalHasta)";
                            cmd.Parameters.AddWithValue("@totalHasta", totalHasta);
                        }
                    }
                }

                if (where != "")
                {
                    sql += " WHERE ";
                    sql += where.Substring(5);
                }
                if(orden != "")
                {
                    sql += " ORDER BY " + orden;
                }
                cmd.CommandText = sql;
                cmd.Connection = con;
                SqlDataReader dr = cmd.ExecuteReader();

                while (dr.Read())
                {

                    Reparacion r = new Reparacion();
                    Vehiculo v = new Vehiculo();
                    Cliente c = new Cliente();
                    EstadoReparacion e = new EstadoReparacion();

                    v.dominio = dr["dominio"].ToString();
                    c.apellido = dr["apellido"].ToString();
                    c.nombre = dr["nombre"].ToString();
                    c.completarNombre();
                    e.nombreEstado = dr["nombreEstado"].ToString();
                    r.idReparacion = (int)dr["idReparacion"];
                    if(dr["fechaFin"] == DBNull.Value)
                    {
                        r.fechaFin = null;
                    }
                    else
                        r.fechaFin = DateTime.Parse(dr["fechaFin"].ToString());
                    r.totalMO = (decimal)dr["totalMO"];

                    v.cliente = c;
                    r.vehiculo = v;
                    r.estadoReparacion = e;

                    listaReparaciones.Add(r);
                }
            }
            catch(SqlException e) {
                throw e;
                    //new ApplicationException("Surgió un porblema al obtener facturas");
            }
            finally
            {
                con.Close();
            }

            return listaReparaciones;
        }
Example #5
0
        public static List<Reparacion> ObtenerTodas()
        {
            List<Reparacion> listaReparaciones = new List<Reparacion>();
            SqlConnection con = new SqlConnection(cadena);
            try
            {
                con.Open();
                SqlCommand cmd = new SqlCommand();
                string sql = "SELECT Vehiculos.dominio, Clientes.apellido, Clientes.nombre, Reparaciones.idReparacion, Reparaciones.totalMO, EstadosReparacion.nombreEstado";
                sql += " FROM Reparaciones INNER JOIN Vehiculos ON Reparaciones.idVehiculo = Vehiculos.idVehiculo INNER JOIN";
                sql += " EstadosReparacion ON Reparaciones.idEstado = EstadosReparacion.idEstado INNER JOIN Clientes ON Vehiculos.idCliente = Clientes.idCliente";
                sql += " WHERE Reparaciones.idEstado = @idEstado";
                cmd.Parameters.AddWithValue("@idEstado", 3);

                cmd.CommandText = sql;
                cmd.Connection = con;
                SqlDataReader dr = cmd.ExecuteReader();

                while (dr.Read())
                {
                    Reparacion r = new Reparacion();
                    Vehiculo v = new Vehiculo();
                    Cliente c = new Cliente();
                    EstadoReparacion e = new EstadoReparacion();

                    r.idReparacion = (int)dr["idReparacion"];
                    v.dominio = dr["dominio"].ToString();
                    c.apellido = dr["apellido"].ToString();
                    c.nombre = dr["nombre"].ToString();
                    c.completarNombre();
                    r.totalMO = (decimal)dr["totalMO"];
                    e.nombreEstado = dr["nombreEstado"].ToString();

                    r.estadoReparacion = e;
                    v.cliente = c;
                    r.vehiculo = v;

                    listaReparaciones.Add(r);
                }
            }
            catch (SqlException e)
            {
                throw new ApplicationException("Surgió un porblema al obtener reparaciones");
            }
            finally
            {
                con.Close();
            }
            return listaReparaciones;
        }
Example #6
0
        public static List<Factura> Obtener(DateTime? fechaDesde, DateTime? fechaHasta, int idCliente, decimal totalDesde, decimal totalHasta)
        {
            List<Factura> listaFacturas = new List<Factura>();

            SqlConnection con = new SqlConnection(cadena);
            try
            {
                con.Open();
                SqlCommand cmd = new SqlCommand();
                string sql = "SELECT Facturas.numeroFactura, Facturas.fechaFactura, Vehiculos.dominio, Clientes.apellido, Clientes.nombre, Clientes.numeroDocumento, Reparaciones.totalMO, Facturas.total";
                sql += " FROM Reparaciones JOIN Facturas ON Reparaciones.idReparacion = Facturas.idReparacion JOIN Vehiculos ON Reparaciones.idVehiculo = Vehiculos.idVehiculo JOIN Clientes ON Vehiculos.idCliente = Clientes.idCliente";

                string where = "";

                if (fechaDesde != null && fechaHasta != null)
                {
                    where += " AND (Facturas.fechaFactura BETWEEN @fechaDesde AND @fechaHasta)";
                    cmd.Parameters.AddWithValue("@fechaDesde", fechaDesde);
                    cmd.Parameters.AddWithValue("@fechaHasta", fechaHasta);
                }
                else
                {
                    if (fechaDesde != null)
                    {
                        where += " AND (Facturas.fechaFactura > @fechaDesde)";
                        cmd.Parameters.AddWithValue("@fechaDesde", fechaDesde);
                    }
                    else
                    {
                        if (fechaHasta != null)
                        {
                            where += " AND (Facturas.fechaFactura < @fechaHasta)";
                            cmd.Parameters.AddWithValue("@fechaHasta", fechaHasta);
                        }
                    }
                }

                if (idCliente != 0)
                {
                    where += " AND (Clientes.idCliente = @idCliente)";
                    cmd.Parameters.AddWithValue("@idCliente", idCliente);
                }

                if (totalDesde > -1 && totalHasta > -1)
                {
                    where += " AND (Facturas.total BETWEEN @totalDesde AND @totalHasta)";
                    cmd.Parameters.AddWithValue("@totalDesde", totalDesde);
                    cmd.Parameters.AddWithValue("@totalHasta", totalHasta);
                }
                else
                {
                    if (totalDesde > -1)
                    {
                        where += " AND (Facturas.total > @totalDesde)";
                        cmd.Parameters.AddWithValue("@totalDesde", totalDesde);
                    }
                    else
                    {
                        if (totalHasta > -1)
                        {
                            where += " AND (Facturas.total < @totalHasta)";
                            cmd.Parameters.AddWithValue("@totalHasta", totalHasta);
                        }
                    }
                }

                if (where != "")
                {
                    sql += " WHERE ";
                    sql += where.Substring(5);
                }

                cmd.CommandText = sql;
                cmd.Connection = con;
                SqlDataReader dr = cmd.ExecuteReader();

                while (dr.Read())
                {
                    Factura f = new Factura();
                    Reparacion r = new Reparacion();
                    Vehiculo v = new Vehiculo();
                    Cliente c = new Cliente();

                    f.numeroFactura = (int)dr["numeroFactura"];
                    f.fechaFactura = DateTime.Parse(dr["fechaFactura"].ToString());
                    v.dominio = dr["dominio"].ToString();
                    c.apellido = dr["apellido"].ToString();
                    c.nombre = dr["nombre"].ToString();
                    c.numeroDocumento = (int)dr["numeroDocumento"];
                    c.completarNombre();
                    r.totalMO = (decimal)dr["totalMO"];
                    f.total = (decimal)dr["total"];

                    v.cliente = c;
                    r.vehiculo = v;
                    f.reparacion = r;

                    listaFacturas.Add(f);
                }
            }
            catch (SqlException e)
            {
                throw new ApplicationException("Surgió un porblema al obtener facturas");
            }
            finally
            {
                con.Close();
            }
            return listaFacturas;
        }
Example #7
0
 public static void InsertarReparacion(Reparacion r, List<DetalleReparacion> listaDetalles)
 {
     ReparacionDAO.InsertarReparacion(r, listaDetalles);
 }