コード例 #1
0
        public static Ingreso BuscarIngreso(int rut, string pasaporte)

        {
            try
            {
                SqlCommand     cmd   = new SqlCommand();
                SqlDataAdapter da    = new SqlDataAdapter(cmd);
                Coneccion      param = Parameter.Leer_parametros();
                cmd.Connection = new SqlConnection(param.ConString);
                cmd.Connection.Open();
                cmd.Parameters.Clear();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "DATOS_MOVIMIENTO";
                if (rut == 0)
                {
                    cmd.Parameters.AddWithValue("@RUT", System.DBNull.Value);
                }
                else
                {
                    cmd.Parameters.AddWithValue("@RUT", rut);
                }
                if (pasaporte == "")
                {
                    cmd.Parameters.AddWithValue("@PASAPORTE", System.DBNull.Value);
                }
                else
                {
                    cmd.Parameters.AddWithValue("@PASAPORTE", pasaporte);
                }

                SqlDataReader rdr         = cmd.ExecuteReader();
                Ingreso       aux_ingreso = new Ingreso();

                while (rdr.Read())
                {
                    aux_ingreso.Nombre       = rdr["NOMBRE"].ToString();
                    aux_ingreso.Idsolicitud  = Int32.Parse(rdr["ID_SOLICITUD"].ToString());
                    aux_ingreso.Estado       = rdr["ESTADO"].ToString();
                    aux_ingreso.Autorizacion = rdr["AUTORIZACION"].ToString();
                    aux_ingreso.Puerto       = rdr["PUERTO"].ToString();
                    aux_ingreso.Usuario      = rdr["USUARIO"].ToString();
                    aux_ingreso.Locacion     = rdr["LOCACION"].ToString();
                    aux_ingreso.Nave         = rdr["NAVE"].ToString();
                    aux_ingreso.Inicio       = rdr["FECHA_DESDE"].ToString();
                    aux_ingreso.Fin          = rdr["FECHA_HASTA"].ToString();
                    aux_ingreso.Empresa      = rdr["EMPRESA"].ToString();
                    aux_ingreso.Idaprobado   = Int32.Parse(rdr["ID_PERSONA_APROBADA"].ToString());
                    aux_ingreso.Pasaporte    = rdr["PASAPORTE"].ToString();
                }

                cmd.Connection.Close();
                cmd.Dispose();
                return(aux_ingreso);
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #2
0
        public static void registraIngreso(Ingreso ingreso)
        {
            // Proporciona la cadena de conexion a base de datos desde el archivo de configuracion
            string connectionString = ConfigurationManager.ConnectionStrings["TiendaConString"].ConnectionString;

            // Crear y abrir la conexión en un bloque using.
            // Esto asegura que todos los recursos serán cerrados y dispuestos cuando el código sale
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                // Crear el objeto Command.
                SqlCommand command = new SqlCommand("RegistroIngreso", connection);
                command.CommandType = CommandType.StoredProcedure;

                command.Parameters.AddWithValue("fechaIngreso", ingreso.fechaIngreso);
                command.Parameters.AddWithValue("idIngreso", 0);

                command.Parameters["idIngreso"].Direction = ParameterDirection.Output;

                try
                {
                    connection.Open();
                    //transacciones
                    SqlTransaction trato = connection.BeginTransaction();
                    command.Transaction = trato;

                    int fila = command.ExecuteNonQuery();


                    if (fila != 0)
                    {
                        int idIngreso = Convert.ToInt32(command.Parameters["idIngreso"].Value);

                        foreach (DetalleIngreso det in ingreso.getDetalles())
                        {
                            SqlCommand comanddet = new SqlCommand("Registro_Detalle", connection);

                            comanddet.CommandType = CommandType.StoredProcedure;


                            comanddet.Parameters.AddWithValue("cantidad", det.Cantidad);
                            comanddet.Parameters.AddWithValue("precioCompra", det.PrecioCompra);
                            comanddet.Parameters.AddWithValue("idIngreso", idIngreso);
                            comanddet.Parameters.AddWithValue("idProducto", det.IdProducto);
                            comanddet.Parameters.AddWithValue("idUnidad", det.IdUnidad);

                            comanddet.Transaction = trato;

                            fila = comanddet.ExecuteNonQuery();

                            SqlCommand comandStock = new SqlCommand("ActualizarStock", connection);

                            comandStock.CommandType = CommandType.StoredProcedure;
                            comandStock.Parameters.AddWithValue("idProducto", det.IdProducto);
                            comandStock.Parameters.AddWithValue("stock", det.Cantidad);

                            comandStock.Transaction = trato;
                            fila = comandStock.ExecuteNonQuery();
                        }
                    }
                    if (fila != 0)
                    {
                        trato.Commit();
                    }
                    else
                    {
                        trato.Rollback();
                    }
                }
                catch (SqlException ex)
                {
                    throw ex;
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
コード例 #3
0
ファイル: Ingreso.cs プロジェクト: Chukaro/analisis
        public static void registraIngreso(Ingreso ingreso)
        {
            // Proporciona la cadena de conexion a base de datos desde el archivo de configuracion
            string connectionString = ConfigurationManager.ConnectionStrings["TiendaConString"].ConnectionString;

            // Crear y abrir la conexión en un bloque using.
            // Esto asegura que todos los recursos serán cerrados y dispuestos cuando el código sale
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                // Crear el objeto Command.
                SqlCommand command = new SqlCommand("RegistroIngreso", connection);
                command.CommandType = CommandType.StoredProcedure;

                command.Parameters.AddWithValue("fechaIngreso", ingreso.fechaIngreso);
                command.Parameters.AddWithValue("idIngreso", 0);

                command.Parameters["idIngreso"].Direction = ParameterDirection.Output;

                try
                {
                    connection.Open();
                    //transacciones
                    SqlTransaction trato = connection.BeginTransaction();
                    command.Transaction = trato;

                    int fila = command.ExecuteNonQuery();

                    if (fila != 0)
                    {

                        int idIngreso = Convert.ToInt32(command.Parameters["idIngreso"].Value);

                        foreach (DetalleIngreso det in ingreso.getDetalles())
                        {
                            SqlCommand comanddet = new SqlCommand("Registro_Detalle", connection);

                            comanddet.CommandType = CommandType.StoredProcedure;

                            comanddet.Parameters.AddWithValue("cantidad", det.Cantidad);
                            comanddet.Parameters.AddWithValue("precioCompra", det.PrecioCompra);
                            comanddet.Parameters.AddWithValue("idIngreso", idIngreso);
                            comanddet.Parameters.AddWithValue("idProducto", det.IdProducto);
                            comanddet.Parameters.AddWithValue("idUnidad", det.IdUnidad);

                            comanddet.Transaction = trato;

                            fila = comanddet.ExecuteNonQuery();

                            SqlCommand comandStock = new SqlCommand("ActualizarStock", connection);

                            comandStock.CommandType = CommandType.StoredProcedure;
                            comandStock.Parameters.AddWithValue("idProducto", det.IdProducto);
                            comandStock.Parameters.AddWithValue("stock", det.Cantidad);

                            comandStock.Transaction = trato;
                            fila = comandStock.ExecuteNonQuery();
                        }
                    }
                    if (fila != 0)
                    {
                        trato.Commit();
                    }
                    else
                    {
                        trato.Rollback();
                    }

                }
                catch (SqlException ex)
                {
                    throw ex;
                }
                catch (Exception)
                {

                    throw;
                }
            }
        }
コード例 #4
0
 public static void RegistraIngreso(DAL.Ingreso ingreso)
 {
     DAL.Ingreso.registraIngreso(ingreso);
 }