Добавьте файлы проекта.
This commit is contained in:
169
SQLVision.UI/Views/MainWindow.xaml.cs
Normal file
169
SQLVision.UI/Views/MainWindow.xaml.cs
Normal file
@@ -0,0 +1,169 @@
|
||||
using Microsoft.UI.Windowing;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using SQLVision.Core.Models;
|
||||
using SQLVision.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Windows.Graphics;
|
||||
|
||||
namespace SQLVision.UI.Views
|
||||
{
|
||||
public sealed partial class MainWindow : Window
|
||||
{
|
||||
// Õðàíèì òåêóùèå ìåòàäàííûå âûáðàííîãî ñêðèïòà
|
||||
private ScriptMetadata currentMetadata;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
SetWindowSize(1200, 800);
|
||||
LoadScripts();
|
||||
}
|
||||
|
||||
private void SetWindowSize(int width, int height)
|
||||
{
|
||||
var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
|
||||
var windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(hwnd);
|
||||
var appWindow = AppWindow.GetFromWindowId(windowId);
|
||||
appWindow.Resize(new SizeInt32(width, height));
|
||||
}
|
||||
|
||||
private void LoadScripts()
|
||||
{
|
||||
var folder = Path.Combine(AppContext.BaseDirectory, "Scripts");
|
||||
if (!Directory.Exists(folder)) return;
|
||||
|
||||
foreach (var file in Directory.GetFiles(folder, "*.sql", SearchOption.AllDirectories))
|
||||
{
|
||||
var node = new TreeViewNode
|
||||
{
|
||||
Content = new ScriptTreeItem
|
||||
{
|
||||
DisplayName = Path.GetFileName(file),
|
||||
FilePath = file
|
||||
}
|
||||
};
|
||||
ScriptsTree.RootNodes.Add(node);
|
||||
}
|
||||
|
||||
ScriptsTree.ItemInvoked += ScriptsTree_ItemInvoked;
|
||||
}
|
||||
|
||||
private void ScriptsTree_ItemInvoked(TreeView sender, TreeViewItemInvokedEventArgs args)
|
||||
{
|
||||
if (args.InvokedItem is TreeViewNode node && node.Content is ScriptTreeItem item)
|
||||
{
|
||||
var file = item.FilePath;
|
||||
var lines = File.ReadAllLines(file);
|
||||
var parser = new SqlScriptParser();
|
||||
currentMetadata = parser.Parse(lines); // ñîõðàíÿåì â ïîëå
|
||||
|
||||
RenderParameters(currentMetadata);
|
||||
|
||||
OutputTabs.TabItems.Clear();
|
||||
foreach (var output in currentMetadata.Outputs)
|
||||
{
|
||||
var tab = new TabViewItem
|
||||
{
|
||||
Header = output.Description,
|
||||
Content = new TextBlock { Text = $"Âûâîä: {output.Type}" }
|
||||
};
|
||||
OutputTabs.TabItems.Add(tab);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RenderParameters(ScriptMetadata metadata)
|
||||
{
|
||||
ParametersPanel.Items.Clear();
|
||||
|
||||
foreach (var param in metadata.Parameters)
|
||||
{
|
||||
FrameworkElement control = null;
|
||||
|
||||
switch (param.Type)
|
||||
{
|
||||
case ParameterType.Int:
|
||||
control = new TextBox { Header = param.Description, Text = param.DefaultValue ?? string.Empty };
|
||||
break;
|
||||
case ParameterType.String:
|
||||
control = new TextBox { Header = param.Description, Text = param.DefaultValue ?? string.Empty };
|
||||
break;
|
||||
case ParameterType.DateTime:
|
||||
control = new DatePicker
|
||||
{
|
||||
Header = param.Description,
|
||||
SelectedDate = DateTime.TryParse(param.DefaultValue, out var dt) ? dt : DateTime.Now
|
||||
};
|
||||
break;
|
||||
case ParameterType.Bool:
|
||||
control = new CheckBox
|
||||
{
|
||||
Content = param.Description,
|
||||
IsChecked = param.DefaultValue?.ToLower() == "true"
|
||||
};
|
||||
break;
|
||||
case ParameterType.Table:
|
||||
var combo = new ComboBox { Header = param.Description };
|
||||
combo.Items.Add("Ìàãàçèí 1");
|
||||
combo.Items.Add("Ìàãàçèí 2");
|
||||
combo.Items.Add("Ìàãàçèí 3");
|
||||
control = combo;
|
||||
break;
|
||||
}
|
||||
|
||||
param.Control = control;
|
||||
ParametersPanel.Items.Add(control);
|
||||
}
|
||||
}
|
||||
|
||||
private Dictionary<string, object> CollectParameterValues()
|
||||
{
|
||||
var values = new Dictionary<string, object>();
|
||||
|
||||
if (currentMetadata == null) return values;
|
||||
|
||||
foreach (var param in currentMetadata.Parameters)
|
||||
{
|
||||
switch (param.Type)
|
||||
{
|
||||
case ParameterType.Int:
|
||||
if (param.Control is TextBox tbInt && int.TryParse(tbInt.Text, out var intVal))
|
||||
values[param.Name] = intVal;
|
||||
break;
|
||||
case ParameterType.String:
|
||||
if (param.Control is TextBox tbStr)
|
||||
values[param.Name] = tbStr.Text;
|
||||
break;
|
||||
case ParameterType.DateTime:
|
||||
if (param.Control is DatePicker dp && dp.SelectedDate.HasValue)
|
||||
values[param.Name] = dp.SelectedDate.Value;
|
||||
break;
|
||||
case ParameterType.Bool:
|
||||
if (param.Control is CheckBox cb)
|
||||
values[param.Name] = cb.IsChecked ?? false;
|
||||
break;
|
||||
case ParameterType.Table:
|
||||
if (param.Control is ComboBox combo && combo.SelectedItem != null)
|
||||
values[param.Name] = combo.SelectedItem.ToString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
private void ExecuteButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var values = CollectParameterValues();
|
||||
|
||||
// Çäåñü ìîæíî ñôîðìèðîâàòü SQL ñ ïîäñòàíîâêîé ïàðàìåòðîâ
|
||||
foreach (var kv in values)
|
||||
{
|
||||
Console.WriteLine($"{kv.Key} = {kv.Value}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user