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.

256 lines
5.9 KiB

  1. using System;
  2. using System.Data;
  3. using System.Web;
  4. using System.Web.UI;
  5. using System.Web.UI.WebControls;
  6. using UDDI;
  7. using UDDI.API.Business;
  8. using UDDI.API.Service;
  9. using UDDI.API.ServiceType;
  10. namespace UDDI.Web
  11. {
  12. public delegate void SelectEventHandler( object sender, string key, string name );
  13. public abstract class SelectionControl : UserControl
  14. {
  15. public event SelectEventHandler Select;
  16. protected Panel resultsPanel = null;
  17. protected TextBox query = null;
  18. protected DataGrid grid = null;
  19. protected Label count = null;
  20. protected RequiredFieldValidator requiredField = null;
  21. public SelectionControl()
  22. {
  23. }
  24. public void ResetControl()
  25. {
  26. resultsPanel.Visible = false;
  27. }
  28. protected override void OnInit( EventArgs e )
  29. {
  30. requiredField.ErrorMessage = Localization.GetString( "ERROR_FIELD_REQUIRED" );
  31. }
  32. protected void Grid_OnItemCommand( object sender, DataGridCommandEventArgs e )
  33. {
  34. switch( e.CommandName )
  35. {
  36. case "select":
  37. OnSelect( this, e );
  38. break;
  39. }
  40. }
  41. protected void Grid_OnPageIndexChange( object sender, DataGridPageChangedEventArgs e )
  42. {
  43. Page.Validate();
  44. if( Page.IsValid )
  45. {
  46. grid.CurrentPageIndex = e.NewPageIndex;
  47. OnSearch( this, query.Text );
  48. }
  49. }
  50. protected void Search_OnClick( object sender, EventArgs e )
  51. {
  52. Page.Validate();
  53. if( Page.IsValid )
  54. {
  55. OnSearch( this, query.Text );
  56. }
  57. }
  58. protected virtual void OnSelect( object sender, DataGridCommandEventArgs e )
  59. {
  60. switch( e.CommandName )
  61. {
  62. case "select":
  63. string key = ((UddiLabel)e.Item.Cells[ 0 ].FindControl( "key" )).Text;
  64. string name = ((LinkButton)e.Item.Cells[ 1 ].FindControl( "name" )).Text;
  65. name = HttpUtility.HtmlDecode( name );
  66. if( null != Select )
  67. Select( this, key, name );
  68. break;
  69. }
  70. }
  71. protected virtual void OnSearch( object sender, string query )
  72. {
  73. resultsPanel.Visible = true;
  74. }
  75. }
  76. public class PublisherSelector : SelectionControl
  77. {
  78. public PublisherSelector()
  79. {
  80. }
  81. protected override void OnSearch( object sender, string query )
  82. {
  83. base.OnSearch( sender, query );
  84. if( query.IndexOf( "%" ) < 0 )
  85. query += "%";
  86. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor();
  87. DataSet ds = new DataSet();
  88. sp.ProcedureName = "ADM_findPublisher";
  89. sp.Parameters.Add( "@name", SqlDbType.NVarChar, UDDI.Constants.Lengths.Name );
  90. sp.Parameters.SetString( "@name", query );
  91. sp.Fill( ds, "Publishers" );
  92. if( null != ds.Tables[ "Publishers" ] )
  93. {
  94. DataView view;
  95. //
  96. // To eliminate the system account from the list
  97. // we should not do it this way. we should change the SP to accept a role
  98. // and then elimiate the rows before they placed in the DataSet.
  99. //
  100. //
  101. // If the user is an Admin, don't filter the data
  102. //
  103. if( UDDI.Context.User.IsAdministrator )
  104. {
  105. view = ds.Tables[ "Publishers" ].DefaultView;
  106. }
  107. else
  108. {
  109. view = new DataView( ds.Tables[ "Publishers" ],//use the publisher table
  110. "PUID <> 'System'", //filter by puid.
  111. "name", //name is the sort column
  112. DataViewRowState.CurrentRows ); // Show all current rows after filtering
  113. }
  114. grid.DataSource = view;
  115. grid.DataBind();
  116. count.Text = String.Format(
  117. Localization.GetString( "TEXT_QUERY_COUNT" ),
  118. view.Count );
  119. }
  120. else
  121. {
  122. grid.DataSource = null;
  123. grid.DataBind();
  124. count.Text = String.Format(
  125. Localization.GetString( "TEXT_QUERY_COUNT" ),
  126. 0 );
  127. }
  128. }
  129. }
  130. public class TModelSelector : SelectionControl
  131. {
  132. public TModelSelector()
  133. {
  134. }
  135. protected override void OnSearch( object sender, string query )
  136. {
  137. base.OnSearch( sender, query );
  138. if( query.IndexOf( "%" ) < 0 )
  139. query += "%";
  140. FindTModel find = new FindTModel();
  141. find.Name = query;
  142. TModelList list = find.Find();
  143. grid.DataSource = list.TModelInfos;
  144. grid.DataBind();
  145. count.Text = String.Format(
  146. Localization.GetString( "TEXT_QUERY_COUNT" ),
  147. list.TModelInfos.Count );
  148. }
  149. }
  150. public class BusinessSelector : SelectionControl
  151. {
  152. public BusinessSelector()
  153. {
  154. }
  155. protected override void OnSearch( object sender, string query )
  156. {
  157. if( null == query )
  158. return;
  159. query = query.Trim();
  160. if( 0 == query.Length )
  161. return;
  162. base.OnSearch( sender, query );
  163. if( query.IndexOf( "%" ) < 0 )
  164. query += "%";
  165. FindBusiness find = new FindBusiness();
  166. find.Names.Add( null, query );
  167. BusinessList list = find.Find();
  168. grid.DataSource = list.BusinessInfos;
  169. grid.DataBind();
  170. count.Text = String.Format(
  171. Localization.GetString( "TEXT_QUERY_COUNT" ),
  172. list.BusinessInfos.Count );
  173. }
  174. }
  175. public class ServiceSelector : SelectionControl
  176. {
  177. public ServiceSelector()
  178. {
  179. }
  180. protected override void OnSearch( object sender, string query )
  181. {
  182. if( null == query )
  183. return;
  184. query = query.Trim();
  185. if( 0 == query.Length )
  186. return;
  187. base.OnSearch( sender, query );
  188. if( query.IndexOf( "%" ) < 0 )
  189. query += "%";
  190. FindService find = new FindService();
  191. find.Names.Add( null, query );
  192. ServiceList list = find.Find();
  193. grid.DataSource = list.ServiceInfos;
  194. grid.DataBind();
  195. count.Text = String.Format(
  196. Localization.GetString( "TEXT_QUERY_COUNT" ),
  197. list.ServiceInfos.Count );
  198. }
  199. }
  200. }