Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

392 lines
9.2 KiB

  1. using System;
  2. using System.Collections;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using System.IO;
  6. using System.Web;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using UDDI;
  10. using UDDI.API;
  11. using UDDI.Diagnostics;
  12. namespace UDDI.Web
  13. {
  14. /// <summary>
  15. /// Summary description for categorybrowser.
  16. /// </summary>
  17. public class CategoryBrowserControl : UddiControl
  18. {
  19. protected LinkButton rootLink;
  20. protected Panel panelTaxonomyList;
  21. protected Panel panelCategoryChooser;
  22. protected DataGrid taxonomyList;
  23. protected DataGrid categoryChooser;
  24. protected Label labelCategoryChooser;
  25. protected Label categoryTree;
  26. protected TaxonomyTreeControl taxonomyTree;
  27. private DataView taxonomies;
  28. protected int SelectedTaxonomyItemIndex;
  29. public CategoryBrowserControl()
  30. {
  31. }
  32. protected KeyedReferenceCollection categoryBag;
  33. protected CacheObject cache = null;
  34. public string ParentKeyValue
  35. {
  36. get{ return parentKeyValue; }
  37. }
  38. protected string parentKeyValue="";
  39. public string TaxonomyID
  40. {
  41. get{ return taxonomyID; }
  42. }
  43. protected string taxonomyID;
  44. public string TaxonomyName
  45. {
  46. get{ return taxonomyName; }
  47. }
  48. protected string taxonomyName;
  49. public string Path
  50. {
  51. get{ return path; }
  52. }
  53. protected string path="";
  54. public string TModelKey
  55. {
  56. get{ return tModelKey; }
  57. }
  58. protected string tModelKey;
  59. public string KeyName
  60. {
  61. get{ return keyName; }
  62. }
  63. protected string keyName;
  64. public string KeyValue
  65. {
  66. get{ return keyValue; }
  67. }
  68. protected string keyValue;
  69. public bool ShowNoCategoriesMessage
  70. {
  71. get { return showNoCategoriesMessage; }
  72. set { showNoCategoriesMessage = value; }
  73. }
  74. protected bool showNoCategoriesMessage;
  75. public int TaxonomyCount
  76. {
  77. get{ return taxonomies != null ? taxonomies.Count : 0; }
  78. }
  79. protected bool showallcategories = false;
  80. public bool ShowAllCategories
  81. {
  82. get{ return showallcategories; }
  83. set{ showallcategories=value; }
  84. }
  85. public void Initialize( KeyedReferenceCollection catbag, CacheObject co )
  86. {
  87. showNoCategoriesMessage = true;
  88. categoryBag = catbag;
  89. cache = co;
  90. }
  91. protected void Page_Init( object sender, EventArgs e )
  92. {
  93. }
  94. protected void Page_Load( object sender, EventArgs e )
  95. {
  96. taxonomyID = Request[ "taxonomyID" ];
  97. taxonomyName = Request[ "taxonomyName" ];
  98. tModelKey = Request[ "tModelKey" ];
  99. keyName = Request[ "keyName" ];
  100. keyValue = Request[ "keyValue" ];
  101. taxonomyTree.Click += new TaxonomyTreeControlEventHandler( TaxonomyTreeControl_Click );
  102. if( null!=rootLink )
  103. {
  104. rootLink.Text = Localization.GetString( "TAG_AVAILABLE_TAXONOMIES" );
  105. rootLink.Enabled = (null!=taxonomyID);
  106. rootLink.Click += new EventHandler( TaxonomyRootLink_Click );
  107. }
  108. Populate();
  109. }
  110. public void Populate()
  111. {
  112. if( null!=taxonomyID && ""!=taxonomyID )
  113. {
  114. if( null!=keyValue && ""!=keyValue )
  115. {
  116. PopulateTaxonomyTree();
  117. PopulateCategoryChooser();
  118. }
  119. }
  120. else
  121. {
  122. PopulateTaxonomyList( false );
  123. }
  124. }
  125. protected void PopulateTaxonomyList( bool single )
  126. {
  127. panelTaxonomyList.Visible = true;
  128. panelCategoryChooser.Visible = false;
  129. //DataView taxonomies = null;
  130. if( !single )
  131. {
  132. if( ShowAllCategories )
  133. {
  134. //get all taxonomies
  135. taxonomies = Taxonomy.GetTaxonomies();
  136. }
  137. else
  138. {
  139. taxonomies = Taxonomy.GetTaxonomiesForBrowsing();
  140. }
  141. }
  142. else
  143. {
  144. //get a single taxonomy for the list
  145. taxonomies = Taxonomy.GetTaxonomiesForBrowsing( "tModelKey = '"+tModelKey+"'","tModelKey" );
  146. }
  147. //make sure the visible text is html encoded
  148. foreach( DataRowView row in taxonomies )
  149. row[ "description" ] = HttpUtility.HtmlEncode( (string)row[ "description" ] );
  150. taxonomyList.DataSource = taxonomies;
  151. taxonomyList.DataBind();
  152. }
  153. protected void PopulateTaxonomyTree( )
  154. {
  155. panelTaxonomyList.Visible = false;
  156. panelCategoryChooser.Visible =true ;
  157. int id=Convert.ToInt32( taxonomyID );
  158. taxonomyTree.TaxonomyID = id;
  159. taxonomyTree.KeyName = taxonomyName;
  160. taxonomyTree.KeyValue = "__r00t__";
  161. TaxonomyTreeItemControl item=null;
  162. if( "__r00t__"!=keyValue && ""!=keyValue )
  163. {
  164. string parent = keyValue;
  165. while( null!=parent && ""!=parent )
  166. {
  167. if( null==item) item=new TaxonomyTreeItemControl();
  168. item.KeyValue = parent;
  169. //replace this with a way to get the keyName with the taxonomyID and the taxonomyValue
  170. item.KeyName = Taxonomy.GetTaxonomyKeyName( id, parent );
  171. item.TaxonomyID = id;
  172. item.Click += new TaxonomyTreeControlEventHandler( TaxonomyTreeControl_Click );
  173. parent = Taxonomy.GetTaxonomyParent( id, parent );
  174. if( ""==parent )break;
  175. TaxonomyTreeItemControl parentitem = new TaxonomyTreeItemControl();;
  176. parentitem.SetChild( item );
  177. item = parentitem;
  178. }
  179. }
  180. if( null!=item )
  181. {
  182. taxonomyTree.SetChild( item );
  183. taxonomyTree.SelectItem( item.Count );
  184. }
  185. else
  186. taxonomyTree.SelectItem( 0 );
  187. taxonomyTree.TaxonomyID = id;
  188. taxonomyTree.KeyName = taxonomyName;
  189. taxonomyTree.KeyValue = "__r00t__";
  190. }
  191. protected void PopulateCategoryChooser( )
  192. {
  193. panelTaxonomyList.Visible = false;
  194. panelCategoryChooser.Visible =true ;
  195. string root = ( "/" == Page.Request.ApplicationPath ) ? "" : Page.Request.ApplicationPath;
  196. int id = Convert.ToInt32( taxonomyID );
  197. if( Utility.StringEmpty( keyValue ) )
  198. {
  199. taxonomies = Taxonomy.GetTaxonomyChildrenRoot( id );
  200. }
  201. else
  202. {
  203. taxonomies = Taxonomy.GetTaxonomyChildrenNode( id, keyValue );
  204. }
  205. if( 0 == taxonomies.Count )
  206. {
  207. categoryChooser.Visible = false;
  208. if( true == showNoCategoriesMessage )
  209. {
  210. labelCategoryChooser.Text = Localization.GetString( "HEADING_NO_CATEGORIES" );
  211. }
  212. }
  213. else
  214. {
  215. foreach( DataRowView row in taxonomies )
  216. row[ "keyName" ] = HttpUtility.HtmlEncode( (string)row[ "keyName" ] );
  217. categoryChooser.Visible = true;
  218. labelCategoryChooser.Text = Localization.GetString( "TAG_SUBCATEGORIES" );
  219. categoryChooser.DataSource = taxonomies;
  220. categoryChooser.DataBind();
  221. }
  222. }
  223. public void Reset()
  224. {
  225. taxonomyID = null;
  226. taxonomyName = null;
  227. tModelKey = null;
  228. keyName = null;
  229. keyValue = null;
  230. PopulateTaxonomyList(false);
  231. }
  232. protected void CategoryChooser_OnPageChange( object sender, DataGridPageChangedEventArgs e )
  233. {
  234. categoryChooser.CurrentPageIndex = e.NewPageIndex;
  235. PopulateTaxonomyTree();
  236. PopulateCategoryChooser();
  237. }
  238. protected void CategoryChooser_Command( object sender, DataGridCommandEventArgs e )
  239. {
  240. switch( e.CommandName )
  241. {
  242. case "select":
  243. categoryChooser.CurrentPageIndex = 0;
  244. taxonomyID = e.Item.Cells[ 0 ].Text;
  245. parentKeyValue = e.Item.Cells[ 1 ].Text;
  246. keyName = e.Item.Cells[ 2 ].Text;
  247. keyValue = e.Item.Cells[ 4 ].Text;
  248. //path = path + "/:/" + keyName ;//+ "|" + keyValue + "|" + taxonomyID;
  249. PopulateTaxonomyTree();
  250. PopulateCategoryChooser();
  251. if( null!=cache )
  252. {
  253. cache.FindBusiness.CategoryBag.Clear();
  254. cache.FindBusiness.CategoryBag.Add( keyName, keyValue, "uuid:"+tModelKey );
  255. cache.FindService.CategoryBag.Clear();
  256. cache.FindService.CategoryBag.Add( keyName, keyValue, "uuid:"+tModelKey );
  257. cache.FindTModel.CategoryBag.Clear();
  258. cache.FindTModel.CategoryBag.Add( keyName, keyValue, "uuid:"+tModelKey );
  259. cache.Save();
  260. }
  261. if( null!=this.categoryBag )
  262. {
  263. }
  264. break;
  265. default:
  266. break;
  267. }
  268. }
  269. protected void TaxonomyList_OnCommand( object sender, DataGridCommandEventArgs e )
  270. {
  271. switch( e.CommandName )
  272. {
  273. case "browse":
  274. categoryChooser.CurrentPageIndex = 0;
  275. panelTaxonomyList.Visible = false;
  276. panelCategoryChooser.Visible = true;
  277. categoryChooser.CurrentPageIndex = 0;
  278. taxonomyID = e.Item.Cells[ 0 ].Text;
  279. taxonomyName = e.Item.Cells[ 1 ].Text;
  280. tModelKey = e.Item.Cells[ 3 ].Text;
  281. keyName = "";
  282. keyValue = "";
  283. path = "";
  284. PopulateTaxonomyTree();
  285. PopulateCategoryChooser();
  286. break;
  287. default:
  288. break;
  289. }
  290. }
  291. private void TaxonomyRootLink_Click( object sender, EventArgs e )
  292. {
  293. this.Reset();
  294. }
  295. private void TaxonomyTreeControl_Click( object sender, TaxonomyTreeControlEventArgs e )
  296. {
  297. //reset the page index on the categoryChooser
  298. this.categoryChooser.CurrentPageIndex = 0;
  299. //set the relevent info from the selected taxonomy item
  300. this.taxonomyID = e.Item.TaxonomyID.ToString();
  301. this.keyName = e.Item.KeyName;
  302. this.keyValue = ( ( "__r00t__"==e.Item.KeyValue)?"":e.Item.KeyValue);
  303. //populate the data
  304. this.PopulateTaxonomyTree();
  305. this.PopulateCategoryChooser();
  306. }
  307. }
  308. }