void BindPeriod()
        {
            //班信息
            DataTable dtPeriod = KPI_PeriodDal.GetPeriodList();

            gvPeriod.DataSource = dtPeriod;
            gvPeriod.DataBind();
        }
        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();
        }
        protected void gvPeriod_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string keyid = e.CommandArgument.ToString();

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


                    BindPeriod();
                }
                else
                {
                    MessageBox.popupClientMessage(this.Page, "删除错误!", "call();");
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// 计算安全历史得分
        /// </summary>
        /// <param name="StartDateTime">开始时间</param>
        /// <param name="EndDateTime">结束时间</param>
        public void ArchiveCalculation(DateTime StartDateTime, DateTime EndDateTime)
        {
            IsCalcShift = false;
            DateTime StartTime, EndTime;
            decimal  StartHour, EndHour, PeriodEndHour, Hours;
            List <KPI_PeriodEntity> list = KPI_PeriodDal.GetPeriodEntityList();
            KPI_PeriodEntity        item;

            //String format = "开始时间:{0} 结束时间:{1}";
            while (StartDateTime < EndDateTime)
            {
                StartTime = StartDateTime;
                EndTime   = StartDateTime.AddHours(1);
                StartHour = StartTime.Hour + StartTime.Minute / 60.0m;
                EndHour   = EndTime.Hour + EndTime.Minute / 60.0m;
                item      = list.Where(p => ((EndHour - p.PeriodEndHour) <= 8.0m) &&
                                       ((EndHour - p.PeriodEndHour) >= -0.5m) && (p.PeriodHours > 0)).First();
                PeriodEndHour = item.PeriodEndHour;
                Hours         = EndHour - PeriodEndHour;
                if ((Hours > 0) && (Hours < 1.0m))
                {
                    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)))
                {
                    CalculateSAScore(StartTime, EndTime);                    //计算当前值安全得分
                    //Console.WriteLine(String.Format(format, StartTime.ToString("yyyy-MM-dd HH:mm:ss"),
                    //    EndTime.ToString("yyyy-MM-dd HH:mm:ss")));
                }
                StartDateTime = StartDateTime.AddHours(1);
            }
        }
        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();");
            }
        }
Beispiel #6
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()被调用");
        }