示例#1
0
        public bool InsertarBoleta(DBoleta boleta)
        {
            int           rpta   = 0;
            string        cadena = "sp_insertar_boleta";
            SqlConnection cn     = new SqlConnection();

            try
            {
                // code here
                cn.ConnectionString = Conexion.conectar;
                cn.Open();

                using (SqlCommand cmd = new SqlCommand(cadena, cn))
                {
                    cmd.Parameters.AddWithValue("@serie", boleta.Serie);
                    cmd.Parameters.AddWithValue("@correlativo", boleta.Correlativo);
                    cmd.Parameters.AddWithValue("@idventa", boleta.IdVenta);
                    cmd.CommandType = CommandType.StoredProcedure;

                    rpta = cmd.ExecuteNonQuery();
                    if (rpta == 1)
                    {
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error ... ???", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);

                throw;
            }
            finally
            {
                if (cn.State == ConnectionState.Open)
                {
                    cn.Close();
                }
            }
            return(false);
        }
示例#2
0
        public string Insertar(DBoleta Boleta)
        {
            string        rpta   = "";
            SqlConnection sqlCon = new SqlConnection();

            try
            {
                sqlCon.ConnectionString = Conexion.cn;
                sqlCon.Open();
                //Comandos
                SqlCommand sqlCmd = new SqlCommand();
                sqlCmd.Connection  = sqlCon;
                sqlCmd.CommandText = "sp_insertarBoleta";
                sqlCmd.CommandType = CommandType.StoredProcedure;

                SqlParameter ParNroBoleta = new SqlParameter();
                ParNroBoleta.ParameterName = "@nroBoleta";
                ParNroBoleta.SqlDbType     = SqlDbType.Int;
                ParNroBoleta.Direction     = ParameterDirection.Output;
                sqlCmd.Parameters.Add(ParNroBoleta);

                SqlParameter ParSerie = new SqlParameter();
                ParSerie.ParameterName = "@serie";
                ParSerie.SqlDbType     = SqlDbType.Int;
                ParSerie.Value         = Boleta.Serie;
                sqlCmd.Parameters.Add(ParSerie);

                SqlParameter ParFecha = new SqlParameter();
                ParFecha.ParameterName = "@fecha";
                ParFecha.SqlDbType     = SqlDbType.DateTime;
                ParFecha.Value         = Boleta.Fecha;
                sqlCmd.Parameters.Add(ParFecha);

                SqlParameter ParIdVenta = new SqlParameter();
                ParIdVenta.ParameterName = "@idVenta";
                ParIdVenta.SqlDbType     = SqlDbType.Int;
                ParIdVenta.Value         = Boleta.IdVenta;
                sqlCmd.Parameters.Add(ParIdVenta);

                SqlParameter ParEstado = new SqlParameter();
                ParEstado.ParameterName = "@estado";
                ParEstado.SqlDbType     = SqlDbType.VarChar;
                ParEstado.Size          = 20;
                ParEstado.Value         = Boleta.Estado;
                sqlCmd.Parameters.Add(ParEstado);

                SqlParameter ParIdCliente = new SqlParameter();
                ParIdCliente.ParameterName = "@idCliente";
                ParIdCliente.SqlDbType     = SqlDbType.Int;
                ParIdCliente.Value         = Boleta.IdCliente;
                sqlCmd.Parameters.Add(ParIdCliente);

                rpta = sqlCmd.ExecuteNonQuery() == 1 ? "OK" : "No se ingresó el Registro";
            }
            catch (Exception ex)
            {
                rpta = ex.Message;
            }
            finally
            {
                if (sqlCon.State == ConnectionState.Open)
                {
                    sqlCon.Close();
                }
            }
            return(rpta);
        }