static public void Agregar(Ccliente obj) { try { string cmdtxt = "INSERT INTO CLIENTES (id_cliente,id_persona) VALUES(" + obj.ID_CLIENTE + "," + obj.ID + ")"; cDatos.ActualizarDatos(cmdtxt); } catch { throw new ArgumentException("Error al cargar la persona"); } }
//HECHOS POR MARIO ********************************************************** public void EditarCliente(Ccliente cliente) { int telefono; int codigo_area; SqlDataReader read; SqlDataReader read2; SqlDataReader read3; try { codigo_area = int.Parse(cliente.Codigo_Area); telefono = int.Parse(cliente.Telefono); ValidacionUsuarioCorreoExiste(cliente.Correo); // validamos que el usuario exista //UPDATE USUARIO string query = "UPDATE U SET U.usu_nombre = '" + cliente.Nombre + "', U.usu_apellido = '" + cliente.Apellido + "' FROM dbo.Usuario AS U WHERE U.usu_correo='" + cliente.Correo + "';"; read = Executer(query); read.Close(); //UPDATE PERFIL string query2 = "UPDATE P SET P.per_genero = '" + cliente.Genero + "' FROM dbo.Perfil AS P INNER JOIN dbo.Usuario AS U ON U.usu_id = P.per_fk_usuario WHERE U.usu_correo='" + cliente.Correo + "';"; read2 = Executer(query2); read2.Close(); //UPDATE PERFIL string query3 = "UPDATE T SET T.tel_cod_area = " + codigo_area + ", T.tel_num_telefonico = " + telefono + " FROM dbo.Telefono AS T INNER JOIN dbo.Perfil AS P ON P.per_fk_telefono = T.tel_id INNER JOIN dbo.Usuario AS U ON U.usu_id = P.per_fk_usuario WHERE U.usu_correo = '" + cliente.Correo + "';"; read3 = Executer(query3); read3.Close(); } catch (ExisteUsuarioCorreoException e) { System.Diagnostics.Debug.WriteLine("Holisss---> CATCH NO EXISTE USUARIO"); throw e; } catch (SqlException e) { System.Diagnostics.Debug.WriteLine("Holisss---> CATCH SQL EXCEPTION"); System.Diagnostics.Debug.WriteLine("Error----> " + e.Message); System.Diagnostics.Debug.WriteLine("Traza----> " + e.StackTrace); throw e; } catch (System.Exception mensaje) { throw new System.Exception(mensaje.Message); } CloseConnection(); }
public Ccliente ValidacionLogin(Ccliente cliente) { try { ValidacionUsuarioCorreoExiste(cliente.Correo); string query = "SELECT usu_id, usu_nombre, usu_apellido, usu_correo, usu_contraseña FROM dbo.Usuario WHERE usu_correo='" + cliente.Correo + "';"; SqlDataReader read = Executer(query); string clave_descifrada = string.Empty; if (read.HasRows) { while (read.Read()) { cliente.Id = read.GetInt32(0); cliente.Nombre = read.GetString(1); cliente.Apellido = read.GetString(2); cliente.Correo = read.GetString(3); clave_descifrada = Seguridad.Descifrar(read.GetString(4)); } if (!clave_descifrada.Equals(cliente.Clave0)) { throw new ClavesDiferentesException(); } } } catch (ExisteUsuarioCorreoException e) { throw new ExisteUsuarioCorreoException(e); } catch (ClavesDiferentesException e) { throw new ClavesDiferentesException(e); } catch (SqlException S) { throw S; } catch (System.Exception mensaje) { throw new System.Exception(mensaje.Message); } CloseConnection(); return(cliente); }
private void btn_Eliminar_Click(object sender, EventArgs e) { try { objCliente = (Ccliente)dgrid_clientes.CurrentRow.DataBoundItem; if (admCuentas.TieneCreditosODebitos(objCliente.DevolverCuentaCorriente())) { Frm_confirmacion frm = new Frm_confirmacion("El cliente tiene creditos o debitos cargados,y no se puede borrar por la integridad de datos.\n Quiere darle de baja?", "Registros del cliente", "No", "Si"); frm.ShowDialog(); if (frm.RESPUESTA == "Si") { admClientes.DarBaja(objCliente); ActualizarGrilla(); Frm_cuenta_corriente form = Frm_ABM_cuentas_corrientes.CuentaAbierta(objCliente); if (form != null) { form.Close(); } Frm_ABM_clientes_Activated(sender, e); } } else { Frm_confirmacion frm = new Frm_confirmacion("Esta seguro que quiere eliminar el registro de " + objCliente.Nombre + " ?", "Eliminación del cliente", "No", "Si"); frm.ShowDialog(); if (frm.RESPUESTA == "Si") { admClientes.Eliminar(objCliente); ActualizarGrilla(); Frm_cuenta_corriente form = Frm_ABM_cuentas_corrientes.CuentaAbierta(objCliente); if (form != null) { form.Close(); } Frm_ABM_clientes_Activated(sender, e); } } objCliente = null; } catch (Exception ex) { Frm_confirmacion frm = new Frm_confirmacion(ex.Message, "Bueno, esto es embarazoso. Pero lo solucionaremos :)", "Aceptar"); frm.ShowDialog(); } }
private void btn_Modificar_Click(object sender, EventArgs e) { Cpersona oPersona; if (dgrid_personas.SelectedRows.Count > 0) { oPersona = (Cpersona)dgrid_personas.CurrentRow.DataBoundItem; Frm_cuenta_corriente frm; frm = CuentaAbierta(oPersona); if (frm != null) { frm.Focus(); } else { if (tag == 1) { Ccliente objcliente = (Ccliente)oPersona; adm.CargarAltasDebitosyCreditos(objcliente.DevolverCuentaCorriente()); adm.CargarCreditosdeDebitos(objcliente.DevolverCuentaCorriente()); frm = new Frm_cuenta_corriente(objcliente, ObjCajaDiaria); frm.Show(); } else if (tag == 2) { Cproveedor objproveedor = (Cproveedor)oPersona; adm.CargarAltasDebitosyCreditos(objproveedor.DevolverCuentaCorriente()); adm.CargarRecibosDePagos(objproveedor.DevolverCuentaCorriente()); frm = new Frm_cuenta_corriente(objproveedor, ObjCajaDiaria); frm.Show(); } else { Cusuario objusuario = (Cusuario)oPersona; adm.CargarAltasDebitosyCreditos(objusuario.DevolverCuentaCorriente()); adm.CargarCreditosdeDebitos(objusuario.DevolverCuentaCorriente()); frm = new Frm_cuenta_corriente(objusuario, ObjCajaDiaria); frm.Show(); } FormulariosAbiertos.Add(frm); } } }
private void Guardar() { if (objCliente == null) { Clocalidad objLoca = (Clocalidad)cb_localidades.SelectedItem; objCliente = new Ccliente(txt_nombre.Text, txt_direccion.Text, txt_tel.Text, txt_cel.Text, txt_mail.Text, objLoca); admClientes.Agregar(objCliente, true); } else { objCliente.Nombre = txt_nombre.Text; objCliente.Cel = txt_cel.Text; objCliente.Domicilio = txt_direccion.Text; objCliente.Tel = txt_tel.Text; objCliente.LOCALIDAD((Clocalidad)cb_localidades.SelectedItem); objCliente.Email = txt_mail.Text; admClientes.Modificar(objCliente); } }
public Ccliente ObtenerCliente(Ccliente cliente) { SqlDataReader read; try { ValidacionUsuarioCorreoExiste(cliente.Correo); // validamos que el usuario exista string query = "SELECT U.usu_nombre, U.usu_apellido, P.per_genero, T.tel_cod_area, T.tel_num_telefonico FROM dbo.Usuario U, dbo.Perfil P, dbo.Telefono T WHERE U.usu_correo='" + cliente.Correo + "' and U.usu_id = P.per_fk_usuario and P.per_fk_telefono = T.tel_id;"; read = Executer(query); if (!read.HasRows) { throw new ExisteUsuarioCorreoException(); } else { while (read.Read()) { cliente.Nombre = read.GetString(0); cliente.Apellido = read.GetString(1); cliente.Genero = read.GetString(2); cliente.Codigo_Area = read.GetInt32(3).ToString(); cliente.Telefono = read.GetInt32(4).ToString(); } } } catch (ExisteUsuarioCorreoException e) { throw e; } catch (SqlException e) { throw e; } catch (System.Exception mensaje) { throw new System.Exception(mensaje.Message); } CloseConnection(); return(cliente); }
//METODOS ABM public void Agregar(Ccliente obj, bool cargarpersona) { try { if (cargarpersona) { obj.ID = ctrlpersona.Agregar(obj); cargarpersona = false; } ultimo++; obj.ID_CLIENTE = ultimo; Cdatos_clientes.Agregar(obj); lista.Add(obj); Actualizar = true; } catch { Agregar(obj, cargarpersona); } }
private void btn_GuardarMas_Click(object sender, EventArgs e) { try { Guardar(); ActualizarGrilla(); Frm_ABM_clientes_Activated(sender, e); txt_cel.Clear(); txt_direccion.Clear(); txt_mail.Clear(); txt_tel.Clear(); txt_nombre.Clear(); objCliente = null; txt_nombre.Focus(); } catch (Exception ex) { Frm_confirmacion frm = new Frm_confirmacion(ex.Message, "Bueno, esto es embarazoso. Pero lo solucionaremos :)", "Aceptar"); frm.ShowDialog(); } }
//METODOS LLAMADA A LA BD public void CargarAltas() { Ctrl_localidades admlocalidades = Ctrl_localidades.ClaseActiva(); DataTable DT = Cdatos_clientes.Devolver(true); Clocalidad localidad; Ccliente ocliente; foreach (DataRow DR in DT.Rows) { localidad = admlocalidades.BuscarPorID(Convert.ToInt32(DR[7])); ocliente = new Ccliente(Convert.ToInt32(DR[0]), Convert.ToInt32(DR[1]), DR[2].ToString(), DR[5].ToString(), DR[3].ToString(), DR[4].ToString(), DR[6].ToString(), localidad); lista.Add(ocliente); ocliente.AgregarCuentaCorriente(new Ccuenta_corriente(Convert.ToInt32(DR[8]), Convert.ToDecimal(DR[9]))); } if (DT.Rows.Count == 0) { ultimo = 0; } else { ultimo = Convert.ToInt32(DT.Rows[0][0]); } }
static public Ccliente Devolver(int id) { try { String cmdtext = "SELECT id_cliente,P.id_persona,C.nombre,telefono,celular,direccion,mail,L.id_localidad,L.nombre FROM CLIENTES P inner join PERSONAS C on C.id_persona=P.id_persona inner join LOCALIDADES L on L.id_localidad= C.id_localidad where id_cliente=" + id; DataTable DT = cDatos.DevolverDatos(cmdtext); if (DT.Rows.Count == 0) { return(null); } else { DataRow DR = DT.Rows[0]; Clocalidad localidad = new Clocalidad(Convert.ToInt32(DR[7]), DR[8].ToString()); Ccliente obj = new Ccliente(Convert.ToInt32(DR[0]), Convert.ToInt32(DR[1]), DR[2].ToString(), DR[6].ToString(), DR[3].ToString(), DR[4].ToString(), DR[5].ToString(), localidad); return(obj); } } catch { throw new ArgumentException("Error al devolver cliente"); } }
public void DarAlta(Ccliente obj) { Cdatos_personas.BajaoAlta(obj, true); lista.Add(obj); listabajas.Remove(obj); }
public void Modificar(Ccliente obj) { ctrlpersona.Modificar(obj); Actualizar = true; }
private void btn_Guardar_Click(object sender, EventArgs e) { try{ Oconcepto = (Cconcepto)cb_concepto.SelectedItem; if (Gasto) { Cgasto obj = new Cgasto(Oconcepto, Convert.ToDecimal(txt_importe.Text), (Cforma_pago)cb_FormasPagos.SelectedValue); if (Ooperacion == null) { if (obj.FORMAPAGO().Altera_caja) { if (ObjCajaDiaria.Efec_final >= obj.Importe) { adm.AgregarOperacion(obj, ObjCajaDiaria); } else { throw new Exception("No tiene suficiente plata en caja como para pagar ese gasto"); } } else { adm.AgregarOperacion(obj, ObjCajaDiaria); } } else { if (obj.FORMAPAGO().Altera_caja) { if (ObjCajaDiaria.Efec_final < (obj.Importe - Ooperacion.Importe)) { throw new Exception("No tiene suficiente plata en caja como para pagar ese gasto"); } } adm.ModificarOperacion((Cgasto)Ooperacion, obj, ObjCajaDiaria); } if (cb_registrar.Checked) { Ctrl_cuentas_corrientes admCuentas = Ctrl_cuentas_corrientes.ClaseActiva(); Cpago_credito objcu = new Cpago_credito(obj.Concepto, obj.Importe, DateTime.Today, true); Cproveedor objproveedor = ((Cproveedor)Opersona); admCuentas.CargarAltasDebitosyCreditos(objproveedor.DevolverCuentaCorriente()); admCuentas.AgregarOperacion(objcu, objproveedor.DevolverCuentaCorriente()); admCuentas.AgregarReferiaEntreOperacion(objcu, obj); } else { if (Opersona != null) { Cgasto ogasto = (Cgasto)Ooperacion; if (obj.Importe != ogasto.Credito().Importe) { Ccuenta_corriente cuenta = Opersona.DevolverCuentaCorriente(); ogasto.Credito().Importe = obj.Importe; cuenta.ModificarCredito(cuenta.BuscarCredito(ogasto.Credito().Numero), obj.Importe); Ctrl_cuentas_corrientes admCuentas = Ctrl_cuentas_corrientes.ClaseActiva(); admCuentas.ModificarOperacion(ogasto.Credito()); } } } } else { Ccobro obj = new Ccobro(Oconcepto, Convert.ToDecimal(txt_importe.Text), (Cforma_pago)cb_FormasPagos.SelectedValue); if (Ooperacion == null) { adm.AgregarOperacion(obj, ObjCajaDiaria); } else { adm.ModificarOperacion((Ccobro)Ooperacion, obj, ObjCajaDiaria); } if (cb_registrar.Checked) { Ctrl_cuentas_corrientes admCuentas = Ctrl_cuentas_corrientes.ClaseActiva(); Crecibo_debito objc = new Crecibo_debito(obj.Concepto, obj.Importe, DateTime.Today, true); Ccliente objcliente = ((Ccliente)Opersona); admCuentas.CargarAltasDebitosyCreditos(objcliente.DevolverCuentaCorriente()); admCuentas.AgregarOperacion(objc, objcliente.DevolverCuentaCorriente()); admCuentas.AgregarReferiaEntreOperacion(objc, obj); } else { if (Opersona != null) { Ccobro ocobro = (Ccobro)Ooperacion; if (obj.Importe != ocobro.Debito().Importe) { Ccuenta_corriente cuenta = Opersona.DevolverCuentaCorriente(); ocobro.Debito().Importe = obj.Importe; cuenta.ModificarDebito(cuenta.BuscarDebito(ocobro.Debito().Numero), obj.Importe); Ctrl_cuentas_corrientes admCuentas = Ctrl_cuentas_corrientes.ClaseActiva(); admCuentas.ModificarOperacion(ocobro.Debito()); } } } } Close(); } catch (Exception ex) { Frm_confirmacion frm = new Frm_confirmacion(ex.Message, "Error", "Aceptar"); frm.ShowDialog(); } }
static public void Eliminar(Ccliente obj) { string cmdtext = "DELETE FROM CLIENTES WHERE id_cliente=" + obj.ID_CLIENTE; cDatos.ActualizarDatos(cmdtext); }
public void ValidacionRegistroCliente(Ccliente cliente) { try { ValidacionUsuarioCorreo(cliente.Correo); string clave = Seguridad.Cifrar(cliente.Clave0); string query = @"INSERT INTO dbo.Usuario(usu_nombre, usu_apellido, usu_correo, usu_contraseña, usu_fk_rol, usu_fechaCreacion, usu_activo)VALUES('" + cliente.Nombre + @"','" + cliente.Apellido + @"','" + cliente.Correo + @"','" + clave + @"','2','" + DateTime.Now.ToString("yyyy-MM-dd") + @"','Activo');"; //query.CommandText = @"INSERT INTO dbo.Usuario VALUES ('" + cliente.Nombre + @"','" + cliente.Apellido + @"','" + cliente.Correo + @"','" + cliente.Clave0 + @"',2," + System.DateTime.Now.ToString("dd/MM/yyyy") + @",'Activo');"; //query.CommandText = @"INSERT INTO dbo.Usuario(usu_nombre, usu_apellido, usu_correo, usu_contraseña, usu_fk_rol, usu_id, usu_fechaCreacion, usu_activo)VALUES('"+cliente.Nombre+@"','"+cliente.Apellido+@"','"+cliente.Correo+@"','"+clave+@"','2',NEXT VALUE FOR usu_id,convert(date,"+@"'"+System.DateTime.Now.ToString("dd/MM/yyyy")+@"'"+"),'Activo');"; //query.CommandText = @"INSERT INTO dbo.Usuario(usu_nombre, usu_apellido, usu_correo, usu_contraseña, usu_fk_rol, usu_id, usu_fechaCreacion, usu_activo)VALUES('"+cliente.Nombre+@"','"+cliente.Apellido+@"','"+cliente.Correo+@"','"+clave+@"','2',NEXT VALUE FOR usu_id,'"+ DateTime.Now.ToString("yyyy-MM-dd") + @"','Activo');"; SqlDataReader read = Executer(query); read.Close(); string query1 = "SELECT usu_id FROM dbo.Usuario Where usu_correo='" + cliente.Correo + "';"; SqlDataReader read1 = Executer(query1); int id_usuario = 0; if (read1.HasRows) { while (read1.Read()) { id_usuario = read1.GetInt32(0); } } read1.Close(); // insertar en Telefono SqlCommand query5 = this.Conexion.CreateCommand(); query5.CommandText = @"INSERT INTO dbo.Telefono(tel_cod_pais, tel_cod_area, tel_num_telefonico)VALUES(0, 0, 0);"; System.Diagnostics.Debug.WriteLine(query5.CommandText); SqlDataReader read5 = query5.ExecuteReader(); read5.Close(); // Buscar id telefono string query7 = "SELECT MAX(tel_id) FROM dbo.Telefono;"; SqlDataReader read7 = Executer(query7); int id_telefono = 0; if (read7.HasRows) { while (read7.Read()) { id_telefono = read7.GetInt32(0); } } read7.Close(); // insertar en Perfil string query6 = @"INSERT INTO dbo.Perfil(per_fk_usuario, per_genero, per_fecha_nacimiento, per_fk_telefono, per_fk_lugar)VALUES(" + id_usuario + @", 'Hombre', '2016-12-14', " + id_telefono + @", 12);"; SqlDataReader read6 = Executer(query6); read6.Close(); // seleccionar ID Perfil string query8 = "SELECT MAX(per_id) FROM dbo.Perfil;"; SqlDataReader read8 = Executer(query8); int id_perfil = 0; if (read8.HasRows) { while (read8.Read()) { id_perfil = read8.GetInt32(0); } } read8.Close(); string query2 = @"INSERT INTO dbo.Pregunta_Respuesta (pr_value,pr_respuesta,fk_perfil) VALUES (" + cliente.PreguntaRespuesta0.Pregunta + @",'" + cliente.PreguntaRespuesta0.Respuesta + @"'," + id_perfil + @");"; SqlDataReader read2 = Executer(query2); read2.Close(); string query3 = @"INSERT INTO dbo.Pregunta_Respuesta (pr_value,pr_respuesta,fk_perfil) VALUES (" + cliente.PreguntaRespuesta1.Pregunta + @",'" + cliente.PreguntaRespuesta1.Respuesta + @"'," + id_perfil + @");"; SqlDataReader read3 = Executer(query3); read3.Close(); string query4 = @"INSERT INTO dbo.Pregunta_Respuesta (pr_value,pr_respuesta,fk_perfil) VALUES (" + cliente.PreguntaRespuesta2.Pregunta + @",'" + cliente.PreguntaRespuesta2.Respuesta + @"'," + id_perfil + @");"; SqlDataReader read4 = Executer(query4); read4.Close(); } catch (ExisteUsuarioCorreoException e) { System.Diagnostics.Debug.WriteLine(e.Message); throw new ExisteUsuarioCorreoException(); } catch (SqlException e) { System.Diagnostics.Debug.WriteLine(e.Message); throw e; } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); throw new Exception(e.Message); } CloseConnection(); }