Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    Definizione DataSet Tipizzati e BLL

    Ciao a tutti, sto cercando di partire da alcuni esempi trovati sul sito ASP.NET nella definizione del livello BLL

    quello che non capisco è come modificare, nel codice che allego, la definizione del tabledataadapter norhwind con i mio tabledataadapter, presente nel dataset tipizzato che ho creato


    per quale motivo se metto: NomeDataSetTipizzato. non viene visualizzato nessun eveno ... idem con NomeTableDatapter.

    ???

    Codice PHP:

    using System
    ;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using NorthwindTableAdapters;

    [
    System.ComponentModel.DataObject]
    public class 
    MailBoxBLL
    {
        private 
    ProductsTableAdapter _productsAdapter null;
        protected 
    ProductsTableAdapter Adapter
        
    {
            
    get {
                if (
    _productsAdapter == null)
                    
    _productsAdapter = new ProductsTableAdapter();

                return 
    _productsAdapter
            }
        }

        [
    System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Selecttrue)]
        public 
    Northwind.ProductsDataTable GetProducts()
        {
            return 
    Adapter.GetProducts();
        }

        [
    System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Selectfalse)]
        public 
    Northwind.ProductsDataTable GetProductByProductID(int productID)
        {
            return 
    Adapter.GetProductByProductID(productID);
        }

        [
    System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Selectfalse)]
        public 
    Northwind.ProductsDataTable GetProductsByCategoryID(int categoryID)
        {
            if (
    categoryID 0)
                return 
    GetProducts();
            else
                return 
    Adapter.GetProductsByCategoryID(categoryID);
        }

        [
    System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Selectfalse)]
        public 
    Northwind.ProductsDataTable GetProductsBySupplierID(int supplierID)
        {
            return 
    Adapter.GetProductsBySupplierID(supplierID);
        }

        
    #region Custom Paging-Related Methods
        
    public int TotalNumberOfProducts()
        {
            return 
    Adapter.TotalNumberOfProducts().GetValueOrDefault();
        }

        [
    System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Selectfalse)]
        public 
    Northwind.ProductsDataTable GetProductsPaged(int startRowIndexint maximumRows)
        {
            return 
    Adapter.GetProductsPaged(startRowIndexmaximumRows);
        }

        [
    System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Selectfalse)]
        public 
    Northwind.ProductsDataTable GetProductsPagedAndSorted(string sortExpressionint startRowIndexint maximumRows)
        {
            return 
    Adapter.GetProductsPagedAndSorted(sortExpressionstartRowIndexmaximumRows);
        }
        
    #endregion

        
    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Inserttrue)]
        public 
    bool AddProduct(string productNameintsupplierIDintcategoryIDstring quantityPerUnit
                              
    decimalunitPriceshortunitsInStockshortunitsOnOrdershortreorderLevel
                              
    bool discontinued)
        {
            
    // Create a new ProductRow instance
            
    Northwind.ProductsDataTable products = new Northwind.ProductsDataTable();
            
    Northwind.ProductsRow product products.NewProductsRow();

            
    product.ProductName productName;
            if (
    supplierID == nullproduct.SetSupplierIDNull(); else product.SupplierID supplierID.Value;
            if (
    categoryID == nullproduct.SetCategoryIDNull(); else product.CategoryID categoryID.Value;
            if (
    quantityPerUnit == nullproduct.SetQuantityPerUnitNull(); else product.QuantityPerUnit quantityPerUnit;
            if (
    unitPrice == nullproduct.SetUnitPriceNull(); else product.UnitPrice unitPrice.Value;
            if (
    unitsInStock == nullproduct.SetUnitsInStockNull(); else product.UnitsInStock unitsInStock.Value;
            if (
    unitsOnOrder == nullproduct.SetUnitsOnOrderNull(); else product.UnitsOnOrder unitsOnOrder.Value;
            if (
    reorderLevel == nullproduct.SetReorderLevelNull(); else product.ReorderLevel reorderLevel.Value;
            
    product.Discontinued discontinued;

            
    // Add the new product
            
    products.AddProductsRow(product);
            
    int rowsAffected Adapter.Update(products);

            
    // Return true if precisely one row was inserted, otherwise false
            
    return rowsAffected == 1;
        }

        
    #region UpdateProduct Overloads
        
    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Updatetrue)]
        public 
    bool UpdateProduct(string productNameintsupplierIDintcategoryIDstring quantityPerUnit,
                                  
    decimalunitPriceshortunitsInStockshortunitsOnOrdershortreorderLevel,
                                  
    bool discontinuedint productID)
        {
            
    Northwind.ProductsDataTable products Adapter.GetProductByProductID(productID);
            if (
    products.Count == 0)
                
    // no matching record found, return false
                
    return false;

            
    Northwind.ProductsRow product products[0];

            
    // Business rule check - cannot discontinue a product that's supplied by only
            // one supplier
            
    if (discontinued)
            {
                
    // Get the products we buy from this supplier
                
    Northwind.ProductsDataTable productsBySupplier Adapter.GetProductsBySupplierID(product.SupplierID);

                if (
    productsBySupplier.Count == 1)
                    
    // this is the only product we buy from this supplier
                    
    throw new ApplicationException("You cannot mark a product as discontinued if its the only product purchased from a supplier");
            }

            
    product.ProductName productName;
            if (
    supplierID == nullproduct.SetSupplierIDNull(); else product.SupplierID supplierID.Value;
            if (
    categoryID == nullproduct.SetCategoryIDNull(); else product.CategoryID categoryID.Value;
            if (
    quantityPerUnit == nullproduct.SetQuantityPerUnitNull(); else product.QuantityPerUnit quantityPerUnit;
            if (
    unitPrice == nullproduct.SetUnitPriceNull(); else product.UnitPrice unitPrice.Value;
            if (
    unitsInStock == nullproduct.SetUnitsInStockNull(); else product.UnitsInStock unitsInStock.Value;
            if (
    unitsOnOrder == nullproduct.SetUnitsOnOrderNull(); else product.UnitsOnOrder unitsOnOrder.Value;
            if (
    reorderLevel == nullproduct.SetReorderLevelNull(); else product.ReorderLevel reorderLevel.Value;
            
    product.Discontinued discontinued;

            
    // Update the product record
            
    int rowsAffected Adapter.Update(product);

            
    // Return true if precisely one row was updated, otherwise false
            
    return rowsAffected == 1;
        }

        [
    System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Updatefalse)]
        public 
    bool UpdateProduct(string productNamedecimalunitPriceint productID)
        {
            
    Northwind.ProductsDataTable products Adapter.GetProductByProductID(productID);
            if (
    products.Count == 0)
                
    // no matching record found, return false
                
    return false;

            
    Northwind.ProductsRow product products[0];

            
    product.ProductName productName;
            if (
    unitPrice == nullproduct.SetUnitPriceNull(); else product.UnitPrice unitPrice.Value;

            
    // Update the product record
            
    int rowsAffected Adapter.Update(product);

            
    // Return true if precisely one row was updated, otherwise false
            
    return rowsAffected == 1;
        }

        [
    System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Updatefalse)]
        public 
    bool UpdateProduct(string productNamedecimalunitPriceshortunitsInStockint productID)
        {
            
    Northwind.ProductsDataTable products Adapter.GetProductByProductID(productID);
            if (
    products.Count == 0)
                
    // no matching record found, return false
                
    return false;

            
    Northwind.ProductsRow product products[0];

            
    // Make sure the price hasn't more than doubled
            
    if (unitPrice != null && !product.IsUnitPriceNull())
                if (
    unitPrice product.UnitPrice 2)
                    throw new 
    ApplicationException("When updating a product's price, the new price cannot exceed twice the original price.");


            
    product.ProductName productName;
            if (
    unitPrice == nullproduct.SetUnitPriceNull(); else product.UnitPrice unitPrice.Value;
            if (
    unitsInStock == nullproduct.SetUnitsInStockNull(); else product.UnitsInStock unitsInStock.Value;

            
    // Update the product record
            
    int rowsAffected Adapter.Update(product);

            
    // Return true if precisely one row was updated, otherwise false
            
    return rowsAffected == 1;
        }

        [
    System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Updatefalse)]
        public 
    bool UpdateProduct(string productNameintcategoryIDintsupplierIDbool discontinuedint productID)
        {
            
    Northwind.ProductsDataTable products Adapter.GetProductByProductID(productID);
            if (
    products.Count == 0)
                
    // no matching record found, return false
                
    return false;

            
    Northwind.ProductsRow product products[0];

            
    product.ProductName productName;
            if (
    supplierID == nullproduct.SetSupplierIDNull(); else product.SupplierID supplierID.Value;
            if (
    categoryID == nullproduct.SetCategoryIDNull(); else product.CategoryID categoryID.Value;
            
    product.Discontinued discontinued;

            
    // Update the product record
            
    int rowsAffected Adapter.Update(product);

            
    // Return true if precisely one row was updated, otherwise false
            
    return rowsAffected == 1;
        }

        [
    System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Updatefalse)]
        public 
    bool UpdateProduct(string productNamestring quantityPerUnitint productID)
        {
            
    Northwind.ProductsDataTable products Adapter.GetProductByProductID(productID);
            if (
    products.Count == 0)
                
    // no matching record found, return false
                
    return false;

            
    Northwind.ProductsRow product products[0];

            
    product.ProductName productName;
            if (
    quantityPerUnit == nullproduct.SetQuantityPerUnitNull(); else product.QuantityPerUnit quantityPerUnit;

            
    // Update the product record
            
    int rowsAffected Adapter.Update(product);

            
    // Return true if precisely one row was updated, otherwise false
            
    return rowsAffected == 1;
        }

        public 
    bool UpdateProduct(decimal unitPriceAdjustmentPercentageint productID)
        {
            
    Northwind.ProductsDataTable products Adapter.GetProductByProductID(productID);
            if (
    products.Count == 0)
                
    // no matching record found, return false
                
    return false;

            
    Northwind.ProductsRow product products[0];

            
    // Adjust the UnitPrice by the specified percentage (if it's not NULL)
            
    if (!product.IsUnitPriceNull())
                
    product.UnitPrice *= unitPriceAdjustmentPercentage;

            
    // Update the product record
            
    int rowsAffected Adapter.Update(product);

            
    // Return true if precisely one row was updated, otherwise false
            
    return rowsAffected == 1;
        }
        
    #endregion

        
    public int DiscontinueAllProductsForSupplier(int supplierID)
        {
            return 
    Adapter.DiscontinueAllProductsForSupplier(supplierID);
        }

        [
    System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Deletetrue)]
        public 
    bool DeleteProduct(int productID)
        {
            
    int rowsAffected Adapter.Delete(productID);

            
    // Return true if precisely one row was deleted, otherwise false
            
    return rowsAffected == 1;
        }


  2. #2
    Nessun aiutino??

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.