示例#1
0
        /// <summary>
        /// 通过时间变更小时数
        /// </summary>
        /// <param name="WorkID">主键</param>
        /// <returns></returns>
        public static double GetIDLHour(string WorkID)
        {
            double IDLHour = 1;

            KPI_WorkEntity entity = KPI_WorkDal.GetEntity(WorkID);

            int    nBaseShifts = entity.WorkBaseShifts;
            string strSequence = entity.WorkSequence;

            //strSequence = strSequence.Remove(strSequence.LastIndexOf('-'));
            string[] AllPeriods = strSequence.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries);

            //当天班的顺序
            //string[] strCurrentPeriod = new string[nBaseShifts];
            for (int i = 0; i < nBaseShifts; i++)
            {
                string strC = AllPeriods[nBaseShifts + i];

                KPI_PeriodEntity pd = KPI_PeriodDal.GetEntity(strC);

                int nIDL = int.Parse(pd.PeriodIsIDL);
                if (nIDL == 1)
                {
                    IDLHour = Convert.ToDouble(pd.PeriodEndHour);
                    break;
                }
            }

            return(IDLHour);
        }
示例#2
0
        protected void gvPeriod_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            string sID = ((HtmlInputHidden)(gvPeriod.Rows[e.RowIndex].Cells[0].FindControl("periodid"))).Value.ToString().Trim();

            string sName  = ((TextBox)(gvPeriod.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim();
            string sDesc  = ((TextBox)(gvPeriod.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim();
            string sStart = ((TextBox)(gvPeriod.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim();
            string sEnd   = ((TextBox)(gvPeriod.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim();
            //string sLong = ((TextBox)(gvPeriod.Rows[e.RowIndex].Cells[6].Controls[0])).Text.ToString().Trim();
            string sIDL   = ((DropDownList)(gvPeriod.Rows[e.RowIndex].Cells[7].FindControl("ddlIDL"))).SelectedValue;
            string sValid = ((DropDownList)(gvPeriod.Rows[e.RowIndex].Cells[8].FindControl("ddlValid"))).SelectedValue;
            string sNote  = ((TextBox)(gvPeriod.Rows[e.RowIndex].Cells[9].Controls[0])).Text.ToString().Trim();

            if (sName == "")
            {
                MessageBox.popupClientMessage(this.Page, "名称不能为空!", "call();");
                return;
            }

            //名称是否重复
            if (KPI_PeriodDal.PeriodNameExists(sName, sID))
            {
                MessageBox.popupClientMessage(this.Page, "已存在相同的名称!");
                return;
            }

            //更新
            KPI_PeriodEntity ote = new KPI_PeriodEntity();

            ote.PeriodID         = sID;
            ote.PeriodName       = sName;
            ote.PeriodDesc       = sDesc;
            ote.PeriodStartHour  = decimal.Parse(sStart);
            ote.PeriodEndHour    = decimal.Parse(sEnd);
            ote.PeriodHours      = sIDL == "1" ? (decimal.Parse(sEnd) + 24 - decimal.Parse(sStart)) : (decimal.Parse(sEnd) - decimal.Parse(sStart));
            ote.PeriodIsIDL      = sIDL;
            ote.PeriodIsValid    = sValid;
            ote.PeriodNote       = sNote;
            ote.PeriodModifyTime = DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss");

            if (KPI_PeriodDal.Update(ote))
            {
                MessageBox.popupClientMessage(this.Page, "编辑成功!", "call();");
            }
            else
            {
                MessageBox.popupClientMessage(this.Page, "编辑错误!", "call();");
            }

            gvPeriod.EditIndex = -1;

            BindPeriod();
        }
示例#3
0
        protected void btnAddPeriod_Click(object sender, EventArgs e)
        {
            //集团信息,新增页面
            //string strjs = "<script language=javascript>window.open('KPI_SubRunPeriod.aspx','newwindow','width=500,height=400')</script>";

            //ClientScript.RegisterStartupScript(this.GetType(), "", strjs);

            int index = KPI_PeriodDal.PeriodIDCounts();

            string sID = PageControl.GetGuid();

            KPI_PeriodEntity ote = new KPI_PeriodEntity();

            ote.PeriodID        = sID;
            ote.PeriodCode      = KPI_PeriodDal.GetNextCode();
            ote.PeriodName      = "InputName";
            ote.PeriodDesc      = "";
            ote.PeriodStartHour = 8;
            ote.PeriodEndHour   = 17;
            ote.PeriodHours     = 9;
            ote.PeriodIsIDL     = "0";
            ote.PeriodIsValid   = "1";
            ote.PeriodNote      = "";

            ote.PeriodCreateTime = DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss");
            ote.PeriodModifyTime = ote.PeriodCreateTime;

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

                gvPeriod.EditIndex = index;

                BindPeriod();
            }
            else
            {
                MessageBox.popupClientMessage(this.Page, "添加错误!", "call();");
            }
        }
示例#4
0
        /// <summary>
        /// 计算安全实时得分
        /// </summary>
        public void Calculation()
        {
            //DateTime EndTime = DateTime.Now;
            String format = "开始时间:{0} 结束时间:{1}";

            IsCalcShift = false;
            DateTime EndTime             = DateTime.Now;
            DateTime StartTime           = EndTime.AddHours(-1);
            decimal  End                 = EndTime.Hour + EndTime.Minute / 60.0m;
            decimal  Start               = StartTime.Hour + StartTime.Minute / 60.0m;
            List <KPI_PeriodEntity> list = KPI_PeriodDal.GetPeriodEntityList();
            KPI_PeriodEntity        item = list.Where(p => ((End - p.PeriodEndHour) <= 8) &&
                                                      ((End - p.PeriodEndHour) >= 0) && (p.PeriodHours > 0)).First();
            decimal PeriodEndHour = item.PeriodEndHour;
            decimal hours         = End - PeriodEndHour;

            if ((hours > 0) && (hours < 1.0m))
            {
                //EndTime = DateTime.Now;
                StartTime = EndTime.AddHours(-1 * Convert.ToDouble(hours));
                //Console.WriteLine(String.Format(format, StartTime.ToString("yyyy-MM-dd HH:mm:ss"),
                //        EndTime.ToString("yyyy-MM-dd HH:mm:ss")));
                CalculateSAScore(StartTime, EndTime);                //计算当前值安全得分

                //计算前值安全得分
                EndTime   = StartTime;
                hours     = 1.0m - hours;
                StartTime = EndTime.AddHours(-1 * Convert.ToDouble(hours));
                //Console.WriteLine(String.Format(format, StartTime.ToString("yyyy-MM-dd HH:mm:ss"),
                //        EndTime.ToString("yyyy-MM-dd HH:mm:ss")));
                CalculateSAScore(StartTime, EndTime);
            }
            if ((hours >= 1.0m) || ((hours <= 0) && (hours >= -0.5m)))
            {
                //Console.WriteLine(String.Format(format, StartTime.ToString("yyyy-MM-dd HH:mm:ss"),
                //        EndTime.ToString("yyyy-MM-dd HH:mm:ss")));
                CalculateSAScore(StartTime, EndTime);                //计算当前值安全得分
            }
            //m_Log.Info("Calculation()被调用");
        }
示例#5
0
        /// <summary>
        /// 通过时间获得当前值、当前班、开始时间、结束时间
        /// </summary>
        /// <param name="WorkID">主键</param>
        /// <returns></returns>
        public static bool GetShiftAndPeriod(string WorkID, string QueryTime,
                                             ref string ShiftName, ref string PeriodName,
                                             ref string StartTime, ref string EndTime)
        {
            ShiftName  = "";
            PeriodName = "";
            StartTime  = "";
            EndTime    = "";

            KPI_WorkEntity entity = KPI_WorkDal.GetEntity(WorkID);

            DateTime dtQueryTime = DateTime.Parse(QueryTime);

            string strStartTime = entity.WorkStartTime;
            int    nBaseShifts  = entity.WorkBaseShifts;
            int    nBaseDays    = entity.WorkBaseDays;
            string strSequence  = entity.WorkSequence;
            string strShift     = entity.WorkShift;

            //判断是否查询时间超出范围
            if (DateTime.Parse(strStartTime) > dtQueryTime)
            {
                return(false);
            }

            //int[] timearray = new int[6] { dtQueryTime.Year, dtQueryTime.Month, dtQueryTime.Day, dtQueryTime.Hour, 0, 0 };
            DateTime dtStartTime = dtQueryTime;
            DateTime dtEndTime   = dtQueryTime;


            //获得值班顺序
            //strSequence = strSequence.Remove(strSequence.LastIndexOf('-'));
            string[] AllPeriods = strSequence.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries);

            //strShift = strShift.Remove(strShift.LastIndexOf('-'));
            string[] AllShifts = strShift.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries);

            TimeSpan tspan = DateTime.Parse(QueryTime) - DateTime.Parse(strStartTime);

            //当天班的序号
            int nDay = tspan.Days % nBaseDays;

            //当天班的顺序
            string[] strCurrentPeriod = new string[nBaseShifts];
            for (int i = 0; i < nBaseShifts; i++)
            {
                strCurrentPeriod[i] = AllPeriods[nDay * nBaseShifts + i];
            }

            decimal CurrentHour = Convert.ToDecimal(dtQueryTime.Hour + dtQueryTime.Minute / 60.0m);
            //DateTime dt
            bool bPeriod  = false;
            bool bLastDay = false;

            int id = 0;

            for (id = 0; id < nBaseShifts; id++)
            {
                bPeriod  = false;
                bLastDay = false;

                string           strP = strCurrentPeriod[id];
                KPI_PeriodEntity pe   = KPI_PeriodDal.GetEntity(strP);

                int nIDL = int.Parse(pe.PeriodIsIDL);

                if (pe.PeriodStartHour == -1)
                {
                    continue;
                }

                if (nIDL == 0 && (CurrentHour >= pe.PeriodStartHour && CurrentHour < pe.PeriodEndHour))
                {
                    bPeriod = true;

                    //班名称,开始时间,结束时间
                    PeriodName = pe.PeriodName;

                    //班开始结束时间的小时、分钟转换,考虑有半点交班的情况。
                    int sh = (int)Math.Floor(pe.PeriodStartHour);
                    int sm = (int)((pe.PeriodStartHour - sh) * 60);
                    int eh = (int)Math.Floor(pe.PeriodEndHour);
                    int em = (int)((pe.PeriodEndHour - eh) * 60);

                    dtStartTime = new DateTime(dtQueryTime.Year, dtQueryTime.Month, dtQueryTime.Day, sh, sm, 0);
                    dtEndTime   = new DateTime(dtQueryTime.Year, dtQueryTime.Month, dtQueryTime.Day, eh, em, 0);
                }

                if (nIDL == 1 && (CurrentHour >= pe.PeriodStartHour && CurrentHour < 24))
                {
                    bPeriod = true;

                    //班名称,开始时间,结束时间
                    PeriodName = pe.PeriodName;


                    //班开始结束时间的小时、分钟转换,考虑有半点交班的情况。
                    int sh = (int)Math.Floor(pe.PeriodStartHour);
                    int sm = (int)((pe.PeriodStartHour - sh) * 60);
                    int eh = (int)Math.Floor(pe.PeriodEndHour);
                    int em = (int)((pe.PeriodEndHour - eh) * 60);

                    dtStartTime = new DateTime(dtQueryTime.Year, dtQueryTime.Month, dtQueryTime.Day, sh, sm, 0);
                    DateTime dtNextTime = dtQueryTime.AddDays(1);
                    dtEndTime = new DateTime(dtNextTime.Year, dtNextTime.Month, dtNextTime.Day, eh, em, 0);
                }

                if (nIDL == 1 && (CurrentHour >= 0 && CurrentHour < pe.PeriodEndHour))
                {
                    bPeriod  = true;
                    bLastDay = true;

                    //班名称,开始时间,结束时间
                    PeriodName = pe.PeriodName;


                    //班开始结束时间的小时、分钟转换,考虑有半点交班的情况。
                    int sh = (int)Math.Floor(pe.PeriodStartHour);
                    int sm = (int)((pe.PeriodStartHour - sh) * 60);
                    int eh = (int)Math.Floor(pe.PeriodEndHour);
                    int em = (int)((pe.PeriodEndHour - eh) * 60);

                    DateTime dtLastTime = dtQueryTime.AddDays(-1);
                    dtStartTime = new DateTime(dtLastTime.Year, dtLastTime.Month, dtLastTime.Day, sh, sm, 0);
                    dtEndTime   = new DateTime(dtQueryTime.Year, dtQueryTime.Month, dtQueryTime.Day, eh, em, 0);
                }

                //已经获得开始时间和结束时间。
                if (bPeriod)
                {
                    break;
                }
            }

            if (bPeriod)
            {
                if (bLastDay)
                {
                    //前一天的序号
                    int nLastDay = (nDay + (nBaseDays - 1)) % nBaseDays;
                    //前一天班的顺序
                    string[] strLastPeriod = new string[nBaseShifts];
                    for (int i = 0; i < nBaseShifts; i++)
                    {
                        strLastPeriod[i] = AllPeriods[nLastDay * nBaseShifts + i];
                    }

                    for (int i = 0; i < nBaseShifts; i++)
                    {
                        if (strCurrentPeriod[id] == strLastPeriod[i])
                        {
                            ShiftName = KPI_ShiftDal.GetShiftName(AllShifts[i]);

                            break;
                        }
                    }
                }
                else
                {
                    ShiftName = KPI_ShiftDal.GetShiftName(AllShifts[id]);
                }

                StartTime = dtStartTime.ToString("yyy-MM-dd HH:mm:ss");
                EndTime   = dtEndTime.ToString("yyy-MM-dd HH:mm:ss");
            }
            else
            {
                return(false);
            }


            return(true);
        }