Example #1
0
        /// <summary>
        /// Race_Archive的操作
        /// </summary>
        /// <returns></returns>
        public static bool LastShiftCalc(string UnitID, string HStartTime, string HEndTime)
        {
            bool bGood = false;

            if (UnitID == "")
            {
                return(false);
            }

            string UnitName = KPI_UnitDal.GetUnitName(UnitID);
            //DataTable tags = Race_TagDal.GetTags(UnitID);
            List <Race_TagEntity> RaceTagList;

            using (Race_TagDal DataAccess = new Race_TagDal()) {
                RaceTagList = DataAccess.GetTagList(UnitID);
            }
            if (RaceTagList.Count <= 0)
            {
                return(true);
            }
            //if (tags == null || tags.Rows.Count <= 0) {
            //    return true;
            //}

            //delete
            string sql = @"delete Race_Archive where UnitID='{0}'  and  (TagStartTime>'{1}' and TagStartTime<'{2}') ";

            sql = string.Format(sql, UnitID, HStartTime, HEndTime);
            DBAccess.GetRelation().ExecuteNonQuery(sql);
            //insert
            string WorkID     = KPI_UnitDal.GetWorkIDByID(UnitID);
            string ShiftName  = "";
            string PeriodName = "";
            string StartTime  = "";
            string EndTime    = "";

            bGood = KPI_WorkDal.GetShiftAndPeriod(WorkID, HStartTime, ref ShiftName, ref PeriodName, ref StartTime, ref EndTime);
            if (!bGood)
            {
                return(false);
            }
            DateTime dts = DateTime.Parse(StartTime);
            DateTime dte = DateTime.Parse(EndTime);

            //string PeriodID = KPI_PeriodDal.GetPeriodID(PeriodName);
            //string ShiftID = KPI_ShiftDal.GetShiftID(ShiftName);

            //历史计算
            foreach (Race_TagEntity RaceTag in RaceTagList)
            {
                //string TagID = tags.Rows[i]["TagID"].ToString();
                decimal     TagValue = decimal.MinValue;
                RTInterface RTDB     = DBAccess.GetRealTime();
                //Race_TagEntity tentity = Race_TagDal.GetEntity(RaceTag.TagID);
                if (RaceTag.TagCalcExpType == 0)
                {
                    TagValue = Convert.ToDecimal(RTDB.TagCalculatedData(RaceTag.TagCalcExp, dts, dte, RaceTag.TagFilterExp, GetRaceTagCalcType(RaceTag.TagCalcType)));
                    //Random rdm = new Random();
                    //TagValue = rdm.NextDouble() * 100;

                    if (TagValue == decimal.MinValue)
                    {
                        LogUtil.LogMessage(RaceTag.TagDesc + "数据出现错误!");
                        continue;
                    }
                    TagValue = TagValue * RaceTag.TagFactor + RaceTag.TagOffset;
                }
                else if (RaceTag.TagCalcExpType == 1)
                {
                    TagValue = Convert.ToDecimal(RTDB.ExpCalculatedData(RaceTag.TagCalcExp, dts, dte, RaceTag.TagFilterExp, GetRaceTagCalcType(RaceTag.TagCalcType)));
                    //Random rdm = new Random();
                    //TagValue = rdm.NextDouble() * 100;
                    if (TagValue == decimal.MinValue)
                    {
                        LogUtil.LogMessage(RaceTag.TagDesc + "数据出现错误!");
                        continue;
                    }
                    TagValue = TagValue * RaceTag.TagFactor + RaceTag.TagOffset;
                }
                else if (RaceTag.TagCalcExpType == 2)
                {
                    Random rdm = new Random();
                    TagValue = Convert.ToDecimal(rdm.NextDouble() * 100);
                    if (TagValue == decimal.MinValue)
                    {
                        LogUtil.LogMessage(RaceTag.TagDesc + "数据出现错误!");
                        continue;
                    }
                    TagValue = TagValue * RaceTag.TagFactor + RaceTag.TagOffset;
                }

                //update Snapshot
                if (GetSnapshotExits(RaceTag.TagID, ShiftName))
                {
                    //update
                    //Race_SnapshotEntity sse = new Race_SnapshotEntity();

                    ////sse.TagID = TagID;
                    ////sse.UnitID = UnitID;
                    ////sse.TagType = tentity.TagType;

                    //sse.TagShift = ShiftID;
                    //sse.TagPeriod = PeriodID;
                    //sse.TagStartTime = StartTime;
                    //sse.TagEndTime = EndTime;
                    //sse.TagValue = TagValue;

                    sql = @"update Race_Snapshot
                                    set TagPeriod='{0}', TagStartTime='{1}', 
                                            TagEndTime='{2}', TagValue={3} 
                                where TagID='{4}' and TagShift='{5}'";
                    sql = string.Format(sql, PeriodName, StartTime, EndTime, TagValue.ToString(), RaceTag.TagID, ShiftName);
                    DBAccess.GetRelation().ExecuteNonQuery(sql);
                }
                else
                {
                    //insert
                    Race_SnapshotEntity sse = new Race_SnapshotEntity();
                    sse.TagID        = RaceTag.TagID;
                    sse.UnitID       = UnitID;
                    sse.TagType      = RaceTag.TagType;
                    sse.TagShift     = ShiftName;
                    sse.TagPeriod    = PeriodName;
                    sse.TagStartTime = StartTime;
                    sse.TagEndTime   = EndTime;
                    sse.TagValue     = Convert.ToDouble(TagValue);
                    Race_SnapshotDal.Insert(sse);
                }

                //insert Archive
                //insert
                Race_ArchiveEntity sae = new Race_ArchiveEntity();
                sae.TagID  = RaceTag.TagID;
                sae.UnitID = UnitID;
                //  sae.TagType = tentity.TagType;
                sae.TagShift     = ShiftName;
                sae.TagPeriod    = PeriodName;
                sae.TagStartTime = StartTime;
                sae.TagEndTime   = EndTime;
                sae.TagValue     = Convert.ToDouble(TagValue);
                Race_ArchiveDal.Insert(sae);
            }

            return(true);
        }