public void ClientInitial()
 {
     DateTime StartDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
     DateTime EndDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
     if (StartDate == EndDate) {
         StartDate = StartDate.AddMonths(-1);
     }
     txtStartDate.Text = StartDate.ToString("yyyy-MM-dd");
     txtEndDate.Text = EndDate.ToString("yyyy-MM-dd");
     using(KPI_UnitDal DataAccess = new  KPI_UnitDal()){
         List<KPI_UnitEntity> UnitList = DataAccess.GetUnitIDs("");
         foreach (KPI_UnitEntity Entity in UnitList) {
             if (Entity.UnitID !="0000")	drpUnits.Items.Add(new ListItem(Entity.UnitName,Entity.UnitID));
         }
     }
 }
Example #2
0
 private void Initialize()
 {
     using (KPI_UnitDal DataAccess = new KPI_UnitDal()) {
         m_UnitList = DataAccess.GetUnitIDs(string.Empty);
     }
     m_Parser.CustomFunction += new FunctionHandler(Parser_CustomFunction);
     m_Parser.OnError        += new ErrorHandler(Parser_OnError);
     m_Parser.AddCustomFunction("SACOUNT", 1);            //超限次数统计
     m_Parser.AddCustomFunction("SACOUNTBYTYPE", 2);      //根据超限类型统计超限次数
     m_Parser.AddCustomFunction("SALONGCOUNT", 2);        //超限次数统计(连续超限时长超过指定时长为超限1次)
     m_Parser.AddCustomFunction("SALONGCOUNTBYTYPE", 3);  //根据超限类型统计超限次数(连续超限时长超过指定时长为超限1次)
     m_Parser.AddCustomFunction("SADURATION", 1);
     m_Parser.AddCustomFunction("SADURATIONBYTYPE", 2);
     m_Parser.AddCustomFunction("SALONGDURATION", 2);
     m_Parser.AddCustomFunction("SALONGDURATIONBYTYPE", 3);
 }
Example #3
0
        public void ClientInitial()
        {
            DateTime StartDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            DateTime EndDate   = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);

            if (StartDate == EndDate)
            {
                StartDate = StartDate.AddMonths(-1);
            }
            txtStartDate.Text = StartDate.ToString("yyyy-MM-dd");
            txtEndDate.Text   = EndDate.ToString("yyyy-MM-dd");
            using (KPI_UnitDal DataAccess = new  KPI_UnitDal()){
                List <KPI_UnitEntity> UnitList = DataAccess.GetUnitIDs("");
                foreach (KPI_UnitEntity Entity in UnitList)
                {
                    if (Entity.UnitID != "0000")
                    {
                        drpUnits.Items.Add(new ListItem(Entity.UnitName, Entity.UnitID));
                    }
                }
            }
        }
Example #4
0
        public bool SnapshotCalc()
        {
            bool bGood = false;
            bool bIDL  = false;
            //DataTable dtUnit = KPI_UnitDal.GetUnitIDs("");
            //if (dtUnit == null || dtUnit.Rows.Count <= 0) {
            //    return true;
            //}
            //else {
            List <KPI_UnitEntity> UnitList;

            using (KPI_UnitDal DataAccess = new KPI_UnitDal()) {
                UnitList = DataAccess.GetUnitIDs("");
            }

            foreach (KPI_UnitEntity Unit in UnitList)
            {
                //string UnitID = Unit.UnitID;
                //string UnitName = KPI_UnitDal.GetUnitName(UnitID);
                if (string.IsNullOrEmpty(Unit.UnitID))
                {
                    continue;
                }
                //DataTable tags = Race_TagDal.GetTags(Unit.UnitID);
                List <Race_TagEntity> RaceTagList;
                using (Race_TagDal DataAccess = new Race_TagDal()) {
                    RaceTagList = DataAccess.GetTagList(Unit.UnitID);
                }
                //if (tags == null || tags.Rows.Count <= 0) {
                //    return true;
                //}
                if (RaceTagList.Count <= 0)
                {
                    return(true);
                }
                string WorkID      = Unit.WorkID;
                string CurrentTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                string ShiftName   = "";
                string PeriodName  = "";
                string StartTime   = "";
                string EndTime     = "";
                bGood = KPI_WorkDal.GetShiftAndPeriod(WorkID, CurrentTime, ref ShiftName, ref PeriodName, ref StartTime, ref EndTime);
                if (!bGood)
                {
                    return(false);
                }
                DateTime dts = DateTime.Parse(StartTime);
                DateTime dte = DateTime.Parse(EndTime);
                //从当前值的开始时间到当前时间的统计
                DateTime dtc = DateTime.Parse(CurrentTime);
                //////////////////////////////////////////////////////////////////////////////////
                //是否需要补算上一班的数据
                //并将数据写入到Archive中
                TimeSpan tspan = dtc - dts;
                if (tspan.TotalMinutes < 10)
                {
                    //刚好在交班时间内,需要将历史统计一下
                    bIDL = true;
                }
                if (bIDL)
                {
                    string HStartTime = dts.AddMinutes(-2 * tspan.TotalMinutes).ToString("yyyy-MM-dd HH:mm:ss");
                    string HEndTime   = dtc.ToString("yyyy-MM-dd HH:mm:ss");

                    LastShiftCalc(Unit.UnitID, HStartTime, HEndTime);
                }
                ////////////////////////////////////////////////////////////////////////
                //判断时间是否太小
                TimeSpan tscs = dtc - dts;
                if (tscs.TotalMinutes < 5)
                {
                    //间隔太小,不计算
                    continue;
                }
                ////////////////////////////////////////////////////////////////////////
                //string PeriodID = KPI_PeriodDal.GetPeriodID(PeriodName);
                //string ShiftID = KPI_ShiftDal.GetShiftID(ShiftName);

                RTInterface RTDB = DBAccess.GetRealTime();
                //实时计算
                foreach (Race_TagEntity RaceTag  in RaceTagList)
                {
                    //string TagID = tags.Rows[i]["TagID"].ToString();
                    decimal TagValue = decimal.MinValue;
                    //Race_TagEntity tentity = Race_TagDal.GetEntity(TagID);
                    if (RaceTag.TagCalcExpType == 0)
                    {
                        TagValue = Convert.ToDecimal(RTDB.TagCalculatedData(RaceTag.TagCalcExp, dts, dtc, RaceTag.TagFilterExp, GetRaceTagCalcType(RaceTag.TagCalcType)));
                        //Random rdm = new Random();
                        //TagValue = rdm.NextDouble() * 100;
                        if (TagValue == decimal.MinValue)
                        {
                            LogUtil.LogMessage(RaceTag.TagDesc + "数据出现错误!");
                            continue;
                        }
                        TagValue = Convert.ToDecimal(TagValue) * RaceTag.TagFactor + RaceTag.TagOffset;
                    }
                    else if (RaceTag.TagCalcExpType == 1)
                    {
                        TagValue = Convert.ToDecimal(RTDB.ExpCalculatedData(RaceTag.TagCalcExp, dts, dtc, 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 and insert
                    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;
                        string 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       = Unit.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);
                    }


                    //update and insert
                    if (GetArchiveExits(RaceTag.TagID, ShiftName, StartTime))
                    {
                        //update
                        //Race_ArchiveEntity sse = new Race_ArchiveEntity();

                        ////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;
                        string sql = @"update Race_Archive 
                                        set TagPeriod='{0}', TagEndTime='{1}', TagValue={2} 
                                    where TagID='{3}' and TagShift='{4}' and TagStartTime='{5}'";
                        sql = string.Format(sql, PeriodName, EndTime, TagValue.ToString(), RaceTag.TagID, ShiftName, StartTime);
                        DBAccess.GetRelation().ExecuteNonQuery(sql);
                    }
                    else
                    {
                        //insert
                        Race_ArchiveEntity sse = new Race_ArchiveEntity();

                        sse.TagID        = RaceTag.TagID;
                        sse.UnitID       = Unit.UnitID;
                        sse.TagType      = RaceTag.TagType;
                        sse.TagShift     = ShiftName;
                        sse.TagPeriod    = PeriodName;
                        sse.TagStartTime = StartTime;
                        sse.TagEndTime   = EndTime;
                        sse.TagValue     = Convert.ToDouble(TagValue);
                        Race_ArchiveDal.Insert(sse);
                    }
                }
            }
            return(true);
        }
Example #5
0
        /// <summary>
        /// Race_Archive的操作
        /// </summary>
        /// <returns></returns>
        public static bool HistoryCalc(DateTime dtSTime, DateTime dtETime)
        {
            bool bGood = false;
            //bool bIDL = false;

            //DataTable dtUnit = KPI_UnitDal.GetUnitIDs("");
            List <KPI_UnitEntity> UnitList;

            using (KPI_UnitDal DataAccess = new KPI_UnitDal()) {
                UnitList = DataAccess.GetUnitIDs("");
            }

            //if (dtUnit == null || dtUnit.Rows.Count <= 0) {
            //    return true;
            //}
            //else {
            //    for (int k = 0; k < dtUnit.Rows.Count; k++) {
            foreach (KPI_UnitEntity Unit in UnitList)
            {
                //string UnitID = dtUnit.Rows[k]["UnitID"].ToString();
                //string UnitName = KPI_UnitDal.GetUnitName(UnitID);

                string HStartTime = dtSTime.ToString("yyyy-MM-dd HH:mm:ss");
                string HEndTime   = dtETime.ToString("yyyy-MM-dd HH:mm:ss");
                if (string.IsNullOrEmpty(Unit.UnitID))
                {
                    continue;
                }

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

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

                sql = string.Format(sql, Unit.UnitID, HStartTime, HEndTime);

                DBAccess.GetRelation().ExecuteNonQuery(sql);

                //insert
                string WorkID = KPI_UnitDal.GetWorkIDByID(Unit.UnitID);

                bool bCalc = true;
                while (bCalc)
                {
                    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);
                    }

                    if (DateTime.Parse(EndTime) > DateTime.Parse(HEndTime))
                    {
                        //While 循环结束
                        bCalc = false;

                        continue;
                    }

                    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;
                        }
                        //insert Archive
                        //insert
                        Race_ArchiveEntity sae = new Race_ArchiveEntity();
                        sae.TagID        = RaceTag.TagID;
                        sae.UnitID       = Unit.UnitID;
                        sae.TagType      = RaceTag.TagType;
                        sae.TagShift     = ShiftName;
                        sae.TagPeriod    = PeriodName;
                        sae.TagStartTime = StartTime;
                        sae.TagEndTime   = EndTime;
                        sae.TagValue     = Convert.ToDouble(TagValue);
                        Race_ArchiveDal.Insert(sae);
                    }
                    HStartTime = EndTime;
                }
            }
            return(true);
        }
Example #6
0
 private void Initialize()
 {
     using (KPI_UnitDal DataAccess = new KPI_UnitDal()) {
         m_UnitList = DataAccess.GetUnitIDs(string.Empty);
     }
     m_Parser.CustomFunction += new FunctionHandler(Parser_CustomFunction);
     m_Parser.OnError += new ErrorHandler(Parser_OnError);
     m_Parser.AddCustomFunction("SACOUNT", 1);//超限次数统计
     m_Parser.AddCustomFunction("SACOUNTBYTYPE", 2);//根据超限类型统计超限次数
     m_Parser.AddCustomFunction("SALONGCOUNT", 2);//超限次数统计(连续超限时长超过指定时长为超限1次)
     m_Parser.AddCustomFunction("SALONGCOUNTBYTYPE", 3);//根据超限类型统计超限次数(连续超限时长超过指定时长为超限1次)
     m_Parser.AddCustomFunction("SADURATION", 1);
     m_Parser.AddCustomFunction("SADURATIONBYTYPE", 2);
     m_Parser.AddCustomFunction("SALONGDURATION", 2);
     m_Parser.AddCustomFunction("SALONGDURATIONBYTYPE", 3);
 }
Example #7
0
        /// <summary>
        /// Race_Archive的操作
        /// </summary>
        /// <returns></returns>
        public static bool HistoryCalc(DateTime dtSTime, DateTime dtETime)
        {
            bool bGood = false;
            //bool bIDL = false;

            //DataTable dtUnit = KPI_UnitDal.GetUnitIDs("");
            List<KPI_UnitEntity> UnitList;
            using (KPI_UnitDal DataAccess = new KPI_UnitDal()) {
                UnitList = DataAccess.GetUnitIDs("");
            }

            //if (dtUnit == null || dtUnit.Rows.Count <= 0) {
            //    return true;
            //}
            //else {
            //    for (int k = 0; k < dtUnit.Rows.Count; k++) {
            foreach (KPI_UnitEntity Unit in UnitList) {
                //string UnitID = dtUnit.Rows[k]["UnitID"].ToString();
                //string UnitName = KPI_UnitDal.GetUnitName(UnitID);

                string HStartTime = dtSTime.ToString("yyyy-MM-dd HH:mm:ss");
                string HEndTime = dtETime.ToString("yyyy-MM-dd HH:mm:ss");
                if (string.IsNullOrEmpty(Unit.UnitID)) {
                    continue;
                }

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

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

                sql = string.Format(sql, Unit.UnitID, HStartTime, HEndTime);

                DBAccess.GetRelation().ExecuteNonQuery(sql);

                //insert
                string WorkID = KPI_UnitDal.GetWorkIDByID(Unit.UnitID);

                bool bCalc = true;
                while (bCalc) {
                    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;
                    }

                    if (DateTime.Parse(EndTime) > DateTime.Parse(HEndTime)) {
                        //While 循环结束
                        bCalc = false;

                        continue;
                    }

                    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;
                        }
                        //insert Archive
                        //insert
                        Race_ArchiveEntity sae = new Race_ArchiveEntity();
                        sae.TagID = RaceTag.TagID;
                        sae.UnitID = Unit.UnitID;
                        sae.TagType = RaceTag.TagType;
                        sae.TagShift = ShiftName;
                        sae.TagPeriod = PeriodName;
                        sae.TagStartTime = StartTime;
                        sae.TagEndTime = EndTime;
                        sae.TagValue = Convert.ToDouble(TagValue);
                        Race_ArchiveDal.Insert(sae);
                    }
                    HStartTime = EndTime;
                }
            }
            return true;
        }
Example #8
0
        public bool SnapshotCalc()
        {
            bool bGood = false;
            bool bIDL = false;
            //DataTable dtUnit = KPI_UnitDal.GetUnitIDs("");
            //if (dtUnit == null || dtUnit.Rows.Count <= 0) {
            //    return true;
            //}
            //else {
            List<KPI_UnitEntity> UnitList;
            using (KPI_UnitDal DataAccess = new KPI_UnitDal()) {
                UnitList = DataAccess.GetUnitIDs("");
            }

            foreach (KPI_UnitEntity Unit in UnitList) {
                //string UnitID = Unit.UnitID;
                //string UnitName = KPI_UnitDal.GetUnitName(UnitID);
                if (string.IsNullOrEmpty(Unit.UnitID)) {
                    continue;
                }
                //DataTable tags = Race_TagDal.GetTags(Unit.UnitID);
                List<Race_TagEntity> RaceTagList;
                using (Race_TagDal DataAccess = new Race_TagDal()) {
                    RaceTagList = DataAccess.GetTagList(Unit.UnitID);
                }
                //if (tags == null || tags.Rows.Count <= 0) {
                //    return true;
                //}
                if (RaceTagList.Count <= 0) return true;
                string WorkID = Unit.WorkID;
                string CurrentTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                string ShiftName = "";
                string PeriodName = "";
                string StartTime = "";
                string EndTime = "";
                bGood = KPI_WorkDal.GetShiftAndPeriod(WorkID, CurrentTime, ref ShiftName, ref PeriodName, ref StartTime, ref EndTime);
                if (!bGood) {
                    return false;
                }
                DateTime dts = DateTime.Parse(StartTime);
                DateTime dte = DateTime.Parse(EndTime);
                //从当前值的开始时间到当前时间的统计
                DateTime dtc = DateTime.Parse(CurrentTime);
                //////////////////////////////////////////////////////////////////////////////////
                //是否需要补算上一班的数据
                //并将数据写入到Archive中
                TimeSpan tspan = dtc - dts;
                if (tspan.TotalMinutes < 10) {
                    //刚好在交班时间内,需要将历史统计一下
                    bIDL = true;
                }
                if (bIDL) {
                    string HStartTime = dts.AddMinutes(-2 * tspan.TotalMinutes).ToString("yyyy-MM-dd HH:mm:ss");
                    string HEndTime = dtc.ToString("yyyy-MM-dd HH:mm:ss");

                    LastShiftCalc(Unit.UnitID, HStartTime, HEndTime);
                }
                ////////////////////////////////////////////////////////////////////////
                //判断时间是否太小
                TimeSpan tscs = dtc - dts;
                if (tscs.TotalMinutes < 5) {
                    //间隔太小,不计算
                    continue;
                }
                ////////////////////////////////////////////////////////////////////////
                //string PeriodID = KPI_PeriodDal.GetPeriodID(PeriodName);
                //string ShiftID = KPI_ShiftDal.GetShiftID(ShiftName);

                RTInterface RTDB = DBAccess.GetRealTime();
                //实时计算
                foreach (Race_TagEntity RaceTag  in RaceTagList) {
                    //string TagID = tags.Rows[i]["TagID"].ToString();
                    decimal TagValue = decimal.MinValue;
                    //Race_TagEntity tentity = Race_TagDal.GetEntity(TagID);
                    if (RaceTag.TagCalcExpType == 0) {
                        TagValue = Convert.ToDecimal(RTDB.TagCalculatedData(RaceTag.TagCalcExp, dts, dtc, RaceTag.TagFilterExp, GetRaceTagCalcType(RaceTag.TagCalcType)));
                        //Random rdm = new Random();
                        //TagValue = rdm.NextDouble() * 100;
                        if (TagValue == decimal.MinValue) {
                            LogUtil.LogMessage(RaceTag.TagDesc + "数据出现错误!");
                            continue;
                        }
                        TagValue = Convert.ToDecimal(TagValue) * RaceTag.TagFactor + RaceTag.TagOffset;
                    }
                    else if (RaceTag.TagCalcExpType == 1) {
                        TagValue = Convert.ToDecimal(RTDB.ExpCalculatedData(RaceTag.TagCalcExp, dts, dtc, 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 and insert
                    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;
                        string 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 = Unit.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);
                    }

                    //update and insert
                    if (GetArchiveExits(RaceTag.TagID, ShiftName, StartTime)) {
                        //update
                        //Race_ArchiveEntity sse = new Race_ArchiveEntity();

                        ////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;
                        string sql = @"update Race_Archive
                                        set TagPeriod='{0}', TagEndTime='{1}', TagValue={2}
                                    where TagID='{3}' and TagShift='{4}' and TagStartTime='{5}'";
                        sql = string.Format(sql, PeriodName, EndTime, TagValue.ToString(), RaceTag.TagID, ShiftName, StartTime);
                        DBAccess.GetRelation().ExecuteNonQuery(sql);

                    }
                    else {
                        //insert
                        Race_ArchiveEntity sse = new Race_ArchiveEntity();

                        sse.TagID = RaceTag.TagID;
                        sse.UnitID = Unit.UnitID;
                        sse.TagType = RaceTag.TagType;
                        sse.TagShift = ShiftName;
                        sse.TagPeriod = PeriodName;
                        sse.TagStartTime = StartTime;
                        sse.TagEndTime = EndTime;
                        sse.TagValue = Convert.ToDouble(TagValue);
                        Race_ArchiveDal.Insert(sse);
                    }
                }
            }
            return true;
        }