public string Editar(DatosAperturaCierre AperturaCierre, ref MySqlConnection MySqlConexion, ref MySqlTransaction MySqlTransaccion) { string respuesta = ""; try { MySqlCommand ComandoMySql = new MySqlCommand(); ComandoMySql.Connection = MySqlConexion; ComandoMySql.Transaction = MySqlTransaccion; ComandoMySql.CommandText = "spEditarAperturaCierre"; ComandoMySql.CommandType = CommandType.StoredProcedure; MySqlParameter parametroIdAperturaCierre = new MySqlParameter(); parametroIdAperturaCierre.ParameterName = "parIdAperturaCierre"; parametroIdAperturaCierre.MySqlDbType = MySqlDbType.Int32; parametroIdAperturaCierre.Value = AperturaCierre.IdAperturaCierre; ComandoMySql.Parameters.Add(parametroIdAperturaCierre); MySqlParameter parametroIdCierre = new MySqlParameter(); parametroIdCierre.ParameterName = "parIdCierre"; parametroIdCierre.MySqlDbType = MySqlDbType.Int32; parametroIdCierre.Value = AperturaCierre.IdCierre; ComandoMySql.Parameters.Add(parametroIdCierre); MySqlParameter parametroDiferencia = new MySqlParameter(); parametroDiferencia.ParameterName = "parDiferencia"; parametroDiferencia.MySqlDbType = MySqlDbType.Decimal; parametroDiferencia.Value = AperturaCierre.Diferencia; ComandoMySql.Parameters.Add(parametroDiferencia); MySqlParameter parametroEstado = new MySqlParameter(); parametroEstado.ParameterName = "parEstado"; parametroEstado.MySqlDbType = MySqlDbType.VarChar; parametroEstado.Value = AperturaCierre.Estado; ComandoMySql.Parameters.Add(parametroEstado); respuesta = ComandoMySql.ExecuteNonQuery() == 1 ? "OK" : "Ocurrió un error al intentar editar el registro. Intente nuevamente."; } catch (Exception ex) { respuesta = ex.Message; } return(respuesta); }
public string Insertar(DatosAperturaCierre AperturaCierre, ref int idAperturaCierre, ref MySqlConnection MySqlConexion, ref MySqlTransaction MySqlTransaccion) { string respuesta = ""; try { MySqlCommand ComandoMySql = new MySqlCommand(); ComandoMySql.Connection = MySqlConexion; ComandoMySql.Transaction = MySqlTransaccion; ComandoMySql.CommandText = "spInsertarAperturaCierre"; ComandoMySql.CommandType = CommandType.StoredProcedure; MySqlParameter parametroIdAperturaCierre = new MySqlParameter(); parametroIdAperturaCierre.ParameterName = "parIdAperturaCierre"; parametroIdAperturaCierre.MySqlDbType = MySqlDbType.Int32; parametroIdAperturaCierre.Direction = ParameterDirection.Output; ComandoMySql.Parameters.Add(parametroIdAperturaCierre); MySqlParameter parametroIdApertura = new MySqlParameter(); parametroIdApertura.ParameterName = "parIdApertura"; parametroIdApertura.MySqlDbType = MySqlDbType.Int32; parametroIdApertura.Value = AperturaCierre.IdApertura; ComandoMySql.Parameters.Add(parametroIdApertura); MySqlParameter parametroEstado = new MySqlParameter(); parametroEstado.ParameterName = "parEstado"; parametroEstado.MySqlDbType = MySqlDbType.VarChar; parametroEstado.Value = AperturaCierre.Estado; ComandoMySql.Parameters.Add(parametroEstado); respuesta = ComandoMySql.ExecuteNonQuery() == 1 ? "OK" : "Ocurrió un error al intentar ingresar el registro. Intente nuevamente."; idAperturaCierre = Convert.ToInt32(ComandoMySql.Parameters["parIdAperturaCierre"].Value); } catch (Exception ex) { respuesta = ex.Message; } //finally //{ // if (MySqlConexion.State == ConnectionState.Open) MySqlConexion.Close(); //} return(respuesta); }
public string Insertar(DatosApertura Apertura, List <DatosDetalleApertura> Detalle, DatosAperturaCierre AperturaCierre, ref int idAperturaCierre) { string respuesta = ""; MySqlConnection MySqlConexion = new MySqlConnection(); //MySQL try { //MySql MySqlConexion.ConnectionString = ConexionMySQL.cadenaConexion; MySqlConexion.Open(); MySqlTransaction MySqlTransaccion = MySqlConexion.BeginTransaction(); MySqlCommand ComandoMySql = new MySqlCommand(); ComandoMySql.Connection = MySqlConexion; ComandoMySql.Transaction = MySqlTransaccion; ComandoMySql.CommandText = "spInsertarApertura"; ComandoMySql.CommandType = CommandType.StoredProcedure; MySqlParameter parametroIdApertura = new MySqlParameter(); parametroIdApertura.ParameterName = "parIdApertura"; parametroIdApertura.MySqlDbType = MySqlDbType.Int32; parametroIdApertura.Direction = ParameterDirection.Output; ComandoMySql.Parameters.Add(parametroIdApertura); MySqlParameter parametroIdCaja = new MySqlParameter(); parametroIdCaja.ParameterName = "parIdCaja"; parametroIdCaja.MySqlDbType = MySqlDbType.Int32; parametroIdCaja.Value = Apertura.IdCaja; ComandoMySql.Parameters.Add(parametroIdCaja); MySqlParameter parametroIdEmpleado = new MySqlParameter(); parametroIdEmpleado.ParameterName = "parIdEmpleado"; parametroIdEmpleado.MySqlDbType = MySqlDbType.Int32; parametroIdEmpleado.Value = Apertura.IdEmpleado; ComandoMySql.Parameters.Add(parametroIdEmpleado); MySqlParameter parametroFechaHora = new MySqlParameter(); parametroFechaHora.ParameterName = "parFechaHora"; parametroFechaHora.MySqlDbType = MySqlDbType.DateTime; parametroFechaHora.Value = Apertura.FechaHora; ComandoMySql.Parameters.Add(parametroFechaHora); MySqlParameter parametroMontoInicial = new MySqlParameter(); parametroMontoInicial.ParameterName = "parMontoInicial"; parametroMontoInicial.MySqlDbType = MySqlDbType.Decimal; parametroMontoInicial.Value = Apertura.MontoInicial; ComandoMySql.Parameters.Add(parametroMontoInicial); //MySqlParameter parametroAperturaPorDefecto = new MySqlParameter(); //parametroAperturaPorDefecto.ParameterName = "parAperturaPorDefecto"; //parametroAperturaPorDefecto.MySqlDbType = MySqlDbType.Byte; //parametroAperturaPorDefecto.Value = Apertura.AperturaPorDefecto; //ComandoMySql.Parameters.Add(parametroAperturaPorDefecto); respuesta = ComandoMySql.ExecuteNonQuery() == 1 ? "OK" : "Ocurrió un error al intentar ingresar el registro. Intente nuevamente."; if (respuesta.Equals("OK")) { IdApertura = Convert.ToInt32(ComandoMySql.Parameters["parIdApertura"].Value); foreach (DatosDetalleApertura detalle in Detalle) { detalle.IdApertura = IdApertura; respuesta = detalle.Insertar(detalle, ref MySqlConexion, ref MySqlTransaccion); if (!respuesta.Equals("OK")) { break; } } if (respuesta.Equals("OK")) { //DatosAperturaCierre AperturaCierre = new DatosAperturaCierre(); AperturaCierre.IdApertura = IdApertura; respuesta = AperturaCierre.Insertar(AperturaCierre, ref idAperturaCierre, ref MySqlConexion, ref MySqlTransaccion); } } if (respuesta.Equals("OK")) { DatosCaja Caja = new DatosCaja(); Caja.IdCaja = IdCaja; respuesta = Caja.Abrir(Caja, ref MySqlConexion, ref MySqlTransaccion); } if (respuesta.Equals("OK")) { MySqlTransaccion.Commit(); } else { MySqlTransaccion.Rollback(); } } catch (Exception ex) { respuesta = ex.Message; } finally { if (MySqlConexion.State == ConnectionState.Open) { MySqlConexion.Close(); } } return(respuesta); }