Guest User

Untitled

a guest
Jan 8th, 2021
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.21 KB | None | 0 0
  1. public async Task EditTable(string TableName)
  2. {
  3. var db = new SqlConnection(connectionString);
  4. await db.OpenAsync();
  5. await db.QueryAsync($"DROP TABLE IF EXISTS [{TableName}_COPY]");
  6. await db.QueryAsync($"DROP TABLE IF EXISTS [USUMODEl{TableName}_COPY]");
  7. await db.QueryAsync($"Drop TABLE IF EXISTS [SPS_COPY]");
  8. await db.QueryAsync($"SELECT * INTO [{TableName + "_COPY"}] FROM [{TableName}];");
  9. await db.QueryAsync($"SELECT * INTO [{"USUMODEL" + TableName + "_COPY"}] FROM [{"USUMODEL" + TableName}];");
  10. await db.QueryAsync($"SELECT * INTO [SPS_COPY] FROM [SPS];");
  11. transitioner = new Transitioner { AutoApplyTransitionOrigins = true, SelectedIndex = 0, Height = 400, Width = 700, FocusVisualStyle = null };
  12. TransitionerSlide SlideMain = new TransitionerSlide { ForwardWipe = new SlideOutWipe(), FocusVisualStyle = null };
  13. transitioner.Items.Add(SlideMain);
  14. TransitionerSlide SlideConfig = new TransitionerSlide { BackwardWipe = new CircleWipe(), FocusVisualStyle = null };
  15. transitioner.Items.Add(SlideConfig);
  16. #region Childrens
  17. Grid DialogGrid = new Grid { VerticalAlignment = VerticalAlignment.Stretch, HorizontalAlignment = HorizontalAlignment.Stretch, Focusable = false, Background = (Brush)FindResource("MaterialDesignTextFieldBoxBackground") };
  18. ScrollViewer scrollViewer = new ScrollViewer { Margin = new Thickness(0, 45, 0, 75), VerticalAlignment = VerticalAlignment.Stretch, HorizontalAlignment = HorizontalAlignment.Stretch, Focusable = false };
  19. DialogGrid.Children.Add(scrollViewer);
  20. Card border = new Card { Background = Brushes.White, UniformCornerRadius = 20, Height = 80, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Bottom, Margin = new Thickness(0, 0, 0, -20) };
  21. DialogGrid.Children.Add(border);
  22. Button AddColumn = new Button
  23. {
  24. HorizontalAlignment = HorizontalAlignment.Center,
  25. VerticalAlignment = VerticalAlignment.Bottom,
  26. Margin = new Thickness(0, 0, 0, 30),
  27. FocusVisualStyle = null,
  28. Content = new PackIcon { Kind = PackIconKind.Add, Foreground = Brushes.Black, Height = 25, Width = 25 },
  29. Style = (Style)FindResource("MaterialDesignFloatingActionButton")
  30. };
  31. DialogGrid.Children.Add(AddColumn);
  32. Button OK = new Button
  33. {
  34. Content = "OK",
  35. VerticalAlignment = VerticalAlignment.Bottom,
  36. HorizontalAlignment = HorizontalAlignment.Right,
  37. Margin = new Thickness(0, 0, 100, 10),
  38. FocusVisualStyle = null,
  39. Height = 40,
  40. Style = (Style)FindResource("MaterialDesignFlatButton"),
  41. Command = DialogHost.CloseDialogCommand
  42. };
  43. DialogGrid.Children.Add(OK);
  44. Button Cancel = new Button
  45. {
  46. Content = "Отмена",
  47. VerticalAlignment = VerticalAlignment.Bottom,
  48. HorizontalAlignment = HorizontalAlignment.Right,
  49. Margin = new Thickness(0, 0, 15, 10),
  50. Focusable = false,
  51. Height = 40,
  52. Style = (Style)FindResource("MaterialDesignFlatButton"),
  53. Command = DialogHost.CloseDialogCommand
  54. };
  55. DialogGrid.Children.Add(Cancel);
  56. #endregion
  57. {
  58. DialogGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
  59. DialogGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(200, GridUnitType.Pixel) });
  60. DialogGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(120, GridUnitType.Pixel) });
  61. }
  62. #region Заголовок
  63. {
  64. TextBlock Column = new TextBlock { VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Center, Margin = new Thickness(0, 10, 0, 0), Text = "Имя столбца" };
  65. Column.SetValue(Grid.ColumnProperty, 0);
  66. Column.SetResourceReference(TextBlock.StyleProperty, "MaterialDesignHeadline5TextBlock");
  67. DialogGrid.Children.Add(Column);
  68. }
  69. {
  70. TextBlock Column = new TextBlock { VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Center, Margin = new Thickness(0, 10, 0, 0), Text = "Тип данных" };
  71. Column.SetValue(Grid.ColumnProperty, 1);
  72. Column.SetResourceReference(TextBlock.StyleProperty, "MaterialDesignHeadline5TextBlock");
  73. DialogGrid.Children.Add(Column);
  74. }
  75. #endregion
  76. #region Scroll
  77. scrollViewer.SetValue(Grid.ColumnSpanProperty, 3);
  78. StackPanel scrollStack = new StackPanel { VerticalAlignment = VerticalAlignment.Stretch, HorizontalAlignment = HorizontalAlignment.Stretch, Focusable = false, Orientation = Orientation.Vertical, Margin = new Thickness(0, 10, 0, 0) };
  79. scrollViewer.Content = scrollStack;
  80. foreach (var el in (await db.QueryAsync($"SELECT * FROM [USUMODEL{TableName}] ORDER BY [Порядковый номер] ASC ")).Select(b => (IDictionary<string, object>)b).ToList())
  81. {
  82. scrollStack.Children.Add(await AddColumnInColumns(el["Имя столбца"].ToString()));
  83. }
  84. #endregion
  85. #region NavBar
  86. border.SetValue(Grid.ColumnSpanProperty, 3);
  87. Panel.SetZIndex(border, 1001);
  88. #endregion
  89. #region Add
  90. AddColumn.SetValue(Grid.ColumnSpanProperty, 3);
  91. Panel.SetZIndex(AddColumn, 1002);
  92. AddColumn.Click += async (sender, e) =>
  93. {
  94. await db.OpenAsync();
  95. try
  96. {
  97. db.Query($"ALTER TABLE [{TableName + "_COPY"}] ADD [ ] NVARCHAR(MAX) NULL;");
  98. int max;
  99. if (db.Query<string>($"SELECT MAX([Порядковый номер]) FROM [{"USUMODEL" + TableName + "_COPY"}]").First() != null)
  100. {
  101. max = db.Query<int>($"SELECT MAX([Порядковый номер]) FROM [{"USUMODEL" + TableName + "_COPY"}]").First() + 1;
  102. }
  103. else
  104. {
  105. max = 0;
  106. }
  107. db.Query($"INSERT [USUMODEL{TableName}_COPY] ([Порядковый номер],[Имя столбца],[Тип данных],[Конфигурация],[IsType],[IsDelete]) VALUES ({max},N' ',N'Строка',N'',1,1);");
  108. scrollStack.Children.Add(await AddColumnInColumns(" "));
  109. OK.IsEnabled = false;
  110. }
  111. catch { }
  112. db.Close();
  113. };
  114. #endregion
  115. #region OK
  116. OK.SetValue(ButtonAssist.CornerRadiusProperty, new CornerRadius(20));
  117. OK.SetValue(Grid.ColumnSpanProperty, 3);
  118. Panel.SetZIndex(OK, 1002);
  119. OK.Click += (object sender, RoutedEventArgs e) =>
  120. {
  121. db.Open();
  122. int j = 1;
  123. foreach (Grid el in scrollStack.Children)
  124. {
  125. db.Query($"UPDATE [USUMODEL{TableName}_COPY] SET [Порядковый номер] = {j} WHERE [Имя столбца] = N'{((TextBox)el.Children[1]).Text}'");
  126. j++;
  127. el.Height += 1;
  128. }
  129. db.Query($"Drop TABLE[{TableName}]");
  130. db.Query($"EXEC sp_rename N'{TableName}_COPY', N'{TableName}'");
  131. db.Query($"Drop TABLE[USUMODEL{TableName}]");
  132. db.Query($"EXEC sp_rename N'USUMODEL{TableName}_COPY', N'USUMODEL{TableName}'");
  133. db.Query($"Drop TABLE[SPS]");
  134. db.Query($"EXEC sp_rename 'SPS_COPY', 'SPS'");
  135. db.Close();
  136. MenuOfTable.Visibility = Visibility.Hidden;
  137. dataGrid.Visibility = Visibility.Hidden;
  138. if ((TreeViewItem)TreeView.SelectedItem != null)
  139. {
  140. ((TreeViewItem)TreeView.SelectedItem).IsSelected = false;
  141. }
  142. };
  143. #endregion
  144. #region Cancel
  145. Cancel.SetValue(ButtonAssist.CornerRadiusProperty, new CornerRadius(20));
  146. Cancel.SetValue(Grid.ColumnSpanProperty, 3);
  147. Panel.SetZIndex(Cancel, 1002);
  148. Cancel.Click += (object sender, RoutedEventArgs e) =>
  149. {
  150. db.Open();
  151. db.Query($"Drop TABLE[{TableName + "_COPY"}]");
  152. db.Query($"Drop TABLE[{"USUMODEL" + TableName + "_COPY"}]");
  153. db.Query($"Drop TABLE IF EXISTS [SPS_COPY]");
  154. db.Close();
  155. };
  156. #endregion
  157. SlideMain.Content = DialogGrid;
  158. await DialogHost.ShowDialog(transitioner);
  159. async Task<Grid> AddColumnInColumns(string ColumnName)
  160. {
  161. db = new SqlConnection(connectionString);
  162. await db.OpenAsync();
  163. string Name = ColumnName;
  164. Grid Column = new Grid { Height = 45, Margin = new Thickness(0, -15, 0, 15), VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Stretch };
  165. Column.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(30, GridUnitType.Pixel) });
  166. Column.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
  167. Column.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(150, GridUnitType.Pixel) });
  168. Column.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(45, GridUnitType.Pixel) });
  169. Column.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(45, GridUnitType.Pixel) });
  170. int counter = 0;
  171. #region Drag and Drop
  172. double y = 0;
  173. Button DragDrop = new Button
  174. {
  175. Height = 25,
  176. FocusVisualStyle = null,
  177. BorderBrush = Brushes.Transparent,
  178. Background = Brushes.Transparent,
  179. Content = new PackIcon { Kind = PackIconKind.DragHorizontal, Foreground = Brushes.Black, Width = 25, Height = 25 },
  180. HorizontalAlignment = HorizontalAlignment.Center,
  181. VerticalAlignment = VerticalAlignment.Bottom,
  182. Margin = new Thickness(5, 0, 0, 0),
  183. Style = (Style)FindResource("MaterialDesignFloatingActionMiniButton")
  184. };
  185. DragDrop.SetValue(Grid.ColumnProperty, counter);
  186. #region drag
  187. DragDrop.PreviewMouseLeftButtonDown += (object sender, MouseButtonEventArgs e) =>
  188. {
  189. y = e.GetPosition(null).Y;
  190. DragDrop.PreviewMouseMove += DragDrop_MouseMove;
  191. };
  192. DragDrop.PreviewMouseLeftButtonUp += (object sender, MouseButtonEventArgs e) =>
  193. {
  194. DragDrop.PreviewMouseMove -= DragDrop_MouseMove;
  195. };
  196. void DragDrop_MouseMove(object sender1, System.Windows.Input.MouseEventArgs e1)
  197. {
  198. double mousey = e1.GetPosition(null).Y;
  199. int pos = scrollStack.Children.IndexOf(Column);
  200. if (mousey < y - 45)
  201. {
  202. if (pos - 1 >= 0)
  203. {
  204. scrollStack.Children.Remove(Column);
  205. scrollStack.Children.Insert(pos - 1, Column);
  206. y = e1.GetPosition(null).Y;
  207. }
  208. }
  209. else if (mousey > y + 45)
  210. {
  211. if (scrollStack.Children.Count > pos + 1)
  212. {
  213. scrollStack.Children.Remove(Column);
  214. scrollStack.Children.Insert(pos + 1, Column);
  215. y = e1.GetPosition(null).Y;
  216. }
  217. }
  218. if (pos != scrollStack.Children.IndexOf(Column))
  219. {
  220. using (IDbConnection Db = new SqlConnection(connectionString))
  221. {
  222. string id1 = Db.Query<string>($"SELECT [Id] FROM [SPS_COPY] WHERE [KEY] LIKE N'{TableName}%' AND [VALUE] LIKE N'{pos + 1}'").FirstOrDefault();
  223. string id2 = Db.Query<string>($"SELECT [Id] FROM [SPS_COPY] WHERE [KEY] LIKE N'{TableName}%' AND [VALUE] LIKE N'{scrollStack.Children.IndexOf(Column) + 1}'").FirstOrDefault();
  224. Db.Query($"UPDATE [SPS_COPY] SET [VALUE] = N'{scrollStack.Children.IndexOf(Column) + 1}' WHERE [Id] = N'{id1}'");
  225. Db.Query($"UPDATE [SPS_COPY] SET [VALUE] = N'{pos + 1}' WHERE [Id] = N'{id2}'");
  226. }
  227. }
  228. }
  229. #endregion
  230. Column.Children.Add(DragDrop);
  231. counter++;
  232. #endregion
  233. #region Имя Столбца
  234. TextBox NameColumn = new TextBox
  235. {
  236. Height = 45,
  237. HorizontalAlignment = HorizontalAlignment.Stretch,
  238. VerticalContentAlignment = VerticalAlignment.Bottom,
  239. Margin = new Thickness(5, 0, 5, 0),
  240. Style = (Style)FindResource("MaterialDesignFloatingHintTextBox"),
  241. Text = " "
  242. };
  243. NameColumn.SetValue(Grid.ColumnProperty, counter);
  244. #region changed
  245. NameColumn.TextChanged += (sender, e) =>
  246. {
  247. db.Close();
  248. db.Open();
  249. if (NameColumn.Text.Trim() != string.Empty)
  250. {
  251. try
  252. {
  253. db.Query($"EXEC sp_rename N'{TableName + "_COPY"}.[{ColumnName}]', N'{NameColumn.Text}', 'COLUMN';");
  254. db.Query($"UPDATE [{"USUMODEL" + TableName + "_COPY"}] SET [Имя столбца] = N'{NameColumn.Text}' WHERE [Имя столбца] = N'{ColumnName}'");
  255. ColumnName = NameColumn.Text;
  256. NameColumn.SetValue(HintAssist.HelperTextProperty, "");
  257. }
  258. catch
  259. {
  260. NameColumn.SetValue(HintAssist.HelperTextProperty, "Столбец с таким названием уже есть");
  261. }
  262. }
  263. else
  264. {
  265. NameColumn.SetValue(HintAssist.HelperTextProperty, "Введите название столбца");
  266. }
  267. OK.IsEnabled = true;
  268. foreach (TextBox text in scrollStack.Children.Cast<Grid>().Select(b => b.Children[1]))
  269. {
  270. if (!(text.GetValue(HintAssist.HelperTextProperty) == "" || text.GetValue(HintAssist.HelperTextProperty) == null))
  271. {
  272. OK.IsEnabled = false;
  273. break;
  274. }
  275. }
  276. db.Close();
  277. };
  278. NameColumn.Text = ColumnName.Trim();
  279. NameColumn.LostFocus += (object sender, RoutedEventArgs e) =>
  280. {
  281. if (NameColumn.GetValue(HintAssist.HelperTextProperty) == "Столбец с таким названием уже есть" && NameColumn.IsFocused == false)
  282. {
  283. Dispatcher.BeginInvoke((ThreadStart)delegate
  284. {
  285. NameColumn.Focus();
  286. });
  287. }
  288. };
  289. #endregion
  290. Column.Children.Add(NameColumn);
  291. counter++;
  292. #endregion
  293. #region Тип данных
  294. ComboBox TypeColumn = new ComboBox
  295. {
  296. VerticalAlignment = VerticalAlignment.Bottom,
  297. HorizontalAlignment = HorizontalAlignment.Stretch,
  298. ItemsSource = TypeToTypeDb.Keys.ToList(),
  299. Margin = new Thickness(5, 0, 5, 0),
  300. IsEnabled = db.Query<bool>($"SELECT [IsType] FROM [USUMODEL{TableName}_COPY] WHERE [Имя столбца] = N'{ColumnName}'").First()
  301. };
  302. TypeColumn.SetValue(Grid.ColumnProperty, counter);
  303. try { TypeColumn.SelectedValue = db.QueryAsync<string>($"SELECT [Тип данных] FROM [USUMODEL{TableName}_COPY] WHERE [Имя столбца] = N'{ColumnName}'").Result.First(); }
  304. catch { TypeColumn.SelectedValue = TypeToTypeDb.Keys.ToList()[0]; }
  305. TypeColumn.SelectionChanged += (object sender, SelectionChangedEventArgs e1) =>
  306. {
  307. Grid MessageGrid = new Grid { Height = 180, Width = 470 };
  308. {
  309. TextBlock Header = new TextBlock
  310. {
  311. VerticalAlignment = VerticalAlignment.Top,
  312. Margin = new Thickness(15, 10, 15, 0),
  313. Text = "Измениние типа данных"
  314. };
  315. Header.SetResourceReference(StyleProperty, "MaterialDesignHeadline5TextBlock");
  316. MessageGrid.Children.Add(Header);
  317. }//Header
  318. {
  319. StackPanel stackPanel = new StackPanel
  320. {
  321. Orientation = Orientation.Horizontal,
  322. Margin = new Thickness(10, 7, 01, 7),
  323. Background = Brushes.Transparent
  324. };
  325. PackIcon icon = new PackIcon
  326. {
  327. Kind = PackIconKind.Alert,
  328. Foreground = Brushes.Red,
  329. Width = 22,
  330. Height = 22,
  331. Margin = new Thickness(5, 0, 5, 0),
  332. VerticalAlignment = VerticalAlignment.Center
  333. };
  334. stackPanel.Children.Add(icon);
  335. TextBlock text = new TextBlock
  336. {
  337. Foreground = Brushes.Red,
  338. VerticalAlignment = VerticalAlignment.Center,
  339. Text = "Измениние типа данных приводит к очищению всего столбца"
  340. };
  341. stackPanel.Children.Add(text);
  342. ColorZone colorZone = new ColorZone
  343. {
  344. Margin = new Thickness(15, 50, 15, 0),
  345. VerticalAlignment = VerticalAlignment.Top,
  346. Content = stackPanel,
  347. Background = new SolidColorBrush(Color.FromArgb(100, 250, 231, 231))
  348. };
  349. MessageGrid.Children.Add(colorZone);
  350. }//Warning
  351. {
  352. TextBlock textBlock = new TextBlock
  353. {
  354. VerticalAlignment = VerticalAlignment.Top,
  355. Margin = new Thickness(15, 100, 15, 0),
  356. Text = "Подвердить операцию?"
  357. };
  358. textBlock.SetResourceReference(StyleProperty, "MaterialDesignTextBlock");
  359. MessageGrid.Children.Add(textBlock);
  360. }//Question
  361. {
  362. Button ok = new Button
  363. {
  364. Content = "Да",
  365. VerticalAlignment = VerticalAlignment.Bottom,
  366. HorizontalAlignment = HorizontalAlignment.Right,
  367. Margin = new Thickness(0, 0, 75, 15),
  368. Focusable = false,
  369. Command = DialogHost.CloseDialogCommand,
  370. Style = (Style)FindResource("MaterialDesignFlatButton")
  371. };
  372. ok.SetValue(Grid.ColumnSpanProperty, 3);
  373. ok.Click += (object sender1, RoutedEventArgs e) =>
  374. {
  375. using (IDbConnection Db = new SqlConnection(connectionString))
  376. {
  377. Db.Query($"ALTER TABLE [{TableName + "_COPY"}] DROP COLUMN [{ColumnName}]");
  378. ComboBox comboBox = (ComboBox)sender;
  379. Button button = (Button)((Grid)comboBox.Parent).Children[3];
  380. switch (comboBox.SelectedItem)
  381. {
  382. case "Целое число":
  383. case "Дробное число":
  384. case "Строка":
  385. button.IsEnabled = true;
  386. break;
  387. case "Процент":
  388. case "Дата":
  389. case "Время":
  390. case "Фото":
  391. button.IsEnabled = false;
  392. break;
  393. }
  394. string str = $"ALTER TABLE [{TableName}_COPY] ADD [{ColumnName}] {TypeToTypeDb.Where(b => b.Key == comboBox.SelectedItem.ToString()).Select(b => b.Value).First()}";
  395. Db.Query(str);
  396. Db.Query($"UPDATE [USUMODEL{TableName}_COPY] SET [Тип данных] = N'{comboBox.SelectedItem}', [Конфигурация] = N'' WHERE [Имя столбца] = N'{ColumnName}'");
  397. }
  398. };
  399. MessageGrid.Children.Add(ok);
  400. }//OK
  401. {
  402. Button cancel = new Button
  403. {
  404. Content = "Нет",
  405. VerticalAlignment = VerticalAlignment.Bottom,
  406. HorizontalAlignment = HorizontalAlignment.Right,
  407. Margin = new Thickness(0, 0, 15, 15),
  408. Command = DialogHost.CloseDialogCommand,
  409. Focusable = false,
  410. Style = (Style)FindResource("MaterialDesignFlatButton")
  411. };
  412. cancel.SetValue(Grid.ColumnSpanProperty, 3);
  413. MessageGrid.Children.Add(cancel);
  414. }//CANCEL
  415. {
  416. DialogHost Host = new DialogHost { VerticalAlignment = VerticalAlignment.Stretch, IsManipulationEnabled = true };
  417. Host.SetResourceReference(StyleProperty, "MaterialDesignEmbeddedDialogHost");
  418. Host.SetValue(Grid.ColumnSpanProperty, 3);
  419. Host.SetValue(Grid.RowSpanProperty, 2);
  420. Host.SetValue(Panel.ZIndexProperty, 2000);
  421. grid.Children.Add(Host);
  422. Host.ShowDialog(MessageGrid);
  423. }//DialogHost
  424. };
  425. Column.Children.Add(TypeColumn);
  426. counter++;
  427. #endregion
  428. #region Конфигурация
  429. Button Configuration = new Button
  430. {
  431. VerticalAlignment = VerticalAlignment.Bottom,
  432. HorizontalAlignment = HorizontalAlignment.Center,
  433. Width = 40,
  434. Height = 40,
  435. Content = new PackIcon { Kind = PackIconKind.Tune, Foreground = Brushes.Black },
  436. Command = Transitioner.MoveNextCommand,
  437. FocusVisualStyle = null,
  438. Style = (Style)FindResource("MaterialDesignIconForegroundButton"),
  439. };
  440. Configuration.SetValue(Grid.ColumnProperty, counter);
  441. Configuration.Click += (object sender, RoutedEventArgs e) =>
  442. {
  443. SlideConfig.Content = EditConfigOfColumn(TableName, ColumnName);
  444. };
  445. Column.Children.Add(Configuration);
  446. counter++;
  447. #endregion
  448. #region Удаление
  449. Button Delete = new Button
  450. {
  451. VerticalAlignment = VerticalAlignment.Bottom,
  452. HorizontalAlignment = HorizontalAlignment.Center,
  453. Width = 40,
  454. Height = 40,
  455. Focusable = false,
  456. Content = new PackIcon { Kind = PackIconKind.Delete, Foreground = Brushes.Black },
  457. IsEnabled = db.Query<bool>($"SELECT [IsDelete] FROM [USUMODEL{TableName}_COPY] WHERE [Имя столбца] = N'{ColumnName}'").First(),
  458. Style = (Style)FindResource("MaterialDesignIconForegroundButton")
  459. };
  460. Delete.SetValue(Grid.ColumnProperty, counter);
  461. Delete.Click += (object sender, RoutedEventArgs e) =>
  462. {
  463. db.Open();
  464. db.Query($"ALTER TABLE [{TableName + "_COPY"}] DROP COLUMN [{ColumnName}]");
  465. db.Query($"DELETE FROM [{"USUMODEL" + TableName + "_COPY"}] WHERE [Имя столбца] = N'{ColumnName}'; ");
  466. scrollStack.Children.Remove(Column);
  467. OK.IsEnabled = true;
  468. foreach (Grid el in scrollStack.Children)
  469. {
  470. TextBox text = (TextBox)el.Children[1];
  471. if (!(text.GetValue(HintAssist.HelperTextProperty) == "" || text.GetValue(HintAssist.HelperTextProperty) == null))
  472. {
  473. OK.IsEnabled = false;
  474. break;
  475. }
  476. }
  477. db.Close();
  478. };
  479. Column.Children.Add(Delete);
  480. counter++;
  481. #endregion
  482. db.Close();
  483. Column.SizeChanged += (object sender, SizeChangedEventArgs e) =>
  484. {
  485. foreach (string USUMODELTABLE in db.Query<string>("SELECT [TABLE_NAME] FROM INFORMATION_SCHEMA.TABLES WHERE [TABLE_NAME] LIKE N'USUMODEL%'").ToList())
  486. {
  487. foreach (IDictionary<string, object> Configurat in db.Query($"SELECT * FROM [{USUMODELTABLE}] WHERE [Конфигурация] LIKE N'%Таблица:{TableName};%Столбец:{Name};%'").ToList().Select(b => (IDictionary<string, object>)b))
  488. {
  489. db.Query($"UPDATE [{USUMODELTABLE}] SET [Конфигурация] = N'{Configurat["Конфигурация"].ToString().Replace($"Столбец:{Name};", $"Столбец:{NameColumn.Text};")}' WHERE [Id] = N'{Configurat["Id"]}'");
  490. }
  491. }
  492. };
  493. return Column;
  494. }
  495. db.Close();
  496. }
Advertisement
Add Comment
Please, Sign In to add comment