Пример #1
0
        public void DoUpdateRegs()
        {
            //Thread.Sleep(1000);
            //inputCommPortSingleton.GetInstance().initComm();
            //if (false == inputCommPortSingleton.GetInstance().openComm())
            //{
            //    btnStop_Click(null, null);
            //}
            //Random random = new Random();
            while (m_updateDataFlg)
            {
                try
                {
                    int ret = inputCommPortSingleton.GetInstance().readRegister(ref modbusRegs);
                    if (ret != inputCommPortSingleton.RET_OK)
                    {
                        if (ret == inputCommPortSingleton.RET_TIMEOUT)
                        {
                            continue;
                        }
                        else
                        {
                            // set label communication error
                        }
                        break;
                    }
                    UpdateMainUIInvoke umi = new UpdateMainUIInvoke(UpdateUIData);

                    while (!this.IsHandleCreated)
                    {
                        Thread.Sleep(100);
                    }
                    BeginInvoke(umi, modbusRegs);
                    if (modbusRegs.stReg[CHECKFINISH].getHighReg() != 0 && !l_report_flg)
                    {
                        byte[] imageLeft = WindowManager.GetInstance().wrd1.getImageData();
                        //byte[] imageRight = WindowManager.GetInstance().wrd2.getImageData();

                        //Left room
                        string sql1 = "insert into ModbusResultTable(room, TestDate, TestTime, TestResult, TestNo, Operator, [TestImage]) values('left','" + DateTime.Now + "', '" + textBoxTime0.Text + "', '" + coldfilterpoint0.ToString() + "', '" + textBoxNo0.Text + "', '" + textBoxOp0.Text + "', @imageLeft)";

                        OleDbParameter[] pars = new OleDbParameter[1];

                        OleDbParameter p = new OleDbParameter("@imageLeft", OleDbType.VarBinary, imageLeft.Length);
                        p.Value = imageLeft;

                        pars[0] = p;
                        int i = AccessHelper.ExecuteNonQuery(AccessHelper.ConnString, sql1, pars);

                        //Right room
                        //string sql2 = "insert into ModbusResultTable(room, TestDate, TestTime, TestResult, TestNo, Operator, [TestImage]) values('right','" + DateTime.Now + "', '" + textBoxTime2.Text + "','" + coldfilterpoint1.ToString() + "', '" + textBoxNo2.Text + "', '" + textBoxOp2.Text + "', @imageRight)";
                        //OleDbParameter[] pars2 = new OleDbParameter[1];

                        // OleDbParameter p2 = new OleDbParameter("@imageRight", OleDbType.VarBinary, imageRight.Length);
                        //p2.Value = imageRight;

                        //pars2[0] = p2;
                        //i = AccessHelper.ExecuteNonQuery(AccessHelper.ConnString, sql2, pars2);
                        //stopUpdateRegs();
                        saveXMLFile(ROOMNUM_LEFT);
                        saveExcelFile(ROOMNUM_LEFT);
                        byte[] serverData = getAsciiData(coldfilterpoint0.ToString(), textBoxTime0.Text, textBoxNo0.Text, textBoxName0.Text, textBoxDevNo0.Text, textBoxOp0.Text);
                        transResultToServer(serverData);
                        //getAsciiData("", "", "", "", "", "");
                        l_report_flg = true;
                    }

                    if (modbusRegs.stReg[CHECKFINISH].getLowReg() != 0 && !r_report_flg)
                    {
                        //byte[] imageLeft = WindowManager.GetInstance().wrd1.getImageData();
                        byte[] imageRight = WindowManager.GetInstance().wrd2.getImageData();

                        //Left room
                        //string sql1 = "insert into ModbusResultTable(room, TestDate, TestTime, TestResult, TestNo, Operator, [TestImage]) values('left','" + DateTime.Now + "', '" + textBoxTime1.Text + "', '" + coldfilterpoint0.ToString() + "', '" + textBoxNo1.Text + "', '" + textBoxOp1.Text + "', @imageLeft)";

                        //OleDbParameter[] pars = new OleDbParameter[1];

                        //OleDbParameter p = new OleDbParameter("@imageLeft", OleDbType.VarBinary, imageLeft.Length);
                        //p.Value = imageLeft;

                        //pars[0] = p;
                        //int i = AccessHelper.ExecuteNonQuery(AccessHelper.ConnString, sql1, pars);

                        //Right room
                        string           sql2  = "insert into ModbusResultTable(room, TestDate, TestTime, TestResult, TestNo, Operator, [TestImage]) values('right','" + DateTime.Now + "', '" + textBoxTime1.Text + "','" + coldfilterpoint1.ToString() + "', '" + textBoxNo1.Text + "', '" + textBoxOp1.Text + "', @imageRight)";
                        OleDbParameter[] pars2 = new OleDbParameter[1];

                        OleDbParameter p2 = new OleDbParameter("@imageRight", OleDbType.VarBinary, imageRight.Length);
                        p2.Value = imageRight;

                        pars2[0] = p2;
                        int i = AccessHelper.ExecuteNonQuery(AccessHelper.ConnString, sql2, pars2);
                        //stopUpdateRegs();
                        saveXMLFile(ROOMNUM_RIGHT);
                        saveExcelFile(ROOMNUM_RIGHT);
                        byte[] serverData = getAsciiData(coldfilterpoint1.ToString(), textBoxTime1.Text, textBoxNo1.Text, textBoxName1.Text, textBoxDevNo1.Text, textBoxOp1.Text);
                        transResultToServer(serverData);
                        r_report_flg = true;
                    }
                    Thread.Sleep(1000);
                }
                catch (Exception ex)
                {
                    LogClass.GetInstance().WriteExceptionLog(ex);
                    //MessageBox.Show(ex.ToString(), "Error - No Ports available", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;
                }
            }

            while (m_updateDataFlg)
            {
                try
                {
                    Thread.Sleep(1000);
                }
                catch (Exception ex)
                {
                    LogClass.GetInstance().WriteExceptionLog(ex);
                }
            }
            inputCommPortSingleton.GetInstance().closeComm();
        }
Пример #2
0
        public void RefreshData()
        {
            DataSet ds = new DataSet();

            //dt = accdb.SelectToDataTable("select * from MyTable");

            if (bSelectDateFlg)
            {
                string           sql  = "select ID, TestTime, TestResult, TestNo, Operator from ModbusResultTable where [room] = 'left' and [TestDate] between @start_datetime and @end_datetime";
                OleDbParameter[] pars = new OleDbParameter[2];

                OleDbParameter ps = new OleDbParameter("@start_datetime", OleDbType.Date);
                ps.Value = start_datetime;
                pars[0]  = ps;

                OleDbParameter pe = new OleDbParameter("@end_datetime", OleDbType.Date);
                pe.Value = end_datetime;

                pars[1] = pe;
                ds      = AccessHelper.ExecuteDataSet(AccessHelper.ConnString, sql, pars);
            }
            else
            {
                ds = AccessHelper.ExecuteDataSet(AccessHelper.ConnString, "select ID, TestTime, TestResult, TestNo, Operator from ModbusResultTable where [room] = 'left'", null);
            }

            dataGridView1.DataSource          = ds.Tables[0].DefaultView;
            dataGridView1.AllowUserToAddRows  = false;//datagridview
            dataGridView1.Columns[0].Visible  = false;
            dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            DataSet ds2 = new DataSet();

            //dt = accdb.SelectToDataTable("select * from MyTable");

            if (bSelectDateFlg)
            {
                string           sql  = "select ID, TestTime, TestResult, TestNo, Operator from ModbusResultTable where [room] = 'right' and [TestDate] between @start_datetime and @end_datetime";
                OleDbParameter[] pars = new OleDbParameter[2];

                OleDbParameter ps = new OleDbParameter("@start_datetime", OleDbType.Date);
                ps.Value = start_datetime;
                pars[0]  = ps;

                OleDbParameter pe = new OleDbParameter("@end_datetime", OleDbType.Date);
                pe.Value = end_datetime;

                pars[1] = pe;
                ds2     = AccessHelper.ExecuteDataSet(AccessHelper.ConnString, sql, pars);
            }
            else
            {
                ds2 = AccessHelper.ExecuteDataSet(AccessHelper.ConnString, "select ID, TestTime, TestResult, TestNo, Operator from ModbusResultTable where [room] = 'right'", null);
            }
            dataGridView2.DataSource          = ds2.Tables[0].DefaultView;
            dataGridView2.AllowUserToAddRows  = false;//datagridview
            dataGridView2.Columns[0].Visible  = false;
            dataGridView2.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            dellist_left.Clear();
            dellist_right.Clear();
            //bDataLoaded = true;
        }