示例#1
0
        /// <summary>
        /// 从数据库获取数据到绑定UI
        /// </summary>
        private void getDBDataToUI()
        {
            #region

            string connectString = ConfigurationManager
                                   .ConnectionStrings["ConnectString"].ConnectionString;

            if (string.IsNullOrEmpty(connectString))
            {
                this.btnConnectDBState.Content = "数据库状态:程序无配置!";
                return;
            }
            //异步连接数据库,防止阻塞UI造成假死现象。
            DLConnectDB testconnectdb = new
                                        DLConnectDB(this.testConnectDB);

            testconnectdb.BeginInvoke(connectString,
                                      new AsyncCallback((IAsyncResult) =>
            {
                //Wpf中UI线程中处理控件
                this.Dispatcher.BeginInvoke(
                    new DLControlProgress(() =>
                {
                    //TimeManager.CaculateQuerySpan(() =>
                    //{
                    initController();
                    //}, this.btnQuerySpan, this.ctlProgress);
                }), null);
            })
                                      , testconnectdb);

            #endregion
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void testDbConnect(object sender
                                   , RoutedEventArgs e)
        {
            #region
            this.ctlprogress.IsActive = true;
            string newConnectString = "Data Source={0};Initial Catalog={1};Persist Security Info=True;User ID={2};Password={3};";

            string[] cStrArr = new string[4];
            cStrArr[0]       = this.tbDataSource.Text.Trim();
            cStrArr[1]       = this.tbDataBase.Text.Trim();
            cStrArr[2]       = this.tbUsername.Text.Trim();
            cStrArr[3]       = this.tbPassword.Text.Trim();
            newConnectString = String.Format(newConnectString, cStrArr);
            DLConnectDB connectdb = new DLConnectDB(this.ConnectDB);
            connectdb.BeginInvoke(newConnectString, null, null);
            #endregion
        }