Beispiel #1
0
        private void mainForm_Load(object sender, EventArgs e)
        {
            String connstr = @"Data Source=|DataDirectory|\data.db;Pooling=true;FailIfMissing=true";

            //初始化数据库
            if (false == System.IO.File.Exists(Application.StartupPath + @"\data.db"))
            {
                MessageBox.Show("缺少数据文件");
            }
            this.m_db = new dbdriver(connstr);

            //初始化html界面
            String url = Application.StartupPath + @"\assets\index.html";

            if (false == System.IO.File.Exists(url))
            {
                MessageBox.Show("缺少Assets下的界面文件");
            }
            else
            {
                this.m_webClient.Navigate(url);
                this.m_webClient.ObjectForScripting = this; // 可以js中可以通过 window.external. 访问 this中的方法
            }

            //初始化串口配置
            m_comSettingDlg = new ComSetting();
            m_comSettingDlg.LoadData(this.m_db);
            this.m_comClient = new SerialPortClient();
            this.m_comClient.Setting(m_comSettingDlg.GetComName(),
                                     m_comSettingDlg.GetBund(),
                                     m_comSettingDlg.GetDataBit(),
                                     m_comSettingDlg.GetStopBit(),
                                     m_comSettingDlg.GetParity()
                                     );
        }
Beispiel #2
0
        public void LoadData(dbdriver dbh)
        {
            this.m_dbh = dbh;
            this.m_comName.Items.Clear();
            String[] names = SerialPort.GetPortNames();
            foreach (String i in names)
            {
                this.m_comName.Items.Add(i);
            }
            ArrayList result = m_dbh.Query("select rowid,com,bund,stop,parity,databit from setting limit 0,1");

            if (result.Count > 0)
            {
                Hashtable row  = (Hashtable)result[0];
                string    name = Convert.ToString(row["com"]);
                for (int i = 0; i < this.m_comName.Items.Count; i++)
                {
                    if (this.m_comName.Items[i].ToString() == name)
                    {
                        this.m_comName.SelectedIndex = i;
                        break;
                    }
                }
                this.m_bundRate.SelectedIndex       = Convert.ToInt32(row["bund"]);
                this.m_wndCheckMethod.SelectedIndex = Convert.ToInt32(row["parity"]);
                this.m_stopBit.Text = Convert.ToString(row["stop"]);
                this.m_dataBit.Text = Convert.ToString(row["databit"]);
                this.m_rowid        = Convert.ToInt32(row["rowid"]);
            }
            else
            {
                this.m_bNeedInsert = true;
                if (this.m_comName.Items.Count > 0)
                {
                    this.m_comName.SelectedIndex = 0;
                }
                this.m_bundRate.SelectedIndex       = 3;
                this.m_wndCheckMethod.SelectedIndex = 0;
            }
        }