private void modificarNumero(object sender, EventArgs e) { if (cctbNumTelefono.Text != string.Empty) { if (Convert.ToInt64(cctbNumTelefono.Text) != Telefono.telefono) { using (MABEntities db = new MABEntities()) { Telefono.telefono = Convert.ToInt64(cctbNumTelefono.Text); db.Entry(Telefono).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); MessageBox.Show("Telefono Modificado Correctamente"); } } else { MessageBox.Show("El numero de telefono no ha cambiado", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("El campo Telefono es invalido", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private int totalClientesGuardados() { using (MABEntities db = new MABEntities()) { return(db.Clientes.Count()); } }
private void refreshNumTelefonos() { using (MABEntities db = new MABEntities()) { cclblNumTelefonos.Text = db.Clientes.Find(cliente.Id).Telefonos.Count.ToString(); } }
private string lavarropasConMasReparaciones() { using (MABEntities db = new MABEntities()) { int idLavarropas = -1; int maxReparaciones = 0; foreach (Models.Lavarropas lavarropa in db.Lavarropas) { int reparaciones = lavarropa.Reparacion.Count(); if (reparaciones >= maxReparaciones) { maxReparaciones = reparaciones; idLavarropas = lavarropa.Id; } } if (idLavarropas != -1) { Models.Lavarropas l = db.Lavarropas.Find(idLavarropas); return(l.marca + " " + l.modelo + " del cliente " + l.Cliente.nombre + " " + l.Cliente.apellido); } else { return(""); } } }
private string marcaMasReparada() { using (MABEntities db = new MABEntities()) { return(db.MarcaMasReparado().FirstOrDefault());; } }
private string clienteConMasLavarropas() { using (MABEntities db = new MABEntities()) { int idCliente = -1; int maxLavarropas = 0; foreach (Models.Clientes cliente in db.Clientes) { int lavarropas = cliente.Lavarropas.Count(); if (lavarropas >= maxLavarropas) { maxLavarropas = lavarropas; idCliente = cliente.Id; } } if (idCliente != -1) { Models.Clientes c = db.Clientes.Find(idCliente); return(c.nombre + " " + c.apellido); } else { return(""); } } }
private int totalDeLavarropasGuardados() { using (MABEntities db = new MABEntities()) { return(db.Lavarropas.Count()); } }
private void agregarReparacion(object sender, EventArgs e) { if ((cctbErrorAReparar.Text != string.Empty) && (dtpFechaIngreso.Value <= DateTime.Now)) { using (MABEntities db = new MABEntities()) { Models.Reparaciones reparacion = new Models.Reparaciones(); reparacion.fechaIngreso = dtpFechaIngreso.Value; reparacion.fechaEgreso = null; reparacion.errorAReparar = cctbErrorAReparar.Text; reparacion.estadoReparacion = estadosReparacion.EnCurso; reparacion.mesesGarantia = null; reparacion.reparacionRealizada = ""; reparacion.manoDeObra = 0; reparacion.totalRepuestos = 0; reparacion.LavarropasId = lavarropas.Id; db.Reparaciones.Add(reparacion); db.SaveChanges(); MessageBox.Show("Reparacion agregada correctamente", "Guardada Correctamente", MessageBoxButtons.OK, MessageBoxIcon.Information); cctbErrorAReparar.Text = ""; cctbErrorAReparar.Focus(); } } else { MessageBox.Show("Hay campos que faltan completar o la fecha es incorrecta \n" + "Por favor revise la informacion y vuelva a intentarlo.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void agregarRepuesto(object sender, EventArgs e) { if (cctbNombre.Text != string.Empty && cctbDescripcion.Text != string.Empty && cctbStock.Text != string.Empty && cctbPrecio.Text != string.Empty) { using (MABEntities db = new MABEntities()) { Models.Repuestos repuesto = new Models.Repuestos(); repuesto.nombre = cctbNombre.Text; repuesto.descripcion = cctbDescripcion.Text; repuesto.disponibles = Convert.ToInt32(cctbStock.Text); repuesto.precio = Convert.ToDouble(cctbPrecio.Text); db.Repuestos.Add(repuesto); db.SaveChanges(); MessageBox.Show("Repuesto agregado correctamente", "Guardado Correctamente", MessageBoxButtons.OK, MessageBoxIcon.Information); cctbNombre.Text = ""; cctbDescripcion.Text = ""; cctbPrecio.Text = ""; cctbStock.Text = ""; cctbNombre.Focus(); } } else { MessageBox.Show("Faltan campos por llenar", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void agregarEntrega(object sender, EventArgs e) { if (cctbMonto.Text != string.Empty) { Models.Entregas entrega = new Models.Entregas(); entrega.ClientesId = reparacion.Lavarropas.Cliente.Id; entrega.ReparacionesId = reparacion.Id; entrega.monto = Convert.ToInt32(cctbMonto.Text); entrega.fecha = dtpFechaEntrega.Value; using (MABEntities db = new MABEntities()) { db.Entregas.Add(entrega); db.SaveChanges(); DialogResult resp = MessageBox.Show("Entrega Creada Correctamente \n ¿Desea crear un Comprobante de Recibo?", "Guardado Correctamente", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (resp == DialogResult.Yes) { frmComprobanteDeRecibo frm = new frmComprobanteDeRecibo(entrega); frm.ShowDialog(); } cctbMonto.Text = ""; cctbMonto.Focus(); } } else { MessageBox.Show("Falta llenar el monto de la entrega", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void buscarLavarropas(object sender, EventArgs e) { frmBuscarLavarropas frm = new frmBuscarLavarropas(); frm.ShowDialog(); if (frm.getResultados.Count != 0) { using (MABEntities db = new MABEntities()) { List <Models.Lavarropas> lavarropas = new List <Models.Lavarropas>(); foreach (int id in frm.getResultados) { var lav = db.Lavarropas.Find(id); if (!lavarropas.Contains(lav)) { lavarropas.Add(lav); } } ucDGVTabla.dataSource(lavarropas); } } }
private void buscarReparacion(object sender, EventArgs e) { frmBuscarRepuesto frm = new frmBuscarRepuesto(); frm.ShowDialog(); if (frm.getRepuestos.Count != 0) { using (MABEntities db = new MABEntities()) { List <Models.Repuestos> repuestos = new List <Models.Repuestos>(); foreach (int id in frm.getRepuestos) { var repuesto = db.Repuestos.Find(id); if (!repuestos.Contains(repuesto)) { repuestos.Add(repuesto); } } ucDGVTabla.dataSource(repuestos); } } }
private string modeloMasReparado() { using (MABEntities db = new MABEntities()) { return(db.ModeloMasReparado().FirstOrDefault()); } }
private string clienteConMasReparaciones() { using (MABEntities db = new MABEntities()) { int idCliente = -1; int maxReparaciones = 0; foreach (Models.Clientes cliente in db.Clientes) { int reparaciones = 0; foreach (Models.Lavarropas lavarropa in cliente.Lavarropas) { reparaciones += lavarropa.Reparacion.Count(); } if (reparaciones >= maxReparaciones) { maxReparaciones = reparaciones; idCliente = cliente.Id; } } if (idCliente != -1) { Models.Clientes c = db.Clientes.Find(idCliente); return(c.nombre + ' ' + c.apellido); } else { return(""); } } }
private void rbRepuestoUsadoAnualmente_CheckedChanged(object sender, EventArgs e) { using (MABEntities db = new MABEntities()) { /** * select COUNT(r.ReparacionesId) * from ReparacionesRepuestos as r * where r.RepuestoId = ** El Id del Repuesto que este seleccionado en el cbo ** * group by MONTH(r.Reparacion.fechaEgreso); * */ if (idRepuestos != null) { var data = (from r in db.ReparacionesRepuestos where r.RepuestosId == idRepuestos group r by new { month = r.Reparaciones.fechaEgreso.Value.Year } into grouped select new { count = grouped.Count() }).ToList(); chartCantRepOut.DataSource = data; } else { MessageBox.Show("Debe seleccionar primero un repuesto", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
private void cargarCliente(int idCliente) { using (MABEntities db = new MABEntities()) { cliente = db.Clientes.Find(idCliente); } }
private void btnAgregar(object sender, EventArgs e) { if (reparacion != null) { frmSeleccionarRepuesto frm = new frmSeleccionarRepuesto(); frm.ShowDialog(); int idRepuesto = frm.repuestoSeleccionado; if (idRepuesto != -1) { using (MABEntities db = new MABEntities()) { Models.ReparacionesRepuestos repuRepa = new ReparacionesRepuestos(); repuRepa.ReparacionesId = reparacion.Id; repuRepa.RepuestosId = idRepuesto; db.ReparacionesRepuestos.Add(repuRepa); db.SaveChanges(); } } cargarDGV(reparacion.Id); } else { frmAgregarRepuesto frm = new frmAgregarRepuesto(); frm.ShowDialog(); cargarDGV(null); } }
private void btnSearch(object sender, EventArgs e) { frmBuscarLavarropas frm = new frmBuscarLavarropas(); frm.ShowDialog(); if (frm.getResultados.Count != 0) { using (MABEntities db = new MABEntities()) { List <object> lavarropas = new List <object>(); foreach (int id in frm.getResultados) { var lavarropa = db.Lavarropas.Find(id); if (!lavarropas.Contains(lavarropa)) { db.Entry(lavarropa).Reference("Cliente").Load(); db.Entry(lavarropa).Collection("Reparacion").Load(); lavarropas.Add(lavarropa); } } ucDGVTabla.dataSource(lavarropas); ucDGVTabla.Columns["Id"].Visible = false; ucDGVTabla.Columns["Cliente"].Visible = false; ucDGVTabla.Columns["ClienteId"].Visible = false; ucDGVTabla.Columns["Reparacion"].Visible = false; } } }
private void guardarLavarropas(object sender, EventArgs e) { if ((cctbMarca.Text != string.Empty) && (cctbModelo.Text != string.Empty) && (cctbEstado.Text != string.Empty)) { using (MABEntities db = new MABEntities()) { Models.Lavarropas Lavarropas = new Models.Lavarropas(); Lavarropas.marca = cctbMarca.Text; Lavarropas.modelo = cctbModelo.Text; Lavarropas.estadoGeneral = cctbEstado.Text; Lavarropas.ClienteId = Cliente.Id; db.Lavarropas.Add(Lavarropas); db.SaveChanges(); MessageBox.Show("Lavarropas agregado correctamente", "Guardado Correctamente", MessageBoxButtons.OK, MessageBoxIcon.Information); cctbMarca.Text = ""; cctbModelo.Text = ""; cctbEstado.Text = ""; cctbMarca.Focus(); } } else { MessageBox.Show("Hay campos que faltan completar", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnBuscar(object sender, EventArgs e) { if (reparacion != null) { MessageBox.Show("La busqueda se realiza sobre todos los repuestos", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Warning); } frmBuscarRepuesto frm = new frmBuscarRepuesto(); frm.ShowDialog(); if (frm.getRepuestos.Count != 0) { using (MABEntities db = new MABEntities()) { List <Models.Repuestos> repuestos = new List <Models.Repuestos>(); foreach (int id in frm.getRepuestos) { var repuesto = db.Repuestos.Find(id); if (!repuestos.Contains(repuesto)) { db.Entry(repuesto).Collection("Reparaciones").Load(); repuestos.Add(repuesto); } } ucDGVTabla.dataSource(repuestos); ucDGVTabla.Columns["Reparaciones"].Visible = false; } } }
private void buscarReparacion(object sender, EventArgs e) { using (MABEntities db = new MABEntities()) { List <Models.Reparaciones> reparaciones = db.Reparaciones.ToList(); foreach (Models.Reparaciones reparacion in reparaciones) { if ((reparacion.fechaIngreso >= dtpInicioIngreso.Value) && (reparacion.fechaIngreso <= dtpFinIngreso.Value)) { idResultados.Add(reparacion.Id); break; } else if ((reparacion.fechaEgreso >= dtpInicioEgreso.Value) && (reparacion.fechaEgreso <= dtpFinEgreso.Value)) { idResultados.Add(reparacion.Id); break; } } } if (idResultados.Count != 0) { this.Close(); } else { MessageBox.Show("No se encontraron reparaciones en esos rangos de Fechas. Pruebe con otros", "Sin Resultados", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void modificarEntrega(object sender, EventArgs e) { if (dtpFechaEntrega.Value > DateTime.Now) { dtpFechaEntrega.Value = DateTime.Now; } if (cctbMonto.Text != string.Empty) { entrega.monto = Convert.ToDouble(cctbMonto.Text); entrega.fecha = dtpFechaEntrega.Value; using (MABEntities db = new MABEntities()) { db.Entry(entrega).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); MessageBox.Show("Entrega modificada Correctamente"); } } else { MessageBox.Show("Falta completar el campo de monto", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void buscarCliente(object sender, EventArgs e) { frmBuscarCliente frm = new frmBuscarCliente(); frm.ShowDialog(); if (frm.idClientes != null && frm.idClientes.Count != 0) { List <int> idClientes = frm.idClientes; List <Models.Clientes> clientes = new List <Models.Clientes>(); using (MABEntities db = new MABEntities()) { foreach (int id in idClientes) { var cliente = db.Clientes.Find(id); if (!clientes.Contains(cliente)) { clientes.Add(cliente); } } ucDGVTabla.dataSource(clientes); } } }
private void cargarReparaciones(int idCliente) { using (MABEntities db = new MABEntities()) { cliente = db.Clientes.Find(idCliente); reparaciones = (from rep in db.Reparaciones where rep.Lavarropas.Cliente.Id == cliente.Id select rep).ToList(); } ucDGVTabla.dataSource(reparaciones); Text = "Seleccione una Reparacion del cliente " + cliente.nombre + " " + cliente.apellido; ucDGVTabla.Columns["Id"].Visible = false; ucDGVTabla.Columns["mesesGarantia"].Visible = false; ucDGVTabla.Columns["reparacionRealizada"].Visible = false; ucDGVTabla.Columns["manoDeObra"].Visible = false; ucDGVTabla.Columns["totalRepuestos"].Visible = false; ucDGVTabla.Columns["LavarropasId"].Visible = false; ucDGVTabla.Columns["Lavarropas"].Visible = false; ucDGVTabla.Columns["Entregas"].Visible = false; ucDGVTabla.Columns["Repuestos"].Visible = false; }
private int guardarCliente() { Models.Clientes cliente; if ((cctbApellido.Text != string.Empty) && (cctbDireccion.Text != string.Empty)) { using (MABEntities db = new MABEntities()) { cliente = new Models.Clientes(); cliente.nombre = cctbNombre.Text; cliente.apellido = cctbApellido.Text; cliente.direccion = cctbDireccion.Text; db.Clientes.Add(cliente); db.SaveChanges(); return(cliente.Id); } } else { MessageBox.Show("Faltan campos por completar", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(-1); }
private void eliminarSeleccionado(object sender, EventArgs e) { if (ucDGVTabla.selectedRow() != null) { long telefono = Convert.ToInt64(ucDGVTabla.selectedRow().Cells["Telefono"].Value); using (MABEntities db = new MABEntities()) { var Telefono = (from tel in db.Telefonos where tel.telefono == telefono where tel.estado != false select tel).First(); DialogResult resp = MessageBox.Show( "Esta a punto de eliminar el Telefono " + Telefono.telefono + Environment.NewLine + "del Cliente " + Telefono.Cliente.nombre + " " + Telefono.Cliente.apellido + Environment.NewLine + "¿Quiere continuar con la eliminacion?", "Estas a Punto de eliminar un Telefono", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (resp == DialogResult.Yes) { Telefono.estado = false; db.Entry(Telefono).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } } refrescarTelefonos(cliente.Id); }
private void guardarModificacion(object sender, EventArgs e) { if (dtpFechaEgreso.Value > DateTime.Now) { dtpFechaEgreso.Value = DateTime.Now; } if (cctbMesesGarantia.Text == string.Empty) { cctbMesesGarantia.Text = "3"; } if (cctbManoObra.Text != string.Empty && cctbTotalRepuestos.Text != string.Empty) { reparacion.estadoReparacion = (estadosReparacion)cboEstadoReparacion.SelectedItem; reparacion.mesesGarantia = Convert.ToInt32(cctbMesesGarantia.Text); reparacion.fechaEgreso = dtpFechaEgreso.Value; reparacion.reparacionRealizada = cctbReparacionRealizada.Text; reparacion.manoDeObra = Convert.ToInt32(cctbManoObra.Text); reparacion.totalRepuestos = Convert.ToInt32(cctbTotalRepuestos.Text); using (MABEntities db = new MABEntities()) { db.Entry(reparacion).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); MessageBox.Show("Reparacion finalizada correctamente"); } } else { MessageBox.Show("Faltan campos por completar", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void cargarCliente(int id) { using (MABEntities db = new MABEntities()) { cliente = db.Clientes.Find(id); cclblNombreCliente.Text = cliente.nombre + " " + cliente.apellido; } }
private void btnModificar(object sender, EventArgs e) { if (reparacion != null) { int idRepuestoOriginal = Convert.ToInt32(ucDGVTabla.selectedRow().Cells["Id"].Value); /** Desde aca se hace un guardar que voy a tener que modificar, claramente */ frmSeleccionarRepuesto frm = new frmSeleccionarRepuesto(); frm.ShowDialog(); int idRepuestoNuevo = frm.repuestoSeleccionado; if (idRepuestoNuevo != -1) { using (MABEntities db = new MABEntities()) { Models.ReparacionesRepuestos repaRepu = db.ReparacionesRepuestos.Find(reparacion.Id, idRepuestoOriginal); db.Entry(repaRepu).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); Models.ReparacionesRepuestos nuevoRepaRepu = new Models.ReparacionesRepuestos(); nuevoRepaRepu.ReparacionesId = reparacion.Id; nuevoRepaRepu.RepuestosId = idRepuestoNuevo; db.ReparacionesRepuestos.Add(nuevoRepaRepu); db.SaveChanges(); } } cargarDGV(reparacion.Id); } else { if (ucDGVTabla.selectedRow() != null) { int idRepuesto = Convert.ToInt32(ucDGVTabla.selectedRow().Cells["Id"].Value); frmModificarRepuesto frm = new frmModificarRepuesto(idRepuesto); frm.ShowDialog(); if (reparacion != null) { cargarDGV(reparacion.Id); } else { cargarDGV(null); } } } }
private void rbCantRepInMensual_CheckedChanged(object sender, EventArgs e) { if (rbCantRepInMensual.Checked) { using (MABEntities db = new MABEntities()) { // Revisar lo que el negro hiso en su .java chartCantRepIn.Series[0].Points.DataBind(db.reparacionesIngresadasMensuales().ToList(), "Reparaciones", "Mes", ""); } } }