Esempio n. 1
0
        public string Cerrar(DatosCaja Caja, ref MySqlConnection MySqlConexion, ref MySqlTransaction MySqlTransaccion)
        {
            string respuesta = "";

            try
            {
                MySqlCommand ComandoMySql = new MySqlCommand();
                ComandoMySql.Connection  = MySqlConexion;
                ComandoMySql.Transaction = MySqlTransaccion;
                ComandoMySql.CommandText = "spCerrarCaja";
                ComandoMySql.CommandType = CommandType.StoredProcedure;

                MySqlParameter parametroIdCaja = new MySqlParameter();
                parametroIdCaja.ParameterName = "parIdCaja";
                parametroIdCaja.MySqlDbType   = MySqlDbType.Int32;
                parametroIdCaja.Value         = Caja.IdCaja;
                ComandoMySql.Parameters.Add(parametroIdCaja);

                respuesta = ComandoMySql.ExecuteNonQuery() == 1 ? "OK" : "Ocurrió un error al intentar editar el registro. Intente nuevamente.";
            }
            catch (Exception ex)
            {
                respuesta = ex.Message;
            }
            return(respuesta);
        }
Esempio n. 2
0
        public string Eliminar(DatosCaja Caja, List <DatosDetalleCaja> DetallesCaja)
        {
            string          respuesta     = "";
            MySqlConnection MySqlConexion = new MySqlConnection(); // MySQL

            try
            {
                //MySQL
                MySqlConexion.ConnectionString = ConexionMySQL.cadenaConexion;
                MySqlConexion.Open();
                MySqlCommand     ComandoMySql     = new MySqlCommand();
                MySqlTransaction MySqlTransaccion = MySqlConexion.BeginTransaction();
                ComandoMySql.Connection  = MySqlConexion;
                ComandoMySql.CommandText = "spEliminarCaja";
                ComandoMySql.CommandType = CommandType.StoredProcedure;

                MySqlParameter parametroIdCaja = new MySqlParameter();
                parametroIdCaja.ParameterName = "parIdCaja";
                parametroIdCaja.MySqlDbType   = MySqlDbType.Int32;
                parametroIdCaja.Value         = Caja.IdCaja;
                ComandoMySql.Parameters.Add(parametroIdCaja);

                respuesta = ComandoMySql.ExecuteNonQuery() == 1 ? "OK" : "Ocurrió un error al intentar eliminar el registro. Intente nuevamente.";

                if (respuesta.Equals("OK"))
                {
                    foreach (DatosDetalleCaja detalleCaja in DetallesCaja)
                    {
                        detalleCaja.IdDetalleCaja = Convert.ToInt32(ComandoMySql.Parameters["parIdDetalleCaja"].Value);
                        respuesta = detalleCaja.Eliminar(detalleCaja, ref MySqlConexion, ref MySqlTransaccion);
                        if (!respuesta.Equals("OK"))
                        {
                            break;
                        }
                    }
                }

                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);
        }
Esempio n. 3
0
        public string Eliminar(DatosCaja Caja)
        {
            string          respuesta     = "";
            MySqlConnection MySqlConexion = new MySqlConnection(); // MySQL

            try
            {
                //MySQL
                MySqlConexion.ConnectionString = ConexionMySQL.cadenaConexion;
                MySqlConexion.Open();
                MySqlCommand ComandoMySql = new MySqlCommand();
                ComandoMySql.Connection  = MySqlConexion;
                ComandoMySql.CommandText = "spEliminarCaja";
                ComandoMySql.CommandType = CommandType.StoredProcedure;

                MySqlParameter parametroIdCaja = new MySqlParameter();
                parametroIdCaja.ParameterName = "parIdCaja";
                parametroIdCaja.MySqlDbType   = MySqlDbType.Int32;
                parametroIdCaja.Value         = Caja.IdCaja;
                ComandoMySql.Parameters.Add(parametroIdCaja);

                respuesta = ComandoMySql.ExecuteNonQuery() == 1 ? "OK" : "Ocurrió un error al intentar eliminar el registro. Intente nuevamente.";
            }
            catch (Exception ex)
            {
                respuesta = ex.Message;
            }
            finally
            {
                if (MySqlConexion.State == ConnectionState.Open)
                {
                    MySqlConexion.Close();
                }
            }
            return(respuesta);
        }
Esempio n. 4
0
        public string Editar(DatosCaja Caja, List <DatosDetalleCaja> DetallesCaja)
        {
            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.CommandText = "spEditarCaja";
                ComandoMySql.CommandType = CommandType.StoredProcedure;

                MySqlParameter parametroIdCaja = new MySqlParameter();
                parametroIdCaja.ParameterName = "parIdCaja";
                parametroIdCaja.MySqlDbType   = MySqlDbType.Int32;
                parametroIdCaja.Value         = Caja.IdCaja;
                ComandoMySql.Parameters.Add(parametroIdCaja);

                MySqlParameter parametroCaja = new MySqlParameter();
                parametroCaja.ParameterName = "parCaja";
                parametroCaja.MySqlDbType   = MySqlDbType.VarChar;
                parametroCaja.Size          = 30;
                parametroCaja.Value         = Caja.Caja;
                ComandoMySql.Parameters.Add(parametroCaja);

                MySqlParameter parametroFormaCobro = new MySqlParameter();
                parametroFormaCobro.ParameterName = "parFormaCobro";
                parametroFormaCobro.MySqlDbType   = MySqlDbType.VarChar;
                parametroFormaCobro.Size          = 20;
                parametroFormaCobro.Value         = Caja.FormaCobro;
                ComandoMySql.Parameters.Add(parametroFormaCobro);

                MySqlParameter parametroAperturaAutomatica = new MySqlParameter();
                parametroAperturaAutomatica.ParameterName = "parAperturaAutomatica";
                parametroAperturaAutomatica.MySqlDbType   = MySqlDbType.Byte;
                parametroAperturaAutomatica.Value         = Caja.AperturaAutomatica;
                ComandoMySql.Parameters.Add(parametroAperturaAutomatica);

                MySqlParameter parametroTerminal = new MySqlParameter();
                parametroTerminal.ParameterName = "parTerminal";
                parametroTerminal.MySqlDbType   = MySqlDbType.VarChar;
                parametroTerminal.Size          = 45;
                parametroTerminal.Value         = Caja.Terminal;
                ComandoMySql.Parameters.Add(parametroTerminal);

                respuesta = ComandoMySql.ExecuteNonQuery() == 1 ? "OK" : "Ocurrió un error al intentar editar el registro. Intente nuevamente.";

                if (respuesta.Equals("OK"))
                {
                    foreach (DatosDetalleCaja detalleCaja in DetallesCaja)
                    {
                        if (detalleCaja.IdDetalleCaja < 1)
                        {
                            respuesta = detalleCaja.Insertar(detalleCaja, ref MySqlConexion, ref MySqlTransaccion);
                        }
                        else
                        {
                            respuesta = detalleCaja.Editar(detalleCaja, ref MySqlConexion, ref MySqlTransaccion);
                        }
                        if (!respuesta.Equals("OK"))
                        {
                            break;
                        }
                    }
                }

                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);
        }
Esempio n. 5
0
        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);
        }