Пример #1
0
        public BDeviceCutTime(IDbName database, int deviceId, int totalCutTime)
        {
            BeamCutQuery = new BeamCutQuery(database);

            var statistic = BeamCutQuery.GetBMachineStatistic(deviceId, DateTime.Now);

            if (statistic == null)
            {
                statistic = BeamCutQuery.AddNewBcutStatistic(deviceId, DateTime.Now);
            }

            if (statistic.BDeviceCutTimeRecords != null)
            {
                foreach (var item in statistic.BDeviceCutTimeRecords)
                {
                    TotalCutTime += ShareFuncs.GetInt(item.TotalCutTime);
                }
            }

            var lastRecord = BeamCutQuery.Get_DeviceLastRecord(deviceId);

            if (lastRecord != null)
            {
                DateTime updateTime = (DateTime)lastRecord.UpdateTime;
                if (updateTime.DayOfYear == DateTime.Now.DayOfYear &&
                    updateTime.Minute == DateTime.Now.Minute &&
                    updateTime.Hour == DateTime.Now.Hour)
                {
                    // duplicate update detected
                    Exception = new RespException(false, "The cut time has been recorded", EKB_SYS_REQUEST.CUT_TIME_RECORD);
                    return;
                }
            }

            BDeviceCutTimeRecord record = new BDeviceCutTimeRecord
            {
                TotalCutTime         = totalCutTime,
                BeamCutDevice_Id     = deviceId,
                BMachineStatistic_Id = statistic.id,
            };

            if (!BeamCutQuery.AddNewBCutTimeRecord(record))
            {
                Exception = new RespException(true, "Add new record failed", EKB_SYS_REQUEST.CUT_TIME_RECORD);
                return;
            }

            TotalCutTime += totalCutTime;
        }