Exemplo n.º 1
0
        public string Eliminar(DACFLOCT_LOCAL parCategorias)
        {
            string        Respuesta   = "";
            SqlConnection SqlConexion = new SqlConnection();

            try
            {
                SqlConexion.ConnectionString = DConexion.CnBDActivo;
                SqlConexion.Open();

                SqlCommand SqlComando = new SqlCommand();
                SqlComando.Connection  = SqlConexion;
                SqlComando.CommandText = "Produccion.EliminarCategoria";
                SqlComando.CommandType = CommandType.StoredProcedure;

                SqlParameter ParLOCID = new SqlParameter();
                ParLOCID.ParameterName = "@LOCID";
                ParLOCID.SqlDbType     = SqlDbType.Int;
                ParLOCID.Value         = parCategorias.LOCID;
                SqlComando.Parameters.Add(ParLOCID);

                SqlComando.ExecuteNonQuery();
                Respuesta = "Y";
            }

            catch (SqlException ex)
            {
                if (ex.Number == 547)
                {
                    Respuesta = "No puedes eliminar una categoría que cuenta con Productos. Debes eliminar o actualizar sus Productos antes de eliminar la categoría.";
                }

                else
                {
                    Respuesta = "Error al intentar ejecutar el procedimiento almacenado Produccion.EliminarCategoria. " + ex.Message;
                }
            }

            finally
            {
                if (SqlConexion.State == ConnectionState.Open)
                {
                    SqlConexion.Close();
                }
            }

            return(Respuesta);
        }
Exemplo n.º 2
0
        public DataTable Buscar(DACFLOCT_LOCAL parLOC)
        {
            DataTable     TablaDatos  = new DataTable("dbo.DACFLOCT_LOCAL");
            SqlConnection SqlConexion = new SqlConnection();

            try
            {
                SqlConexion.ConnectionString = DConexion.CnBDActivo;
                SqlConexion.Open();

                SqlCommand SqlComando = new SqlCommand();
                SqlComando.Connection  = SqlConexion;
                SqlComando.CommandText = "dbo.SpBuscar";
                SqlComando.CommandType = CommandType.StoredProcedure;

                SqlParameter ParNombre_Buscado = new SqlParameter();
                ParNombre_Buscado.ParameterName = "@NombreBuscado";
                ParNombre_Buscado.SqlDbType     = SqlDbType.VarChar;
                ParNombre_Buscado.Size          = parLOC.Nombre_Buscado.Length;
                ParNombre_Buscado.Value         = parLOC.Nombre_Buscado;
                SqlComando.Parameters.Add(ParNombre_Buscado);

                SqlDataAdapter SqlAdaptadorDatos = new SqlDataAdapter(SqlComando);
                SqlAdaptadorDatos.Fill(TablaDatos);
            }

            catch (Exception ex)
            {
                TablaDatos = null;
                throw new Exception("Error al intentar ejecutar el procedimiento almacenado Produccion.BuscarCategoria. " + ex.Message, ex);
            }

            finally
            {
                if (SqlConexion.State == ConnectionState.Open)
                {
                    SqlConexion.Close();
                }
            }

            return(TablaDatos);
        }
Exemplo n.º 3
0
        public string Editar(DACFLOCT_LOCAL parLocal)
        {
            string        Respuesta   = "";
            SqlConnection SqlConexion = new SqlConnection();

            try
            {
                SqlConexion.ConnectionString = DConexion.CnBDActivo;
                SqlConexion.Open();

                SqlCommand SqlComando = new SqlCommand();
                SqlComando.Connection  = SqlConexion;
                SqlComando.CommandText = "dbo.SpACFLOCT_LOCALActualizar";
                SqlComando.CommandType = CommandType.StoredProcedure;

                SqlParameter ParLOCID = new SqlParameter();
                ParLOCID.ParameterName = "@LOCID";
                ParLOCID.SqlDbType     = SqlDbType.Int;
                ParLOCID.Value         = parLocal.LOCID;
                SqlComando.Parameters.Add(ParLOCID);

                SqlParameter ParLOCLOCAL = new SqlParameter();
                ParLOCLOCAL.ParameterName = "@LOCLOCAL";
                ParLOCLOCAL.SqlDbType     = SqlDbType.VarChar;
                ParLOCLOCAL.Size          = parLocal.LOCLOCAL.Length;
                ParLOCLOCAL.Value         = parLocal.LOCLOCAL;
                SqlComando.Parameters.Add(ParLOCLOCAL);

                SqlParameter ParLOCDIRECCION = new SqlParameter();
                ParLOCDIRECCION.ParameterName = "@LOCDIRECCION";
                ParLOCDIRECCION.SqlDbType     = SqlDbType.VarChar;
                ParLOCDIRECCION.Size          = parLocal.LOCDIRECCION.Length;
                ParLOCDIRECCION.Value         = parLocal.LOCDIRECCION;
                SqlComando.Parameters.Add(ParLOCDIRECCION);

                SqlParameter ParSEGMENT = new SqlParameter();
                ParSEGMENT.ParameterName = "@SEGMENT";
                ParSEGMENT.SqlDbType     = SqlDbType.VarChar;
                ParSEGMENT.Size          = parLocal.SEGMENT.Length;
                ParSEGMENT.Value         = parLocal.SEGMENT;
                SqlComando.Parameters.Add(ParSEGMENT);


                SqlComando.ExecuteNonQuery();
                Respuesta = "Y";
            }

            catch (SqlException ex)
            {
                if (ex.Number == 8152)
                {
                    Respuesta = "Has introducido demasiados caracteres en uno de los campos.";
                }
                else if (ex.Number == 2627)
                {
                    Respuesta = "Ya existe una categoría con ese Nombre.";
                }
                else if (ex.Number == 515)
                {
                    Respuesta = "No puedes dejar el campo Nombre vacío.";
                }
                else
                {
                    Respuesta = "Error al intentar ejecutar el procedimiento almacenado Produccion.EditarCategoria. " + ex.Message;
                }
            }

            finally
            {
                if (SqlConexion.State == ConnectionState.Open)
                {
                    SqlConexion.Close();
                }
            }

            return(Respuesta);
        }