19a0a42c0086f4798f964d25ca8cbfbc63f56c4a.svn-base 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. extern alias G1;
  2. extern alias G2;
  3. extern alias T1;
  4. extern alias T2;
  5. using System;
  6. using System.Drawing;
  7. using System.Collections;
  8. using System.ComponentModel;
  9. using System.Windows.Forms;
  10. using System.Reflection;
  11. using Toolbar1 = G1::Infragistics.Win.UltraWinToolbars;
  12. using Toolbar2 = G2::Infragistics.Win.UltraWinToolbars;
  13. using UltraText1 = T1::Infragistics.Win.UltraWinEditors;
  14. using UltraText2 = T2::Infragistics.Win.UltraWinEditors;
  15. using System.Text.RegularExpressions;
  16. namespace Core.Mes.ClientFrameWork
  17. {
  18. /// <summary>
  19. /// Core Mes 平台所有业务子窗体的基类
  20. /// </summary>
  21. public class FrmBase : System.Windows.Forms.Form
  22. {
  23. #region " RemotingGate "
  24. public string Key = "";
  25. public bool On_Off_Thread = false;
  26. public Form _ParentForm;
  27. #endregion
  28. private System.ComponentModel.IContainer components = null;
  29. public FrmBase()
  30. {
  31. //
  32. // Windows 窗体设计器支持所必需的
  33. //
  34. InitializeComponent();
  35. //
  36. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  37. //
  38. }
  39. /// <summary>
  40. /// 清理所有正在使用的资源。
  41. /// </summary>
  42. protected override void Dispose(bool disposing)
  43. {
  44. if (disposing)
  45. {
  46. if (components != null)
  47. {
  48. components.Dispose();
  49. }
  50. }
  51. base.Dispose(disposing);
  52. }
  53. #region Windows 窗体设计器生成的代码
  54. /// <summary>
  55. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  56. /// 此方法的内容。
  57. /// </summary>
  58. private void InitializeComponent()
  59. {
  60. this.SuspendLayout();
  61. //
  62. // FrmBase
  63. //
  64. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  65. this.ClientSize = new System.Drawing.Size(1012, 733);
  66. this.Name = "FrmBase";
  67. this.Text = "FrmBase";
  68. this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
  69. this.Load += new System.EventHandler(this.FrmBase_Load);
  70. this.ResumeLayout(false);
  71. }
  72. #endregion
  73. private void FrmBase_Load(object sender, EventArgs e)
  74. {
  75. AddToolBarListener();
  76. }
  77. private void AddToolBarListener()
  78. {
  79. //获取所有控件
  80. System.Reflection.FieldInfo[] fieldInfo = this.GetType().GetFields(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
  81. for (int i = 0; i < fieldInfo.Length; i++)
  82. {
  83. try
  84. {
  85. if (fieldInfo[i].FieldType == typeof(Toolbar1.UltraToolbarsManager))
  86. {
  87. Toolbar1.UltraToolbarsManager ut1 = fieldInfo[i].GetValue(this) as Toolbar1.UltraToolbarsManager;
  88. ut1.ToolClick += new Toolbar1.ToolClickEventHandler(_ToolbarClick_Listener1);
  89. //EventInfo ei = fieldInfo[i].FieldType.GetEvent("ToolClick");
  90. //MethodInfo mi = this.GetType().GetMethod("_ToolbarClick_Listener", BindingFlags.Instance);
  91. //Delegate dg = Delegate.CreateDelegate(ei.EventHandlerType, fieldInfo[i].GetValue(this), mi);
  92. //ei.AddEventHandler(fieldInfo[i].GetValue(this), dg);
  93. }
  94. else if (fieldInfo[i].FieldType == typeof(Toolbar2.UltraToolbarsManager))
  95. {
  96. Toolbar2.UltraToolbarsManager ut2 = fieldInfo[i].GetValue(this) as Toolbar2.UltraToolbarsManager;
  97. ut2.ToolClick += new Toolbar2.ToolClickEventHandler(_ToolbarClick_Listener2);
  98. }
  99. else if (fieldInfo[i].FieldType == typeof(ToolStrip))
  100. {
  101. ToolStrip t1 = fieldInfo[i].GetValue(this) as ToolStrip;
  102. t1.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this._toolStrip_ItemClicked);
  103. }
  104. else if (fieldInfo[i].FieldType == typeof(System.Windows.Forms.TextBox))
  105. {
  106. System.Windows.Forms.TextBox text = fieldInfo[i].GetValue(this) as System.Windows.Forms.TextBox;
  107. text.TextChanged += new System.EventHandler(TextBox_Listener);
  108. //text.KeyUp += new KeyEventHandler(TextBox_Listener);
  109. }
  110. else if (fieldInfo[i].FieldType == typeof(UltraText1.UltraTextEditor))
  111. {
  112. UltraText1.UltraTextEditor t1 = fieldInfo[i].GetValue(this) as UltraText1.UltraTextEditor;
  113. t1.TextChanged += new System.EventHandler(TextEditor_Listener1);
  114. //t1.KeyUp += new KeyEventHandler(TextEditor_Listener1);
  115. }
  116. else if (fieldInfo[i].FieldType == typeof(UltraText2.UltraTextEditor))
  117. {
  118. UltraText2.UltraTextEditor t2 = fieldInfo[i].GetValue(this) as UltraText2.UltraTextEditor;
  119. t2.TextChanged += new System.EventHandler(TextEditor_Listener2);
  120. //t2.KeyUp += new KeyEventHandler(TextEditor_Listener2);
  121. }
  122. }
  123. catch
  124. {
  125. }
  126. }
  127. }
  128. public void _ToolbarClick_Listener1(object sender, Toolbar1.ToolClickEventArgs e)
  129. {
  130. ClientCommon.RecordUserEvent("点击", "按钮[ToolBar]", e.Tool.CaptionResolved, this.Text, this.ProductName, "");
  131. }
  132. public void _ToolbarClick_Listener2(object sender, Toolbar2.ToolClickEventArgs e)
  133. {
  134. ClientCommon.RecordUserEvent("点击", "按钮[ToolBar]", e.Tool.CaptionResolved, this.Text, this.ProductName, "");
  135. }
  136. private void _toolStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  137. {
  138. ClientCommon.RecordUserEvent("点击", "按钮[ToolBar]", e.ClickedItem.Text, this.Text, this.ProductName, "");
  139. }
  140. private bool isDangerous(string target)
  141. {
  142. if (target == null)
  143. {
  144. target = "";
  145. }
  146. string targetUpper = target.ToUpper();
  147. bool isDanger = false;
  148. string matchStr = "EXEC|INSERT|SELECT|DELETE|UPDATE|DROP|TRUNCATE|DECLARE|AND|UNION|OR|CREATE|XP_CMDSHELL|NET USER|NET LOCALGROUP|ASC|ORDER";
  149. if (targetUpper != "")
  150. {
  151. string[] matchStrArray = matchStr.Split('|');
  152. for (int i = 0; i < matchStrArray.Length; i++)
  153. {
  154. if (targetUpper.IndexOf(matchStrArray[i]) > -1)
  155. {
  156. return true;
  157. }
  158. }
  159. }
  160. return isDanger;
  161. }
  162. private string filterDangerStr(string source)
  163. {
  164. if (source == null)
  165. {
  166. return "";
  167. }
  168. source = source.Replace("'", "“");
  169. //去除执行SQL语句的命令关键字
  170. source = Regex.Replace(source, "select", "", RegexOptions.IgnoreCase);
  171. source = Regex.Replace(source, "insert", "", RegexOptions.IgnoreCase);
  172. source = Regex.Replace(source, "update", "", RegexOptions.IgnoreCase);
  173. source = Regex.Replace(source, "delete", "", RegexOptions.IgnoreCase);
  174. source = Regex.Replace(source, "drop", "", RegexOptions.IgnoreCase);
  175. source = Regex.Replace(source, "truncate", "", RegexOptions.IgnoreCase);
  176. source = Regex.Replace(source, "declare", "", RegexOptions.IgnoreCase);
  177. source = Regex.Replace(source, "xp_cmdshell", "", RegexOptions.IgnoreCase);
  178. source = Regex.Replace(source, "/add", "", RegexOptions.IgnoreCase);
  179. source = Regex.Replace(source, "net user", "", RegexOptions.IgnoreCase);
  180. //source = Regex.Replace(source, "mid", "", RegexOptions.IgnoreCase);
  181. source = Regex.Replace(source, "create", "", RegexOptions.IgnoreCase);
  182. //source = Regex.Replace(source, "char", "", RegexOptions.IgnoreCase);
  183. //去除执行存储过程的命令关键字
  184. source = Regex.Replace(source, "exec", "", RegexOptions.IgnoreCase);
  185. source = Regex.Replace(source, "execute", "", RegexOptions.IgnoreCase);
  186. //去除系统存储过程或扩展存储过程关键字
  187. //source = Regex.Replace(source, "xp_", "x p_", RegexOptions.IgnoreCase);
  188. //source = Regex.Replace(source, "sp_", "s p_", RegexOptions.IgnoreCase);
  189. //防止16进制注入
  190. //source = Regex.Replace(source, "0x", "0 x", RegexOptions.IgnoreCase);
  191. return source;
  192. }
  193. private void TextBox_Listener(object sender, EventArgs e)
  194. {
  195. TextBox text1 = sender as TextBox;
  196. string old_str = text1.Text;
  197. text1.TextChanged -= new System.EventHandler(TextBox_Listener);
  198. text1.Text = filterDangerStr(text1.Text);
  199. text1.TextChanged += new System.EventHandler(TextBox_Listener);
  200. if (!text1.Text.Equals(old_str))
  201. {
  202. MessageBox.Show("输入的字符串中含有数据库危险字符,已过滤。" + old_str);
  203. }
  204. }
  205. private void TextEditor_Listener1(object sender, EventArgs e)
  206. {
  207. UltraText1.UltraTextEditor text1 = sender as UltraText1.UltraTextEditor;
  208. string old_str = text1.Text;
  209. text1.TextChanged -= new System.EventHandler(TextEditor_Listener1);
  210. text1.Text = filterDangerStr(text1.Text);
  211. text1.TextChanged += new System.EventHandler(TextEditor_Listener1);
  212. if (!text1.Text.Equals(old_str))
  213. {
  214. MessageBox.Show("输入的字符串中含有数据库危险字符,已过滤。" + old_str);
  215. }
  216. }
  217. private void TextEditor_Listener2(object sender, EventArgs e)
  218. {
  219. UltraText2.UltraTextEditor text2 = sender as UltraText2.UltraTextEditor;
  220. string old_str = text2.Text;
  221. text2.TextChanged -= new System.EventHandler(TextEditor_Listener2);
  222. text2.Text = filterDangerStr(text2.Text);
  223. text2.TextChanged += new System.EventHandler(TextEditor_Listener2);
  224. if (!text2.Text.Equals(old_str))
  225. {
  226. MessageBox.Show("输入的字符串中含有数据库危险字符,已过滤。" + old_str);
  227. }
  228. }
  229. }
  230. }