Advertisement
Sonic3R

UI+BL

Oct 21st, 2011
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.00 KB | None | 0 0
  1. /*  USER INTERFACE */
  2.  
  3. public partial class UserInterfaceLayer : System.Web.UI.Page
  4.    {
  5.       protected void Page_Load( object sender, EventArgs e ) {
  6.          LoadTree( tree );
  7.          //TreeLoad( tree, @"D:\XML Project\XMLAppStabiplan\XMLAppStabiplan\example.xml" );
  8.       }
  9.       protected void LoadTree( TreeView tree ) {
  10.          tree.Nodes.Clear();
  11.          BusinessLayerArcht layer = new BusinessLayerArcht();
  12.          layer.Load();
  13.  
  14.          foreach ( CategoriesCtrlDto cto in layer.Categories ) {
  15.             TreeNode node_category = new TreeNode(cto.Name);
  16.             tree.Nodes.Add( node_category );
  17.  
  18.             foreach ( LinksCtrlDto lk in cto.Links ) {
  19.                TreeNode node_link = new TreeNode( lk.Name );
  20.                node_category.ChildNodes.Add( node_link );
  21.             }          
  22.          }
  23.       }
  24.  
  25.  
  26.  
  27.  
  28.  
  29. /* BUSINESS LAYER ARCHITECTURE */
  30. public class BusinessLayerArcht
  31.    {
  32.       /// <summary>
  33.       /// list of categories
  34.       /// </summary>
  35.       private List<CategoriesCtrlDto> _categories;
  36.  
  37.       /// <summary>
  38.       /// call to urlstorage class
  39.       /// </summary>
  40.       private UrlStorage store = UrlStorage.instance;
  41.      
  42.       /// <summary>
  43.       /// public constructor
  44.       /// </summary>
  45.       public BusinessLayerArcht() {
  46.       }
  47.  
  48.       /// <summary>
  49.       /// Load categories
  50.       /// </summary>
  51.       public void Load() {
  52.          _categories = store.readXMLtoLIST();
  53.       }
  54.  
  55.       /// <summary>
  56.       /// browse the category and get the matched name
  57.       /// </summary>
  58.       /// <param name="name"></param>
  59.       /// <returns></returns>
  60.       private CategoriesCtrlDto GetCategWithName(string name) {
  61.          CategoriesCtrlDto categ = null;
  62.  
  63.          foreach ( CategoriesCtrlDto ct in _categories ) {
  64.             if ( ct.Name == name ) {
  65.                categ = ct;
  66.                break;
  67.             }
  68.          }
  69.  
  70.          return categ;
  71.       }
  72.  
  73.       /// <summary>
  74.       /// add link function, it has lists to sent to data layer for insert process
  75.       /// </summary>
  76.       /// <param name="source"></param>
  77.       /// <param name="Categ"></param>
  78.       /// <param name="lks"></param>
  79.       /// <returns></returns>
  80.       public bool add_link( string link_name, string link_url, string link_descr, string category_name ) {
  81.  
  82.          //bool if_exist = false;
  83.          bool added_successfully = false;
  84.  
  85.          if ( string.IsNullOrEmpty( link_name ) )
  86.             throw new ArgumentNullException( "add_link link_name BL" );
  87.          if ( string.IsNullOrEmpty( category_name ) )
  88.             throw new ArgumentNullException( "add_link category_name BL" );
  89.          if ( string.IsNullOrEmpty( link_url ) )
  90.             throw new ArgumentNullException( "add_link link_url BL" );
  91.          if ( string.IsNullOrEmpty( link_descr ) )
  92.             throw new ArgumentNullException( "add_link link_descr BL" );
  93.  
  94.          CategoriesCtrlDto categ = GetCategWithName(category_name);
  95.          
  96.          if(categ != null)
  97.          {
  98.             if ( categ.LinkExists( link_url ) ) {
  99.                throw new ArgumentOutOfRangeException( "add link BL" );
  100.             } else {
  101.                List<LinksCtrlDto> lists = categ.AddLink( link_url, link_name, link_descr );
  102.                _categories.Add( categ );
  103.  
  104.                added_successfully = store.add_link(category_name,link_url,link_name,link_descr);
  105.             }
  106.          }
  107.          else
  108.          {
  109.             throw new ArgumentNullException( "find category BL" );
  110.          }          
  111.  
  112.          return added_successfully;
  113.       }
  114.  
  115.  
  116.       /// <summary>
  117.       /// add a category and create a list of category and send to DL for insert process
  118.       /// </summary>
  119.       /// <param name="source"></param>
  120.       /// <param name="category_name"></param>
  121.       /// <returns></returns>
  122.       public bool add_category( string category_name ) {
  123.  
  124.          //bool if_exist = false;
  125.          bool added_successfully = false;
  126.  
  127.          if ( string.IsNullOrEmpty( category_name ) )
  128.             throw new ArgumentNullException( "add_category link_descr BL" );
  129.  
  130.          CategoriesCtrlDto categ = GetCategWithName( category_name );
  131.  
  132.          if ( categ != null ) {
  133.             throw new ArgumentOutOfRangeException( "add_category BL" );
  134.          } else {
  135.             _categories.Add( new CategoriesCtrlDto( category_name, null ) );
  136.             added_successfully = store.add_category( category_name );
  137.          }
  138.  
  139.          return added_successfully;
  140.       }
  141.  
  142.  
  143.       /// <summary>
  144.       /// Delete a link and add to a list to be passed to DL for deletion process
  145.       /// after if the deletion process returns true then we can remove that link from the list
  146.       /// </summary>
  147.       /// <param name="source"></param>
  148.       /// <param name="link_url"></param>
  149.       /// <param name="category_name"></param>
  150.       /// <returns></returns>
  151.       public bool delete_link(string link_url, string category_name) {
  152.        
  153.          bool removed_successfully = false;
  154.        
  155.  
  156.          if ( string.IsNullOrEmpty( link_url ) )
  157.             throw new ArgumentNullException( "delete_link link_url BL" );
  158.          if ( string.IsNullOrEmpty( category_name ) )
  159.             throw new ArgumentNullException( "delete_link link_url BL" );
  160.          
  161.          CategoriesCtrlDto categ = GetCategWithName( category_name );
  162.  
  163.          if ( categ != null ) {
  164.             if ( categ.LinkExists( link_url ) ) {            
  165.                removed_successfully = store.delete_link( category_name, link_url );
  166.                categ.DeleteLink( link_url );
  167.             }
  168.          } else {
  169.             throw new ArgumentNullException( "delete_link BL" );
  170.          }      
  171.  
  172.             return removed_successfully;  
  173.       }
  174.  
  175.  
  176.       /// <summary>
  177.       /// delete a category (if it exists) and send parameter to DL
  178.       /// for deletion process
  179.       /// </summary>
  180.       /// <param name="source"></param>
  181.       /// <param name="category_name"></param>
  182.       /// <returns></returns>
  183.       public bool delete_category( string category_name ) {
  184.          //bool if_exist = false;
  185.          bool removed_successfully = false;
  186.  
  187.          if ( string.IsNullOrEmpty( category_name ) )
  188.             throw new ArgumentNullException( "remove_category cat_name BL" );
  189.  
  190.          CategoriesCtrlDto categ = GetCategWithName( category_name );
  191.  
  192.          if ( categ == null ) {
  193.             throw new ArgumentOutOfRangeException( "remove_category BL" );
  194.          } else {
  195.             removed_successfully = store.delete_category( category_name );
  196.             _categories.Remove( categ );
  197.          }
  198.  
  199.          return removed_successfully;
  200.       }
  201.  
  202.  
  203.       /// <summary>
  204.       /// set List as readonly collection
  205.       /// </summary>
  206.       public ReadOnlyCollection<CategoriesCtrlDto> Categories {
  207.          get {
  208.             if ( this._categories == null )
  209.                throw new ArgumentNullException( "ReadonlyCategory BL Exception" );
  210.             else
  211.             return _categories.AsReadOnly();
  212.          }
  213.  
  214.       }
  215.    }
  216.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement