Beispiel #1
0
 /// <summary>
 /// Отправка запроса в базу данных
 /// </summary>
 /// <param name="sql"></param>
 public void GoToDataBase(string sql)
 {
     try
     {
         SQLDataBase dataBase = new SQLDataBase();
         dataBase.sql_upgade(sql);
     }
     catch (Exception exception)
     {
         MessageBox.Show(exception.Message, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Удаление
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButDelete_Click(object sender, RoutedEventArgs e)
        {
            SQLDataBase dataBase = new SQLDataBase();

            if (TabItemNatural.IsSelected)
            {
                if (list_natural_clients.SelectedItem != null)
                {
                    var temp = list_natural_clients.SelectedItem as SimpleNaturalClient;
                    Bank.Remove(list_natural_clients.SelectedItem);
                    dataBase.sql_delete(temp);
                }
            }
            else if (TabItemLegal.IsSelected)
            {
                if (list_legal_clients.SelectedItem != null)
                {
                    var temp = list_legal_clients.SelectedItem as SimpleLegalEnity;
                    Bank.Remove(list_legal_clients.SelectedItem);
                    dataBase.sql_delete(temp);
                }
            }
            else if (TabItemVip.IsSelected)
            {
                if (list_vip_legal_clients.SelectedItem != null)
                {
                    var temp = list_vip_legal_clients.SelectedItem as VipLegalEnity;
                    Bank.Remove(list_vip_legal_clients.SelectedItem);
                    dataBase.sql_delete(temp);
                }

                else if (list_vip_Natural_clients.SelectedItem != null)
                {
                    var temp = list_vip_Natural_clients.SelectedItem as VipNaturalClient;
                    Bank.Remove(list_vip_Natural_clients.SelectedItem);
                    dataBase.sql_delete(temp);
                }
            }
            Update();
        }
Beispiel #3
0
        /// <summary>
        /// Закрытие вклада
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CloseContribution(object sender, RoutedEventArgs e)
        {
            SQLDataBase dataBase = new SQLDataBase();

            if (client is SimpleNaturalClient)
            {
                var temp = client as SimpleNaturalClient;
                temp.Notify += SaveToLogContrubutionMessage;
                temp.CloseContribution();
                temp.Notify -= SaveToLogContrubutionMessage;
                using (var cmd = new SqlCommand($@"UPDATE AllNaturalClients SET  [AmountOfMoney] = @AmountOfMoney, [CheckContribution] = @CheckContribution WHERE Id = {temp.ID}", dataBase.connection))
                {
                    dataBase.connection.Open();
                    cmd.Parameters.Add("@AmountOfMoney", SqlDbType.Decimal).Value     = temp.AmountOfMoney;
                    cmd.Parameters.Add("@CheckContribution", SqlDbType.Decimal).Value = temp.CheckContribution;
                    cmd.ExecuteNonQuery();
                }
            }

            else if (client is SimpleLegalEnity)
            {
                var temp = client as SimpleLegalEnity;
                temp.Notify += SaveToLogContrubutionMessage;
                temp.CloseContribution();
                temp.Notify -= SaveToLogContrubutionMessage;
                using (var cmd =
                           new SqlCommand(
                               $@"UPDATE AllLegalClients SET  [AmountOfMoney] = @AmountOfMoney, [CheckContribution] = @CheckContribution WHERE Id = {temp.ID}",
                               dataBase.connection))
                {
                    dataBase.connection.Open();
                    cmd.Parameters.Add("@AmountOfMoney", SqlDbType.Decimal).Value     = temp.AmountOfMoney;
                    cmd.Parameters.Add("@CheckContribution", SqlDbType.Decimal).Value = temp.CheckContribution;
                    cmd.ExecuteNonQuery();
                }
            }

            else if (client is VipLegalEnity)
            {
                var temp = client as VipLegalEnity;
                temp.Notify += SaveToLogContrubutionMessage;
                temp.CloseContribution();
                temp.Notify -= SaveToLogContrubutionMessage;
                using (var cmd =
                           new SqlCommand(
                               $@"UPDATE AllVipLegalClients SET  [AmountOfMoney] = @AmountOfMoney, [CheckContribution] = @CheckContribution WHERE Id = {temp.ID}",
                               dataBase.connection))
                {
                    dataBase.connection.Open();
                    cmd.Parameters.Add("@AmountOfMoney", SqlDbType.Decimal).Value     = temp.AmountOfMoney;
                    cmd.Parameters.Add("@CheckContribution", SqlDbType.Decimal).Value = temp.CheckContribution;
                    cmd.ExecuteNonQuery();
                }
            }

            else if (client is VipNaturalClient)
            {
                var temp = client as VipNaturalClient;
                temp.Notify += SaveToLogContrubutionMessage;
                temp.CloseContribution();
                temp.Notify -= SaveToLogContrubutionMessage;
                using (var cmd =
                           new SqlCommand(
                               $@"UPDATE AllVipNaturalClients SET  [AmountOfMoney] = @AmountOfMoney, [CheckContribution] = @CheckContribution WHERE Id = {temp.ID}",
                               dataBase.connection))
                {
                    dataBase.connection.Open();
                    cmd.Parameters.Add("@AmountOfMoney", SqlDbType.Decimal).Value     = temp.AmountOfMoney;
                    cmd.Parameters.Add("@CheckContribution", SqlDbType.Decimal).Value = temp.CheckContribution;
                    cmd.ExecuteNonQuery();
                }
            }
            Update();
        }
Beispiel #4
0
        /// <summary>
        /// Сохранить
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButSerializ_Click(object sender, RoutedEventArgs e)
        {
            string[] sql    = new string[Bank.naturals_clients.Count];
            int      number = 0;

            foreach (var item in Bank.naturals_clients)
            {
                sql[number] = $@"
UPDATE AllNaturalClients SET [FirstName] = N'{item.FirstName}', [LastName] = N'{item.LastName}', 
[DateOfBirth] = '{Convert.ToDateTime(item.DateofBirth).ToString("yyyy-MM-dd")}', 
[reputation] = N'{(item as SimpleNaturalClient).reputation}',[Department] = N'{item.Department}', 
[AccountNumber] = {item.AccountNumber}, [AmountOfMoney] = {item.AmountOfMoney},
[CheckContribution] = {(item as SimpleNaturalClient).CheckContribution}, [CheckDebt] = {(item as SimpleNaturalClient).CheckDebt}
WHERE Id = {item.ID}
" + "\n";
                number++;
            }
            try
            {
                SQLDataBase dataBase = new SQLDataBase();
                dataBase.sql_upgade(sql);
                MessageBox.Show("Готово", "Complite", MessageBoxButton.OK, MessageBoxImage.Asterisk);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            //Юр лица
            sql    = new string[Bank.legals_clients.Count];
            number = 0;
            foreach (var item in Bank.legals_clients)
            {
                sql[number] = $@"
UPDATE AllLegalClients SET [Name] = N'{item.Name}', 
[DateOfBirth] = '{Convert.ToDateTime(item.DateofBirth).ToString("yyyy-MM-dd")}', 
[reputation] = N'{(item as SimpleLegalEnity).reputation}',[Department] = N'{item.Department}', 
[AccountNumber] = {item.AccountNumber}, [AmountOfMoney] = {item.AmountOfMoney},
[CheckContribution] = {(item as SimpleLegalEnity).CheckContribution}, [CheckDebt] = {(item as SimpleLegalEnity).CheckDebt}
WHERE Id = {item.ID}
" + "\n";
                number++;
            }
            try
            {
                SQLDataBase dataBase = new SQLDataBase();
                dataBase.sql_upgade(sql);
                MessageBox.Show("Готово", "Complite", MessageBoxButton.OK, MessageBoxImage.Asterisk);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            //VIP
            sql    = new string[Bank.vip_clients.Count];
            number = 0;
            foreach (var item in Bank.vip_clients)
            {
                if (item is VipNaturalClient)
                {
                    sql[number] = $@"
UPDATE AllVipNaturalClients SET [FirstName] = N'{(item as VipNaturalClient).FirstName}', [LastName] = N'{(item as VipNaturalClient).LastName}', 
[DateOfBirth] = '{Convert.ToDateTime(item.DateofBirth).ToString("yyyy-MM-dd")}', 
[Department] = N'{item.Department}', 
[AccountNumber] = {item.AccountNumber}, [AmountOfMoney] = {item.AmountOfMoney},
[CheckContribution] = {item.CheckContribution}, [CheckDebt] = {item.CheckDebt}
WHERE Id = {item.ID}
" + "\n";
                    number++;
                }
                else
                {
                    sql[number] = $@"
UPDATE AllVipLegalClients SET [Name] = N'{(item as VipLegalEnity).Name}', 
[DateOfBirth] = '{Convert.ToDateTime(item.DateofBirth).ToString("yyyy-MM-dd")}', 
[Department] = N'{item.Department}', 
[AccountNumber] = {item.AccountNumber}, [AmountOfMoney] = {item.AmountOfMoney},
[CheckContribution] = {item.CheckContribution}, [CheckDebt] = {item.CheckDebt}
WHERE Id = {item.ID}
" + "\n";
                    number++;
                }
            }
            try
            {
                SQLDataBase dataBase = new SQLDataBase();
                dataBase.sql_upgade(sql);
                MessageBox.Show("Готово", "Complite", MessageBoxButton.OK, MessageBoxImage.Asterisk);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Закрыть кредит
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            SQLDataBase dataBase = new SQLDataBase();

            if (TabItemNatural.IsSelected)
            {
                if (list_natural_clients.SelectedItem != null)
                {
                    var temp = list_natural_clients.SelectedItem as SimpleNaturalClient;
                    (list_natural_clients.SelectedItem as SimpleNaturalClient).Notify += SaveToLogCreditMessage;
                    (list_natural_clients.SelectedItem as SimpleNaturalClient).CloseCredit();
                    (list_natural_clients.SelectedItem as SimpleNaturalClient).Notify -= SaveToLogCreditMessage;
                    using (var cmd = new SqlCommand($@"UPDATE AllNaturalClients SET  [AmountOfMoney] = @AmountOfMoney, [CheckDebt] = @CheckDebt WHERE Id = {temp.ID}", dataBase.connection))
                    {
                        dataBase.connection.Open();
                        cmd.Parameters.Add("@AmountOfMoney", SqlDbType.Decimal).Value = temp.AmountOfMoney;
                        cmd.Parameters.Add("@CheckDebt", SqlDbType.Decimal).Value     = temp.CheckDebt;
                        cmd.ExecuteNonQuery();
                    }
                }
                else
                {
                    MessageBox.Show("Выберите клиента!", "WARNING", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
            if (TabItemLegal.IsSelected)
            {
                if (list_legal_clients.SelectedItem != null)
                {
                    var temp = list_legal_clients.SelectedItem as SimpleLegalEnity;
                    (list_legal_clients.SelectedItem as SimpleLegalEnity).Notify += SaveToLogCreditMessage;
                    (list_legal_clients.SelectedItem as SimpleLegalEnity).CloseCredit();
                    (list_legal_clients.SelectedItem as SimpleLegalEnity).Notify -= SaveToLogCreditMessage;
                    using (var cmd = new SqlCommand($@"UPDATE AllLegalClients SET  [AmountOfMoney] = @AmountOfMoney, [CheckDebt] = @CheckDebt WHERE Id = {temp.ID}", dataBase.connection))
                    {
                        dataBase.connection.Open();
                        cmd.Parameters.Add("@AmountOfMoney", SqlDbType.Decimal).Value = temp.AmountOfMoney;
                        cmd.Parameters.Add("@CheckDebt", SqlDbType.Decimal).Value     = temp.CheckDebt;
                        cmd.ExecuteNonQuery();
                    }
                }
                else
                {
                    MessageBox.Show("Выберите клиента!", "WARNING", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
            if (TabItemVip.IsSelected)
            {
                if (list_vip_legal_clients.SelectedItem != null)
                {
                    var temp = list_vip_legal_clients.SelectedItem as VipLegalEnity;
                    (list_vip_legal_clients.SelectedItem as VipClient).Notify += SaveToLogCreditMessage;
                    (list_vip_legal_clients.SelectedItem as VipClient).CloseCredit();
                    (list_vip_legal_clients.SelectedItem as VipClient).Notify -= SaveToLogCreditMessage;
                    using (var cmd = new SqlCommand($@"UPDATE AllVipLegalClients SET  [AmountOfMoney] = @AmountOfMoney, [CheckDebt] = @CheckDebt WHERE Id = {temp.ID}", dataBase.connection))
                    {
                        dataBase.connection.Open();
                        cmd.Parameters.Add("@AmountOfMoney", SqlDbType.Decimal).Value = temp.AmountOfMoney;
                        cmd.Parameters.Add("@CheckDebt", SqlDbType.Decimal).Value     = temp.CheckDebt;
                        cmd.ExecuteNonQuery();
                    }
                }

                else if (list_vip_Natural_clients.SelectedItem != null)
                {
                    var temp = list_vip_Natural_clients.SelectedItem as VipNaturalClient;
                    (list_vip_Natural_clients.SelectedItem as VipClient).Notify += SaveToLogCreditMessage;
                    (list_vip_Natural_clients.SelectedItem as VipClient).CloseCredit();
                    (list_vip_Natural_clients.SelectedItem as VipClient).Notify -= SaveToLogCreditMessage;
                    using (var cmd = new SqlCommand($@"UPDATE AllVipNaturalClients SET  [AmountOfMoney] = @AmountOfMoney, [CheckDebt] = @CheckDebt WHERE Id = {temp.ID}", dataBase.connection))
                    {
                        dataBase.connection.Open();
                        cmd.Parameters.Add("@AmountOfMoney", SqlDbType.Decimal).Value = temp.AmountOfMoney;
                        cmd.Parameters.Add("@CheckDebt", SqlDbType.Decimal).Value     = temp.CheckDebt;
                        cmd.ExecuteNonQuery();
                    }
                }
                else
                {
                    MessageBox.Show("Выбере клиента!", "WARNING", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
            // dataBase.sql_upgade(sql);
            Update();
        }
Beispiel #6
0
        /// <summary>
        /// Кнопка закрытия клада
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CloseContibution_Click(object sender, RoutedEventArgs e)
        {
            SQLDataBase dataBase = new SQLDataBase();

            if (TabItemNatural.IsSelected)
            {
                if (list_natural_clients.SelectedItem != null)
                {
                    var temp = list_natural_clients.SelectedItem as SimpleNaturalClient;
                    (list_natural_clients.SelectedItem as SimpleNaturalClient).Notify += SaveToLogContrubutionMessage;
                    (list_natural_clients.SelectedItem as SimpleNaturalClient).CloseContribution();
                    (list_natural_clients.SelectedItem as SimpleNaturalClient).Notify -= SaveToLogContrubutionMessage;
                    using (var cmd = new SqlCommand($@"UPDATE AllNaturalClients SET  [AmountOfMoney] = @AmountOfMoney, [CheckContribution] = @CheckContribution WHERE Id = {temp.ID}", dataBase.connection))
                    {
                        dataBase.connection.Open();
                        cmd.Parameters.Add("@AmountOfMoney", SqlDbType.Decimal).Value     = temp.AmountOfMoney;
                        cmd.Parameters.Add("@CheckContribution", SqlDbType.Decimal).Value = temp.CheckContribution;
                        cmd.ExecuteNonQuery();
                    }
                }
            }
            else if (TabItemLegal.IsSelected)
            {
                if (list_legal_clients.SelectedItem != null)
                {
                    var temp = list_legal_clients.SelectedItem as SimpleLegalEnity;
                    (list_legal_clients.SelectedItem as SimpleLegalEnity).Notify += SaveToLogContrubutionMessage;
                    (list_legal_clients.SelectedItem as SimpleLegalEnity).CloseContribution();
                    (list_legal_clients.SelectedItem as SimpleLegalEnity).Notify -= SaveToLogContrubutionMessage;
                    using (var cmd = new SqlCommand($@"UPDATE AllLegalClients SET  [AmountOfMoney] = @AmountOfMoney, [CheckContribution] = @CheckContribution WHERE Id = {temp.ID}", dataBase.connection))
                    {
                        dataBase.connection.Open();
                        cmd.Parameters.Add("@AmountOfMoney", SqlDbType.Decimal).Value     = temp.AmountOfMoney;
                        cmd.Parameters.Add("@CheckContribution", SqlDbType.Decimal).Value = temp.CheckContribution;
                        cmd.ExecuteNonQuery();
                    }
                }
            }
            else if (TabItemVip.IsSelected)
            {
                if (list_vip_legal_clients.SelectedItem != null)
                {
                    var temp = list_vip_legal_clients.SelectedItem as VipLegalEnity;
                    (list_vip_legal_clients.SelectedItem as VipLegalEnity).Notify += SaveToLogContrubutionMessage;
                    (list_vip_legal_clients.SelectedItem as VipLegalEnity).CloseContribution();
                    (list_vip_legal_clients.SelectedItem as VipLegalEnity).Notify -= SaveToLogContrubutionMessage;
                    using (var cmd = new SqlCommand($@"UPDATE AllVipLegalClients SET  [AmountOfMoney] = @AmountOfMoney, [CheckContribution] = @CheckContribution WHERE Id = {temp.ID}", dataBase.connection))
                    {
                        dataBase.connection.Open();
                        cmd.Parameters.Add("@AmountOfMoney", SqlDbType.Decimal).Value     = temp.AmountOfMoney;
                        cmd.Parameters.Add("@CheckContribution", SqlDbType.Decimal).Value = temp.CheckContribution;
                        cmd.ExecuteNonQuery();
                    }
                }

                else if (list_vip_Natural_clients.SelectedItem != null)
                {
                    var temp = list_vip_Natural_clients.SelectedItem as VipNaturalClient;
                    (list_vip_Natural_clients.SelectedItem as VipNaturalClient).Notify += SaveToLogContrubutionMessage;
                    (list_vip_Natural_clients.SelectedItem as VipNaturalClient).CloseContribution();
                    (list_vip_Natural_clients.SelectedItem as VipNaturalClient).Notify -= SaveToLogContrubutionMessage;
                    using (var cmd = new SqlCommand($@"UPDATE AllVipNaturalClients SET  [AmountOfMoney] = @AmountOfMoney, [CheckContribution] = @CheckContribution WHERE Id = {temp.ID}", dataBase.connection))
                    {
                        dataBase.connection.Open();
                        cmd.Parameters.Add("@AmountOfMoney", SqlDbType.Decimal).Value     = temp.AmountOfMoney;
                        cmd.Parameters.Add("@CheckContribution", SqlDbType.Decimal).Value = temp.CheckContribution;
                        cmd.ExecuteNonQuery();
                    }
                }
            }
            Update();
        }
Beispiel #7
0
        /// <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();
        }
Beispiel #8
0
        /// <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);
            }
        }
Beispiel #9
0
        /// <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");
        }