Ejemplo n.º 1
0
        /// <summary>
        /// both of above two values
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bothupdate_btn_Click(object sender, EventArgs e)
        {
            if ((pointselected = PointSelected()) == false)
            {
                MessageBox.Show("未在列表框选中计量点");
                return;
            }
            else
            {
                pointstrselected.Clear();
                foreach (string ps in PointListBox.CheckedItems)
                {
                    pointstrselected.Add(ps);
                }
            }
            StartInvalid();
            //calculate the amout of calculation
            WorkArgs wa = calculateamout(worktype.both);

            if (wa != null)
            {
                bgw.RunWorkerAsync(wa);
            }
            else
            {
                MessageBox.Show("无效参数");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// avg value background func
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AvgFunc(object sender, DoWorkEventArgs e)
        {
            WorkArgs warg = (WorkArgs)e.Argument;

            //the line below will be moved
            //warg.total = 100;
            foreach (string ps in pointstrselected)
            {
                DateTime st = DateTime.Parse(DateTime.Parse(StartdateTimePicker.Text).ToString("yyyy-MM-dd HH:00:00"));
                DateTime et = DateTime.Parse(DateTime.Parse(EnddateTimePicker.Text).ToString("yyyy-MM-dd HH:00:00"));
                while (st <= et)
                {
                    if (((BackgroundWorker)sender).CancellationPending)
                    {
                        //set cancelled true
                        e.Cancel = true;
                        return;
                    }

                    //get value for the point
                    double?rv;
                    if (pointdelay.ContainsKey(ps))
                    {
                        rv = (new PI.PIFunc2((string)(new AppSettingsReader()).GetValue("ip", typeof(string)), (string)(new AppSettingsReader()).GetValue("username", typeof(string)), (string)(new AppSettingsReader()).GetValue("password", typeof(string)))).GetAverageValue(ps, st.AddSeconds(pointdelay[ps].delay), st.AddHours(1.0).AddSeconds(pointdelay[ps].delay));
                        //rv = 0;
                    }
                    else
                    {
                        rv = null;
                    }

                    if (rv != null)
                    {
                        (new LocalPIData.SQLPart()).UpdateAvgRd(ps, st, (float)rv);
                    }

                    warg.currentdone++;
                    bgw.ReportProgress((int)(((float)warg.currentdone / (float)warg.total) * 100), new CurrentState()
                    {
                        pointname = ps, ts = st, pv = rv
                    });
                    st = st.AddHours(1.0);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Bgw_DoWork(object sender, DoWorkEventArgs e)
        {
            WorkArgs warg = (WorkArgs)e.Argument;

            if (warg.wt == worktype.real)
            {
                RealFunc(sender, e);
            }
            else if (warg.wt == worktype.avg)
            {
                AvgFunc(sender, e);
            }
            else if (warg.wt == worktype.both)
            {
                RealFunc(sender, e);
                AvgFunc(sender, e);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// real value backgroud func
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RealFunc(object sender, DoWorkEventArgs e)
        {
            WorkArgs warg = (WorkArgs)e.Argument;

            //the line below will be moved
            //warg.total = 100;
            foreach (string ps in pointstrselected)
            {
                DateTime st = DateTime.Parse(StartdateTimePicker.Text);
                DateTime et = DateTime.Parse(EnddateTimePicker.Text);
                while (st <= et)
                {
                    if (((BackgroundWorker)sender).CancellationPending)
                    {
                        //set cancelled true
                        e.Cancel = true;
                        return;
                    }

                    //get his value for the point
                    PI.RetVal rv = (new PI.PIFunc2((string)(new AppSettingsReader()).GetValue("ip", typeof(string)), (string)(new AppSettingsReader()).GetValue("username", typeof(string)), (string)(new AppSettingsReader()).GetValue("password", typeof(string)))).GetPointHisValue(ps, st);
                    if (rv != null)
                    {
                        int status = (new LocalPIData.SQLPart()).UpdatePiRecord(st, ps, (float)rv.pvalue, pointdelay[ps].machineid, (int)plantid);
                        if (status == -1)
                        {
                            (new Log()).AddExceptionLog(new ExceptionBody()
                            {
                                et = ExceptionType.Error, info = "数据调整异常", ts = DateTime.Now
                            }, logtype.console);
                        }
                    }

                    warg.currentdone++;
                    bgw.ReportProgress((int)(((float)warg.currentdone / (float)warg.total) * 100), new CurrentState()
                    {
                        pointname = ps, ts = st, pv = rv.pvalue
                    });
                    st = st.AddMinutes(1.0);
                }
            }
        }