Ejemplo n.º 1
0
 protected override void OnLoad(EventArgs e)
 {
     base.OnLoad(e);
     if (!IsPostBack)
     {
         String strStartTime            = "";
         String strEndTime              = "";
         String CurrentShift            = "";
         String Period                  = "";
         List <KPI_UnitEntity> UnitList = KPI_UnitDal.GetAllEntity();
         if (UnitList.Count > 0)
         {
             String         UnitID = UnitList.First().UnitID;
             KPI_UnitEntity Entity = KPI_UnitDal.GetEntity(UnitID);
             if (Entity != null)
             {
                 String strWorkID        = Entity.WorkID;
                 String strCurrentMinute = DateTime.Now.ToString("yyyy-MM-dd HH:mm:00");
                 KPI_WorkDal.GetShiftAndPeriod(strWorkID, strCurrentMinute,
                                               ref CurrentShift, ref Period, ref strStartTime, ref strEndTime);
             }
             lblShift.Text  = CurrentShift;
             Shift          = CurrentShift;
             ShiftStartTime = Convert.ToDateTime(strStartTime);
             ShiftEndTime   = Convert.ToDateTime(strEndTime);
         }
         DataBind();
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取班次与值次
        /// </summary>
        /// <param name="UnitID">机组编码</param>
        /// <param name="Shift">当前值</param>
        /// <param name="Period">当前班</param>
        private void GetShiftAndPeriod(String UnitID, out String Shift, out String Period, DateTime CalcTime)
        {
            String strStartTime = "";
            String strEndTime   = "";

            Shift  = "";
            Period = "";
            KPI_UnitEntity Entity = KPI_UnitDal.GetEntity(UnitID);

            if (Entity == null)
            {
                return;
            }
            try
            {
                String strWorkID        = Entity.WorkID;
                String strCurrentMinute = CalcTime.ToString("yyyy-MM-dd HH:mm:00");
                KPI_WorkDal.GetShiftAndPeriod(strWorkID, strCurrentMinute,
                                              ref Shift, ref Period, ref strStartTime, ref strEndTime);
            }
            catch (Exception ex)
            {
                m_Logger.Error(ex.Message, ex);
            }
        }
Ejemplo n.º 3
0
        public void Execute(IJobExecutionContext context)
        {
            MonitorDurationDal    DataAccess = new MonitorDurationDal();
            List <KPI_UnitEntity> UnitList   = KPI_UnitDal.GetAllEntity();

            foreach (KPI_UnitEntity Unit in UnitList)
            {
                if (String.IsNullOrEmpty(Unit.WorkID))
                {
                    return;
                }
                if (UnitIsRunning(Unit.UnitID))
                {
                    m_Loger.InfoFormat("开始计算{0}操盘时间", Unit.UnitName);
                    MonitorDurationEntity MonitorDuration = new MonitorDurationEntity();
                    DateTime Now              = DateTime.Now;
                    String   strStartTime     = "";
                    String   strEndTime       = "";
                    String   Shift            = "";
                    String   Period           = "";
                    String   strCurrentMinute = Now.ToString("yyyy-MM-dd HH:mm:00");
                    KPI_WorkDal.GetShiftAndPeriod(Unit.WorkID, strCurrentMinute,
                                                  ref Shift, ref Period, ref strStartTime, ref strEndTime);
                    DateTime ShiftStartTime = Convert.ToDateTime(strStartTime);
                    DateTime ShiftEndTime   = Convert.ToDateTime(strEndTime);
                    MonitorDuration.UnitID    = Unit.UnitID;
                    MonitorDuration.Shift     = Shift;
                    MonitorDuration.CheckDate = Now.Date;
                    MonitorDuration.Duration  = GetDuration(ShiftStartTime, ShiftEndTime);
                    m_Loger.InfoFormat("{0}值值班开始时间{1}值班结束时间{2}当天操盘时长是{3}小时", Shift, ShiftStartTime, ShiftEndTime, MonitorDuration.Duration);
                    DataAccess.SaveMonitorDuration(MonitorDuration);
                    m_Loger.InfoFormat("{0}操盘时间计算结束", Unit.UnitName);
                }
            }
        }
Ejemplo n.º 4
0
        public override void DataBind()
        {
            string SpecialField = Request.Params["ecweb"];
            string queryTime    = DateTime.Now.ToString("yyyy-MM-dd HH:mm:00");
            String PlantCode    = Request.Params["plantcode"];
            String UnitCode     = Request.Params["unitcode"];
            String PlantID      = KPI_PlantDal.GetPlantIDByCode(PlantCode);
            String UnitID       = KPI_UnitDal.GetUnitIDByCode(UnitCode);

            gvReal.DataSource = KPI_RealValueDal.GetRealValue(PlantID, "");
            base.DataBind();

            nowtime.Text  = "计算时间:" + queryTime;
            nowshift.Text = "轮班值次:";
            if (!String.IsNullOrWhiteSpace(UnitID))
            {
                string workid     = KPI_UnitDal.GetWorkIDByID(UnitID);
                string ShiftName  = "";
                string PeriodName = "";
                string StartTime  = "";
                string EndTime    = "";
                bool   bGood      = KPI_WorkDal.GetShiftAndPeriod(workid, queryTime, ref ShiftName,
                                                                  ref PeriodName, ref StartTime, ref EndTime);
                nowshift.Text = "轮班值次:" + ShiftName;
            }
        }
Ejemplo n.º 5
0
        void BindWork()
        {
            DataTable dt = KPI_WorkDal.GetWorkList();

            gvWork.DataSource = dt;
            gvWork.DataBind();
        }
Ejemplo n.º 6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                btnApply.Attributes.Add("onclick", "setDivPos('Lay1');Lay1.style.visibility='';progress_update();");

                btnCancel.Attributes.Add("onclick", "javascript:return confirm('确认关闭吗?');");

                //电厂信息
                DataTable dt = KPI_PlantDal.GetPlants("");
                foreach (DataRow dr in dt.Rows)
                {
                    ddl_PlantID.Items.Add(new ListItem(dr["Name"].ToString(), dr["ID"].ToString()));
                }

                //倒班信息
                dt = KPI_WorkDal.GetWorks();
                ddl_UnitWorkID.Items.Add(new ListItem("无", "NULL"));
                foreach (DataRow dr in dt.Rows)
                {
                    ddl_UnitWorkID.Items.Add(new ListItem(dr["Name"].ToString(), dr["ID"].ToString()));
                }


                //判断是否新建或编辑
                if (Request.QueryString["unitid"] != null)
                {
                    ViewState["unitid"] = Request.QueryString["unitid"].ToString();

                    BindValues();
                }
                else
                {
                    //添加
                    ViewState["unitid"] = "";

                    //
                    txt_UnitIndex.Value      = "1";
                    ddl_UnitIsValid.Value    = "1";
                    ddl_UnitIsKPI.Value      = "1";
                    ddl_UnitIsSnapshot.Value = "1";
                    ddl_UnitIsSort.Value     = "0";
                    ddl_UnitIsSecurity.Value = "0";
                    ddl_UnitIsPower.Value    = "0";


                    btnApply.Visible  = true;
                    btnCancel.Visible = true;

                    //ImgSeqReview.Visible = false;
                    //ImgSeqConfig.Visible = false;
                }
            }
        }
Ejemplo n.º 7
0
        void BindWorkID(string WorkID)
        {
            //初始化
            KPI_WorkEntity kwe = KPI_WorkDal.GetEntity(WorkID);

            txt_WorkID.Value = WorkID;

            int nShifts = kwe.WorkBaseShifts;
            int nDays   = kwe.WorkBaseDays;


            ddl_BaseDays.SelectedValue   = nDays.ToString();
            ddl_BaseShifts.SelectedValue = nShifts.ToString();

            txt_WorkName.Value = kwe.WorkName;
            txt_WorkDesc.Value = kwe.WorkDesc;

            ddl_WorkIsValid.SelectedValue = kwe.WorkIsValid.ToString();

            txt_WorkNote.Value = kwe.WorkNote;

            txt_date.Value = kwe.WorkStartTime;

            string sWorkSequence = kwe.WorkSequence;
            string sWorkShift    = kwe.WorkShift;

            string[] ws = sWorkSequence.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries);
            string[] fs = sWorkShift.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries);


            //值初始化
            for (int i = 0; i < nShifts; i++)
            {
                string       id  = string.Format("ddl_shift{0:d2}", i);
                DropDownList ddl = (DropDownList)this.FindControl(id);

                ddl.SelectedValue = fs[i];
            }

            //班初始化
            for (int j = 0; j < nDays; j++)
            {
                for (int i = 0; i < nShifts; i++)
                {
                    string       id  = string.Format("ddl_period{0}{1}", i, j);
                    DropDownList ddl = (DropDownList)this.FindControl(id);
                    ddl.SelectedValue = ws[j * nShifts + i];
                }
            }
            SetDisplay();
        }
Ejemplo n.º 8
0
        private static void GetShift()
        {
            String strCurrentShift  = "";
            String strCurrentPeriod = "";
            String strStartTime     = "";
            String strEndTime       = "";
            //获取班次与值次
            //KPI_UnitDal.GetValidEntity()
            String strWorkID        = "48883e53-0647-47f1-98d6-fa6b4f8464cb";
            String strCurrentMinute = DateTime.Now.ToString("yyyy-MM-dd HH:mm:00");

            KPI_WorkDal.GetShiftAndPeriod(strWorkID, strCurrentMinute,
                                          ref strCurrentShift, ref strCurrentPeriod, ref strStartTime, ref strEndTime);
            Console.WriteLine("当前值是:" + strCurrentShift);
            Console.WriteLine("当前班是:" + strCurrentPeriod);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 交接时关闭上一班报警
        /// </summary>
        /// <param name="faultConfiguration"></param>
        private void StopLastShiftAlarm(OverLimitConfigEntity faultConfiguration)
        {
            KPI_UnitEntity Entity = KPI_UnitDal.GetEntity(faultConfiguration.UnitID);

            if (Entity == null)
            {
                return;
            }
            String strWorkID        = Entity.WorkID;
            String strStartTime     = "";
            String strEndTime       = "";
            String Shift            = "";
            String Period           = "";
            String strCurrentMinute = DateTime.Now.ToString("yyyy-MM-dd HH:mm:00");

            KPI_WorkDal.GetShiftAndPeriod(strWorkID, strCurrentMinute,
                                          ref Shift, ref Period, ref strStartTime, ref strEndTime);
            DateTime ShiftStartTime = Convert.ToDateTime(strStartTime);
            DateTime CurrentTime    = DateTime.Now;
            TimeSpan Span           = CurrentTime - ShiftStartTime;
            double   TotalMinutes   = Span.TotalMinutes;

            if (TotalMinutes <= 10)
            {
                try {
                    using (KPI_OverLimitRecordDal DataAccess = new KPI_OverLimitRecordDal()) {
                        KPI_OverLimitRecordEntity entity = new KPI_OverLimitRecordEntity();
                        for (int i = 1; i < 4; i++)
                        {
                            entity.TagID          = faultConfiguration.TagName;
                            entity.AlarmStartTime = ShiftStartTime;
                            entity.AlarmType      = i;
                            DataAccess.UpdateOverLimitRecord(entity);
                        }
                    }
                }
                catch (Exception ex) {
                    m_Logger.InfoFormat("StopLastShiftAlarm安全指标超限报警计算错误,错误信息是:{0},调用栈信息是:{1}",
                                        ex.Message, ex.StackTrace);
                    m_Logger.Error(ex);
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 获取班次与值次
        /// </summary>
        /// <param name="UnitID">机组编码</param>
        /// <param name="Shift">当前值</param>
        /// <param name="Period">当前班</param>
        private void GetShiftAndPeriod(String UnitID, out String Shift, out String Period)
        {
            String strStartTime = "";
            String strEndTime   = "";

            Shift  = "";
            Period = "";
            KPI_UnitEntity Entity = KPI_UnitDal.GetEntity(UnitID);

            if (Entity == null)
            {
                return;
            }
            String strWorkID        = Entity.WorkID;
            String strCurrentMinute = DateTime.Now.ToString("yyyy-MM-dd HH:mm:00");

            KPI_WorkDal.GetShiftAndPeriod(strWorkID, strCurrentMinute,
                                          ref Shift, ref Period, ref strStartTime, ref strEndTime);
        }
Ejemplo n.º 11
0
        private CurrentWorkInfo GetWorkInfo(String unitID, DateTime CalcDateTime)
        {
            CurrentWorkInfo Result = new CurrentWorkInfo();
            KPI_UnitEntity  Entity = KPI_UnitDal.GetEntity(unitID);

            Result.WorkID = Entity.WorkID;
            String strStartTime     = "";
            String strEndTime       = "";
            String Shift            = "";
            String Period           = "";
            String strCurrentMinute = CalcDateTime.ToString("yyyy-MM-dd HH:mm:00");

            KPI_WorkDal.GetShiftAndPeriod(Result.WorkID, strCurrentMinute,
                                          ref Shift, ref Period, ref strStartTime, ref strEndTime);
            Result.Shift     = Shift;
            Result.Period    = Period;
            Result.StartTime = Convert.ToDateTime(strStartTime);
            Result.EndTime   = Convert.ToDateTime(strEndTime);
            return(Result);
        }
Ejemplo n.º 12
0
        protected void gvWork_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string keyid = e.CommandArgument.ToString();

            if (e.CommandName == "dataDelete")
            {
                if (KPI_WorkDal.DeleteWork(keyid))
                {
                    MessageBox.popupClientMessage(this.Page, "删除成功!", "call();");

                    BindWork();
                }
                else
                {
                    MessageBox.popupClientMessage(this.Page, "删除错误!", "call();");
                }
            }
            else if (e.CommandName == "dataView")
            {
                BindWorkID(keyid);
            }
        }
Ejemplo n.º 13
0
        public void Execute(IJobExecutionContext context)
        {
            MonitorDurationEntity MonitorDuration = new MonitorDurationEntity();
            DateTime Now              = DateTime.Now;
            decimal  Hours            = Now.Hour + Now.Minute / 60.0m;
            String   strStartTime     = "";
            String   strEndTime       = "";
            String   Shift            = "";
            String   Period           = "";
            String   strCurrentMinute = Now.AddMinutes(-2).ToString("yyyy-MM-dd HH:mm:00");

            try {
                KPI_WorkDal.GetShiftAndPeriod(WorkID, strCurrentMinute,
                                              ref Shift, ref Period, ref strStartTime, ref strEndTime);
                DateTime ShiftStartTime = Convert.ToDateTime(strStartTime);
                DateTime CurrentTime    = DateTime.Now;
                TimeSpan Span           = CurrentTime - ShiftStartTime;
                MonitorDuration.Shift     = Shift;
                MonitorDuration.CheckDate = Now.AddMinutes(-1);
                MonitorDuration.Duration  = 0.5m;
                //if ((Hours > 16.5m) && (Hours <= 24.0m)) MonitorDuration.Duration = 7.5m;//SET @Duration=7.5
                //if ((Hours >= 0.0m) && (Hours <= 0.5m)) MonitorDuration.Duration = 0.5m;
                List <KPI_UnitEntity> Units = KPI_UnitDal.GetAllEntity();

                using (MonitorDurationDal DataAccess = new MonitorDurationDal()) {
                    foreach (KPI_UnitEntity Unit in Units)
                    {
                        MonitorDuration.UnitID = Unit.UnitID;
                        DataAccess.SaveMonitorDuration(MonitorDuration);
                    }
                }
            }
            catch (Exception ex) {
                m_Log.Error("各值监盘时间计算错误", ex);
            }
        }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
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);
        }
Ejemplo n.º 17
0
        protected void btnAddWork_Click(object sender, EventArgs e)
        {
            //检查名称是否重复
            string sName = txt_WorkName.Value.Trim();

            if (KPI_WorkDal.WorkNameExists(sName, ""))
            {
                MessageBox.popupClientMessage(this.Page, "名称已存在,请修改倒班名称!", "call();");

                return;
            }


            int nShifts = int.Parse(ddl_BaseShifts.SelectedValue);
            int nDays   = int.Parse(ddl_BaseDays.SelectedValue);

            string sWorkSequence = "";

            //WorkSequence
            for (int j = 0; j < nDays; j++)
            {
                for (int i = 0; i < nShifts; i++)
                {
                    string       id  = string.Format("ddl_period{0}{1}", i, j);
                    DropDownList ddl = (DropDownList)this.FindControl(id);
                    sWorkSequence += ddl.SelectedValue + "-";
                }
            }

            string sWorkShift = "";

            //WorkShift
            for (int i = 0; i < nShifts; i++)
            {
                string       id  = string.Format("ddl_shift0{0}", i);
                DropDownList ddl = (DropDownList)this.FindControl(id);

                sWorkShift += ddl.SelectedValue + "-";
            }

            string keyid = PageControl.GetGuid();

            //////////////////////////////////////////////////////////////////////////////
            KPI_WorkEntity kwe = new KPI_WorkEntity();

            kwe.WorkID         = keyid;
            kwe.WorkName       = txt_WorkName.Value;
            kwe.WorkDesc       = txt_WorkDesc.Value;
            kwe.WorkStartTime  = txt_date.Value;
            kwe.WorkEndTime    = DateTime.Now.AddYears(10).ToLocalTime().ToString("yyyy-MM-dd");
            kwe.WorkBaseShifts = nShifts;
            kwe.WorkBaseDays   = nDays;
            kwe.WorkSequence   = sWorkSequence;
            kwe.WorkShift      = sWorkShift;
            kwe.WorkIsValid    = int.Parse(ddl_WorkIsValid.SelectedValue);
            kwe.WorkNote       = txt_WorkNote.Value;
            kwe.WorkCreateTime = DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss");

            kwe.WorkModifyTime = kwe.WorkCreateTime;

            ///////////////////////////////////////////////////////////////////////////////
            if (KPI_WorkDal.Insert(kwe))
            {
                MessageBox.popupClientMessage(this.Page, "添加成功!", "call();");

                BindWork();
            }
            else
            {
                MessageBox.popupClientMessage(this.Page, "添加错误!", "call();");
            }

            if (KPI_WorkDal.Update(kwe))
            {
                MessageBox.popupClientMessage(this.Page, "修改成功!", "call();");

                BindWork();
            }
            else
            {
                MessageBox.popupClientMessage(this.Page, "修改错误!", "call();");
            }
        }