Exemplo n.º 1
0
        //public void SetDBConnector(SqlConnUtil mConntor)
        //{
        //    m_connector = mConntor;
        //}

        private void OnDataError(object sender, DataGridViewDataErrorEventArgs e)
        {
            //FrmMain.PromptError(e.Exception.Message);
            if (e.Context == DataGridViewDataErrorContexts.Commit)
            {
                Debug.Print("Commit error: {0}", e.ToString());
            }
            if (e.Context == DataGridViewDataErrorContexts.CurrentCellChange)
            {
                Debug.Print("Cell change: {0}", e.ToString());
            }
            if (e.Context == DataGridViewDataErrorContexts.Parsing)
            {
                Debug.Print("parsing error: {0}", e.ToString());
            }
            if (e.Context == DataGridViewDataErrorContexts.LeaveControl)
            {
                Debug.Print("leave control error: {0}", e.ToString());
            }
            if (e.Exception is ConstraintException)
            {
                DataGridView view = (DataGridView)sender;
                view.Rows[e.RowIndex].ErrorText = "an error";
                view.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = "an error";
                e.ThrowException = false;
                FrmMain.PromptError("约束有问题");
            }
        }
Exemplo n.º 2
0
        private void btnQuery_Click(object sender, EventArgs e)
        {
            string strSql = this.tboxSql.Text.Trim();

            if (string.IsNullOrEmpty(strSql))
            {
                return;
            }
            if (!CheckValid(strSql))
            {
                FrmMain.PromptError(MyRes.Err_QueryInvalid);
                return;
            }

            Cursor.Current = System.Windows.Forms.Cursors.AppStarting;
            using (
                var dbConn = new NativeDBHelper(m_connector.DBHost, m_connector.DBUser, m_connector.DBPassword,
                                                m_connector.CurDBName)
                )
            {
                var dt = dbConn.Execute(strSql);
                ShowData(null, dt);
            }

            Cursor.Current = System.Windows.Forms.Cursors.Default;
        }
Exemplo n.º 3
0
 public void ShowData(string sSql, DataTable dt)
 {
     if (null != sSql)
     {
         this.tboxSql.Text = sSql;
     }
     try
     {
         this.dgView.DataSource = dt;
     }
     catch (Exception e)
     {
         FrmMain.PromptError(e.Message);
     }
 }
Exemplo n.º 4
0
        private void SaveRecentHistory()
        {
            bool bSaveInfo = chkSavePassword.Checked;

            Configuration      config   = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            HistoryConfSection historys = (HistoryConfSection)config.GetSection("Historys");

            historys.SaveInfo = bSaveInfo;
            historys.Historys.Clear();

            if (bSaveInfo)
            {
                try
                {
                    var sHost     = tboxHost.Text.Trim();
                    var sUser     = tboxUser.Text.Trim();
                    var sPassword = tboxPassword.Text;
                    var newHis    = new TConnHis {
                        sHost = sHost, sUser = sUser, sPassword = sPassword
                    };
                    if (mConnHises.ContainsKey(sHost))
                    {
                        mConnHises[sHost] = newHis;
                    }
                    else
                    {
                        mConnHises.Add(sHost, newHis);
                    }
                }
                catch (ArgumentException ex)
                {
                }

                //System.Configuration.ConfigurationManager;
                //save history
                int i = 0;
                foreach (var item in mConnHises)
                {
                    var his = new HistoryElement();
                    his.Host               = item.Value.sHost;
                    his.User               = item.Value.sUser;
                    his.Password           = item.Value.sPassword;
                    historys.Historys[i++] = his;
                }
                Debug.Print("write rec:{0}", i);
                try
                {
                    config.Save(ConfigurationSaveMode.Modified);
                }
                //catch (System.Configuration.ConfigurationErrorsException ex)
                //{
                //    FrmMain.PromptError(ex.Message);
                //}
                catch (Exception ex)
                {
                    FrmMain.PromptError(MyRes.Err_WritePriv);
                }
            }
            else if (mConnHises.Count > 0)
            {
                //清空列表
                mConnHises.Clear();
                tboxHost.AutoCompleteCustomSource = null;
                try
                {
                    config.Save(ConfigurationSaveMode.Modified);
                }
                catch (Exception ex)
                {
                    FrmMain.PromptError(MyRes.Err_WritePriv);
                }
            }
        }