ManageForms.aspx.cs
上传用户:husern
上传日期:2022-03-24
资源大小:534k
文件大小:5k
源码类别:

编辑器/阅读器

开发平台:

C#

  1. // -- FILE ------------------------------------------------------------------
  2. // name       : ManageForms.aspx.cs
  3. // project    : Itenso Web User Forms
  4. // created    : Jani Giannoudis - 2008.10.30
  5. // language   : c#
  6. // environment: .NET 2.0
  7. // copyright  : (c) 2008 by Itenso GmbH, Switzerland
  8. // --------------------------------------------------------------------------
  9. using System;
  10. using System.IO;
  11. using System.Configuration;
  12. using System.Web.UI;
  13. using System.Web.UI.WebControls;
  14. using Itenso.WebUserForms.Controls;
  15. // --------------------------------------------------------------------------
  16. public partial class ManageFormsPage : System.Web.UI.Page
  17. {
  18. // ------------------------------------------------------------------------
  19. private string WorkingFormName
  20. {
  21. get { return ViewState[ "WorkingForm" ] as string; }
  22. set { ViewState[ "WorkingForm" ] = value; }
  23. } // WorkingFormName
  24. // ------------------------------------------------------------------------
  25. private string FormsPath
  26. {
  27. get { return ConfigurationManager.AppSettings[ "FormsPath" ]; }
  28. } // FormsPath
  29. // ------------------------------------------------------------------------
  30. private string LookupItemText
  31. {
  32. get { return ConfigurationManager.AppSettings[ "LookupItemText" ]; }
  33. } // LookupItemText
  34. // ------------------------------------------------------------------------
  35. private string LookupItemValue
  36. {
  37. get { return ConfigurationManager.AppSettings[ "LookupItemValue" ]; }
  38. } // LookupItemValue
  39. // ------------------------------------------------------------------------
  40. private int LookupItemCount
  41. {
  42. get { return int.Parse( ConfigurationManager.AppSettings[ "LookupItemCount" ] ); }
  43. } // LookupItemCount
  44. // ------------------------------------------------------------------------
  45. protected override void OnLoad( EventArgs e )
  46. {
  47. if ( !Page.IsPostBack )
  48. {
  49. SetupFormList();
  50. }
  51. SetupForm();
  52. base.OnLoad( e );
  53. } // OnLoad
  54. // ------------------------------------------------------------------------
  55. private void SetupForm()
  56. {
  57. FormPlaceHolder.Controls.Clear();
  58. string workingFormName = WorkingFormName;
  59. if ( string.IsNullOrEmpty( workingFormName ) )
  60. {
  61. return;
  62. }
  63. // load form control
  64. UserControl userForm = new UserFormLoader( workingFormName, "workForm" ).Load();
  65. FormPlaceHolder.Controls.Add( userForm );
  66. FormTitleLabel.Text = workingFormName;
  67. // lookups
  68. SetupLookups( userForm );
  69. // data-binding expressions
  70. DataBind();
  71. } // SetupForm
  72. // ------------------------------------------------------------------------
  73. private void SetupFormList()
  74. {
  75. string formsPath = FormsPath;
  76. if ( string.IsNullOrEmpty( formsPath ) )
  77. {
  78. throw new InvalidOperationException( "missing FormsPath setting" );
  79. }
  80. string physicalFormsPath = MapPath( formsPath );
  81. DirectoryInfo directoryInfo = new DirectoryInfo( physicalFormsPath );
  82. if ( Directory.Exists( directoryInfo.FullName ) )
  83. {
  84. foreach ( FileInfo fileInfo in directoryInfo.GetFiles( "*" + UserFormInfo.FileExtension ) )
  85. {
  86. FormListBox.Items.Add( new ListItem(
  87. fileInfo.Name.Replace( UserFormInfo.FileExtension, string.Empty ),
  88. formsPath + "/" + fileInfo.Name ) );
  89. }
  90. }
  91. if ( FormListBox.Items.Count > 0 )
  92. {
  93. FormListLabel.Visible = true;
  94. FormListBox.Visible = true;
  95. FormListBox.SelectedIndex = 0;
  96. WorkingFormName = FormListBox.Items[ 0 ].Value;
  97. }
  98. else
  99. {
  100. FormListLabel.Visible = false;
  101. FormListBox.Visible = false;
  102. FormTitleLabel.Text = "Please place a UserControl into the folder " + FormsPath;
  103. }
  104. } // SetupFormList
  105. // ------------------------------------------------------------------------
  106. private void SetupLookups( Control control )
  107. {
  108. // lookup setup
  109. LookupFieldCollector lookupCollector = new LookupFieldCollector( control );
  110. lookupCollector.Collect();
  111. foreach ( ILookupField listBoxLookup in lookupCollector.LookupFields )
  112. {
  113. listBoxLookup.Items.Clear();
  114. for ( int i = 0; i < LookupItemCount; i++ )
  115. {
  116. listBoxLookup.Items.Add( new ListItem( 
  117. string.Format( LookupItemText, i + 1 ),
  118. string.Format( LookupItemValue, i + 1 ).ToString() ) );
  119. }
  120. if ( listBoxLookup.Items.Count > 0 )
  121. {
  122. listBoxLookup.Items[ 0 ].Selected = true;
  123. }
  124. }
  125. } // SetupLookups
  126. // ------------------------------------------------------------------------
  127. protected void SelectedFormChanged( object sender, EventArgs e )
  128. {
  129. WorkingFormName = FormListBox.SelectedValue;
  130. SetupForm();
  131. } // SelectedFormChanged
  132. } // class ManageFormsPage
  133. // -- EOF -------------------------------------------------------------------