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> /// Deletes 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> /// <summary> /// Selects the Single object of Caja_ChicaModel table. /// </summary> /// <summary> /// Selects all the objects of Caja_ChicaModel table. /// </summary> /// public CajaChicaModel GetCajaChicaModel(int aID) { CajaChicaModel GetCajaChicaModel = 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_tCajaChica"; SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { int ID = (int)(reader["ID"]); string Tipo_Accion = (string)(reader["Tipo_Accion"]); int Id_TurnoUsuario1 = (int)(reader["Id_TurnoUsuario1"]); int Id_TurnoUsuario2 = (int)(reader["Id_TurnoUsuario2"]); GetCajaChicaModel = new CajaChicaModel { Id = ID, Tipo_Accion = Tipo_Accion, Id_TurnoUsuario1 = Id_TurnoUsuario1, Id_TurnoUsuario2 = Id_TurnoUsuario2, }; } } } return(GetCajaChicaModel); } 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(CajaChicaModel aCaja_ChicaModel, 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", aCaja_ChicaModel.Id); command.Parameters.AddWithValue("@Tipo_Accion", aCaja_ChicaModel.Tipo_Accion); command.Parameters.AddWithValue("@Id_TurnoUsuario1", aCaja_ChicaModel.Id_TurnoUsuario1); command.Parameters.AddWithValue("@Id_TurnoUsuario2", aCaja_ChicaModel.Id_TurnoUsuario2); command.CommandType = CommandType.StoredProcedure; command.CommandText = "sp_tCajaChica"; 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> /// Saves 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 int Insert(CajaChicaModel aCaja_ChicaModel, int id_user) { try { using (var connection = Util.ConnectionFactory.conexion()) { connection.Open(); SqlCommand command = connection.CreateCommand(); command.Parameters.AddWithValue("@pMode", 4); command.Parameters.AddWithValue("@ID_user", id_user); command.Parameters.AddWithValue("@ID", aCaja_ChicaModel.Id); command.Parameters.AddWithValue("@Tipo_Accion", aCaja_ChicaModel.Tipo_Accion); command.Parameters.AddWithValue("@Id_TurnoUsuario1", aCaja_ChicaModel.Id_TurnoUsuario1); command.Parameters.AddWithValue("@Id_TurnoUsuario2", aCaja_ChicaModel.Id_TurnoUsuario2); //command.Parameters.AddWithValue("@IDENTITY",SqlDbType.Int,ParameterDirection.Output); SqlParameter paramId = new SqlParameter("@IDENTITY", SqlDbType.Int); paramId.Direction = ParameterDirection.Output; command.Parameters.Add(paramId); command.CommandType = CommandType.StoredProcedure; command.CommandText = "sp_tCajaChica"; int afectados = 0; afectados = (int)command.ExecuteNonQuery(); //devuelve el identity creado int identity = Convert.ToInt32(command.Parameters["@IDENTITY"].Value.ToString()); connection.Close(); connection.Dispose(); if (afectados > 0) { return(identity); } else { return(0); } } } catch (Exception) { return(0); } }
public bool Editar(CajaChicaModel aCajaChica, int id_user) { return(BLCajaChica.Editar(aCajaChica, id_user)); }
/// <summary> /// Updates a record to the 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(CajaChicaModel aCajaChica, int id_user) { return(ADCajaChicaManager.Update(aCajaChica, id_user)); }
public int Crear(CajaChicaModel aCajaChica, int id_user) { return(BLCajaChica.Crear(aCajaChica, id_user)); }
/// <summary> /// Saves a record to the caja chica table. /// returns True if value saved successfully else false /// Throw exception with message value EXISTS if the data is duplicate /// </summary> public int Crear(CajaChicaModel aCajaChica, int id_user) { return(ADCajaChicaManager.Insert(aCajaChica, id_user)); }