예제 #1
0
        /// <summary>
        /// 查询点击事件,todo此处需要改成异步的,否则长时间的查询会造成假死
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string conString = txtDbString.Text?.Trim() ?? string.Empty;
                if (string.IsNullOrEmpty(conString))
                {
                    MessageBox.Show("数据库字符串不能为空");
                    return;
                }
                string sqlString = txtSqlString.Text?.Trim() ?? string.Empty;
                if (string.IsNullOrEmpty(sqlString))
                {
                    MessageBox.Show("请输入sql语句");
                    return;
                }
                SqlLiteDataCommand.InsertDBStringLog(new DBStringLog()
                {
                    DBString = conString, CreateTime = DateTime.Now
                }, sqliteConnectionCreate.Conn);
                SqlLiteDataCommand.InsertSqlStringLog(new SqlStringLog()
                {
                    SqlString = sqlString, DBStringID = 1, CreateTime = DateTime.Now
                }, sqliteConnectionCreate.Conn);

                DataTable dataTable = new DataTable();
                using (IDbConnection conn = ConnectionCreate.GetDBConection(conString))
                {
                    dataTable.Load(conn.ExecuteReader(sqlString));
                }
                string result = JsonConvert.SerializeObject(dataTable, new DataTableConverter());
                txtJsonString.Text = ConvertJsonString(result);
            }
            catch (Exception ex)
            {
                txtJsonString.Text = ex.ToString();
            }
        }
예제 #2
0
 /// <summary>
 /// 初始化相关控制的值,取最近的一条记录
 /// </summary>
 public void InitTextValue()
 {
     txtDbString.Text  = SqlLiteDataCommand.GetNewDBStringLog(sqliteConnectionCreate.Conn);
     txtSqlString.Text = SqlLiteDataCommand.GetNewSqlStringLog(sqliteConnectionCreate.Conn);
 }