BaseDock.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Linq;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using DevExpress.XtraEditors;
  11. namespace ProjectBase.Controls
  12. {
  13. public partial class BaseDock : DevExpress.XtraEditors.XtraForm
  14. {
  15. /// <summary>
  16. /// 子窗体数据保存的触发
  17. /// </summary>
  18. public event EventHandler OnDataSaved;
  19. /// <summary>
  20. /// 进行数据过滤的Sql条件,默认通过 Cache.Instance["DataFilterCondition"]获取
  21. /// </summary>
  22. public string DataFilterCondition { get; set; }
  23. /// <summary>
  24. /// 选择查看的公司ID
  25. /// </summary>
  26. public string SelectedCompanyID { get; set; }
  27. public BaseDock()
  28. {
  29. InitializeComponent();
  30. //为了保证一些界面控件的权限控制和身份确认,以及简化操作,在界面初始化的时候,从缓存里面内容(如果存在的话)
  31. //继承的子模块,也可以通过InitFunction()进行指定用户相关信息
  32. //this.LoginUserInfo = Cache.Instance["LoginUserInfo"] as LoginUserInfo;
  33. //this.FunctionDict = Cache.Instance["FunctionDict"] as Dictionary<string, string>;
  34. //// 进行数据过滤的Sql条件
  35. //this.DataFilterCondition = Cache.Instance["DataFilterCondition"] as string;
  36. //this.SelectedCompanyID = Cache.Instance["SelectedCompanyID"] as string;
  37. }
  38. /// <summary>
  39. /// 处理数据保存后的事件触发
  40. /// </summary>
  41. public virtual void ProcessDataSaved(object sender, EventArgs e)
  42. {
  43. if (OnDataSaved != null)
  44. {
  45. OnDataSaved(sender, e);
  46. }
  47. }
  48. /// <summary>
  49. /// 记录异常
  50. /// </summary>
  51. /// <param name="ex"></param>
  52. public void WriteException(Exception ex)
  53. {
  54. // 在本地记录异常
  55. //LogTextHelper.Error(ex);
  56. //MessageDxUtil.ShowError(ex.Message);
  57. }
  58. /// <summary>
  59. /// 处理异常信息
  60. /// </summary>
  61. /// <param name="ex">异常</param>
  62. public void ProcessException(Exception ex)
  63. {
  64. this.WriteException(ex);
  65. // 显示异常页面
  66. //FrmException frmException = new FrmException(this.UserInfo, ex);
  67. //frmException.ShowDialog();
  68. MessageBox.Show(ex.Message);//临时处理
  69. }
  70. /// <summary>
  71. /// 可供重写的窗体加载函数,子窗体特殊处理只需重写该函数
  72. /// </summary>
  73. public virtual void FormOnLoad()
  74. {
  75. }
  76. protected override void OnControlAdded(ControlEventArgs e)
  77. {
  78. if (!this.DesignMode)
  79. {
  80. System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(BaseDock));
  81. //this.Icon = WHC.WareHouseMis.DotUI.Properties.Resources.app;
  82. //this.StartPosition = FormStartPosition.CenterScreen;
  83. base.OnControlAdded(e);
  84. }
  85. }
  86. protected override void OnLoad(EventArgs e)
  87. {
  88. if (!this.DesignMode)
  89. {
  90. System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(BaseDock));
  91. this.StartPosition = FormStartPosition.CenterScreen;
  92. base.OnLoad(e);
  93. }
  94. }
  95. private void BaseForm_Load(object sender, EventArgs e)
  96. {
  97. if (!this.DesignMode)
  98. {
  99. // 设置鼠标繁忙状态
  100. this.Cursor = Cursors.WaitCursor;
  101. try
  102. {
  103. this.FormOnLoad();
  104. }
  105. catch (Exception ex)
  106. {
  107. this.ProcessException(ex);
  108. }
  109. finally
  110. {
  111. // 设置鼠标默认状态
  112. this.Cursor = Cursors.Default;
  113. }
  114. }
  115. }
  116. private void BaseForm_KeyUp(object sender, KeyEventArgs e)
  117. {
  118. switch (e.KeyCode)
  119. {
  120. case Keys.F5://刷新
  121. this.FormOnLoad();
  122. break;
  123. }
  124. }
  125. /// <summary>
  126. /// 初始化权限控制信息
  127. /// </summary>
  128. //public void InitFunction(LoginUserInfo userInfo, Dictionary<string, string> functionDict)
  129. //{
  130. // if (userInfo != null)
  131. // {
  132. // this.LoginUserInfo = userInfo;
  133. // }
  134. // if (functionDict != null && functionDict.Count > 0)
  135. // {
  136. // this.FunctionDict = functionDict;
  137. // }
  138. //}
  139. /// <summary>
  140. /// 是否具有访问指定控制ID的权限
  141. /// </summary>
  142. /// <param name="controlId">功能控制ID</param>
  143. /// <returns></returns>
  144. public bool HasFunction(string controlId)
  145. {
  146. bool result = false;
  147. if (string.IsNullOrEmpty(controlId))
  148. {
  149. result = true;
  150. }
  151. else if (FunctionDict != null && FunctionDict.ContainsKey(controlId))
  152. {
  153. result = true;
  154. }
  155. return result;
  156. }
  157. /// <summary>
  158. /// 登陆用户基础信息
  159. /// </summary>
  160. //public LoginUserInfo LoginUserInfo { get; set; }
  161. /// <summary>
  162. /// 登录用户具有的功能字典集合
  163. /// </summary>
  164. public Dictionary<string, string> FunctionDict { get; set; }
  165. //private AppInfo m_AppInfo = new AppInfo();
  166. /// <summary>
  167. /// 应用程序基础信息
  168. /// </summary>
  169. //public AppInfo AppInfo
  170. //{
  171. // get { return m_AppInfo; }
  172. // set { this.m_AppInfo = value; }
  173. //}
  174. }
  175. }