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.

67 line
2.0 KiB

  1. using StuMgmLib.MyNameSpace;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.IO;
  6. using System.Runtime.Serialization.Formatters.Binary;
  7. namespace StuMgmClient
  8. {
  9. class Utility
  10. {
  11. //序列化
  12. internal static bool BinSerialize<T>(T data, out byte[] buff)
  13. {
  14. try
  15. {
  16. MemoryStream ms = new MemoryStream();
  17. BinaryFormatter iFormatter = new BinaryFormatter();
  18. iFormatter.Serialize(ms, data);
  19. buff = ms.GetBuffer();
  20. return true;
  21. }
  22. catch (Exception e)
  23. {
  24. Debug.Print(e.Message);
  25. buff = null;
  26. return false;
  27. }
  28. }
  29. //反序列化
  30. internal static bool BinDeserialize(byte[] data, out ServerResponse o)
  31. {
  32. try
  33. {
  34. MemoryStream ms = new MemoryStream(data);
  35. BinaryFormatter iFormatter = new BinaryFormatter();
  36. o = (ServerResponse)iFormatter.Deserialize(ms);
  37. return true;
  38. }
  39. catch (Exception e)
  40. {
  41. Debug.Print(e.Message);
  42. o = null;
  43. return false;
  44. }
  45. }
  46. //字典转字符串
  47. internal static string DicParsing(Dictionary<short, CourseStatusEnum> dic)
  48. {
  49. string stateText = "";
  50. foreach (var item in dic)
  51. {
  52. stateText = stateText + item.Key.ToString() + ":" + ((int)item.Value).ToString() + ";";
  53. }
  54. return stateText;
  55. }
  56. internal static string InitState(int state)
  57. {
  58. Dictionary<int, string> dic = new Dictionary<int, string>();
  59. dic.Add(0, "未开始"); dic.Add(1, "进行中"); dic.Add(2, "待验收"); dic.Add(3, "验收成功"); dic.Add(4, "验收失败");
  60. return dic[state];
  61. }
  62. }
  63. }