Information.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using System;
  2. namespace SAGA.RevitUtils
  3. {
  4. public class Information
  5. {
  6. private string _infor;
  7. /// <summary>
  8. /// 电线名
  9. /// </summary>
  10. public string Name { get; set; }
  11. /// <summary>
  12. /// 物料组号
  13. /// </summary>
  14. public string GroupNum { get; set; }
  15. /// <summary>
  16. /// 物料号
  17. /// </summary>
  18. public string ObjectNum { get; set; }
  19. /// <summary>
  20. /// 长度
  21. /// </summary>
  22. public double Length { get; set; }
  23. /// <summary>
  24. /// 是否正确
  25. /// </summary>
  26. public bool IsRight { get; set; }
  27. public Information(string information)
  28. {
  29. _infor = information;
  30. this.IsRight = true;
  31. GetName();
  32. GetGroupNum();
  33. GetObjectNum();
  34. GetLength();
  35. }
  36. /// <summary>
  37. /// 获取物料号
  38. /// </summary>
  39. /// <returns></returns>
  40. private void GetObjectNum()
  41. {
  42. string objNum;
  43. int indexObj = _infor.IndexOf("ObjectNum", StringComparison.Ordinal);
  44. int indexL = _infor.IndexOf("Length", StringComparison.Ordinal);
  45. if (indexObj == -1||indexL==-1)
  46. {
  47. this.IsRight = false;
  48. return;
  49. }
  50. try
  51. {
  52. objNum = _infor.Substring(indexObj + 10, indexL - 1 - (indexObj + 10));
  53. int num = Convert.ToInt32(objNum);
  54. }
  55. catch (Exception)
  56. {
  57. this.IsRight = false;
  58. return;
  59. }
  60. this.ObjectNum = objNum;
  61. }
  62. /// <summary>
  63. /// 获取电线名
  64. /// </summary>
  65. private void GetName()
  66. {
  67. string name;
  68. int index = _infor.IndexOf("GroupNum", StringComparison.Ordinal);
  69. if (index == -1)
  70. {
  71. this.IsRight = false;
  72. return;
  73. }
  74. try
  75. {
  76. name = _infor.Substring(5, index - 1 - 5);
  77. }
  78. catch (Exception)
  79. {
  80. this.IsRight = false;
  81. return;
  82. }
  83. this.Name = name;
  84. }
  85. /// <summary>
  86. /// 获取物料组号
  87. /// </summary>
  88. private void GetGroupNum()
  89. {
  90. string group;
  91. int indexG = _infor.IndexOf("GroupNum", StringComparison.Ordinal);
  92. int indexObj = _infor.IndexOf("ObjectNum", StringComparison.Ordinal);
  93. if (indexG == -1 || indexObj == -1)
  94. {
  95. this.IsRight = false;
  96. return;
  97. }
  98. try
  99. {
  100. group = _infor.Substring(indexG + 9, indexObj - 1 - (indexG + 9));
  101. }
  102. catch (Exception)
  103. {
  104. this.IsRight = false;
  105. return;
  106. }
  107. this.GroupNum = group;
  108. }
  109. /// <summary>
  110. /// 获取长度
  111. /// </summary>
  112. private void GetLength()
  113. {
  114. double length;
  115. int index = _infor.IndexOf("Length", StringComparison.Ordinal);
  116. if (index == -1)
  117. {
  118. this.IsRight = false;
  119. return;
  120. }
  121. try
  122. {
  123. string l = _infor.Substring(index + 7);
  124. length = Convert.ToDouble(l);
  125. }
  126. catch (Exception)
  127. {
  128. this.IsRight = false;
  129. return;
  130. }
  131. this.Length = length;
  132. }
  133. }
  134. }