public string eliminar(int idCliente) { DClientes obj = new DClientes(); obj.id_Cliente = idCliente; return obj.Eliminar(obj); }
public static DataTable Buscar(String parNombre_Cliente_Buscado) { DClientes clientes = new DClientes(); clientes.Nombre_Cliente_Buscado = parNombre_Cliente_Buscado; return clientes.Buscar(clientes); }
public static String Eliminar(int parId_Cliente) { DClientes clientes = new DClientes(); clientes.Id_Cliente = parId_Cliente; return clientes.Eliminar(clientes); }
public DataTable BuscarNum_Documento(DClientes Clientes) { DataTable DtResultado = new DataTable("Clientes"); SqlConnection SqlCon = new SqlConnection(); try { SqlCon.ConnectionString = Conexion.Cn; SqlCommand SqlCmd = new SqlCommand(); SqlCmd.Connection = SqlCon; SqlCmd.CommandText = "spbuscar_cliente_num_documento"; SqlCmd.CommandType = CommandType.StoredProcedure; SqlParameter ParTextoBuscar = new SqlParameter(); ParTextoBuscar.ParameterName = "@textobuscar"; ParTextoBuscar.SqlDbType = SqlDbType.VarChar; ParTextoBuscar.Size = 50; ParTextoBuscar.Value = Clientes.CTextoBuscar; SqlCmd.Parameters.Add(ParTextoBuscar); SqlDataAdapter SqlDat = new SqlDataAdapter(SqlCmd); SqlDat.Fill(DtResultado); } catch (Exception ex) { DtResultado = null; } return(DtResultado); }
public string modificar(int idCliente, string nombreCliente, string apellido1, string apellido2, DateTime nacimiento, int estado) { DClientes obj = new DClientes(); obj.id_Cliente = idCliente; obj.NombreCliente = nombreCliente; obj.Apellido1 = apellido1; obj.Apellido2 = apellido2; obj.Fecha = nacimiento; obj.Estado = estado; return obj.Editar(obj); }
public string Eliminar(DClientes parClientes) { string Respuesta = ""; SqlConnection SqlConexion = new SqlConnection(); try { SqlConexion.ConnectionString = DConexion.CnBDEmpresa; SqlConexion.Open(); SqlCommand SqlComando = new SqlCommand(); SqlComando.Connection = SqlConexion; SqlComando.CommandText = "Ventas.EliminarCliente"; SqlComando.CommandType = CommandType.StoredProcedure; SqlParameter ParId_Cliente = new SqlParameter(); ParId_Cliente.ParameterName = "@Id_Cliente"; ParId_Cliente.SqlDbType = SqlDbType.Int; ParId_Cliente.Value = parClientes.Id_Cliente; SqlComando.Parameters.Add(ParId_Cliente); SqlComando.ExecuteNonQuery(); Respuesta = "Y"; } catch (SqlException ex) { if (ex.Number == 547) { Respuesta = "No puedes eliminar un cliente que cuenta con uno o varios Pedidos. Debes eliminar o actualizar sus Pedidos antes de eliminar el cliente."; } else { Respuesta = "Error al intentar ejecutar el procedimiento almacenado Ventas.EliminarCliente. " + ex.Message; } } finally { if (SqlConexion.State == ConnectionState.Open) { SqlConexion.Close(); } } return(Respuesta); }
//public static String Insertar(String parNombre_Cliente, String parNombre_Contacto, // String parDireccion, String parCiudad, String parRegion, String parPais, // String parTelefono, String parFax, String parEmail) //{ // DClientes clientes = new DClientes(); // clientes.Nombre_Cliente = parNombre_Cliente; // clientes.Apellido_Cliente = parNombre_Contacto; // clientes.Telefono = parTelefono; // clientes.Email = parEmail; // return clientes.Insertar(clientes); //} public static String Insertar(String nombre, String apellido, long cuil, String razonSocial, long cuit, String telFijo, String telMovil, String email, int tipo, List<string> dir) { DClientes cliente = new DClientes(); cliente.Nombre = nombre; cliente.Apellido = apellido; cliente.Cuil = cuil; cliente.Razon_Social = razonSocial; cliente.Cuit = cuit; cliente.Telefono_Fijo = telFijo; cliente.Telefono_Movil = telMovil; cliente.Email = email; cliente.Tipo_Cliente = tipo; return cliente.Insertar(cliente,dir); }
public static String Insertar(String parNombre_Cliente, String parNombre_Contacto, String parDireccion, String parCiudad, String parRegion, String parPais, String parTelefono, String parFax, String parEmail) { DClientes clientes = new DClientes(); clientes.Nombre_Cliente = parNombre_Cliente; clientes.Nombre_Contacto = parNombre_Contacto; clientes.Direccion = parDireccion; clientes.Ciudad = parCiudad; clientes.Region = parRegion; clientes.Pais = parPais; clientes.Telefono = parTelefono; clientes.Fax = parFax; clientes.Email = parEmail; return clientes.Insertar(clientes); }
public DClientes BuscarPorId(int id) { DClientes cliente = new DClientes(); SqlConnection SqlConexion = new SqlConnection(); try { SqlConexion.ConnectionString = DConexion.CnBDEmpresa; SqlConexion.Open(); SqlCommand SqlComando = new SqlCommand(); SqlComando.Connection = SqlConexion; SqlComando.CommandText = "select * from Clientes where Id_Cliente =" + id; SqlComando.CommandType = CommandType.Text; SqlDataReader reader = SqlComando.ExecuteReader(); foreach (DataRow row in reader) { cliente.Id_Cliente = id; cliente.Nombre = row[1].ToString(); cliente.Apellido = row[2].ToString(); //cliente.Telefono = row[3].ToString(); cliente.Email = row[4].ToString(); } } catch (Exception ex) { cliente = null; throw new Exception("Error al intentar ejecutar el procedimiento almacenado Ventas.BuscarCliente. " + ex.Message, ex); } finally { if (SqlConexion.State == ConnectionState.Open) { SqlConexion.Close(); } } return(cliente); }
/*Método Eliminar - Obtiene resultados del procedimiento almacenado Clientes.Eliminar para eliminar un cliente * previamente registrado en el sistema.*/ public string Eliminar(DClientes Cliente) { //Crea variable resultado y crea instancia de la conexión con SQL Server. string Respuesta = ""; SqlConnection ConexionSql = new SqlConnection(); try { //Establece la conexión con la base de datos. ConexionSql.ConnectionString = DConexion.CnFacturacion; ConexionSql.Open(); //Crea el comando SQL. SqlCommand ComandoSql = new SqlCommand(); ComandoSql.Connection = ConexionSql; ComandoSql.CommandText = "Clientes.Eliminar"; ComandoSql.CommandType = CommandType.StoredProcedure; //Parámetro que indica el código del cliente. SqlParameter parIdCliente = new SqlParameter(); parIdCliente.ParameterName = "@IdCliente"; parIdCliente.SqlDbType = SqlDbType.Int; parIdCliente.Value = Cliente.IdCliente; ComandoSql.Parameters.Add(parIdCliente); //Ejecuta el comando. ComandoSql.ExecuteNonQuery(); Respuesta = "OK"; } catch (SqlException ex) { //En caso de error devuelve mensaje de notificación en la variable resultado. Respuesta = "Error al intentar ejecutar el procedimiento almacenado \"Clientes.Eliminar\". \n" + ex.Message; } finally { //Cierra la conexión si se encuentra abierta. if (ConexionSql.State == ConnectionState.Open) { ConexionSql.Close(); } } return(Respuesta); }
public static string Insertar(string nombre, string apellido, string denominacion, string dniCuit, string tel1, string tel2, string email, string calle, int numero, string ciudad, string provincia, string observaciones) { DClientes cliente = new DClientes(); cliente.Nombre = nombre; cliente.Apellido = apellido; cliente.Denomiacion = denominacion; cliente.DniCuit = dniCuit; cliente.Telefono1 = tel1; cliente.Telefono2 = tel2; cliente.Email = email; cliente.Calle = calle; cliente.Numero = numero; cliente.Ciudad = ciudad; cliente.Provincia = provincia; cliente.Observaciones = observaciones; return cliente.Insertar(cliente); }
//------------------- METODO BAJAS/ELIMINAR ----------------------------------------------------------------- public string Eliminar(DClientes Clientes) { string rpta = ""; SqlConnection SqlCon = new SqlConnection(); try { //Código SqlCon.ConnectionString = Conexion.Cn; SqlCon.Open(); //Establecer el Comando SqlCommand SqlCmd = new SqlCommand(); SqlCmd.Connection = SqlCon; SqlCmd.CommandText = "speliminar_cliente"; SqlCmd.CommandType = CommandType.StoredProcedure; SqlParameter ParIdCliente = new SqlParameter(); ParIdCliente.ParameterName = "@idCodcli"; ParIdCliente.SqlDbType = SqlDbType.Int; ParIdCliente.Value = Clientes.IdCodcli; SqlCmd.Parameters.Add(ParIdCliente); //Ejecutamos nuestro comando, es decir estamos llamando al procedimiento almacenado para que se ejecute rpta = SqlCmd.ExecuteNonQuery() == 1 ? "OK" : "NO se Elimino el Registro"; } catch (Exception ex) { rpta = ex.Message; } finally { if (SqlCon.State == ConnectionState.Open) { SqlCon.Close(); } } return(rpta); }
public DataTable Buscar(DClientes parClientes) { DataTable TablaDatos = new DataTable("Ventas.Clientes"); SqlConnection SqlConexion = new SqlConnection(); try { SqlConexion.ConnectionString = DConexion.CnBDEmpresa; SqlConexion.Open(); SqlCommand SqlComando = new SqlCommand(); SqlComando.Connection = SqlConexion; SqlComando.CommandText = "Ventas.BuscarCliente"; SqlComando.CommandType = CommandType.StoredProcedure; //SqlParameter ParNombre_Cliente_Buscado = new SqlParameter(); //ParNombre_Cliente_Buscado.ParameterName = "@NombreClienteBuscado"; //ParNombre_Cliente_Buscado.SqlDbType = SqlDbType.VarChar; //ParNombre_Cliente_Buscado.Size = parClientes.Nombre_Cliente_Buscado.Length; //ParNombre_Cliente_Buscado.Value = parClientes.Nombre_Cliente_Buscado; //SqlComando.Parameters.Add(ParNombre_Cliente_Buscado); SqlDataAdapter SqlAdaptadorDatos = new SqlDataAdapter(SqlComando); SqlAdaptadorDatos.Fill(TablaDatos); } catch (Exception ex) { TablaDatos = null; throw new Exception("Error al intentar ejecutar el procedimiento almacenado Ventas.BuscarCliente. " + ex.Message, ex); } finally { if (SqlConexion.State == ConnectionState.Open) { SqlConexion.Close(); } } return(TablaDatos); }
//Metodo Eliminar public string Eliminar(DClientes cliente) { string rspt = ""; SqlConnection sqlcon = new SqlConnection(); try { //codigo de conexion sqlcon.ConnectionString = Conexion.Cn; sqlcon.Open(); // codigo del comando de insertar SqlCommand sqlCmd = new SqlCommand(); sqlCmd.Connection = sqlcon; sqlCmd.CommandText = "pa_eliminarCliente"; sqlCmd.CommandType = CommandType.StoredProcedure; SqlParameter ParIdCliente = new SqlParameter(); ParIdCliente.ParameterName = "@clienteId"; ParIdCliente.SqlDbType = SqlDbType.Int; ParIdCliente.Value = cliente.id_Cliente; sqlCmd.Parameters.Add(ParIdCliente); rspt = sqlCmd.ExecuteNonQuery() == 1 ? "OK" : "No se Elimino el Cliente"; } catch (Exception ex) { rspt = ex.Message; } finally { if (sqlcon.State == ConnectionState.Open) sqlcon.Close(); } return rspt; }
//----------------------------------------------------------------------------------// // BLOQUE DE METODOS PARA ALTAS, BAJAS, MODIFICACIONES ..... //----------------------------------------------------------------------------------// //------------------- METODO ALTAS ------------------------------------------------------------------ public string Insertar(DClientes Clientes) { string rpta = ""; //--> rpta - Variable para saber el valor de retorno SqlConnection SqlCon = new SqlConnection(); //--> SqlCon - Variable de tipo Conexión SQL try //--->Control de Errores { SqlCon.ConnectionString = Conexion.Cn; //--> Le digo a ConnectionString cual es nuestra conexión que tengo en la clase Conexión y en la variable Cn SqlCon.Open(); //--> Abrimos la conexión SqlCommand SqlCmd = new SqlCommand(); //--> SqlCmd - Variable de la clase SqlCommand para poder utilizar los comandos de SQL SqlCmd.Connection = SqlCon; //--> Le pasamos la conexión. SqlCmd.CommandText = "spinsertar_cliente"; //--> Le decimos el nombre del Procedimiento a ejecutar SqlCmd.CommandType = CommandType.StoredProcedure; //--> Le decimos que el tipo de comando es un PRC //-->Descripción del campo idCodcli //----------------------------------------------------------------------------------- SqlParameter ParIdCliente = new SqlParameter(); //-> Esto es para "parametrizar", poder enviar parametros en consultas ParIdCliente.ParameterName = "@idCodcli"; //-> Nombre del parametro, este es el mismo que tengo puesto en el PRC ParIdCliente.SqlDbType = SqlDbType.Int; //-> Tipo del campo ParIdCliente.Direction = ParameterDirection.Output; //-> Este campo es Identity por lo tanto indicar que es de salida Output SqlCmd.Parameters.Add(ParIdCliente); //-> Acción que tiene que llevar a cabo, AÑADIR en este caso con los parametros contenidos en ParNombre SqlParameter ParCNomCli = new SqlParameter(); //--> Esto es para "parametrizar", poder enviar parametros en consultas ParCNomCli.ParameterName = "@cNomCli"; //--> Nombre del paramentro como está en el PRC ParCNomCli.SqlDbType = SqlDbType.VarChar; //--> Tipo del campo. ParCNomCli.Size = 100; //--> Longuitud del campo ParCNomCli.Value = Clientes.CNomCli; //--> Aquí sí, le enviamos el valor que tenemos en la Propiedad OjO SqlCmd.Parameters.Add(ParCNomCli); //--> Acción que tiene que llevar a cabo, AÑADIR en este caso con los parametros contenidos en ParNombre SqlParameter ParcDirCli = new SqlParameter(); //--> Esto es para "parametrizar", poder enviar parametros en consultas ParcDirCli.ParameterName = "@cDirCli"; //--> Nombre del paramentro como está en el PRC ParcDirCli.SqlDbType = SqlDbType.VarChar; //--> Tipo del campo. ParcDirCli.Size = 100; //--> Longuitud del campo ParcDirCli.Value = Clientes.CDirCli; //--> Aquí sí, le enviamos el valor que tenemos en la Propiedad OjO SqlCmd.Parameters.Add(ParcDirCli); //--> Acción que tiene que llevar a cabo, AÑADIR en este caso con los parametros contenidos en ParNombre SqlParameter ParcPobCli = new SqlParameter(); //--> Esto es para "parametrizar", poder enviar parametros en consultas ParcPobCli.ParameterName = "@cPobCli"; //--> Nombre del paramentro como está en el PRC ParcPobCli.SqlDbType = SqlDbType.VarChar; //--> Tipo del campo. ParcPobCli.Size = 100; //--> Longuitud del campo ParcPobCli.Value = Clientes.CPobCli; //--> Aquí sí, le enviamos el valor que tenemos en la Propiedad OjO SqlCmd.Parameters.Add(ParcPobCli); //--> Acción que tiene que llevar a cabo, AÑADIR en este caso con los parametros contenidos en ParNombre SqlParameter ParcDniCif = new SqlParameter(); //--> Esto es para "parametrizar", poder enviar parametros en consultas ParcDniCif.ParameterName = "@cDniCif"; //--> Nombre del paramentro como está en el PRC ParcDniCif.SqlDbType = SqlDbType.VarChar; //--> Tipo del campo. ParcDniCif.Size = 17; //--> Longuitud del campo ParcDniCif.Value = Clientes.CDniCif; //--> Aquí sí, le enviamos el valor que tenemos en la Propiedad OjO SqlCmd.Parameters.Add(ParcDniCif); //--> Acción que tiene que llevar a cabo, AÑADIR en este caso con los parametros contenidos en ParNombre SqlParameter ParcContacto = new SqlParameter(); //--> Esto es para "parametrizar", poder enviar parametros en consultas ParcContacto.ParameterName = "@cContacto"; //--> Nombre del paramentro como está en el PRC ParcContacto.SqlDbType = SqlDbType.VarChar; //--> Tipo del campo. ParcContacto.Size = 100; //--> Longuitud del campo ParcContacto.Value = Clientes.CDniCif; //--> Aquí sí, le enviamos el valor que tenemos en la Propiedad OjO SqlCmd.Parameters.Add(ParcContacto); //--> Acción que tiene que llevar a cabo, AÑADIR en este caso con los parametros contenidos en ParNombre SqlParameter ParcCtaContable = new SqlParameter(); //--> Esto es para "parametrizar", poder enviar parametros en consultas ParcCtaContable.ParameterName = "@cCtaContable"; //--> Nombre del paramentro como está en el PRC ParcCtaContable.SqlDbType = SqlDbType.VarChar; //--> Tipo del campo. ParcCtaContable.Size = 12; //--> Longuitud del campo ParcCtaContable.Value = Clientes.CCtaContable; //--> Aquí sí, le enviamos el valor que tenemos en la Propiedad OjO SqlCmd.Parameters.Add(ParcCtaContable); //--> Acción que tiene que llevar a cabo, AÑADIR en este caso con los parametros contenidos en ParNombre SqlParameter ParnDto = new SqlParameter(); //--> Esto es para "parametrizar", poder enviar parametros en consultas ParnDto.ParameterName = "@nDto"; //--> Nombre del paramentro como está en el PRC ParnDto.SqlDbType = SqlDbType.Decimal; //--> Tipo del campo. ParnDto.Value = Clientes.NDto; //--> Aquí sí, le enviamos el valor que tenemos en la Propiedad OjO SqlCmd.Parameters.Add(ParnDto); //--> Acción que tiene que llevar a cabo, AÑADIR en este caso con los parametros contenidos en ParNombre SqlParameter ParcTele = new SqlParameter(); //--> Esto es para "parametrizar", poder enviar parametros en consultas ParcTele.ParameterName = "@cTelefono1"; //--> Nombre del paramentro como está en el PRC ParcTele.SqlDbType = SqlDbType.VarChar; //--> Tipo del campo. ParcTele.Value = Clientes.CTelefono1; //--> Aquí sí, le enviamos el valor que tenemos en la Propiedad OjO SqlCmd.Parameters.Add(ParcTele); //--> Acción que tiene que llevar a cabo, AÑADIR en este caso con los parametros contenidos en ParNombre SqlParameter ParcMail = new SqlParameter(); //--> Esto es para "parametrizar", poder enviar parametros en consultas ParcMail.ParameterName = "@cEmail"; //--> Nombre del paramentro como está en el PRC ParcMail.SqlDbType = SqlDbType.VarChar; //--> Tipo del campo. ParcMail.Value = Clientes.CEmail; //--> Aquí sí, le enviamos el valor que tenemos en la Propiedad OjO SqlCmd.Parameters.Add(ParcMail); //--> Acción que tiene que llevar a cabo, AÑADIR en este caso con los parametros contenidos en ParNombre SqlParameter ParcPostal = new SqlParameter(); //--> Esto es para "parametrizar", poder enviar parametros en consultas ParcPostal.ParameterName = "@cCodPostal"; //--> Nombre del paramentro como está en el PRC ParcPostal.SqlDbType = SqlDbType.VarChar; //--> Tipo del campo. ParcPostal.Value = Clientes.CCodPostal; //--> Aquí sí, le enviamos el valor que tenemos en la Propiedad OjO SqlCmd.Parameters.Add(ParcPostal); //--> Acción que tiene que llevar a cabo, AÑADIR en este caso con los parametros contenidos en ParNombre SqlParameter PardFecha = new SqlParameter(); //--> Esto es para "parametrizar", poder enviar parametros en consultas PardFecha.ParameterName = "@dFechaNaci"; //--> Nombre del paramentro como está en el PRC PardFecha.SqlDbType = SqlDbType.Date; //--> Tipo del campo. PardFecha.Value = Clientes.DFechaNaci; //--> Aquí sí, le enviamos el valor que tenemos en la Propiedad OjO SqlCmd.Parameters.Add(PardFecha); //--> Acción que tiene que llevar a cabo, AÑADIR en este caso con los parametros contenidos en ParNombre //--> Ahora Ejecutamos nuestro comando (tipo TERNARIO), es decir estamos llamando al procedimiento almacenado para que se ejecute // Controlamos el éxito de la operación con el valor retornado en la variable rpta // if ( SqlCmd.ExecuteNonQuery() == 1 ) // { // rpta = "OK"; // } // : else // { // rpta "NO se Ingreso el Registro"; // } rpta = SqlCmd.ExecuteNonQuery() == 1 ? "OK" : "NO se Ingreso el Registro"; } catch (Exception ex) { rpta = ex.Message; //-->Mostramos el mensaje. } finally //--> el finally se ejecuta siempre tanto si hay error como si no lo hay, así que cerramos la conexión que ya sabemos chupa mucha memoria. { if (SqlCon.State == ConnectionState.Open) { SqlCon.Close(); } } return(rpta); }
public DClientes BuscarClientePorId(int idCliente) { DClientes cliente = new DClientes(); SqlConnection SqlConexion = new SqlConnection(); try { SqlConexion.ConnectionString = Conexion.CnBDSistema; SqlConexion.Open(); SqlCommand SqlComando = new SqlCommand(); SqlComando.Connection = SqlConexion; string consulta = "select * from Clientes where id =" + idCliente; SqlComando.CommandText = consulta; SqlComando.CommandType = CommandType.Text; SqlDataReader row = SqlComando.ExecuteReader(); while (row.Read()) { cliente.Id = idCliente; cliente.Nombre = row[1].ToString(); cliente.Apellido = row[2].ToString(); cliente.Denomiacion = row[3].ToString(); cliente.DniCuit = row[4].ToString(); cliente.Telefono1 = row[5].ToString(); cliente.Telefono2 = row[6].ToString(); cliente.Email = row[7].ToString(); cliente.Calle = row[8].ToString(); cliente.Numero = int.Parse(row[9].ToString()); cliente.Ciudad = row[10].ToString(); cliente.Provincia = row[11].ToString(); cliente.Observaciones = row[12].ToString(); } } catch (Exception ex) { cliente = null; throw new Exception("Error al intentar BuscarCliente por ID. " + ex.Message, ex); } finally { if (SqlConexion.State == ConnectionState.Open) { SqlConexion.Close(); } } return cliente; }
public string Modificar(DClientes cliente) { string Respuesta = ""; SqlConnection SqlConexion = new SqlConnection(); SqlTransaction transaccion = null; try { SqlConexion.ConnectionString = Conexion.CnBDSistema; SqlConexion.Open(); transaccion = SqlConexion.BeginTransaction(); SqlCommand SqlComando = new SqlCommand(); SqlComando.Transaction = transaccion; SqlComando.Connection = SqlConexion; SqlComando.CommandType = CommandType.Text; string consulta = "UPDATE [dbo].[CLIENTES] SET " + "[nombre]='" + cliente.Nombre + "', [apellido]= '" + cliente.Apellido + "', [denominacion]= '" + cliente.Denomiacion + "',[dni_cuit]='" + cliente.DniCuit + "', [telefono_1] ='" + cliente.Telefono1 + "',[telefono_2]='" + cliente.Telefono2 + "',[email]='" + cliente.Email + "',[calle]='" + cliente.Calle + "',[numero]=" + cliente.Numero + ",[ciudad]='" + cliente.Ciudad + "',[provincia]='" + cliente.Provincia + "',[observaciones]='" + cliente.Observaciones + "' where id=" + cliente.Id; SqlComando.CommandText = consulta; SqlComando.ExecuteNonQuery(); transaccion.Commit(); Respuesta = "Y"; } catch (SqlException ex) { transaccion.Rollback(); throw new Exception("Error al intentar modifcar cliente. " + ex.Message, ex); } finally { if (SqlConexion.State == ConnectionState.Open) { SqlConexion.Close(); } } return Respuesta; }
public string Editar(DClientes cliente, List <string> dir) { string Respuesta = ""; SqlConnection SqlConexion = new SqlConnection(); SqlTransaction transaccion = null; try { SqlConexion.ConnectionString = DConexion.CnBDEmpresa; SqlConexion.Open(); transaccion = SqlConexion.BeginTransaction(); SqlCommand SqlComando = new SqlCommand(); SqlComando.Transaction = transaccion; SqlComando.Connection = SqlConexion; SqlComando.CommandType = CommandType.Text; //direccion //clinte string query = "UPDATE [dbo].[DIRECCIONES] SET [calle]='" + dir[0].ToString() + "', [numero]=" + int.Parse(dir[1].ToString()) + ", [piso]='" + dir[2].ToString() + "', [departamento] ='" + dir[3].ToString() + "',[ciudad]='" + dir[5].ToString() + "',[provincia]='" + dir[6].ToString() + "',[pais]='" + dir[7].ToString() + "',[codigo_postal]=" + dir[4].ToString() + " where id_direccion=" + int.Parse(dir[8].ToString()); SqlComando.CommandText = query; SqlComando.ExecuteNonQuery(); //clinte query = "UPDATE [dbo].[CLIENTES] SET [nombre]='" + cliente.Nombre + "', [apellido]= '" + cliente.Apellido + "', [razon_social]='" + cliente.Razon_Social + "', [telefono_fijo] ='" + cliente.Telefono_Fijo + "',[telefono_movil]='" + cliente.Telefono_Movil + "',[email]='" + cliente.Email + "',[cuil]=" + cliente.Cuil + ",[cuit]=" + cliente.Cuit + ",[tipo_cliente_id]=" + cliente.Tipo_Cliente + " where Id_Cliente=" + cliente.Id_Cliente; SqlComando.CommandText = query; SqlComando.ExecuteNonQuery(); transaccion.Commit(); Respuesta = "Y"; } catch (SqlException ex) { if (ex.Number == 8152) { Respuesta = "Has introducido demasiados caracteres en uno de los campos"; } else if (ex.Number == 2627) { Respuesta = "Ya existe un cliente con ese Nombre"; } else if (ex.Number == 515) { Respuesta = "Sólo puedes dejar vacíos los campos Nombre de Contacto, Región, País, Teléfono, Fax y Email"; } else { Respuesta = "Error al intentar ejecutar el procedimiento almacenado Ventas.InsertarCliente. " + ex.Message; } } finally { if (SqlConexion.State == ConnectionState.Open) { SqlConexion.Close(); } } return(Respuesta); }
//Metodo Buscar public DataTable BuscarNombre(DClientes cliente) { DataTable tablaResultado = new DataTable("Clientes"); SqlConnection sqlcon = new SqlConnection(); try { sqlcon.ConnectionString = Conexion.Cn; SqlCommand sqlCmd = new SqlCommand(); sqlCmd.Connection = sqlcon; sqlCmd.CommandText = "pa_mostrarCliente"; sqlCmd.CommandType = CommandType.StoredProcedure; SqlParameter ParBuscarCliente = new SqlParameter(); ParBuscarCliente.ParameterName = "@textoBuscar"; ParBuscarCliente.SqlDbType = SqlDbType.VarChar; ParBuscarCliente.Size = 50; ParBuscarCliente.Value = cliente.TextoBuscar; sqlCmd.Parameters.Add(ParBuscarCliente); SqlDataAdapter sqlData = new SqlDataAdapter(sqlCmd); sqlData.Fill(tablaResultado); } catch (Exception ex) { tablaResultado = null; } return tablaResultado; }
public string Editar(DClientes parClientes) { string Respuesta = ""; SqlConnection SqlConexion = new SqlConnection(); try { SqlConexion.ConnectionString = DConexion.CnBDEmpresa; SqlConexion.Open(); SqlCommand SqlComando = new SqlCommand(); SqlComando.Connection = SqlConexion; SqlComando.CommandText = "Ventas.EditarCliente"; SqlComando.CommandType = CommandType.StoredProcedure; SqlParameter ParId_Cliente = new SqlParameter(); ParId_Cliente.ParameterName = "@Id_Cliente"; ParId_Cliente.SqlDbType = SqlDbType.Int; ParId_Cliente.Value = parClientes.Id_Cliente; SqlComando.Parameters.Add(ParId_Cliente); SqlParameter ParNombre_Cliente = new SqlParameter(); ParNombre_Cliente.ParameterName = "@Nombre_Cliente"; ParNombre_Cliente.SqlDbType = SqlDbType.VarChar; ParNombre_Cliente.Size = parClientes.Nombre_Cliente.Length; ParNombre_Cliente.Value = parClientes.Nombre_Cliente; SqlComando.Parameters.Add(ParNombre_Cliente); SqlParameter ParNombre_Contacto = new SqlParameter(); ParNombre_Contacto.ParameterName = "@Nombre_Contacto"; ParNombre_Contacto.SqlDbType = SqlDbType.VarChar; ParNombre_Contacto.Size = parClientes.Nombre_Contacto.Length; ParNombre_Contacto.Value = parClientes.Nombre_Contacto; SqlComando.Parameters.Add(ParNombre_Contacto); SqlParameter ParDireccion = new SqlParameter(); ParDireccion.ParameterName = "@Direccion"; ParDireccion.SqlDbType = SqlDbType.VarChar; ParDireccion.Size = parClientes.Direccion.Length; ParDireccion.Value = parClientes.Direccion; SqlComando.Parameters.Add(ParDireccion); SqlParameter ParCiudad = new SqlParameter(); ParCiudad.ParameterName = "@Ciudad"; ParCiudad.SqlDbType = SqlDbType.VarChar; ParCiudad.Size = parClientes.Ciudad.Length; ParCiudad.Value = parClientes.Ciudad; SqlComando.Parameters.Add(ParCiudad); SqlParameter ParRegion = new SqlParameter(); ParRegion.ParameterName = "@Region"; ParRegion.SqlDbType = SqlDbType.VarChar; ParRegion.Size = parClientes.Region.Length; ParRegion.Value = parClientes.Region; SqlComando.Parameters.Add(ParRegion); SqlParameter ParPais = new SqlParameter(); ParPais.ParameterName = "@Pais"; ParPais.SqlDbType = SqlDbType.VarChar; ParPais.Size = parClientes.Pais.Length; ParPais.Value = parClientes.Pais; SqlComando.Parameters.Add(ParPais); SqlParameter ParTelefono = new SqlParameter(); ParTelefono.ParameterName = "@Telefono"; ParTelefono.SqlDbType = SqlDbType.VarChar; ParTelefono.Size = parClientes.Telefono.Length; ParTelefono.Value = parClientes.Telefono; SqlComando.Parameters.Add(ParTelefono); SqlParameter ParFax = new SqlParameter(); ParFax.ParameterName = "@Fax"; ParFax.SqlDbType = SqlDbType.VarChar; ParFax.Size = parClientes.Fax.Length; ParFax.Value = parClientes.Fax; SqlComando.Parameters.Add(ParFax); SqlParameter ParEmail = new SqlParameter(); ParEmail.ParameterName = "@Email"; ParEmail.SqlDbType = SqlDbType.VarChar; ParEmail.Size = parClientes.Email.Length; ParEmail.Value = parClientes.Email; SqlComando.Parameters.Add(ParEmail); SqlComando.ExecuteNonQuery(); Respuesta = "Y"; } catch (SqlException ex) { if (ex.Number == 8152) { Respuesta = "Has introducido demasiados caracteres en uno de los campos."; } else if (ex.Number == 2627) { Respuesta = "Ya existe un cliente con ese Nombre"; } else if (ex.Number == 515) { Respuesta = "Sólo puedes dejar vacíos los campos Nombre de Contacto, Región, País, Teléfono, Fax y Email"; } else { Respuesta = "Error al intentar ejecutar el procedimiento almacenado Ventas.EditarCliente. " + ex.Message; } } finally { if (SqlConexion.State == ConnectionState.Open) { SqlConexion.Close(); } } return Respuesta; }
//------------------- METODO MODIFICAR/EDITAR ----------------------------------------------------------------- public string Editar(DClientes Clientes) { string rpta = ""; SqlConnection SqlCon = new SqlConnection(); try { SqlCon.ConnectionString = Conexion.Cn; SqlCon.Open(); //Establecer el Comando SqlCommand SqlCmd = new SqlCommand(); SqlCmd.Connection = SqlCon; SqlCmd.CommandText = "speditar_cliente"; SqlCmd.CommandType = CommandType.StoredProcedure; SqlParameter ParIdCliente = new SqlParameter(); ParIdCliente.ParameterName = "@idCodcli"; ParIdCliente.SqlDbType = SqlDbType.Int; ParIdCliente.Value = Clientes.IdCodcli; SqlCmd.Parameters.Add(ParIdCliente); SqlParameter ParCNomCli = new SqlParameter(); ParCNomCli.ParameterName = "@cNomCli"; ParCNomCli.SqlDbType = SqlDbType.VarChar; ParCNomCli.Size = 100; ParCNomCli.Value = Clientes.CNomCli; SqlCmd.Parameters.Add(ParCNomCli); SqlParameter ParcDirCli = new SqlParameter(); ParcDirCli.ParameterName = "@cDirCli"; ParcDirCli.SqlDbType = SqlDbType.VarChar; ParcDirCli.Size = 100; ParcDirCli.Value = Clientes.CDirCli; SqlCmd.Parameters.Add(ParcDirCli); SqlParameter ParcPobCli = new SqlParameter(); ParcPobCli.ParameterName = "@cPobCli"; ParcPobCli.SqlDbType = SqlDbType.VarChar; ParcPobCli.Size = 100; ParcPobCli.Value = Clientes.CPobCli; SqlCmd.Parameters.Add(ParcPobCli); SqlParameter ParcDniCif = new SqlParameter(); ParcDniCif.ParameterName = "@cDniCif"; ParcDniCif.SqlDbType = SqlDbType.VarChar; ParcDniCif.Size = 17; ParcDniCif.Value = Clientes.CDniCif; SqlCmd.Parameters.Add(ParcDniCif); SqlParameter ParcContacto = new SqlParameter(); ParcContacto.ParameterName = "@cContacto"; ParcContacto.SqlDbType = SqlDbType.VarChar; ParcContacto.Size = 100; ParcContacto.Value = Clientes.CDniCif; SqlCmd.Parameters.Add(ParcContacto); SqlParameter ParcCtaContable = new SqlParameter(); ParcCtaContable.ParameterName = "@cCtaContable"; ParcCtaContable.SqlDbType = SqlDbType.VarChar; ParcCtaContable.Size = 12; ParcCtaContable.Value = Clientes.CCtaContable; SqlCmd.Parameters.Add(ParcCtaContable); SqlParameter ParnDto = new SqlParameter(); ParnDto.ParameterName = "@nDto"; ParnDto.SqlDbType = SqlDbType.Decimal; ParnDto.Value = Clientes.NDto; SqlCmd.Parameters.Add(ParnDto); SqlParameter ParcTele = new SqlParameter(); //--> Esto es para "parametrizar", poder enviar parametros en consultas ParcTele.ParameterName = "@cTelefono1"; //--> Nombre del paramentro como está en el PRC ParcTele.SqlDbType = SqlDbType.VarChar; //--> Tipo del campo. ParcTele.Value = Clientes.CTelefono1; //--> Aquí sí, le enviamos el valor que tenemos en la Propiedad OjO SqlCmd.Parameters.Add(ParcTele); //--> Acción que tiene que llevar a cabo, AÑADIR en este caso con los parametros contenidos en ParNombre SqlParameter ParcMail = new SqlParameter(); //--> Esto es para "parametrizar", poder enviar parametros en consultas ParcMail.ParameterName = "@cEmail"; //--> Nombre del paramentro como está en el PRC ParcMail.SqlDbType = SqlDbType.VarChar; //--> Tipo del campo. ParcMail.Value = Clientes.CEmail; //--> Aquí sí, le enviamos el valor que tenemos en la Propiedad OjO SqlCmd.Parameters.Add(ParcMail); //--> Acción que tiene que llevar a cabo, AÑADIR en este caso con los parametros contenidos en ParNombre SqlParameter ParcPostal = new SqlParameter(); //--> Esto es para "parametrizar", poder enviar parametros en consultas ParcPostal.ParameterName = "@cCodPostal"; //--> Nombre del paramentro como está en el PRC ParcPostal.SqlDbType = SqlDbType.VarChar; //--> Tipo del campo. ParcPostal.Value = Clientes.CCodPostal; //--> Aquí sí, le enviamos el valor que tenemos en la Propiedad OjO SqlCmd.Parameters.Add(ParcPostal); //--> Acción que tiene que llevar a cabo, AÑADIR en este caso con los parametros contenidos en ParNombre SqlParameter PardFecha = new SqlParameter(); //--> Esto es para "parametrizar", poder enviar parametros en consultas PardFecha.ParameterName = "@dFechaNaci"; //--> Nombre del paramentro como está en el PRC PardFecha.SqlDbType = SqlDbType.Date; //--> Tipo del campo. PardFecha.Value = Clientes.DFechaNaci; //--> Aquí sí, le enviamos el valor que tenemos en la Propiedad OjO SqlCmd.Parameters.Add(PardFecha); //--> Acción que tiene que llevar a cabo, AÑADIR en este caso con los parametros contenidos en ParNombre //Ejecutamos nuestro comando, es decir estamos llamando al procedimiento almacenado para que se ejecute rpta = SqlCmd.ExecuteNonQuery() == 1 ? "OK" : "NO se Actualizo el Registro"; } catch (Exception ex) { rpta = ex.Message; } finally { if (SqlCon.State == ConnectionState.Open) { SqlCon.Close(); } } return(rpta); }
//Metodo Insertar public string Insertar(DClientes cliente) { string rspt = ""; SqlConnection sqlcon = new SqlConnection(); try { //codigo de conexion sqlcon.ConnectionString = Conexion.Cn; sqlcon.Open(); // codigo del comando de insertar SqlCommand sqlCmd = new SqlCommand(); sqlCmd.Connection = sqlcon; sqlCmd.CommandText = "pa_insertarCliente"; sqlCmd.CommandType = CommandType.StoredProcedure; SqlParameter ParIdCliente = new SqlParameter(); ParIdCliente.ParameterName = "@clienteId"; ParIdCliente.SqlDbType = SqlDbType.Int; ParIdCliente.Value = cliente.id_Cliente; sqlCmd.Parameters.Add(ParIdCliente); SqlParameter ParNombreCliente = new SqlParameter(); ParNombreCliente.ParameterName = "@nombre"; ParNombreCliente.SqlDbType = SqlDbType.VarChar; ParNombreCliente.Size = 15; ParNombreCliente.Value = cliente.NombreCliente; sqlCmd.Parameters.Add(ParNombreCliente); SqlParameter ParApellido1 = new SqlParameter(); ParApellido1.ParameterName = "@apellido1"; ParApellido1.SqlDbType = SqlDbType.VarChar; ParApellido1.Size = 20; ParApellido1.Value = cliente.Apellido1; sqlCmd.Parameters.Add(ParApellido1); SqlParameter ParApellido2 = new SqlParameter(); ParApellido2.ParameterName = "@apellido2"; ParApellido2.SqlDbType = SqlDbType.VarChar; ParApellido2.Size = 20; ParApellido2.Value = cliente.Apellido2; sqlCmd.Parameters.Add(ParApellido2); SqlParameter ParFechaNacimiento = new SqlParameter(); ParFechaNacimiento.ParameterName = "@fechaNacimiento"; ParFechaNacimiento.SqlDbType = SqlDbType.Date; ParFechaNacimiento.Value = cliente.Fecha; sqlCmd.Parameters.Add(ParFechaNacimiento); SqlParameter ParEstado = new SqlParameter(); ParEstado.ParameterName = "@estado"; ParEstado.SqlDbType = SqlDbType.Int; ParEstado.Value = cliente.Estado; sqlCmd.Parameters.Add(ParEstado); rspt = sqlCmd.ExecuteNonQuery() == 1 ? "OK" : "No se ingreso el Cliente"; } catch (Exception ex) { rspt = ex.Message; } finally { if (sqlcon.State == ConnectionState.Open) sqlcon.Close(); } return rspt; }
//public string Insertar(DClientes parClientes) //{ // string Respuesta = ""; // SqlConnection SqlConexion = new SqlConnection(); // try // { // SqlConexion.ConnectionString = DConexion.CnBDEmpresa; // SqlConexion.Open(); // SqlCommand SqlComando = new SqlCommand(); // SqlComando.Connection = SqlConexion; // SqlComando.CommandText = "Ventas.InsertarCliente"; // SqlComando.CommandType = CommandType.StoredProcedure; // SqlParameter ParNombre_Cliente = new SqlParameter(); // ParNombre_Cliente.ParameterName = "@Nombre_Cliente"; // ParNombre_Cliente.SqlDbType = SqlDbType.VarChar; // ParNombre_Cliente.Size = parClientes.Nombre_Cliente.Length; // ParNombre_Cliente.Value = parClientes.Nombre_Cliente; // SqlComando.Parameters.Add(ParNombre_Cliente); // SqlParameter ParNombre_Contacto = new SqlParameter(); // ParNombre_Contacto.ParameterName = "@Nombre_Contacto"; // ParNombre_Contacto.SqlDbType = SqlDbType.VarChar; // ParNombre_Contacto.Size = parClientes.Apellido_Cliente.Length; // ParNombre_Contacto.Value = parClientes.Apellido_Cliente; // SqlComando.Parameters.Add(ParNombre_Contacto); // //SqlParameter ParDireccion = new SqlParameter(); // //ParDireccion.ParameterName = "@Direccion"; // //ParDireccion.SqlDbType = SqlDbType.VarChar; // //ParDireccion.Size = parClientes.Direccion.Length; // //ParDireccion.Value = parClientes.Direccion; // //SqlComando.Parameters.Add(ParDireccion); // //SqlParameter ParCiudad = new SqlParameter(); // //ParCiudad.ParameterName = "@Ciudad"; // //ParCiudad.SqlDbType = SqlDbType.VarChar; // //ParCiudad.Size = parClientes.Ciudad.Length; // //ParCiudad.Value = parClientes.Ciudad; // //SqlComando.Parameters.Add(ParCiudad); // //SqlParameter ParRegion = new SqlParameter(); // //ParRegion.ParameterName = "@Region"; // //ParRegion.SqlDbType = SqlDbType.VarChar; // //ParRegion.Size = parClientes.Region.Length; // //ParRegion.Value = parClientes.Region; // //SqlComando.Parameters.Add(ParRegion); // //SqlParameter ParPais = new SqlParameter(); // //ParPais.ParameterName = "@Pais"; // //ParPais.SqlDbType = SqlDbType.VarChar; // //ParPais.Size = parClientes.Pais.Length; // //ParPais.Value = parClientes.Pais; // //SqlComando.Parameters.Add(ParPais); // SqlParameter ParTelefono = new SqlParameter(); // ParTelefono.ParameterName = "@Telefono"; // ParTelefono.SqlDbType = SqlDbType.VarChar; // ParTelefono.Size = parClientes.Telefono.Length; // ParTelefono.Value = parClientes.Telefono; // SqlComando.Parameters.Add(ParTelefono); // //SqlParameter ParFax = new SqlParameter(); // //ParFax.ParameterName = "@Fax"; // //ParFax.SqlDbType = SqlDbType.VarChar; // //ParFax.Size = parClientes.Fax.Length; // //ParFax.Value = parClientes.Fax; // //SqlComando.Parameters.Add(ParFax); // SqlParameter ParEmail = new SqlParameter(); // ParEmail.ParameterName = "@Email"; // ParEmail.SqlDbType = SqlDbType.VarChar; // ParEmail.Size = parClientes.Email.Length; // ParEmail.Value = parClientes.Email; // SqlComando.Parameters.Add(ParEmail); // SqlComando.ExecuteNonQuery(); // Respuesta = "Y"; // } // catch (SqlException ex) // { // if (ex.Number == 8152) // { // Respuesta = "Has introducido demasiados caracteres en uno de los campos"; // } // else if (ex.Number == 2627) // { // Respuesta = "Ya existe un cliente con ese Nombre"; // } // else if (ex.Number == 515) // { // Respuesta = "Sólo puedes dejar vacíos los campos Nombre de Contacto, Región, País, Teléfono, Fax y Email"; // } // else // { // Respuesta = "Error al intentar ejecutar el procedimiento almacenado Ventas.InsertarCliente. " + ex.Message; // } // } // finally // { // if (SqlConexion.State == ConnectionState.Open) // { // SqlConexion.Close(); // } // } // return Respuesta; //} public string Insertar(DClientes cliente, List<string> dir) { string Respuesta = ""; SqlConnection SqlConexion = new SqlConnection(); SqlTransaction transaccion = null; try { SqlConexion.ConnectionString = DConexion.CnBDEmpresa; SqlConexion.Open(); transaccion = SqlConexion.BeginTransaction(); SqlCommand SqlComando = new SqlCommand(); SqlComando.Transaction = transaccion; SqlComando.Connection = SqlConexion; SqlComando.CommandType = CommandType.Text; //direccion //clinte string query = "INSERT INTO [dbo].[DIRECCIONES] ([calle],[numero],[piso],[departamento],[ciudad]" + ",[provincia],[pais],[codigo_postal])" + "VALUES('" + dir[0].ToString() + "'," + int.Parse(dir[1].ToString()) + ",'" + dir[2].ToString() + "','" + dir[3].ToString() + "','" + dir[5].ToString() + "','" + dir[6].ToString() + "','" + dir[7].ToString() + "'," + dir[4].ToString() + ") SELECT SCOPE_IDENTITY()"; SqlComando.CommandText = query; int direccion = Convert.ToInt32(SqlComando.ExecuteScalar()); //clinte query = "INSERT INTO [dbo].[CLIENTES] ([nombre],[apellido],[razon_social],[telefono_fijo]" + ",[telefono_movil],[email],[cuil],[cuit],[direccion_id],[tipo_cliente_id])" + "VALUES('" + cliente.Nombre + "','" + cliente.Apellido + "','" + cliente.Razon_Social + "','" + cliente.Telefono_Fijo + "','" + cliente.Telefono_Movil + "','" + cliente.Email + "'," + cliente.Cuil + "," + cliente.Cuit + "," + direccion + "," + cliente.Tipo_Cliente +")"; SqlComando.CommandText = query; SqlComando.ExecuteNonQuery(); transaccion.Commit(); Respuesta = "Y"; } catch (SqlException ex) { transaccion.Rollback(); if (ex.Number == 8152) { Respuesta = "Has introducido demasiados caracteres en uno de los campos"; } else if (ex.Number == 2627) { Respuesta = "Ya existe un cliente con ese Nombre"; } else if (ex.Number == 515) { Respuesta = "Sólo puedes dejar vacíos los campos Nombre de Contacto, Región, País, Teléfono, Fax y Email"; } else { Respuesta = "Error al intentar ejecutar el procedimiento almacenado Ventas.InsertarCliente. " + ex.Message; } } finally { if (SqlConexion.State == ConnectionState.Open) { SqlConexion.Close(); } } return Respuesta; }
public DClientes BuscarPorId(int id) { DClientes cliente = new DClientes(); SqlConnection SqlConexion = new SqlConnection(); try { SqlConexion.ConnectionString = DConexion.CnBDEmpresa; SqlConexion.Open(); SqlCommand SqlComando = new SqlCommand(); SqlComando.Connection = SqlConexion; SqlComando.CommandText = "select * from Clientes where Id_Cliente =" + id; SqlComando.CommandType = CommandType.Text; SqlDataReader reader = SqlComando.ExecuteReader(); foreach (DataRow row in reader) { cliente.Id_Cliente = id; cliente.Nombre = row[1].ToString(); cliente.Apellido = row[2].ToString(); //cliente.Telefono = row[3].ToString(); cliente.Email = row[4].ToString(); } } catch (Exception ex) { cliente = null; throw new Exception("Error al intentar ejecutar el procedimiento almacenado Ventas.BuscarCliente. " + ex.Message, ex); } finally { if (SqlConexion.State == ConnectionState.Open) { SqlConexion.Close(); } } return cliente; }
public static DataTable buscarCliente(string textoBuscar) { DClientes obj = new DClientes(); obj.TextoBuscar = textoBuscar; return obj.BuscarNombre(obj); }
public static String Eliminar(int Id_Cliente) { DClientes clientes = new DClientes(); return clientes.Eliminar(Id_Cliente); }
public string InsertarClientes(DClientes DClientes) { int contador = 0; //asignamos a una cadena string la variable rpta y la iniciamos en vacía string rpta = ""; SqlConnection SqlCon = new SqlConnection(); SqlCon.InfoMessage += new SqlInfoMessageEventHandler(SqlCon_InfoMessage); SqlCon.FireInfoMessageEventOnUserErrors = true; //Capturador de errores try { SqlCon.ConnectionString = Conexion.Cn; SqlCon.Open(); //establecer comando SqlCommand SqlCmd = new SqlCommand { Connection = SqlCon, CommandText = "sp_Insertar_cliente", //Indicamos que es un procedimiento almacenado CommandType = CommandType.StoredProcedure }; SqlParameter Id_cliente = new SqlParameter { ParameterName = "@Id_cliente", SqlDbType = SqlDbType.Int, Direction = ParameterDirection.Output }; SqlCmd.Parameters.Add(Id_cliente); SqlParameter Nombre_cliente = new SqlParameter { ParameterName = "@Nombre_cliente", SqlDbType = SqlDbType.VarChar, Size = 500, Value = DClientes.Variables[contador].Trim().ToUpper() }; SqlCmd.Parameters.Add(Nombre_cliente); contador += 1; SqlParameter Telefono_cliente = new SqlParameter { ParameterName = "@Telefono_cliente", SqlDbType = SqlDbType.VarChar, Size = 50, Value = DClientes.Variables[contador].Trim().ToUpper() }; SqlCmd.Parameters.Add(Telefono_cliente); contador += 1; SqlParameter Correo_electronico = new SqlParameter { ParameterName = "@Correo_electronico", SqlDbType = SqlDbType.VarChar, Size = 500, Value = DClientes.Variables[contador].Trim().ToUpper() }; SqlCmd.Parameters.Add(Correo_electronico); contador += 1; //Ejecutamos nuestro comando //Se puede ejecutar este metodo pero ya tenemos el mensaje que devuelve sql rpta = SqlCmd.ExecuteNonQuery() >= 1 ? "OK" : "NO"; if (rpta != "OK") { if (this.Mensaje_respuesta != null) { rpta = this.Mensaje_respuesta; } } } //Mostramos posible error que tengamos catch (SqlException ex) { rpta = ex.Message; } catch (Exception ex) { rpta = ex.Message; } finally { //Si la cadena SqlCon esta abierta la cerramos if (SqlCon.State == ConnectionState.Open) { SqlCon.Close(); } } return(rpta); }
public DataTable Buscar(DClientes parClientes) { DataTable TablaDatos = new DataTable("Ventas.Clientes"); SqlConnection SqlConexion = new SqlConnection(); try { SqlConexion.ConnectionString = DConexion.CnBDEmpresa; SqlConexion.Open(); SqlCommand SqlComando = new SqlCommand(); SqlComando.Connection = SqlConexion; SqlComando.CommandText = "Ventas.BuscarCliente"; SqlComando.CommandType = CommandType.StoredProcedure; //SqlParameter ParNombre_Cliente_Buscado = new SqlParameter(); //ParNombre_Cliente_Buscado.ParameterName = "@NombreClienteBuscado"; //ParNombre_Cliente_Buscado.SqlDbType = SqlDbType.VarChar; //ParNombre_Cliente_Buscado.Size = parClientes.Nombre_Cliente_Buscado.Length; //ParNombre_Cliente_Buscado.Value = parClientes.Nombre_Cliente_Buscado; //SqlComando.Parameters.Add(ParNombre_Cliente_Buscado); SqlDataAdapter SqlAdaptadorDatos = new SqlDataAdapter(SqlComando); SqlAdaptadorDatos.Fill(TablaDatos); } catch (Exception ex) { TablaDatos = null; throw new Exception("Error al intentar ejecutar el procedimiento almacenado Ventas.BuscarCliente. " + ex.Message, ex); } finally { if (SqlConexion.State == ConnectionState.Open) { SqlConexion.Close(); } } return TablaDatos; }
/*Método Editar - Obtiene resultados del procedimiento almacenado Clientes.Editar para editar un cliente * previamente registrado en el sistema.*/ public string Editar(DClientes Cliente) { //Crea variable resultado y crea instancia de la conexión con SQL Server. string Respuesta = ""; SqlConnection ConexionSql = new SqlConnection(); try { //Establece la conexión con la base de datos. ConexionSql.ConnectionString = DConexion.CnFacturacion; ConexionSql.Open(); //Crea el comando SQL. SqlCommand ComandoSql = new SqlCommand(); ComandoSql.Connection = ConexionSql; ComandoSql.CommandText = "Clientes.Editar"; ComandoSql.CommandType = CommandType.StoredProcedure; //Parámetro que indica el código del cliente. SqlParameter parIdCliente = new SqlParameter(); parIdCliente.ParameterName = "@IdCliente"; parIdCliente.SqlDbType = SqlDbType.Int; parIdCliente.Value = Cliente.IdCliente; ComandoSql.Parameters.Add(parIdCliente); //Parámetro que indica la razón social del nuevo cliente. SqlParameter parRazonSocial = new SqlParameter(); parRazonSocial.ParameterName = "@RazonSocial"; parRazonSocial.SqlDbType = SqlDbType.VarChar; parRazonSocial.Size = 70; parRazonSocial.Value = Cliente.RazonSocial; ComandoSql.Parameters.Add(parRazonSocial); //Parámetro que indica el tipo de documento del nuevo cliente. SqlParameter parDocumento = new SqlParameter(); parDocumento.ParameterName = "@Documento"; parDocumento.SqlDbType = SqlDbType.VarChar; parDocumento.Size = 29; parDocumento.Value = Cliente.Documento; ComandoSql.Parameters.Add(parDocumento); //Parámetro que indica la dirección del nuevo cliente. SqlParameter parDireccion = new SqlParameter(); parDireccion.ParameterName = "@Direccion"; parDireccion.SqlDbType = SqlDbType.VarChar; parDireccion.Size = 500; parDireccion.Value = Cliente.Direccion; ComandoSql.Parameters.Add(parDireccion); //Parámetro que indica el teléfono fiscal del nuevo cliente. SqlParameter parTelefonoFiscal = new SqlParameter(); parTelefonoFiscal.ParameterName = "@TelefonoFiscal"; parTelefonoFiscal.SqlDbType = SqlDbType.Float; parTelefonoFiscal.Value = Cliente.TelefonoFiscal; ComandoSql.Parameters.Add(parTelefonoFiscal); //Parámetro que indica la persona de contacto del nuevo cliente. SqlParameter parPersonaContacto = new SqlParameter(); parPersonaContacto.ParameterName = "@PersonaContacto"; parPersonaContacto.SqlDbType = SqlDbType.VarChar; parPersonaContacto.Size = 50; parPersonaContacto.Value = Cliente.PersonaContacto; ComandoSql.Parameters.Add(parPersonaContacto); //Parámetro que indica el teléfono de contacto 1 del nuevo cliente. SqlParameter parTelefono1 = new SqlParameter(); parTelefono1.ParameterName = "@Telefono1"; parTelefono1.Value = Cliente.Telefono1; ComandoSql.Parameters.Add(parTelefono1); //Parámetro que indica el teléfono de contacto 2 del nuevo cliente. SqlParameter parTelefono2 = new SqlParameter(); parTelefono2.ParameterName = "@Telefono2"; parTelefono2.SqlDbType = SqlDbType.Float; parTelefono2.Value = Cliente.Telefono2; ComandoSql.Parameters.Add(parTelefono2); //Parámetro que indica el teléfono de contacto 3 del nuevo cliente. SqlParameter parTelefono3 = new SqlParameter(); parTelefono3.ParameterName = "@Telefono3"; parTelefono3.SqlDbType = SqlDbType.Float; parTelefono3.Value = Cliente.Telefono3; ComandoSql.Parameters.Add(parTelefono3); //Parámetro que indica el correo de contacto 1 del nuevo cliente. SqlParameter parCorreo1 = new SqlParameter(); parCorreo1.ParameterName = "@Correo1"; parCorreo1.SqlDbType = SqlDbType.VarChar; parCorreo1.Size = 50; parCorreo1.Value = Cliente.Correo1; ComandoSql.Parameters.Add(parCorreo1); //Parámetro que indica el correo de contacto 2 del nuevo cliente. SqlParameter parCorreo2 = new SqlParameter(); parCorreo2.ParameterName = "@Correo2"; parCorreo2.SqlDbType = SqlDbType.VarChar; parCorreo2.Size = 50; parCorreo2.Value = Cliente.Correo2; ComandoSql.Parameters.Add(parCorreo2); //Parámetro que indica la dirección de entrega 1 del nuevo cliente. SqlParameter parEntrega1 = new SqlParameter(); parEntrega1.ParameterName = "@Entrega1"; parEntrega1.SqlDbType = SqlDbType.VarChar; parEntrega1.Size = 50; parEntrega1.Value = Cliente.Entrega1; ComandoSql.Parameters.Add(parEntrega1); //Parámetro que indica la dirección de entrega 2 del nuevo cliente. SqlParameter parEntrega2 = new SqlParameter(); parEntrega2.ParameterName = "@Entrega2"; parEntrega2.SqlDbType = SqlDbType.VarChar; parEntrega2.Size = 50; parEntrega2.Value = Cliente.Entrega2; ComandoSql.Parameters.Add(parEntrega2); //Parámetro que indica la dirección de entrega 3 del nuevo cliente. SqlParameter parEntrega3 = new SqlParameter(); parEntrega3.ParameterName = "@Entrega3"; parEntrega3.SqlDbType = SqlDbType.VarChar; parEntrega3.Size = 50; parEntrega3.Value = Cliente.Entrega3; ComandoSql.Parameters.Add(parEntrega3); //Parámetro que indica la dirección de entrega 4 del nuevo cliente. SqlParameter parEntrega4 = new SqlParameter(); parEntrega4.ParameterName = "@Entrega4"; parEntrega4.SqlDbType = SqlDbType.VarChar; parEntrega4.Size = 50; parEntrega4.Value = Cliente.Entrega4; ComandoSql.Parameters.Add(parEntrega4); //Parámetro que indica la dirección de entrega 5 del nuevo cliente. SqlParameter parEntrega5 = new SqlParameter(); parEntrega5.ParameterName = "@Entrega5"; parEntrega5.SqlDbType = SqlDbType.VarChar; parEntrega5.Size = 50; parEntrega5.Value = Cliente.Entrega5; ComandoSql.Parameters.Add(parEntrega5); //Parámetro que indica el usuario activo. SqlParameter parIdUsuario = new SqlParameter(); parIdUsuario.ParameterName = "@IdUsuario"; parIdUsuario.SqlDbType = SqlDbType.Int; parIdUsuario.Value = Cliente.IdUsuario; ComandoSql.Parameters.Add(parIdUsuario); //Ejecuta el comando. ComandoSql.ExecuteNonQuery(); Respuesta = "OK"; } catch (SqlException ex) { //En caso de error devuelve mensaje de notificación en la variable resultado. if (ex.Number == 2627) //Clave unica infirgida. { Respuesta = "Ya existe un usuario registrado con el número de documento o la razón social indicados."; } else { Respuesta = "Error al intentar ejecutar el procedimiento almacenado \"Clientes.Editar\". \n" + ex.Message; } } finally { //Cierra la conexión si se encuentra abierta. if (ConexionSql.State == ConnectionState.Open) { ConexionSql.Close(); } } return(Respuesta); }