华恒Mes鼎捷代码
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.

280 lines
5.7 KiB

5 months ago
  1. using System;
  2. using System.Collections;
  3. namespace ICSSoft.Frame.DataConnect
  4. {
  5. public enum MessageType
  6. {
  7. Normal,
  8. Debug,
  9. Error,
  10. DisplayError, // ����ʾ��ʱ����Error״̬����IsSuccess�з���True
  11. Success,
  12. Input,
  13. Performance,
  14. Data, //һ��ָ��������ֻ����һ��DATA����
  15. DCTData, //DCT����������ʾ������
  16. DCTClear //������,����ʾ
  17. }
  18. public class MessageTypeCollection:ArrayList
  19. {
  20. public MessageTypeCollection():base()
  21. {
  22. }
  23. public int Add(MessageType value)
  24. {
  25. this.Add(value);
  26. return this.Count ;
  27. }
  28. public MessageType Objects(int index)
  29. {
  30. return (MessageType)this[index];
  31. }
  32. }
  33. public class Message
  34. {
  35. public string id = string.Empty;
  36. public MessageType Type = MessageType.Normal;
  37. public string Body = string.Empty ;
  38. public object[] Values = null;
  39. public System.Exception Exception = null;
  40. public int LineNo = 5;//����DCT����ʾ�к�
  41. public Message()
  42. {
  43. }
  44. public Message( MessageType type, string body , object[] values)
  45. {
  46. this.Type = type;
  47. this.Body = body;
  48. this.Values =values;
  49. }
  50. public Message(MessageType type,string body):this(type,body, null)
  51. {
  52. }
  53. public Message(int lineno, MessageType type, string body)
  54. : this(type, body, null)
  55. {
  56. this.LineNo = lineno;
  57. }
  58. public Message(string body):this(MessageType.Normal, body, null)
  59. {
  60. }
  61. public Message(System.Exception exception):this(MessageType.Error, "", null)
  62. {
  63. this.Exception = exception;
  64. this.Type = MessageType.Error;
  65. }
  66. /*public MessageEventArgs(string body):this(string.Empty, body)
  67. {
  68. }*/
  69. public Message Clone()
  70. {
  71. Message messageEventArgs = new Message();
  72. messageEventArgs.Type = this.Type;
  73. messageEventArgs.Body = this.Body;
  74. messageEventArgs.Values = this.Values;
  75. messageEventArgs.Exception = this.Exception;
  76. return messageEventArgs;
  77. }
  78. public string Debug()
  79. {
  80. string s=this.Type+";"+this.Body+";";
  81. if (Exception !=null)
  82. {
  83. s=s+Exception.Message+";"+Exception.Source+";"+Exception.StackTrace+";" ;
  84. if (Exception.InnerException!=null)
  85. s=s +Exception.InnerException.Message+";"+Exception.Source+";"+Exception.StackTrace+";";
  86. }
  87. if (this.Values !=null)
  88. {
  89. for (int i=0;i<this.Values.Length;i++)
  90. {
  91. s=s+ this.Values[i].ToString();
  92. }
  93. }
  94. return s+"��";
  95. }
  96. public override string ToString()
  97. {
  98. string s=this.Type+";"+this.Body+";";
  99. if (Exception !=null)
  100. {
  101. s=s+Exception.Message+";"+Exception.TargetSite+";";
  102. if (Exception.InnerException!=null)
  103. s=s +Exception.InnerException.Message+";"+Exception.TargetSite+";";
  104. }
  105. return s+"��";
  106. }
  107. }
  108. /// <summary>
  109. /// ָ��������������Ϣ����
  110. /// һ�������� DATAֻ�ܳ���һ��
  111. /// </summary>
  112. public class Messages
  113. {
  114. private ArrayList messageList;
  115. public Messages()
  116. {
  117. messageList=new ArrayList();
  118. }
  119. public int Add(Message value)
  120. {
  121. if (value.Type ==MessageType.Data )
  122. if (GetData()!=null)
  123. DeleteData();
  124. //throw new Exception("$Error_Messages_Data_Repeated");
  125. int i= messageList.Add(value);
  126. return i;
  127. }
  128. public Message GetData()
  129. {
  130. for (int i=0;i<messageList.Count;i++ )
  131. {
  132. if (this.Objects(i).Type ==MessageType.Data )
  133. return this.Objects(i);
  134. }
  135. return null;
  136. }
  137. public void DeleteData()
  138. {
  139. for (int i=0;i<messageList.Count;i++ )
  140. {
  141. if (this.Objects(i).Type ==MessageType.Data )
  142. this.messageList.RemoveAt(i);
  143. }
  144. }
  145. public int Count()
  146. {
  147. return this.messageList.Count;
  148. }
  149. public Message Objects(int index)
  150. {
  151. return (Message)messageList[index];
  152. }
  153. public bool IsSuccess()
  154. {
  155. if (messageList.Count==0)
  156. return true;
  157. for (int i=0;i<messageList.Count;i++ )
  158. {
  159. if (this.Objects(i).Type ==MessageType.Error )
  160. return false;
  161. }
  162. return true;
  163. }
  164. public string Debug()
  165. {
  166. string s="";
  167. for (int i=0;i<messageList.Count;i++ )
  168. {
  169. if ((this.Objects(i).Type ==MessageType.Debug)
  170. ||(this.Objects(i).Type ==MessageType.Error)
  171. || (this.Objects(i).Type == MessageType.Success)
  172. ||(this.Objects(i).Type ==MessageType.Data)
  173. ||(this.Objects(i).Type ==MessageType.Performance)
  174. )
  175. {
  176. s=s+this.Objects(i).Debug();
  177. }
  178. }
  179. return s;
  180. }
  181. public string functionList()
  182. {
  183. string s="";
  184. for (int i=0;i<messageList.Count;i++ )
  185. {
  186. if ((this.Objects(i).Type ==MessageType.Debug)
  187. ||(this.Objects(i).Type ==MessageType.Error)
  188. || (this.Objects(i).Type == MessageType.Success)
  189. )
  190. {
  191. s=s+this.Objects(i).ToString();
  192. }
  193. }
  194. return s;
  195. }
  196. public string OutPut()
  197. {
  198. string s="";
  199. for (int i=0;i<messageList.Count;i++ )
  200. {
  201. if ((this.Objects(i).Type ==MessageType.Error)
  202. || (this.Objects(i).Type == MessageType.Success)
  203. )
  204. {
  205. if (this.Objects(i).Body==string.Empty)
  206. {
  207. if (this.Objects(i).Exception==null)
  208. {
  209. s=s+"Exception.Message not eixt!!";
  210. }
  211. else
  212. {
  213. s=s+this.Objects(i).Exception.Message;
  214. }
  215. }
  216. else
  217. s=s+this.Objects(i).Body;
  218. }
  219. }
  220. return s;
  221. }
  222. public override string ToString()
  223. {
  224. string s="";
  225. for (int i=0;i<messageList.Count;i++ )
  226. {
  227. s=s+this.Objects(i).ToString();
  228. }
  229. return s;
  230. }
  231. public void AddMessages(Messages messages)
  232. {
  233. for (int i=0;i<messages.Count() ;i++)
  234. {
  235. this.Add(messages.Objects(i));
  236. }
  237. }
  238. public void ClearMessages()
  239. {
  240. this.messageList.Clear();
  241. }
  242. /// <summary>
  243. /// ��Error���͵�Message��ת��ΪDisplayError
  244. /// </summary>
  245. public void IgnoreError()
  246. {
  247. for (int i = 0; i < messageList.Count; i++)
  248. {
  249. Message msg = (Message)messageList[i];
  250. if (msg.Type == MessageType.Error)
  251. msg.Type = MessageType.DisplayError;
  252. messageList[i] = msg;
  253. }
  254. }
  255. }
  256. }