-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
179 lines (154 loc) · 6.82 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
using DateTimeTable.Logic;
using Microsoft.Data.SqlClient;
using Ookii.Dialogs.Wpf;
using System;
using System.Data;
using System.Threading.Tasks;
using System.Windows;
namespace DateTimeTable
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private string _srv = "localhost";
private string _db = "";
private string _table = "DimDate";
private string _passs = "";
private string _user = "";
public bool IntegratedEnable { get; set; }
public bool IntegratedChecked { get; set; }
public string SelectedDatebase { get => _db; set => _db = value; }
public string SelectedServer { get => _srv; set => _srv = value; }
public string TableName { get => _table; set => _table = value; }
public MainWindow()
{
IntegratedEnable = true;
IntegratedChecked = true;
InitializeComponent();
this.DataContext = this;
this.Loaded += MainWindow_Loaded;
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
;
}
#region WPFEvent
private void Fill_databases(object sender, RoutedEventArgs e)
{
SQLConnectionHelper helper;
if (IntegratedChecked)
helper = new SQLConnectionHelper(_srv);
else
helper = new SQLConnectionHelper(_srv, _user, _passs);
Databases.ItemsSource = helper.GetDatabases();
}
#endregion
private void NotEnoughData(string why)
{
using TaskDialog dialog = new();
dialog.WindowTitle = ".اطلاعات کافی نمی باشد";
dialog.MainInstruction = "لطفا اطلاعات را صحیح و کامل وارد فرمایید";
dialog.Content = ".این خطا به علت اشتباه بودن اطلاعات وارده یا کمبود اطلاعات می باشد\n .می تواند با کلیک بر اطلاعات بیشتر از علت خطا مطلع شوید";
dialog.ExpandedInformation = why;
dialog.Footer = "Created By Masoud Rahmani.";
dialog.FooterIcon = TaskDialogIcon.Shield;
TaskDialogButton okButton = new TaskDialogButton(ButtonType.Ok);
TaskDialogButton cancelButton = new TaskDialogButton(ButtonType.Cancel);
dialog.Buttons.Add(okButton);
dialog.Buttons.Add(cancelButton);
TaskDialogButton button = dialog.ShowDialog(this);
}
private bool CheckTableExists()
{
SQLConnectionHelper helper;
if (IntegratedChecked) helper = new SQLConnectionHelper(_srv);
else helper = new SQLConnectionHelper(_srv, _user, _passs);
helper.Database = _db;
using var cnn = helper.GetSqlConnection(ConnectionStringConfig.WithDatabase, true, true);
cnn.Open();
var sch = cnn.GetSchema("Tables");
bool result = false;
foreach (DataRow r in sch.Rows)
{
string tablename = (string)r[2];
if (tablename == _table)
{
result = true; break;
}
}
cnn.Close();
return result;
}
private void StartToCreate(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(_db))
NotEnoughData("مقدار دیتابیس خالی می باشد.");
else
{
if (CheckTableExists())
{
NotEnoughData("دیتابیس از قبل موجود می باشد، لطفا نام دیگری انتخاب فرمایید.");
return;
}
UpdateLayoutToInformStartofJob();
DateCreator bl = new(_srv, _db, _table);
CalculateDates(bl);
}
}
private void UpdateLayoutToInformStartofJob()
{
Progressbar.IsIndeterminate = true;
MainGrid.IsEnabled = false;
}
private async void CalculateDates(DateCreator dc)
{
var start = StartDatePicker.SelectedDate ?? new DateTime(1993, 01, 01);
var end = EndDatePicker.SelectedDate ?? new DateTime(2030, 01, 01);
var result = Task.Factory.StartNew(() => { dc.Start(start, end); });
await result;
UpdateLayoutToInfromJobDone();
}
private void UpdateLayoutToInfromJobDone()
{
MainGrid.IsEnabled = true;
Progressbar.IsIndeterminate = false;
Progressbar.Maximum = 1;
Progressbar.Value = 1;
MessageBox.Show("Done.");
}
/// <summary>
/// Unchecked Integrated Security
/// </summary>
/// <param name="sender">CheckBox</param>
private void GetCredentialEvent(object sender, RoutedEventArgs e)
{
using (CredentialDialog credentialDialog = new())
{
credentialDialog.MainInstruction = "رمز و پسورد خود را وارد کنید.";
credentialDialog.Content = "این رمز و پسورد جهت ورود به دیتابیس استفاده میشود و بلافاصله از حافظه پاک میشود.";
//credentialDialog.ShowSaveCheckBox = true;
//credentialDialog.ShowUIForSavedCredentials = true;
//// The target is the key under which the credentials will be stored.
//// It is recommended to set the target to something following the "Company_Application_Server" pattern.
//// Targets are per user, not per application, so using such a pattern will ensure uniqueness.
credentialDialog.Target = "MasoudRahmani_DateTimeCalendarCreator_" + Environment.MachineName + "_" + Environment.UserName;
if (credentialDialog.ShowDialog())
{
_user = credentialDialog.UserName;
_passs = credentialDialog.Password;
bool result = new SQLConnectionHelper(_srv, _user, _passs).CheckCredential();
// Normally, you should verify if the credentials are correct before calling ConfirmCredentials.
// ConfirmCredentials will save the credentials if and only if the user checked the save checkbox.
//if (result)
// credentialDialog.ConfirmCredentials(true);
//else credentialDialog.ConfirmCredentials(false);
if (!result)
NotEnoughData("رمز اشتباه است");
//بررسی cancel
}
}
}
}
}