private void dgvClientes_DoubleClick(object sender, EventArgs e) { if (dgvClientes.CurrentRow.Index != 1) { model.ID = Convert.ToInt32(dgvClientes.CurrentRow.Cells["ID"].Value); using (RentaCarEntities db = new RentaCarEntities()) { model = db.CLIENTE.Where(x => x.ID == model.ID).FirstOrDefault(); txtNombres.Text = model.NOMBRES; txtApellidos.Text = model.APELLIDOS; txtCedula.Text = Convert.ToString(model.CEDULA); txtEmail.Text = model.EMAIL; txtTelefono.Text = model.TELEFONO; txtTarjetaCredito.Text = Convert.ToString(model.TARJETA_CREDITO); numericLimiteCredito.Value = model.LIMITE_CREDITO; cmbTipoCliente.SelectedValue = model.ID_TIPO_CLIENTE; cbEstado.Checked = Convert.ToBoolean(model.ESTADO); lblFechaHoy.Text = model.FECHA_CREACION.ToString(); } if (cbEstado.Checked == true) { button2.Text = "Desactivar"; } else { button2.Text = "Activar"; } btnCrear.Text = "Actualizar"; button2.Enabled = true; } }
private void btnCrear_Click(object sender, EventArgs e) { model.DESCRIPCION = textBox1.Text.Trim(); model.ESTADO = checkBox1.Checked; if (string.IsNullOrWhiteSpace(textBox1.Text)) { MessageBox.Show("Llene los campos"); } else { using (RentaCarEntities db = new RentaCarEntities()) { if (model.ID == 0) { db.TANDA.Add(model); MessageBox.Show("Tanda Agregada"); } else { db.Entry(model).State = EntityState.Modified; MessageBox.Show("Tanda modificada"); } db.SaveChanges(); } Limpiar(); getTandas(); } }
private void btnCrear_Click(object sender, EventArgs e) { if (cedulaValidate()) { model.NOMBRES = txtNombres.Text; model.APELLIDOS = txtApellidos.Text; model.CEDULA = txtCedula.Text; model.TELEFONO = txtTelefono.Text; model.EMAIL = txtEmail.Text; model.TARJETA_CREDITO = txtTarjetaCredito.Text; model.LIMITE_CREDITO = numericLimiteCredito.Value; model.ID_TIPO_CLIENTE = Convert.ToInt32(cmbTipoCliente.SelectedValue); model.ESTADO = Convert.ToBoolean(cbEstado.Checked); model.FECHA_CREACION = Convert.ToDateTime(lblFechaHoy.Text); using (RentaCarEntities db = new RentaCarEntities()) { if (model.ID == 0) { db.CLIENTE.Add(model); MessageBox.Show("Cliente agregado"); } else { db.Entry(model).State = EntityState.Modified; MessageBox.Show("Cliente actualizado"); } db.SaveChanges(); getClientes(); Limpiar(); } } }
private void btnCrear_Click(object sender, EventArgs e) { if (txtCombustible.Text != "") { model.NOMBRE = txtCombustible.Text.Trim(); model.ESTADO = cbEstado.Checked; using (RentaCarEntities db = new RentaCarEntities()) { if (model.ID == 0) { db.COMBUSTIBLE_VEHICULO.Add(model); MessageBox.Show("El combustible ha sido agregado"); } else { db.Entry(model).State = EntityState.Modified; MessageBox.Show("El combustible ha sido modificado"); } db.SaveChanges(); } Limpiar(); getCombustibles(); } else { MessageBox.Show("Rellene los campos"); } }
private void btnCrear_Click(object sender, EventArgs e) { if (cmbMarca.SelectedIndex != -1 || !string.IsNullOrWhiteSpace(txtModelo.Text)) { model.ID_MARCA_VEHICULO = int.Parse(cmbMarca.SelectedValue.ToString()); model.NOMBRE = txtModelo.Text; model.ESTADO = cbEstado.Checked; using (RentaCarEntities db = new RentaCarEntities()) { if (model.ID == 0) { db.MODELO_VEHICULO.Add(model); MessageBox.Show("Modelo de la marca agregado"); } else { db.Entry(model).State = EntityState.Modified; MessageBox.Show("Modelo de la marca modificado"); } db.SaveChanges(); } Limpiar(); getModelos(); } else { MessageBox.Show("Rellene los campos"); } }
private void btnCrear_Click(object sender, EventArgs e) { if (validarData()) { using (RentaCarEntities db = new RentaCarEntities()) { if (renta.ID > 0) { renta.ID_CLIENTE = Convert.ToInt32(cmbCliente.SelectedValue); renta.ID_VEHICULO = Convert.ToInt32(cmbVehiculo.SelectedValue); renta.FECHA_RENTA = dpRenta.Value; renta.FECHA_DEVOLUCION = dpDevolucion.Value; renta.CANTIDAD_DIAS = Convert.ToInt32(lblDias.Text); renta.MONTO_DIA = Convert.ToInt32(numericCostePorDia.Value); renta.DESCRIPCION = txtDescripcion.Text; renta.ESTADO = cbEstado.Checked; db.Entry(renta).State = EntityState.Modified; MessageBox.Show("Renta actualizada"); } else { //Inspección inspeccion.ID_VEHICULO = Convert.ToInt32(cmbVehiculo.SelectedValue); inspeccion.CODIGO = CodigoAleatorio(); inspeccion.ID_CANTIDAD_COMBUSTIBLE = Convert.ToInt32(cmbCantidadCombustible.SelectedValue); inspeccion.TIENE_RAYADURAS = rayaduras.Checked; inspeccion.TIENE_ROTURA_CRISTAL = cristalesRotos.Checked; inspeccion.TIENE_GATO = gato.Checked; inspeccion.FECHA_CREACION = DateTime.Now; inspeccion.GOMA_REPUESTO = gomaRepuesto.Checked; inspeccion.GOMA_DELANTERA_DERECHA = gomaDD.Checked; inspeccion.GOMA_DELANTERA_IZQUIERDA = gomaDI.Checked; inspeccion.GOMA_TRASERA_DERECHA = gomaTD.Checked; inspeccion.GOMA_TRASERA_IZQUIERDA = gomaTI.Checked; db.INSPECCION.Add(inspeccion); //Renta renta.ID_INSPECCION = inspeccion.ID; renta.ID_CLIENTE = Convert.ToInt32(cmbCliente.SelectedValue); renta.ID_EMPLEADO = empleado.ID; renta.ID_VEHICULO = Convert.ToInt32(cmbVehiculo.SelectedValue); renta.FECHA_RENTA = dpRenta.Value; renta.FECHA_DEVOLUCION = dpDevolucion.Value; renta.FECHA_CREACION = DateTime.Now; renta.CANTIDAD_DIAS = Convert.ToInt32(lblDias.Text); renta.MONTO_DIA = Convert.ToDecimal(numericCostePorDia.Value); renta.DESCRIPCION = txtDescripcion.Text; renta.CODIGO = CodigoAleatorio(); renta.ESTADO = false; db.RENTA.Add(renta); MessageBox.Show("Renta agregada"); } db.SaveChanges(); Limpiar(); getRentas(); } } }
private void comboBoxes() { using (RentaCarEntities db = new RentaCarEntities()) { //Cantidad combustible cmbCantidadCombustible.DataSource = db.CANTIDAD_COMBUSTIBLE.ToList(); cmbCantidadCombustible.DisplayMember = "DESCRIPCION"; cmbCantidadCombustible.ValueMember = "ID"; //Cliente cmbCliente.DataSource = db.CLIENTE.Where(x => x.ESTADO == true).Select(x => new { x.ID, NOMBRE = x.NOMBRES + " " + x.APELLIDOS }).ToList(); cmbCliente.DisplayMember = "NOMBRE"; cmbCliente.ValueMember = "ID"; //Vehiculo cmbVehiculo.DataSource = db.VEHICULO.Where(x => x.ESTADO == true).Select(x => new { x.ID, NOMBRE = x.MODELO_VEHICULO.MARCA_VEHICULO.NOMBRE + " - " + x.MODELO_VEHICULO.NOMBRE }).ToList(); cmbVehiculo.DisplayMember = "NOMBRE"; cmbVehiculo.ValueMember = "ID"; } }
private void getTipoCliente() { using (RentaCarEntities db = new RentaCarEntities()) { cmbTipoCliente.DataSource = db.TIPO_CLIENTE.ToList(); cmbTipoCliente.DisplayMember = "DESCRIPCION"; cmbTipoCliente.ValueMember = "ID"; } }
private void getMarcaVehiculos() { using (RentaCarEntities db = new RentaCarEntities()) { cmbMarca.DataSource = db.MARCA_VEHICULO.Where(x => x.ESTADO == true).ToList(); cmbMarca.DisplayMember = "NOMBRE"; cmbMarca.ValueMember = "ID"; } }
private void getTipoClientes() { dgvTiposClientes.AutoGenerateColumns = false; using (RentaCarEntities db = new RentaCarEntities()) { var data = db.TIPO_CLIENTE.Select(x => new { x.ID, x.DESCRIPCION }).ToList(); dgvTiposClientes.DataSource = data; } }
private void getCantidades() { dgwCantidadCombustible.AutoGenerateColumns = false; using (RentaCarEntities db = new RentaCarEntities()) { var data = db.CANTIDAD_COMBUSTIBLE.Select(x => new { x.ID, x.DESCRIPCION, }).ToList(); dgwCantidadCombustible.DataSource = data; } }
private void getTiposEmpleados() { dgvTipoEmpleado.AutoGenerateColumns = false; using (RentaCarEntities db = new RentaCarEntities()) { var data = db.TIPO_EMPLEADO.Select(x => new { x.ID, x.DESCRIPCION }).ToList(); dgvTipoEmpleado.DataSource = data; } }
private void dgvTiposClientes_DoubleClick(object sender, EventArgs e) { if (dgvTiposClientes.CurrentRow.Index != -1) { model.ID = Convert.ToInt32(dgvTiposClientes.CurrentRow.Cells["ID"].Value); using (RentaCarEntities db = new RentaCarEntities()) { model = db.TIPO_CLIENTE.Where(x => x.ID == model.ID).FirstOrDefault(); txtTipoCliente.Text = model.DESCRIPCION; } btnCrear.Text = "Actualizar"; btnBorrar.Enabled = true; } }
private void dgwCantidadCombustible_DoubleClick(object sender, EventArgs e) { if (dgwCantidadCombustible.CurrentRow.Index != -1) { model.ID = Convert.ToInt32(dgwCantidadCombustible.CurrentRow.Cells["ID"].Value); using (RentaCarEntities db = new RentaCarEntities()) { model = db.CANTIDAD_COMBUSTIBLE.Where(x => x.ID == model.ID).FirstOrDefault(); txtCantidadCombustible.Text = model.DESCRIPCION; } btnCrear.Text = "Actualizar"; btnBorrar.Enabled = true; } }
private void getCombustibles() { dgwCombustible.AutoGenerateColumns = false; using (RentaCarEntities db = new RentaCarEntities()) { var data = db.COMBUSTIBLE_VEHICULO.Select(x => new { x.ID, x.NOMBRE, ESTADO = x.ESTADO == true ? "Disponible" : "No disponible" }).ToList(); dgwCombustible.DataSource = data; } }
public ActionResult Refinar(BuscadorPrincipal model) { RentaCarEntities db = new RentaCarEntities(); if (Session["fechas"] == null) { Session.Add("fechas", model); } var lista = db.Vehiculo.ToList(); return(View(lista)); }
private void getTandas() { dataGridView1.AutoGenerateColumns = false; using (RentaCarEntities db = new RentaCarEntities()) { var data = db.TANDA.Select(x => new { x.ID, x.DESCRIPCION, ESTADO = x.ESTADO == true ? "Disponible" : "No disponible" }).ToList(); dataGridView1.DataSource = data; } }
private void getModelos() { dgwModeloVehiculo.AutoGenerateColumns = false; using (RentaCarEntities db = new RentaCarEntities()) { var data = db.MODELO_VEHICULO.Select(x => new { x.ID, MARCA = x.MARCA_VEHICULO.NOMBRE, x.NOMBRE, ESTADO = x.ESTADO == true ? "Disponible" : "No disponible" }).ToList(); dgwModeloVehiculo.DataSource = data; } }
private void btnExportar_Click(object sender, EventArgs e) { using (RentaCarEntities db = new RentaCarEntities()) { var items = db.RENTA.ToList(); var file = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @"Reportes\\ReportesRenta.cshtml"); var html = Engine.Razor.RunCompile(file, Guid.NewGuid().ToString(), null, items, null); var htmlToPDF = new NReco.PdfGenerator.HtmlToPdfConverter(); SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.FileName = "Rentas"; saveFileDialog.DefaultExt = "pdf"; saveFileDialog.ShowDialog(); htmlToPDF.GeneratePdf(html, null, saveFileDialog.FileName + ".pdf"); } }
private void dgwCombustible_DoubleClick(object sender, EventArgs e) { if (dgwCombustible.CurrentRow.Index != -1) { model.ID = Convert.ToInt32(dgwCombustible.CurrentRow.Cells["ID"].Value); using (RentaCarEntities db = new RentaCarEntities()) { model = db.COMBUSTIBLE_VEHICULO.Where(x => x.ID == model.ID).FirstOrDefault(); txtCombustible.Text = model.NOMBRE; cbEstado.Checked = Convert.ToBoolean(model.ESTADO); } btnCrear.Text = "Actualizar"; btnBorrar.Enabled = true; } }
private void dataGridView1_DoubleClick(object sender, EventArgs e) { if (dataGridView1.CurrentRow.Index != -1) { model.ID = Convert.ToInt32(dataGridView1.CurrentRow.Cells["ID"].Value); using (RentaCarEntities db = new RentaCarEntities()) { model = db.TANDA.Where(x => x.ID == model.ID).FirstOrDefault(); textBox1.Text = model.DESCRIPCION; checkBox1.Checked = Convert.ToBoolean(model.ESTADO); } btnCrear.Text = "Actualizar"; btnBorrar.Enabled = true; } }
private void dgwModeloVehiculo_DoubleClick(object sender, EventArgs e) { if (dgwModeloVehiculo.CurrentRow.Index != -1) { model.ID = Convert.ToInt32(dgwModeloVehiculo.CurrentRow.Cells["ID"].Value); using (RentaCarEntities db = new RentaCarEntities()) { model = db.MODELO_VEHICULO.Where(x => x.ID == model.ID).FirstOrDefault(); cmbMarca.SelectedValue = Convert.ToInt32(model.ID_MARCA_VEHICULO); txtModelo.Text = model.NOMBRE; cbEstado.Checked = Convert.ToBoolean(model.ESTADO); } btnCrear.Text = "Actualizar"; btnBorrar.Enabled = true; } }
private void btnBorrar_Click(object sender, EventArgs e) { string Preg = (renta.ESTADO == true) ? "Desea desactivar a esta Renta?" : "Desea activar a esta renta?"; if (MessageBox.Show(Preg, "Mensaje", MessageBoxButtons.YesNo) == DialogResult.Yes) { renta.ESTADO = !renta.ESTADO; using (RentaCarEntities db = new RentaCarEntities()) { db.Entry(renta).State = EntityState.Modified; db.SaveChanges(); } Limpiar(); getRentas(); } }
private void button2_Click(object sender, EventArgs e) { string Preg = (model.ESTADO == true) ? "Desea desactivar a este cliente?" : "Desea activar a este cliente?"; if (MessageBox.Show(Preg, "Mensaje", MessageBoxButtons.YesNo) == DialogResult.Yes) { model.ESTADO = !model.ESTADO; using (RentaCarEntities db = new RentaCarEntities()) { db.Entry(model).State = EntityState.Modified; MessageBox.Show("Estado modificado"); db.SaveChanges(); } Limpiar(); getClientes(); } }
private void getRentas() { dgvRenta.AutoGenerateColumns = false; using (RentaCarEntities db = new RentaCarEntities()) { var data = db.RENTA.Select(x => new { x.ID, x.ID_INSPECCION, VEHICULO = x.VEHICULO.MODELO_VEHICULO.MARCA_VEHICULO.NOMBRE + " - " + x.VEHICULO.MODELO_VEHICULO.NOMBRE, CLIENTE = x.CLIENTE.NOMBRES + " " + x.CLIENTE.APELLIDOS, EMPLEADO = x.EMPLEADO.NOMBRES + " " + x.EMPLEADO.APELLIDOS, x.CODIGO, ESTADO = x.ESTADO == true ? "Activo" : "Inactivo" }).ToList(); dgvRenta.DataSource = data; } }
private void btnCrear_Click(object sender, EventArgs e) { model.DESCRIPCION = txtCantidadCombustible.Text; using (RentaCarEntities db = new RentaCarEntities()) { if (model.ID == 0) { db.CANTIDAD_COMBUSTIBLE.Add(model); } else { db.Entry(model).State = EntityState.Modified; } db.SaveChanges(); getCantidades(); Limpiar(); } }
private void btnBorrar_Click(object sender, EventArgs e) { if (MessageBox.Show("Desea borrar esta tanda?", "Mensaje", MessageBoxButtons.YesNo) == DialogResult.Yes) { using (RentaCarEntities db = new RentaCarEntities()) { var entry = db.Entry(model); if (entry.State == EntityState.Detached) { db.TANDA.Attach(model); } db.TANDA.Remove(model); db.SaveChanges(); Limpiar(); getTandas(); } } }
private bool validarData() { if (cmbVehiculo.SelectedIndex == -1 || cmbCliente.SelectedIndex == -1 || cmbCantidadCombustible.SelectedIndex == -1 || string.IsNullOrWhiteSpace(txtDescripcion.Text)) { MessageBox.Show("Debe llenar los campos"); return(false); } if (model.ID_INSPECCION != 0) { MessageBox.Show("Debe crear inspección"); return(false); } if (numericCostePorDia.Value == 0) { MessageBox.Show("El coste por día no puede ser igual a 0"); return(false); } if (renta.ID == 0) { using (RentaCarEntities db = new RentaCarEntities()) { int ID_VEHICULO = Convert.ToInt32(cmbVehiculo.SelectedValue); DateTime StartDate = dpRenta.Value; DateTime EndDate = dpDevolucion.Value; int VehicleIsRented = db.RENTA .Where(x => x.ID_VEHICULO == ID_VEHICULO && ( (StartDate >= x.FECHA_RENTA && StartDate <= x.FECHA_DEVOLUCION) || (EndDate >= x.FECHA_RENTA && EndDate <= x.FECHA_DEVOLUCION) ) ) .Count(); if (VehicleIsRented > 0) { MessageBox.Show("El vehiculo está rentado."); return(false); } } } return(true); }
private void btnBorrar_Click(object sender, EventArgs e) { if (MessageBox.Show("Desea borrar este modelo de vehículo?", "Mensaje", MessageBoxButtons.YesNo) == DialogResult.Yes) { using (RentaCarEntities db = new RentaCarEntities()) { var entry = db.Entry(model); if (entry.State == EntityState.Detached) { db.MODELO_VEHICULO.Attach(model); } db.MODELO_VEHICULO.Remove(model); db.SaveChanges(); MessageBox.Show("Modelo de vehículo eliminado"); getModelos(); Limpiar(); } } }
private bool cedulaValidate() { if (string.IsNullOrWhiteSpace(txtNombres.Text) || string.IsNullOrWhiteSpace(txtApellidos.Text) || string.IsNullOrWhiteSpace(txtEmail.Text) || string.IsNullOrWhiteSpace(txtCedula.Text) || string.IsNullOrWhiteSpace(txtTelefono.Text) || string.IsNullOrWhiteSpace(txtTarjetaCredito.Text) || cmbTipoCliente.SelectedIndex == -1 || numericLimiteCredito.Value == 0) { MessageBox.Show("Rellene todos los campos"); return(false); } if (txtTarjetaCredito.TextLength != 16) { MessageBox.Show("Por favor ingrese una tarjeta de crédito válida"); return(false); } if (txtTelefono.TextLength != 10) { MessageBox.Show("Por favor ingrese un teléfono válido"); return(false); } if (IsValidDrCedula(txtCedula.Text) == false || txtCedula.TextLength != 11) { MessageBox.Show("Por favor ingrese una cédula válida"); return(false); } if (model.ID == 0) { using (RentaCarEntities db = new RentaCarEntities()) { var cliente = db.CLIENTE.Where(x => x.CEDULA == txtCedula.Text).Count(); if (cliente > 0) { MessageBox.Show("Ya existe un cliente con esta cedula"); return(false); } } } return(true); }