private void btn_Eliminar_Click(object sender, EventArgs e) { if (txt_Nombre.Text == "") { MessageBox.Show("No hay un cliente seleccionado para eliminar"); this.Cliente_Load(); } else { try { Database.DataClassesDataContext cc = new Database.DataClassesDataContext(); int ClienteId = Convert.ToInt32(dgv_Clientes.CurrentRow.Cells[0].Value); Database.Cliente clientedelete = cc.Clientes.Single(w => w.Id == ClienteId); cc.Clientes.DeleteOnSubmit(clientedelete); cc.SubmitChanges(); MessageBox.Show("El Cliente ha sido eliminado!"); this.Cliente_Load(); } catch (Exception ex) { System.Console.WriteLine(ex.Message); MessageBox.Show("No se ha podido eliminar al cliente!"); this.Cliente_Load(); } } }
private void btn_Confirmar_Click(object sender, EventArgs e) { Validaciones.Clear(); Database.DataClassesDataContext cc = new Database.DataClassesDataContext(); if (ValidarCampos()) { switch (operacion) { case "agregar": try { Database.Cliente newcliente = new Database.Cliente(); newcliente.Nombre = txt_Nombre.Text.Trim(); newcliente.Apellido = txt_Apellido.Text.Trim(); newcliente.Direccion = txt_Domicilio.Text.Trim(); newcliente.Telefono = txt_Telefono.Text.Trim(); cc.Clientes.InsertOnSubmit(newcliente); cc.SubmitChanges(); MessageBox.Show("Nuevo cliente cargado!"); break; } catch (Exception ex) { System.Console.WriteLine(ex.Message); MessageBox.Show("No se pudo guardar el cliente ingresado!"); break; } case "modificar": try { int ClienteId = Convert.ToInt32(dgv_Clientes.CurrentRow.Cells[0].Value); var query = cc.Clientes.Where(w => w.Id == ClienteId).FirstOrDefault(); query.Nombre = txt_Nombre.Text.Trim(); query.Apellido = txt_Apellido.Text.Trim(); query.Direccion = txt_Domicilio.Text.Trim(); query.Telefono = txt_Telefono.Text.Trim(); cc.SubmitChanges(); MessageBox.Show("Cliente Actualizado!"); break; } catch (Exception ex) { System.Console.WriteLine(ex.Message); MessageBox.Show("No se pudo actualizar correctamente el cliente!"); break; } } this.Cliente_Load(); } }
public ActionResult Login(string usuario, string senha, string returnUrl) { Cliente cliente = new Database.Cliente(); if (ModelState.IsValid) { cliente = ValidaLogin(usuario, senha); if (cliente != null) { FormsAuthentication.SetAuthCookie(cliente.emailCliente, false); return(RedirectToLocal(returnUrl)); } else { cliente = new Database.Cliente(); ModelState.AddModelError("", "Email ou Senha inválidos"); } } return(View(cliente)); }
public int SetSolicitud(string data) { try { JObject o = JObject.Parse(data); var ctx = new Database.DB_InspeccionesEntities(); string motivo = (string)o["tipoNegocio"]; DateTime fechaCoordinacion = Convert.ToDateTime((string)o["fechaCoordinacion"]); string rutCliente = (string)o["rutCliente"].ToString().Replace(".", "").Replace(".", ""); string nombre = o["nombre"].ToString(); string apellidoPaterno = o["apellidoPaterno"].ToString(); string apellidoMaterno = o["apellidoMaterno"].ToString(); bool esEmpresa = Convert.ToBoolean(o["esEmpresa"]); string direccion = o["direccion"].ToString(); string telefono1 = o["telefono1"].ToString(); string telefono2 = o["telefono2"].ToString(); string email = o["Email"].ToString(); string contacto = o["contacto"].ToString(); int idUsuario = Convert.ToInt32(o["usuario"].ToString()); int comuna = Convert.ToInt32(o["comuna"]); JArray vehiculos = (JArray)o["vehiculos"]; var cliExiste = (from c in ctx.Cliente where c.Rut == rutCliente select c).FirstOrDefault(); Database.Cliente cliente = null; if (cliExiste != null) { //Se actualiza cliente = cliExiste; } else { cliente = new Database.Cliente() { Rut = rutCliente, Nombre = nombre, RazonSocial = nombre, ApellidoPaterno = apellidoPaterno, ApellidoMaterno = apellidoMaterno, Direccion = direccion, Comuna = comuna, Fono1 = telefono1, Fono2 = telefono2, Email = email, NombreContacto = contacto, Estado = 1 }; ctx.Cliente.Add(cliente); ctx.SaveChanges(); } var solicitud = new Database.Solicitud() { Cliente1 = cliente, Contacto = contacto, Corredor = 1, Estado = 1, FechaSolicitud = DateTime.Now, FechaFinalizacion = DateTime.Now, UsuarioSolicitud = idUsuario }; ctx.Solicitud.Add(solicitud); ctx.SaveChanges(); var usuario = (from u in ctx.Usuario where u.Id == idUsuario select u).FirstOrDefault(); foreach (var item in vehiculos) { int idUsuarioACargo = 0; string nombreSucursal = item["Sucursal"].ToString(); var sucursal = (from s in ctx.Sucursal where s.Nombre == nombreSucursal select s).FirstOrDefault(); //Si es inspector if (usuario.UsuarioSucursal.FirstOrDefault().Cargo == 1) { idUsuarioACargo = usuario.Id; } else { var InspSucursal = (from usuSuc in ctx.UsuarioSucursal where usuSuc.Sucursal == sucursal.Id select usuSuc).ToList(); if (InspSucursal.Count == 1) { idUsuarioACargo = InspSucursal[0].Usuario; } else { idUsuarioACargo = (from u in InspSucursal where u.Supervisor == 1 select u).FirstOrDefault().Usuario; } } var inspeccion = new Database.Inspeccion() { Sucursal = sucursal.Id, UsuarioAsociado = idUsuarioACargo, Estado = 1, FechaInspeccion = DateTime.Now, Patente = item["patente"].ToString(), Modelo = Convert.ToInt32(item["idModelo"]), Motivo = Convert.ToInt32(motivo), Solicitud1 = solicitud, TipoVehiculo = item["tipoVehiculo"].ToString(), UsuarioInspector = 1 }; ctx.Inspeccion.Add(inspeccion); ctx.SaveChanges(); } //TODO: Añadir log return solicitud.Id; } catch(Exception ex) { var mensaje = ex.InnerException.ToString(); //TODO: Añadir log. return 0; } }