/// <summary> /// Авторизация за клиента /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GoClient(object sender, RoutedEventArgs e) { SQLDataBase dataBase = new SQLDataBase(); string dep = string.Empty; string sql = string.Empty; if (comboBox.Text == "Физ отдел") { dep = "AllNaturalClients"; } else if (comboBox.Text == "Юр отдел") { dep = "AllLegalClients"; } else if (comboBox.Text == "VIP отдел") { dep = "AllVipNaturalClients"; } sql = $@" SELECT * FROM {dep} WHERE Id = {BoxLogin.Text} "; try { using (var com = new SqlCommand(sql, dataBase.connection)) { dataBase.connection.Open(); SqlDataReader r = com.ExecuteReader(); if (!r.HasRows) { dep = "AllVipLegalClients"; sql = $@" SELECT * FROM {dep} WHERE Id = {BoxLogin.Text} "; } dataBase.connection.Close(); } } catch (Exception error) { MessageBox.Show(error.Message, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); } try { using (var com = new SqlCommand(sql, dataBase.connection)) { dataBase.connection.Open(); SqlDataReader r = com.ExecuteReader(); while (r.Read()) { if (comboBox.Text == "Физ отдел") { var temp = new SimpleNaturalClient(r.GetInt32(0), r["FirstName"].ToString(), r["LastName"].ToString(), r["Department"].ToString(), r.GetDateTime(3), r.GetDecimal(7)); temp.CheckContribution = r.GetDecimal(8).ToString(); temp.CheckDebt = r.GetDecimal(9).ToString(); ClientWindow clientWindow = new ClientWindow(Bank, temp); clientWindow.Activate(); clientWindow.Show(); } else if (comboBox.Text == "Юр отдел") { var temp = new SimpleLegalEnity(r.GetInt32(0), r["Name"].ToString(), r["Department"].ToString(), r.GetDateTime(2), r.GetDecimal(6)); temp.CheckContribution = r.GetDecimal(7).ToString(); temp.CheckDebt = r.GetDecimal(8).ToString(); ClientWindow clientWindow = new ClientWindow(Bank, temp); clientWindow.Activate(); clientWindow.Show(); } else if (comboBox.Text == "VIP отдел") { try { var temp = new VipNaturalClient(r.GetInt32(0), r["FirstName"].ToString(), r["LastName"].ToString(), r["Department"].ToString(), r.GetDateTime(3), r.GetDecimal(6)); temp.CheckContribution = r.GetDecimal(7).ToString(); temp.CheckDebt = r.GetDecimal(8).ToString(); ClientWindow clientWindow = new ClientWindow(Bank, temp); clientWindow.Activate(); clientWindow.Show(); } catch (Exception) { var temp = new VipLegalEnity(r.GetInt32(0), r["Name"].ToString(), r["Department"].ToString(), r.GetDateTime(2), r.GetDecimal(5)); temp.CheckContribution = r.GetDecimal(6).ToString(); temp.CheckDebt = r.GetDecimal(7).ToString(); ClientWindow clientWindow = new ClientWindow(Bank, temp); clientWindow.Activate(); clientWindow.Show(); } } } } } catch (Exception exception) { MessageBox.Show(exception.Message, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); } Close(); }
/// <summary> /// Десериализация /// </summary> /// <param name="mainWindow">Главное окно</param> private void Deserializ(MainWindow mainWindow) { //Физические лица Temptemp temptemp = ProgressiveValue; try { SQLDataBase dataBase = new SQLDataBase(); SqlDataReader reader = dataBase.sql_select("Физический"); if (reader.HasRows) { while (reader.Read()) { int itemID = reader.GetInt32(0); string itemFirstName = reader["FirstName"].ToString(); string itemLastName = reader["LastName"].ToString(); DateTime itemDateOfCreate = reader.GetDateTime(3); string itemRep = reader["reputation"].ToString(); string itemDepartment = reader["Department"].ToString(); decimal itemAmountOfMoney = reader.GetDecimal(7); var new_client = new SimpleNaturalClient(itemID, itemFirstName, itemLastName, itemDepartment, itemDateOfCreate, itemAmountOfMoney); new_client.CheckContribution = reader.GetDecimal(8).ToString(); new_client.CheckDebt = reader.GetDecimal(9).ToString(); Bank.naturals_clients.Add(new_client); var progress = new Progress <int>(value => Dispatcher.Invoke(temptemp, DispatcherPriority.Normal, value)); Task task1 = new Task(() => { Dispatcher.Invoke(ProgressiveZero); for (int i = 0; i < 100; i++) { Dispatcher.Invoke(delegate { label.Content = itemFirstName + itemDepartment; }); ((IProgress <int>)progress).Report(i); Thread.Sleep(1); } }); task1.Start(); Task.WaitAll(task1); task1.Dispose(); } } Dispatcher.Invoke(() => dataBase.ServerDisConnect()); Task task2 = new Task(() => { if (Bank.naturals_clients.Count > 0) { foreach (var VARIABLE in Bank.naturals_clients) { Dispatcher.Invoke(() => mainWindow.list_natural_clients.Items.Add(VARIABLE), DispatcherPriority.Normal); } } }); //Юр лица reader = dataBase.sql_select("Юридический"); if (reader.HasRows) { while (reader.Read()) { int itemID = reader.GetInt32(0); string itemName = reader["Name"].ToString(); DateTime itemDateOfCreate = reader.GetDateTime(2); string itemRep = reader["reputation"].ToString(); string itemDepartment = reader["Department"].ToString(); decimal itemAmountOfMoney = reader.GetDecimal(6); var new_client = new SimpleLegalEnity(itemID, itemName, itemDepartment, itemDateOfCreate, itemAmountOfMoney); new_client.CheckContribution = reader.GetDecimal(7).ToString(); new_client.CheckDebt = reader.GetDecimal(8).ToString(); Bank.legals_clients.Add(new_client); var progress = new Progress <int>(value => Dispatcher.Invoke(temptemp, DispatcherPriority.Normal, value)); Task task1 = new Task(() => { Dispatcher.Invoke(ProgressiveZero); for (int i = 0; i < 100; i++) { Dispatcher.Invoke(delegate { label.Content = itemName + itemDepartment; }); ((IProgress <int>)progress).Report(i); Thread.Sleep(1); } }); task1.Start(); Task.WaitAll(task1); task1.Dispose(); } } Dispatcher.Invoke(() => dataBase.ServerDisConnect()); Task task3 = new Task(() => { if (Bank.legals_clients.Count > 0) { foreach (var VARIABLE in Bank.legals_clients) { Dispatcher.Invoke(() => mainWindow.list_legal_clients.Items.Add(VARIABLE), DispatcherPriority.Normal); } } }); //VIP физ reader = dataBase.sql_select("VIP_физ"); if (reader.HasRows) { while (reader.Read()) { int itemID = reader.GetInt32(0); string itemFirstName = reader["FirstName"].ToString(); string itemLastName = reader["LastName"].ToString(); DateTime itemDateOfCreate = reader.GetDateTime(3); string itemDepartment = reader["Department"].ToString(); decimal itemAmountOfMoney = reader.GetDecimal(6); var new_client = new VipNaturalClient(itemID, itemFirstName, itemLastName, itemDepartment, itemDateOfCreate, itemAmountOfMoney); new_client.CheckContribution = reader.GetDecimal(7).ToString(); new_client.CheckDebt = reader.GetDecimal(8).ToString(); Bank.vip_clients.Add(new_client); var progress = new Progress <int>(value => Dispatcher.Invoke(temptemp, DispatcherPriority.Normal, value)); Task task1 = new Task(() => { Dispatcher.Invoke(ProgressiveZero); for (int i = 0; i < 100; i++) { Dispatcher.Invoke(delegate { label.Content = itemFirstName + itemDepartment; }); ((IProgress <int>)progress).Report(i); Thread.Sleep(1); } }); task1.Start(); Task.WaitAll(task1); task1.Dispose(); } } Dispatcher.Invoke(() => dataBase.ServerDisConnect()); Task task4 = new Task(() => { if (Bank.vip_clients.Count > 0) { foreach (var VARIABLE in Bank.vip_clients) { if (VARIABLE is VipNaturalClient) { Dispatcher.Invoke(() => mainWindow.list_vip_Natural_clients.Items.Add(VARIABLE), DispatcherPriority.Normal); } } } }); //VIP Юр reader = dataBase.sql_select("VIP_юр"); if (reader.HasRows) { while (reader.Read()) { int itemID = reader.GetInt32(0); string itemName = reader["Name"].ToString(); DateTime itemDateOfCreate = reader.GetDateTime(2); string itemDepartment = reader["Department"].ToString(); decimal itemAmountOfMoney = reader.GetDecimal(5); var new_client = new VipLegalEnity(itemID, itemName, itemDepartment, itemDateOfCreate, itemAmountOfMoney); new_client.CheckContribution = reader.GetDecimal(6).ToString(); new_client.CheckDebt = reader.GetDecimal(7).ToString(); Bank.vip_clients.Add(new_client); var progress = new Progress <int>(value => Dispatcher.Invoke(temptemp, DispatcherPriority.Normal, value)); Task task1 = new Task(() => { Dispatcher.Invoke(ProgressiveZero); for (int i = 0; i < 100; i++) { Dispatcher.Invoke(delegate { label.Content = itemName + itemDepartment; }); ((IProgress <int>)progress).Report(i); Thread.Sleep(1); } }); task1.Start(); Task.WaitAll(task1); task1.Dispose(); } } Dispatcher.Invoke(() => dataBase.ServerDisConnect()); Task task5 = new Task(() => { if (Bank.vip_clients.Count > 0) { foreach (var VARIABLE in Bank.vip_clients) { if (VARIABLE is VipLegalEnity) { Dispatcher.Invoke(() => mainWindow.list_vip_legal_clients.Items.Add(VARIABLE), DispatcherPriority.Normal); } } } }); task2.Start(); task3.Start(); task4.Start(); task5.Start(); Dispatcher.Invoke(() => mainWindow.Show()); Dispatcher.Invoke(() => mainWindow.Activate()); Task.WaitAll(task2, task3, task4, task5); task2.Dispose(); task3.Dispose(); task4.Dispose(); task5.Dispose(); Dispatcher.Invoke(Close); } catch (Exception e) { MessageBox.Show(e.Message); Dispatcher.Invoke(() => mainWindow.Show()); Dispatcher.Invoke(Close); } }
/// <summary> /// Поиск по Номеру счета /// </summary> /// <typeparam name="T"></typeparam> /// <param name="AccountNumber"></param> /// <param name="Department"></param> /// <returns></returns> public object Find <T>(int AccountNumber, string Department) { SQLDataBase dataBase = new SQLDataBase(); string dep = string.Empty; string sql = string.Empty; if (Department == "Физический") { dep = "AllNaturalClients"; } else if (Department == "Юридический") { dep = "AllLegalClients"; } else if (Department == "VIP") { dep = "AllVipNaturalClients"; } sql = $@" SELECT * FROM {dep} WHERE AccountNumber = {AccountNumber} "; try { using (var com = new SqlCommand(sql, dataBase.connection)) { dataBase.connection.Open(); SqlDataReader r = com.ExecuteReader(); if (!r.HasRows) { dep = "AllVipLegalClients"; sql = $@" SELECT * FROM {dep} WHERE AccountNumber = {AccountNumber} "; } dataBase.connection.Close(); } } catch (Exception) { } try { using (var com = new SqlCommand(sql, dataBase.connection)) { dataBase.connection.Open(); SqlDataReader r = com.ExecuteReader(); while (r.Read()) { if (Department == "Физический") { var temp = new SimpleNaturalClient(r.GetInt32(0), r["FirstName"].ToString(), r["LastName"].ToString(), r["Department"].ToString(), r.GetDateTime(3), r.GetDecimal(7)); temp.CheckContribution = r.GetDecimal(8).ToString(); temp.CheckDebt = r.GetDecimal(9).ToString(); return(temp); } else if (Department == "Юридический") { var temp = new SimpleLegalEnity(r.GetInt32(0), r["Name"].ToString(), r["Department"].ToString(), r.GetDateTime(2), r.GetDecimal(6)); temp.CheckContribution = r.GetDecimal(7).ToString(); temp.CheckDebt = r.GetDecimal(8).ToString(); return(temp); } else if (Department == "VIP") { try { var temp = new VipNaturalClient(r.GetInt32(0), r["FirstName"].ToString(), r["LastName"].ToString(), r["Department"].ToString(), r.GetDateTime(3), r.GetDecimal(6)); temp.CheckContribution = r.GetDecimal(7).ToString(); temp.CheckDebt = r.GetDecimal(8).ToString(); return(temp); } catch (Exception) { var temp = new VipLegalEnity(r.GetInt32(0), r["Name"].ToString(), r["Department"].ToString(), r.GetDateTime(2), r.GetDecimal(5)); temp.CheckContribution = r.GetDecimal(6).ToString(); temp.CheckDebt = r.GetDecimal(7).ToString(); return(temp); } } } } } catch (Exception exception) { MessageBox.Show(exception.Message, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); return("NOT FOUND"); } return("NOT FOUND"); }
/// <summary> /// Добавить клиента /// </summary> private void AddClient() { SQLDataBase dataBase = new SQLDataBase(); if (RadioNatural.IsChecked == true) { if (TextIsDate(BoxBirthday.Text)) { if (BoxFirstName.Text != string.Empty && BoxLastName.Text != string.Empty && BoxBirthday.Text != string.Empty && BoxSumNatur.Text != string.Empty) { var temp = new VipNaturalClient(BoxFirstName.Text, BoxLastName.Text, "VIP", DateTime.Parse(BoxBirthday.Text), decimal.Parse(BoxSumNatur.Text)); Bank.Add(temp); dataBase.GoToDataBase(dataBase.CreateSQL(temp) + $@" ( {temp.ID}, N'{temp.FirstName}', N'{temp.LastName}', '{Convert.ToDateTime(temp.DateofBirth).ToString("yyyy-MM-dd")}', N'{temp.Department}', {temp.AccountNumber}, {temp.AmountOfMoney}, {temp.CheckContribution}, {temp.CheckDebt} ) "); Close(); } else { MessageBox.Show("Не все поля введены!", "WARNING", MessageBoxButton.OK, MessageBoxImage.Warning); } } else { MessageBox.Show("введите дату в формате dd.MM.yyyy", "WARNING", MessageBoxButton.OK, MessageBoxImage.Warning); } } else { if (TextIsDate(BoxCreateDate.Text)) { if (BoxName.Text != string.Empty && BoxCreateDate.Text != string.Empty && BoxSumLegal.Text != string.Empty) { var temp = new VipLegalEnity(BoxName.Text, "VIP", DateTime.Parse(BoxCreateDate.Text), decimal.Parse(BoxSumLegal.Text)); Bank.Add(temp); dataBase.GoToDataBase(dataBase.CreateSQL(temp) + $@" ( {temp.ID}, N'{temp.Name}', '{Convert.ToDateTime(temp.DateofBirth).ToString("yyyy-MM-dd")}', N'{temp.Department}', {temp.AccountNumber}, {temp.AmountOfMoney}, {temp.CheckContribution}, {temp.CheckDebt} ) "); Close(); } else { MessageBox.Show("Не все поля введены!", "WARNING", MessageBoxButton.OK, MessageBoxImage.Warning); } } else { MessageBox.Show("введите дату в формате dd.MM.yyyy", "WARNING", MessageBoxButton.OK, MessageBoxImage.Warning); } } }
/// <summary> /// Запуск процесса генерации сотрудников /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButGoToMass_Click(object sender, RoutedEventArgs e) { List <string> Client_FirstNames = new List <string>(); Client_FirstNames = LoadNames("../../../resources/Names.txt"); List <string> Client_LastNames = new List <string>(); Client_LastNames = LoadNames("../../../resources/LastNames.txt"); int count_workers = 0; try { count_workers = int.Parse(RandomBox.Text); //количество рабочих } catch (FormatException) { count_workers = default(int); MessageBox.Show("Неверный формат, можно вводить только цифры!", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); } Random r = new Random(); Random random_spec = new Random(); //специальность Random random_name = new Random(); Random random_dep = new Random(); SQLDataBase dataBase = new SQLDataBase(); while (count_workers > 0) { int count = Bank.Count; switch (random_spec.Next(1, 5)) { case 1: { var temp = new SimpleNaturalClient($"{Client_FirstNames[random_name.Next(Client_FirstNames.Count)]}", $"{Client_LastNames[random_name.Next(Client_LastNames.Count)]}", "Физический", DateTime.Now.AddYears(-r.Next(16, 80)), (decimal)r.Next(20000, 2000000)); Bank.Add(temp); dataBase.GoToDataBase(dataBase.CreateSQL(temp) + $@" ( {temp.ID}, N'{temp.FirstName}', N'{temp.LastName}', '{Convert.ToDateTime(temp.DateofBirth).ToString("yyyy-MM-dd")}', N'{temp.reputation}', N'{temp.Department}', {temp.AccountNumber}, {temp.AmountOfMoney}, {temp.CheckContribution}, {temp.CheckDebt} ) "); break; } case 2: { var temp = new SimpleLegalEnity($"{Client_FirstNames[random_name.Next(Client_FirstNames.Count)]}", "Юридический", DateTime.Now.AddYears(-r.Next(18, 80)), (decimal)r.Next(20000, 2000000)); Bank.Add(temp); dataBase.GoToDataBase(dataBase.CreateSQL(temp) + $@" ( {temp.ID}, N'{temp.Name}', '{Convert.ToDateTime(temp.DateofBirth).ToString("yyyy-MM-dd")}', N'{temp.reputation}',N'{temp.Department}', {temp.AccountNumber}, {temp.AmountOfMoney}, {temp.CheckContribution}, {temp.CheckDebt} ) "); break; } case 3: { var temp = new VipNaturalClient($"{Client_FirstNames[random_name.Next(Client_FirstNames.Count)]}", $"{Client_LastNames[random_name.Next(Client_LastNames.Count)]}", "VIP", DateTime.Now.AddYears(-r.Next(18, 80)), (decimal)r.Next(20000, 2000000)); Bank.Add(temp); dataBase.GoToDataBase(dataBase.CreateSQL(temp) + $@" ( {temp.ID}, N'{temp.FirstName}', N'{temp.LastName}', '{Convert.ToDateTime(temp.DateofBirth).ToString("yyyy-MM-dd")}', N'{temp.Department}', {temp.AccountNumber}, {temp.AmountOfMoney}, {temp.CheckContribution}, {temp.CheckDebt} ) "); break; } case 4: { var temp = new VipLegalEnity($"{Client_FirstNames[random_name.Next(Client_FirstNames.Count)]}", "VIP", DateTime.Now.AddYears(-r.Next(16, 80)), (decimal)r.Next(20000, 2000000)); Bank.Add(temp); dataBase.GoToDataBase(dataBase.CreateSQL(temp) + $@" ( {temp.ID}, N'{temp.Name}', '{Convert.ToDateTime(temp.DateofBirth).ToString("yyyy-MM-dd")}', N'{temp.Department}', {temp.AccountNumber}, {temp.AmountOfMoney}, {temp.CheckContribution}, {temp.CheckDebt} ) "); break; } default: break; } count_workers--; } MessageBox.Show("Готово", "Complite", MessageBoxButton.OK, MessageBoxImage.Asterisk); Close(); }