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); } }
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); } }
private void UpdateTextBoxSource() { if (textBoxSource == null) { return; } if (Target == null) { textBoxSource.Text = string.Empty; return; } Db2SourceContext ctx = Target.Context; try { StringBuilder buf = new StringBuilder(); if (IsChecked(checkBoxSourceDropReferredCons)) { foreach (ForeignKeyConstraint f in Target.ReferFrom) { buf.Append(ctx.GetDropSQL(f, string.Empty, ";", 0, false, true)); } if (0 < buf.Length) { buf.AppendLine(); } } if (IsChecked(checkBoxSourceMain)) { foreach (string s in ctx.GetSQL(Target, string.Empty, ";", 0, true, true)) { buf.Append(s); } } List <Constraint> list = new List <Constraint>(Target.Constraints); list.Sort(); int lastLength = buf.Length; foreach (Constraint c in list) { switch (c.ConstraintType) { case ConstraintType.Primary: if (!IsChecked(checkBoxSourceMain) && IsChecked(checkBoxSourceKeyCons)) { // 本体ソース内で出力しているので本体を出力しない場合のみ foreach (string s in ctx.GetSQL(c, string.Empty, ";", 0, true, true)) { buf.Append(s); } } break; case ConstraintType.Unique: if (IsChecked(checkBoxSourceKeyCons)) { foreach (string s in ctx.GetSQL(c, string.Empty, ";", 0, true, true)) { buf.Append(s); } } break; case ConstraintType.ForeignKey: if (IsChecked(checkBoxSourceRefCons)) { foreach (string s in ctx.GetSQL(c, string.Empty, ";", 0, true, true)) { buf.Append(s); } } break; case ConstraintType.Check: if (IsChecked(checkBoxSourceCons)) { foreach (string s in ctx.GetSQL(c, string.Empty, ";", 0, true, true)) { buf.Append(s); } } break; } } if (lastLength < buf.Length) { buf.AppendLine(); } if (IsChecked(checkBoxSourceComment)) { lastLength = buf.Length; if (!string.IsNullOrEmpty(Target.CommentText)) { foreach (string s in ctx.GetSQL(Target.Comment, string.Empty, ";", 0, true)) { buf.Append(s); } } foreach (Column c in Target.Columns) { if (!string.IsNullOrEmpty(c.CommentText)) { foreach (string s in ctx.GetSQL(c.Comment, string.Empty, ";", 0, true)) { buf.Append(s); } } } if (lastLength < buf.Length) { buf.AppendLine(); } } if (IsChecked(checkBoxSourceTrigger)) { lastLength = buf.Length; foreach (Trigger t in Target.Triggers) { foreach (string s in ctx.GetSQL(t, string.Empty, ";", 0, true)) { buf.Append(s); } buf.AppendLine(); } if (lastLength < buf.Length) { buf.AppendLine(); } } if (IsChecked(checkBoxSourceIndex)) { lastLength = buf.Length; foreach (Index i in Target.Indexes) { foreach (string s in ctx.GetSQL(i, string.Empty, ";", 0, true)) { buf.Append(s); } } if (lastLength < buf.Length) { buf.AppendLine(); } } if (IsChecked(checkBoxSourceReferredCons)) { lastLength = buf.Length; foreach (ForeignKeyConstraint f in Target.ReferFrom) { foreach (string s in ctx.GetSQL(f, string.Empty, ";", 0, true, true)) { buf.Append(s); } } if (lastLength < buf.Length) { buf.AppendLine(); } } textBoxSource.Text = buf.ToString(); } catch (Exception t) { textBoxSource.Text = t.ToString(); } }