예제 #1
0
        private void btnRegistrarMov_Click_1(object sender, EventArgs e)
        {
            int identity;

            using (WsSistemaBancario.CajaChicaServiceClient caja = new WsSistemaBancario.CajaChicaServiceClient())
            {
                Modelos.Modelos.CajaChicaModel cc = new CajaChicaModel();
                cc.Id_TurnoUsuario1 = Convert.ToInt32(session.Turno.IdTurUsu);
                cc.Id_TurnoUsuario2 = Convert.ToInt32(this.cmbVentanillas.SelectedValue);
                string tipo = cmbTipoMov.SelectedValue.ToString();
                cc.Tipo_Accion = (tipo.Equals("Cargo") ? "C" : "A");

                identity = caja.Crear(cc, Convert.ToInt32(session.UserCodigo));
                if (identity == 0)
                {
                    MessageBox.Show("No se pudo registrar la cabecera!");
                    return;
                }
            }
            using (WsSistemaBancario.DetalleCajaChicaServiceClient de_cc = new WsSistemaBancario.DetalleCajaChicaServiceClient())
            {
                bool exito = false;
                foreach (DataGridViewRow r in dgvSoles.Rows)
                {
                    int col = Convert.ToInt32(r.Cells[1].Value);
                    if (col != 0)
                    {
                        Modelos.Modelos.DetalleCajaChicaModel det = new DetalleCajaChicaModel();
                        det.Id_CajaChica = identity;
                        det.Denominacion = this.DevuelveDenominacionNumero(r.Cells[0].Value.ToString());
                        det.Cantidad     = Convert.ToInt32(r.Cells[1].Value.ToString());
                        det.Moneda       = "S";
                        exito            = de_cc.DetalleCajaChica_Crear(det, Convert.ToInt32(session.UserCodigo));
                    }
                }
                foreach (DataGridViewRow r in dgvDolares.Rows)
                {
                    int col = Convert.ToInt32(r.Cells[1].Value);
                    if (col != 0)
                    {
                        Modelos.Modelos.DetalleCajaChicaModel det = new DetalleCajaChicaModel();
                        det.Id_CajaChica = identity;
                        det.Denominacion = this.DevuelveDenominacionNumero(r.Cells[0].Value.ToString());
                        det.Cantidad     = Convert.ToInt32(r.Cells[1].Value.ToString());
                        det.Moneda       = "D";
                        exito            = de_cc.DetalleCajaChica_Crear(det, Convert.ToInt32(session.UserCodigo));
                    }
                }
                if (!exito)
                {
                    MessageBox.Show("No se registró correctamente!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show("Se registró correctamente", "Correcto", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
        /// <summary>
        /// Selects all the objects of Caja_ChicaModel table.
        /// </summary>
        ///
        public DetalleCajaChicaModel GetDetalleCajaChicaModel(int aID)
        {
            DetalleCajaChicaModel GetDetalleCajaChicaModel = null;

            try
            {
                using (var connection = Util.ConnectionFactory.conexion())
                {
                    connection.Open();

                    SqlCommand command = connection.CreateCommand();

                    command.Parameters.AddWithValue("@pMode", 2);
                    command.Parameters.AddWithValue("@ID", aID);


                    command.CommandType = CommandType.StoredProcedure;

                    command.CommandText = "sp_tDetalleCajaChica";

                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            int     ID           = (int)(reader["ID"]);
                            int     Id_CajaChica = (int)(reader["Id_CajaChica"]);
                            decimal Denominacion = (decimal)(reader["Denominacion"]);
                            int     Cantidad     = (int)(reader["Cantidad"]);
                            string  Moneda       = (string)(reader["Moneda"]);

                            GetDetalleCajaChicaModel = new DetalleCajaChicaModel
                            {
                                Id           = ID,
                                Id_CajaChica = Id_CajaChica,
                                Denominacion = Denominacion,
                                Cantidad     = Cantidad,
                                Moneda       = Moneda,
                            };
                        }
                    }
                }

                return(GetDetalleCajaChicaModel);
            }
            catch (Exception)
            {
                return(null);
            }
        }
        /// <summary>
        /// Updates a record to the Caja_ChicaModel table.
        /// returns True if value saved successfully else false
        /// Throw exception with message value EXISTS if the data is duplicate
        /// </summary>
        public bool Update(DetalleCajaChicaModel aDetalleCajaChicaModel, int ID_user)
        {
            try
            {
                using (var connection = Util.ConnectionFactory.conexion())
                {
                    connection.Open();

                    SqlTransaction sqlTran = connection.BeginTransaction();

                    SqlCommand command = connection.CreateCommand();

                    command.Transaction = sqlTran;

                    command.Parameters.AddWithValue("@pMode", 5);
                    command.Parameters.AddWithValue("@ID_user", ID_user);
                    command.Parameters.AddWithValue("@ID", aDetalleCajaChicaModel.Id);
                    command.Parameters.AddWithValue("@Id_CajaChica", aDetalleCajaChicaModel.Id_CajaChica);
                    command.Parameters.AddWithValue("@Denominacion", aDetalleCajaChicaModel.Denominacion);
                    command.Parameters.AddWithValue("@Cantidad", aDetalleCajaChicaModel.Cantidad);
                    command.Parameters.AddWithValue("@Moneda", aDetalleCajaChicaModel.Moneda);

                    command.CommandType = CommandType.StoredProcedure;
                    command.CommandText = "sp_tDetalleCajaChica";

                    int afectados = command.ExecuteNonQuery();

                    // Commit the transaction.
                    sqlTran.Commit();

                    connection.Close();
                    connection.Dispose();

                    if (afectados > 0)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
 /// <summary>
 /// Updates a record to the detalle caja chica table.
 /// returns True if value saved successfully else false
 /// Throw exception with message value EXISTS if the data is duplicate
 /// </summary>
 public bool Editar(DetalleCajaChicaModel aCajaChica, int id_user)
 {
     return(ADDetalleCajaChicaManager.Update(aCajaChica, id_user));
 }
 /// <summary>
 /// Saves a record to the detalle caja chica table.
 /// returns True if value saved successfully else false
 /// Throw exception with message value EXISTS if the data is duplicate
 /// </summary>
 public bool Crear(DetalleCajaChicaModel aCajaChica, int id_user)
 {
     return(ADDetalleCajaChicaManager.Insert(aCajaChica, id_user));
 }
 public bool DetalleCajaChica_Editar(DetalleCajaChicaModel aDetalleCajaChica, int id_user)
 {
     return(BLDetalleCajaChica.Editar(aDetalleCajaChica, id_user));
 }