public void Fetch() { if (Target == null) { return; } Db2SourceContext ctx = Target.Context; if (ctx == null) { return; } int?limit = null; if (IsChecked(checkBoxLimitRow) && !string.IsNullOrEmpty(textBoxLimitRow.Text)) { int l; if (!int.TryParse(textBoxLimitRow.Text, out l)) { MessageBox.Show("件数が数字ではありません", "エラー", MessageBoxButton.OK, MessageBoxImage.Error); textBoxLimitRow.Focus(); } limit = l; } int offset; string sql = Target.GetSelectSQL(null, textBoxCondition.Text, string.Empty, limit, HiddenLevel.Visible, out offset); try { using (IDbConnection conn = ctx.NewConnection(true)) { using (IDbCommand cmd = ctx.GetSqlCommand(sql, null, conn)) { UpdateDataGridResult(cmd); } } } catch (Exception t) { ctx.OnLog(ctx.GetExceptionMessage(t), LogStatus.Error, sql); Db2SrcDataSetController.ShowErrorPosition(t, textBoxCondition, ctx, offset); } finally { UpdateTextBlockWarningLimit(); } }
public void Fetch(bool force) { dataGridResult.CommitEdit(); _fetched = false; if (!force && DataGridControllerResult.IsModified) { MessageBoxResult ret = MessageBox.Show("変更が保存されていません。保存しますか?", "確認", MessageBoxButton.YesNoCancel, MessageBoxImage.Exclamation, MessageBoxResult.Yes); switch (ret) { case MessageBoxResult.Yes: DataGridControllerResult.Save(); break; case MessageBoxResult.No: break; case MessageBoxResult.Cancel: return; } } if (Target == null) { return; } Db2SourceContext ctx = Target.Context; if (ctx == null) { return; } int?limit = null; if (IsChecked(checkBoxLimitRow) && !string.IsNullOrEmpty(textBoxLimitRow.Text)) { int l; if (!int.TryParse(textBoxLimitRow.Text, out l)) { MessageBox.Show("件数が数字ではありません", "エラー", MessageBoxButton.OK, MessageBoxImage.Error); textBoxLimitRow.Focus(); } limit = l; } string orderby = sortFields.GetOrderBySql(string.Empty); int offset; string sql = Target.GetSelectSQL(null, textBoxCondition.Text, orderby, limit, VisibleLevel, out offset); try { using (IDbConnection conn = ctx.NewConnection(true)) { using (IDbCommand cmd = ctx.GetSqlCommand(sql, null, conn)) { UpdateDataGridResult(cmd); } } } catch (Exception t) { ctx.OnLog(ctx.GetExceptionMessage(t), LogStatus.Error, sql); Db2SrcDataSetController.ShowErrorPosition(t, textBoxCondition, ctx, offset); } finally { UpdateTextBlockWarningLimit(); GC.Collect(0); } _fetched = true; }
private void UpdateDataGridResult(SQLParts sqls) { Db2SourceContext ctx = CurrentDataSet; using (IDbConnection conn = ctx.NewConnection(true)) { bool modified; Parameters = ParameterStore.GetParameterStores(sqls.ParameterNames, Parameters, out modified); if (modified) { return; } foreach (ParameterStore p in Parameters) { if (p.IsError) { dataGridParameters.Focus(); dataGridParameters.SelectedItem = p; MessageBox.Show(string.Format("パラメータ{0}の値が不正です", p.ParameterName), "エラー", MessageBoxButton.OK, MessageBoxImage.Error); return; } } foreach (SQLPart sql in sqls.Items) { IDbCommand cmd = ctx.GetSqlCommand(sql.SQL, Command_Log, conn); ParameterStoreCollection stores = ParameterStore.GetParameterStores(cmd, Parameters, out modified); DateTime start = DateTime.Now; try { using (IDataReader reader = cmd.ExecuteReader()) { DataGridControllerResult.Load(reader); if (0 <= reader.RecordsAffected) { AddLog(string.Format("{0}行反映しました。", reader.RecordsAffected), null, null, LogStatus.Normal, true); } else if (0 < reader.FieldCount) { tabControlResult.SelectedItem = tabItemDataGrid; } } AddToHistory(sql, stores); } catch (Exception t) { Tuple <int, int> errPos = CurrentDataSet.GetErrorPosition(t, sql.SQL, 0); AddLog(CurrentDataSet.GetExceptionMessage(t), sql.SQL, stores, LogStatus.Error, true, errPos); Db2SrcDataSetController.ShowErrorPosition(t, textBoxSql, CurrentDataSet, sql.Offset); return; } finally { ParameterStore.GetParameterStores(cmd, stores, out modified); UpdateDataGridParameters(); DateTime end = DateTime.Now; TimeSpan time = end - start; string s = string.Format("{0}:{1:00}:{2:00}.{3:000}", (int)time.TotalHours, time.Minutes, time.Seconds, time.Milliseconds); AddLog(string.Format("実行しました (所要時間 {0})", s), cmd.CommandText, stores, LogStatus.Aux, false); textBlockGridResult.Text = string.Format("{0}件見つかりました。 所要時間 {1}", DataGridControllerResult.Rows.Count, s); } } } }