| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- using System;
- namespace SAGA.RevitUtils
- {
- public class Information
- {
- private string _infor;
- /// <summary>
- /// 电线名
- /// </summary>
- public string Name { get; set; }
- /// <summary>
- /// 物料组号
- /// </summary>
- public string GroupNum { get; set; }
- /// <summary>
- /// 物料号
- /// </summary>
- public string ObjectNum { get; set; }
- /// <summary>
- /// 长度
- /// </summary>
- public double Length { get; set; }
- /// <summary>
- /// 是否正确
- /// </summary>
- public bool IsRight { get; set; }
- public Information(string information)
- {
- _infor = information;
- this.IsRight = true;
- GetName();
- GetGroupNum();
- GetObjectNum();
- GetLength();
- }
- /// <summary>
- /// 获取物料号
- /// </summary>
- /// <returns></returns>
- private void GetObjectNum()
- {
- string objNum;
- int indexObj = _infor.IndexOf("ObjectNum", StringComparison.Ordinal);
- int indexL = _infor.IndexOf("Length", StringComparison.Ordinal);
- if (indexObj == -1||indexL==-1)
- {
- this.IsRight = false;
- return;
- }
- try
- {
- objNum = _infor.Substring(indexObj + 10, indexL - 1 - (indexObj + 10));
- int num = Convert.ToInt32(objNum);
- }
- catch (Exception)
- {
- this.IsRight = false;
- return;
- }
- this.ObjectNum = objNum;
- }
- /// <summary>
- /// 获取电线名
- /// </summary>
- private void GetName()
- {
- string name;
- int index = _infor.IndexOf("GroupNum", StringComparison.Ordinal);
- if (index == -1)
- {
- this.IsRight = false;
- return;
- }
- try
- {
- name = _infor.Substring(5, index - 1 - 5);
- }
- catch (Exception)
- {
- this.IsRight = false;
- return;
- }
- this.Name = name;
- }
- /// <summary>
- /// 获取物料组号
- /// </summary>
- private void GetGroupNum()
- {
- string group;
- int indexG = _infor.IndexOf("GroupNum", StringComparison.Ordinal);
- int indexObj = _infor.IndexOf("ObjectNum", StringComparison.Ordinal);
- if (indexG == -1 || indexObj == -1)
- {
- this.IsRight = false;
- return;
- }
- try
- {
- group = _infor.Substring(indexG + 9, indexObj - 1 - (indexG + 9));
- }
- catch (Exception)
- {
- this.IsRight = false;
- return;
- }
- this.GroupNum = group;
- }
- /// <summary>
- /// 获取长度
- /// </summary>
- private void GetLength()
- {
- double length;
- int index = _infor.IndexOf("Length", StringComparison.Ordinal);
- if (index == -1)
- {
- this.IsRight = false;
- return;
- }
- try
- {
- string l = _infor.Substring(index + 7);
- length = Convert.ToDouble(l);
- }
- catch (Exception)
- {
- this.IsRight = false;
- return;
- }
- this.Length = length;
- }
- }
- }
|