예제 #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 UpdateDataGridResult(IDbCommand command)
        {
            DateTime start = DateTime.Now;

            try
            {
                IDbTransaction txn = command.Connection.BeginTransaction();
                try
                {
                    command.Transaction = txn;
                    using (IDataReader reader = command.ExecuteReader())
                    {
                        IEnumerable l = dataGridParameters.ItemsSource;
                        dataGridParameters.ItemsSource = null;
                        dataGridParameters.ItemsSource = l;
                        DataGridControllerResult.Load(reader);
                        if (0 <= reader.RecordsAffected)
                        {
                            AddLog(string.Format("{0}行反映しました。", reader.RecordsAffected), null, LogStatus.Normal, true);
                        }
                        else
                        {
                            tabControlResult.SelectedItem = tabItemDataGrid;
                        }
                    }
                    txn.Commit();
                }
                catch
                {
                    txn.Rollback();
                    throw;
                }
                finally
                {
                    command.Transaction = null;
                    txn.Dispose();
                }
            }
            catch (Exception t)
            {
                Db2SourceContext ctx = Target.Context;
                string           msg = ctx.GetExceptionMessage(t);
                AddLog(msg, command.CommandText, LogStatus.Error, true);
                //MessageBox.Show(msg, "エラー", MessageBoxButton.OK, MessageBoxImage.Error);
                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);
                AddLog(string.Format("実行しました (所要時間 {0})", s), command.CommandText, LogStatus.Aux, false);
                textBlockGridResult.Text = string.Format("{0}件見つかりました。  所要時間 {1}", DataGridControllerResult.Rows.Count, s);
            }
        }
예제 #3
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);
            }
        }
예제 #4
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;
     }
 }
예제 #5
0
        private void menuItemDropProcedue_Click(object sender, RoutedEventArgs e)
        {
            Window           owner = App.FindVisualParent <Window>(this);
            MessageBoxResult ret   = MessageBox.Show(owner, (string)Resources["messageDropSequence"], Properties.Resources.MessageBoxCaption_Drop, MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.Cancel);

            if (ret != MessageBoxResult.Yes)
            {
                return;
            }
            Db2SourceContext ctx = Target.Context;

            string[]  sql    = ctx.GetDropSQL(Target, string.Empty, string.Empty, 0, false, false);
            SqlLogger logger = new SqlLogger();
            bool      failed = false;

            try
            {
                ctx.ExecSqls(sql, logger.Log);
            }
            catch (Exception t)
            {
                logger.Buffer.AppendLine(ctx.GetExceptionMessage(t));
                failed = true;
            }
            string s = logger.Buffer.ToString().TrimEnd();

            if (!string.IsNullOrEmpty(s))
            {
                if (failed)
                {
                    MessageBox.Show(owner, s, Properties.Resources.MessageBoxCaption_Error, MessageBoxButton.OK, MessageBoxImage.Error);
                }
                else
                {
                    MessageBox.Show(owner, s, Properties.Resources.MessageBoxCaption_Result, MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            if (failed)
            {
                return;
            }
            TabItem tab = App.FindLogicalParent <TabItem>(this);

            if (tab != null)
            {
                (tab.Parent as TabControl).Items.Remove(tab);
                Target.Release();
                MainWindow.Current.FilterTreeView(true);
            }
        }
예제 #6
0
        private void buttonApplyTrigger_Click(object sender, RoutedEventArgs e)
        {
            if (Target == null)
            {
                IsEditing = false;
                return;
            }
            Db2SourceContext ctx = Target.Context;

            string[] sqls = Target.GetAlterSQL(string.Empty, string.Empty, 0, false);
            if (sqls == null || sqls.Length == 0)
            {
                return;
            }
            try
            {
                ctx.ExecSqlsWithLog(sqls);
            }
            catch (Exception t)
            {
                string   recoverMsg = "(修復しました)";
                string[] s          = Target.GetRecoverSQL(string.Empty, string.Empty, 0, false);
                if (s != null && s.Length != 0)
                {
                    try
                    {
                        ctx.ExecSqlsWithLog(s);
                    }
                    catch (Exception t2)
                    {
                        recoverMsg = string.Format("(修復失敗: {0})", ctx.GetExceptionMessage(t2));
                    }
                }
                MessageBox.Show(string.Format("エラー: {0}{1}", ctx.GetExceptionMessage(t), recoverMsg));
            }
        }
예제 #7
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();
            }
        }
예제 #8
0
        public void DropTarget(bool cascade)
        {
            Window           owner = App.FindVisualParent <Window>(this);
            Db2SourceContext ctx   = Target.Context;

            string[]  sql    = ctx.GetDropSQL(Target, string.Empty, string.Empty, 0, cascade, false);
            SqlLogger logger = new SqlLogger();
            bool      failed = false;

            try
            {
                ctx.ExecSqls(sql, logger.Log);
            }
            catch (Exception t)
            {
                logger.Buffer.AppendLine(ctx.GetExceptionMessage(t));
                failed = true;
            }
            string s = logger.Buffer.ToString().TrimEnd();

            if (!string.IsNullOrEmpty(s))
            {
                if (failed)
                {
                    MessageBox.Show(owner, s, Properties.Resources.MessageBoxCaption_Error, MessageBoxButton.OK, MessageBoxImage.Error);
                }
                else
                {
                    MessageBox.Show(owner, s, Properties.Resources.MessageBoxCaption_Result, MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            if (failed)
            {
                return;
            }
            TabItem tab = App.FindLogicalParent <TabItem>(this);

            if (tab != null)
            {
                (tab.Parent as TabControl).Items.Remove(tab);
                Target.Release();
                MainWindow.Current.FilterTreeView(true);
            }
        }
예제 #9
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;
        }