private void UC_PlcDataState_Load(object sender, EventArgs e)
        {
            //다른 쓰레드에서 윈폼 컨트롤 사용가능 (비동기 작업에서 사용)
            //Control.CheckForIllegalCrossThreadCalls = false;

            if (!Directory.Exists(MyApp.RootRef))
            {
                Directory.CreateDirectory(MyApp.RootRef);
            }
            if (File.Exists(_PLCRefPath))
            {
                try
                {
                    int    iArrcnt = 0;
                    string Connstr = MyApp.RootMDB(_PLCRefPath);
                    using (OleDbConnection connDB = new OleDbConnection(Connstr))
                    {
                        connDB.Open();
                        foreach (string tbName in Share.GetMDBTable(connDB))
                        {
                            string sql = $"Select *from {tbName} " + "Order by PlcName ASC,BlockNum ASC,IndexNo ASC";

                            Array.Resize(ref tabPage, iArrcnt + 1);
                            Array.Resize(ref Uc_dgv, iArrcnt + 1);

                            tabPage[iArrcnt] = new TabPage();
                            AddTabpage(tbName, iArrcnt);

                            Uc_dgv[iArrcnt] = new UC_DGV();
                            AddDGV(iArrcnt);

                            using (DataSet dsData = new DataSet())
                            {
                                OleDbDataAdapter oledbAdapter = new OleDbDataAdapter(sql, connDB);
                                oledbAdapter.Fill(dsData);

                                //.DoubleBuffered(True)
                                Stopwatch Tchk = new Stopwatch();
                                Tchk.Start();

                                Uc_dgv[iArrcnt].DGVPlc.DataSource = dsData.Tables[0];
                                DataGridViewTextBoxColumn addrCol = new DataGridViewTextBoxColumn();

                                addrCol.Name       = "PLCVal";
                                addrCol.HeaderText = "PLCVal";

                                Uc_dgv[iArrcnt].DGVPlc.Columns.Add(addrCol);

                                Tchk.Stop();
                                Debug.Print(Tchk.Elapsed.ToString());

                                //DetailsView.Dispose();
                                oledbAdapter.Dispose();
                                oledbAdapter = null;

                                for (int i = 0; i < Uc_dgv[iArrcnt].DGVPlc.Columns.Count; i++)
                                {
                                    Uc_dgv[iArrcnt].DGVPlc.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
                                }
                            }
                            Uc_dgv[iArrcnt].DGVPlc.DoubleBuffered();
                            iArrcnt++;
                        }
                        connDB.Close();
                        connDB.Dispose();
                    }
                }
                catch (Exception ex)
                {
                    StackTrace trace      = new StackTrace(ex, true);
                    StackFrame stackFrame = trace.GetFrame(trace.FrameCount - 1);
                    int        lineNumber = stackFrame.GetFileLineNumber();

                    I_Sub.ErrorLog(($"({lineNumber}) : {ex.ToString()}"));
                }
            }
        }
예제 #2
0
        private void frmSetting_Load(object sender, EventArgs e)
        {
            //this.DisableX();
            //this.ControlBox = false;

            Connstr = MyApp.RootMDB(gs_PLCRefPath);
            TabControl1.SelectedIndex = 0;

            ReadSetXml();
            BindingPLCRefFile();
        }