FlyData_ScanHistory.cs 4.51 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FLY.Thick.RemoteHistory;
namespace FLY.Thick.Base.Common
{
    public class FlyData_ScanHistory:IFlyData
    {
        public DateTime Time { get; set; }
        public int[] SampleAD=new int[3];
        public double Comp;
        public int Shift;
        public int Target;
        public int Alarm;
        public bool Valid;
        public int BoltCnt;
        public int BoltNo1st;
        public int[] Data;
        public int Avg;//平均值

        #region IFlyData 成员

        public string GetHeader()
        {
            string header = "时间,温修AD,样品1AD,样品2AD,斜率补偿,平移补偿,目标值,公差,有效";
            for (int i = 0; i < BoltCnt; i++)
            {
                header += "," + (BoltNo1st + i).ToString();
            }
            header += ",平均值";

            return header;
        }
        public override string ToString()
        {
            string str;
            str = Time.ToString() ;
            for (int i = 0; i < 3; i++)
                str += "," + SampleAD[i].ToString();
            str += "," + Comp.ToString("F2");
            str += "," + (Shift/100.0).ToString("F2");
            str += "," + (Target/100.0).ToString("F2");
            str += "," + (Alarm/100.0).ToString("F2");
            str += "," + Valid.ToString();
            int sum = 0;
            int cnt = 0;
            for (int i = 0; i < BoltCnt && i<Data.Count(); i++)
            {
                
                int thick = Data[i];
                str += ",";

                if (Misc.MyBase.ISVALIDATA(thick))
                {
                    str += (thick / 100.0).ToString("F2");
                    sum+=thick;
                    cnt++;
                }
            }
            str += ",";
            if (cnt > 0)
                str += (sum / cnt / 100.0).ToString("F2");

            return str;
        }
        public bool TryParse(string header, string str)
        {
            string[] items = header.Split(new char[] { ',' });
            if (items.Length < 9)
                return false;

            int boltno1st;

            if (int.TryParse(items[9], out boltno1st))
                BoltNo1st = boltno1st;
            else
                return false;

            BoltCnt = items.Length - 9 - 1;

            items = str.Split(new char[] { ',' });
            if ((items.Length-9-1) !=BoltCnt)
                return false;

            DateTime dt;
            int _i;
            double d;
            bool b;

            if (DateTime.TryParse(items[0], out dt))
                Time = dt;
            else
                return false;

            for (int i = 0; i < 3; i++) 
            {

                if (int.TryParse(items[1 + i], out _i))
                    SampleAD[i] = _i;
                else
                    return false;
            }
            if (double.TryParse(items[4], out d))
                Comp = d;
            else
                return false;


            if (double.TryParse(items[5], out d))
                Shift = (int)d*100;
            else
                return false;

            if (double.TryParse(items[6], out d))
                Target = (int)d * 100;
            else
                return false;

            if (double.TryParse(items[7], out d))
                Alarm = (int)d * 100;
            else
                return false;

            if (bool.TryParse(items[8], out b))
                Valid = b;
            else
                return false;

            Data = new int[BoltCnt];

            for (int i = 0; i < BoltCnt; i++)
            {
                string s = items[9 + i];
                if (string.IsNullOrEmpty(s))
                {
                    Data[i] = Misc.MyBase.NULL_VALUE;
                }
                else
                {
                    if (double.TryParse(s, out d))
                        Data[i] = (int)(d * 100);
                    else
                        return false;
                }
            }
            {
                string s = items[9 + BoltCnt];
                if (string.IsNullOrEmpty(s))
                {
                    Avg = Misc.MyBase.NULL_VALUE;
                }
                else
                {
                    if (double.TryParse(s, out d))
                        Avg = (int)d * 100;
                    else
                        return false;
                }
            }
            

            return true;
        }

        #endregion
    }
}