Exemplo n.º 1
0
        /// <summary>
        /// initialize
        /// </summary>
        public Form1()
        {
            InitializeComponent();
            #region hide
            /*temp test*/
            //Calculator.GetRealCount(5, new DateTime(2015, 1, 1, 12, 38, 0), new DateTime(2015, 1, 1, 14, 38, 0));
            //Calculator.GetAvgCount(5, new DateTime(2015, 1, 1, 12, 38, 0), new DateTime(2015, 1, 1, 14, 38, 0));
            #endregion
            //start logger thread
            logt = new Thread(new ThreadStart(LogThread));
            logt.Start();

            try
            {
                pipoints = ((string)(new AppSettingsReader()).GetValue("pipoint", typeof(string))).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                PointListBox.Items.AddRange(pipoints);
                plantid = int.Parse((string)(new AppSettingsReader()).GetValue("plantid", typeof(string)));
            }
            catch (Exception ex)
            {
                //Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "---" + ex.Message);
                ExceptionBody eb = new ExceptionBody() { et = ExceptionType.Error, info = "Initialization?" + ex.Message, ts = DateTime.Now };
                (new PublicLib.Log()).AddExceptionLog(eb, logtype.console);
            }

            if ((PointListBox.Items.Count == 0) || (pipoints.Length == 0))
            {
                InvalidControls();
                ExceptionBody eb = new ExceptionBody() { et = ExceptionType.Warning, info = "Initialization?" + "配置文件中没有找到PI计量点", ts = DateTime.Now };
                (new PublicLib.Log()).AddExceptionLog(eb, logtype.console);
                MessageBox.Show("配置文件中没有找到PI计量点");
                return;
            }
            if (plantid == null)
            {
                InvalidControls();
                ExceptionBody eb = new ExceptionBody() { et = ExceptionType.Warning, info = "Initialization?" + "未能初始化plantid", ts = DateTime.Now };
                (new PublicLib.Log()).AddExceptionLog(eb, logtype.console);
                MessageBox.Show("未能初始化plantid, 检查配置文件");
                return;
            }

            //connect pi
            new PI.PIFunc2((string)(new AppSettingsReader()).GetValue("ip", typeof(string)), (string)(new AppSettingsReader()).GetValue("username", typeof(string)), (string)(new AppSettingsReader()).GetValue("password", typeof(string)));
            //connect sql
            {
                //no special initialization
            }
            //backgroudworker init
            {
                bgw.DoWork += Bgw_DoWork;
                bgw.ProgressChanged += Bgw_ProgressChanged;
                bgw.RunWorkerCompleted += Bgw_RunWorkerCompleted;
                bgw.WorkerReportsProgress = true;
                bgw.WorkerSupportsCancellation = true;
                desktopdl += updatedesktop;
                UpdateprogressBar.Style = ProgressBarStyle.Blocks;
            }
            //other init
            {
                closedl += closeform;
                this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
                this.FormClosing += Form1_FormClosing;
            }
            //machine time delay

            for (int i = 1; i < 10; i++)
            {
                try
                {
                    string[] machineinfo = ((string)(new AppSettingsReader()).GetValue("machinedelay_" + i.ToString(), typeof(string))).Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach(string point in machineinfo[1].Split(','))
                    {
                        if(pointdelay.ContainsKey(point))
                        {
                            pointdelay[point].delay = int.Parse(machineinfo[0]);
                            pointdelay[point].machineid = i;
                        }
                        else
                        {
                            pointdelay.Add(point, new PointInfo()
                            {
                                delay = int.Parse(machineinfo[0]),
                                machineid = i
                            });
                        }
                    }
                }
                catch(Exception ex)
                {

                }
            }

            StartValid();
        }
Exemplo n.º 2
0
        /// <summary>
        /// initialize
        /// </summary>
        public Form1()
        {
            InitializeComponent();
            #region hide
            /*temp test*/
            //Calculator.GetRealCount(5, new DateTime(2015, 1, 1, 12, 38, 0), new DateTime(2015, 1, 1, 14, 38, 0));
            //Calculator.GetAvgCount(5, new DateTime(2015, 1, 1, 12, 38, 0), new DateTime(2015, 1, 1, 14, 38, 0));
            #endregion
            //start logger thread
            logt = new Thread(new ThreadStart(LogThread));
            logt.Start();

            try
            {
                pipoints = ((string)(new AppSettingsReader()).GetValue("pipoint", typeof(string))).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                PointListBox.Items.AddRange(pipoints);
                plantid = int.Parse((string)(new AppSettingsReader()).GetValue("plantid", typeof(string)));
            }
            catch (Exception ex)
            {
                //Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "---" + ex.Message);
                ExceptionBody eb = new ExceptionBody()
                {
                    et = ExceptionType.Error, info = "Initialization?" + ex.Message, ts = DateTime.Now
                };
                (new PublicLib.Log()).AddExceptionLog(eb, logtype.console);
            }

            if ((PointListBox.Items.Count == 0) || (pipoints.Length == 0))
            {
                InvalidControls();
                ExceptionBody eb = new ExceptionBody()
                {
                    et = ExceptionType.Warning, info = "Initialization?" + "配置文件中没有找到PI计量点", ts = DateTime.Now
                };
                (new PublicLib.Log()).AddExceptionLog(eb, logtype.console);
                MessageBox.Show("配置文件中没有找到PI计量点");
                return;
            }
            if (plantid == null)
            {
                InvalidControls();
                ExceptionBody eb = new ExceptionBody()
                {
                    et = ExceptionType.Warning, info = "Initialization?" + "未能初始化plantid", ts = DateTime.Now
                };
                (new PublicLib.Log()).AddExceptionLog(eb, logtype.console);
                MessageBox.Show("未能初始化plantid, 检查配置文件");
                return;
            }

            //connect pi
            new PI.PIFunc2((string)(new AppSettingsReader()).GetValue("ip", typeof(string)), (string)(new AppSettingsReader()).GetValue("username", typeof(string)), (string)(new AppSettingsReader()).GetValue("password", typeof(string)));
            //connect sql
            {
                //no special initialization
            }
            //backgroudworker init
            {
                bgw.DoWork                    += Bgw_DoWork;
                bgw.ProgressChanged           += Bgw_ProgressChanged;
                bgw.RunWorkerCompleted        += Bgw_RunWorkerCompleted;
                bgw.WorkerReportsProgress      = true;
                bgw.WorkerSupportsCancellation = true;
                desktopdl += updatedesktop;
                UpdateprogressBar.Style = ProgressBarStyle.Blocks;
            }
            //other init
            {
                closedl += closeform;
                this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
                this.FormClosing    += Form1_FormClosing;
            }
            //machine time delay

            for (int i = 1; i < 10; i++)
            {
                try
                {
                    string[] machineinfo = ((string)(new AppSettingsReader()).GetValue("machinedelay_" + i.ToString(), typeof(string))).Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string point in machineinfo[1].Split(','))
                    {
                        if (pointdelay.ContainsKey(point))
                        {
                            pointdelay[point].delay     = int.Parse(machineinfo[0]);
                            pointdelay[point].machineid = i;
                        }
                        else
                        {
                            pointdelay.Add(point, new PointInfo()
                            {
                                delay     = int.Parse(machineinfo[0]),
                                machineid = i
                            });
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }

            StartValid();
        }