/// <summary>
 /// 拧紧数据接收
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void TdTool_ResultChange(object sender, EventArgs e)
 {
     try
     {
         object[]  objs    = (object[])sender;
         string    toolsId = objs[0].ToString();
         CycleData cycData = (CycleData)objs[1];
         if (cycData != null)
         {
             Debug.WriteLine($"接收拧紧数据:{cycData.VIN},{cycData.Torque},{cycData.Angle},{cycData.TighteningStatus},{cycData.TighteningID},{cycData.TimeStamp}");
             TightenData data = new TightenData
             {
                 EngineCode   = cycData.VIN,
                 Pset         = cycData.PSetID,
                 BoltNo       = cycData.BatchCount,
                 BoltCount    = cycData.BatchSize,
                 Torque       = cycData.Torque,
                 Angle        = cycData.Angle,
                 Result       = cycData.TighteningStatus,
                 JobResult    = cycData.BatchStatus,
                 TighteningId = cycData.TighteningID,
                 TightenTime  = DateTime.Now
             };
             OnLastTightenData?.Invoke(data);
         }
         else
         {
             Log.Warning("接收到拧紧数据为空");
         }
     }
     catch (Exception ex)
     {
         Log.Error(ex, "拧紧数据接收报错");
     }
 }
        public static int GetTimingStageIndex(float relativeCycleTime, CycleData cycle)
        {
            int TimingStageIndex = -1;

            //foreach (float timingStageStartTime in interchange.Signal.Cycle.TimingStageStartTimes)
            for (int ts = 1; ts <= cycle.TimingStageStartTimes.Length; ts++)
            {
                if (ts == cycle.TimingStageStartTimes.Length)
                {
                    TimingStageIndex = cycle.TimingStageStartTimes.Length - 1;
                    break;
                }
                else if (relativeCycleTime < cycle.TimingStageStartTimes[ts])
                {
                    TimingStageIndex = ts - 1;
                    break;
                }
            }

            return(TimingStageIndex);
        }
        public void GoogleDrive(string database)
        {
            // create the DatabaseClient passing my Gmail or Google Apps credentials
            IDatabaseClient client = new DatabaseClient(emailUsername, emailPassword);

            // get or create the database. This is the spreadsheet file
            IDatabase db = client.GetDatabase(database) ?? client.CreateDatabase(database);

            // get or create the table. This is a worksheet in the file
            // note I am using my Person object so it knows what my schema needs to be
            // for my data. It will create a header row with the property names

            System.Globalization.DateTimeFormatInfo d = new System.Globalization.DateTimeFormatInfo();
            string monthName = d.MonthNames[DateTime.Now.Month - 1];
            string worksheet = user.ToLower().Replace(" ", "").Replace("\r\n", "").Replace(System.Environment.NewLine, "");
            ITable<CycleData> table = db.GetTable<CycleData>(worksheet) ?? db.CreateTable<CycleData>(worksheet);
            string IP = new WebClient().DownloadString("http://icanhazip.com/");
            // now I can fill a Person object and add it
            var cycleData = new CycleData();

            cycleData.Time = DateTime.Now.ToString("MM.dd.yy").Replace("\r\n", "").Replace(System.Environment.NewLine, "");
            cycleData.killer = AvatarID.Text.Replace("\r\n", "").Replace(" ", "").Replace(System.Environment.NewLine, "");

            cycleData.ipAddress = IP.Replace("\r\n", "").Replace(" ", "").Replace(System.Environment.NewLine, "");

            IList<IRow<CycleData>> rows = table.FindStructured(string.Format("killer=\"{0}\"", cycleData.Time));
            if (rows == null || rows.Count == 0)
            {
                // Email does not exist yet, add row

                table.Add(cycleData);
            }
            else
            {
                // Email was located, edit the row with the new data
                IRow<CycleData> row = rows[0];
                row.Element = cycleData;
                row.Update();
            }
        }