예제 #1
0
        private void UpdateDataGridResult(IDbCommand command)
        {
            dataGridResult.CancelEdit();
            DateTime start = DateTime.Now;

            try
            {
                IDataReader reader = null;
                try
                {
                    reader = command.ExecuteReader();
                    DataGridControllerResult.Load(reader, Target);
                }
                catch (Exception t)
                {
                    Db2SourceContext ctx = Target.Context;
                    ctx.OnLog(ctx.GetExceptionMessage(t), LogStatus.Error, command.CommandText);
                    return;
                }
            }
            finally
            {
                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);
                textBlockGridResult.Text = string.Format("{0}件見つかりました。  所要時間 {1}", DataGridControllerResult.Rows.Count, s);
            }
        }
예제 #2
0
 private void ButtonApply_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         DataGridControllerResult.Save();
     }
     catch (Exception t)
     {
         Db2SourceContext ctx = Target.Context;
         ctx.OnLog(ctx.GetExceptionMessage(t), LogStatus.Error, Target.Context.LastSql);
         return;
     }
 }
예제 #3
0
        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();
            }
        }
예제 #4
0
        public void Execute()
        {
            if (Target == null)
            {
                return;
            }
            Db2SourceContext ctx = Target.Context;

            if (ctx == null)
            {
                return;
            }
            try
            {
                foreach (ParamEditor p in dataGridParameters.ItemsSource)
                {
                    p.SetValue();
                }
                using (IDbConnection conn = ctx.NewConnection(true))
                {
                    IDbCommand cmd = Target.DbCommand;
                    try
                    {
                        cmd.Connection = conn;
                        UpdateDataGridResult(cmd);
                    }
                    catch (Exception t)
                    {
                        ctx.OnLog(ctx.GetExceptionMessage(t), LogStatus.Error, Target.FullName);
                    }
                    finally
                    {
                        cmd.Connection = null;
                    }
                }
            }
            catch (Exception t)
            {
                MessageBox.Show(ctx.GetExceptionMessage(t), "エラー", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
예제 #5
0
        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;
        }