private void Button_Generate_Person_click(object sender, RoutedEventArgs e) { if (timesToGenerateUpDown.Value > 20 || timesToGenerateUpDown.Value <= 0) { MessageBox.Show("Введите корректное число генерации", "Ошибка"); } if (textBoxTableName.Text == "" && (bool)checkBoxInsert.IsChecked || textBoxTableName.Text == null && (bool)checkBoxInsert.IsChecked) { MessageBox.Show("Введите корректное имя таблицы", "Ошибка"); return; } for (int i = 0; i < timesToGenerateUpDown.Value; i++) { Person.Name person = GetterRandomPerson.getRandomPerson(); if (person == null) { MessageBox.Show("Проверьте подключение к интернету", "Ошибка"); return; } if ((bool)checkBoxInsert.IsChecked && (bool)checkBoxComma.IsChecked) { textBoxGenerate.Text += "INSERT INTO " + textBoxTableName.Text + " VALUES (" + toSqlFormat(person.last) + toSqlFormat(person.first) + ")\n"; } //else if ((bool)checkBoxInsert.IsChecked && !(bool)checkBoxComma.IsChecked) //{ // textBoxGenerate.Text += "INSERT INTO " + textBoxTableName.Text + " VALUES (" + toSqlFormat(person.lname, person.fname, person.patronymic) + toSqlFormat(person.login) + "'" + person.password + "'" + ")\n"; //} } }
public static void GenerateFull(int whoToGenerate, TextBox textBoxGenerate, bool isInsert, string tableName) { try { Person.Name person = GetterRandomPerson.getRandomPerson(); textBoxGenerate.Text = person.last + person.first; } catch (Exception) { MessageBox.Show("Проверьте подключение к интернету. Будет использована базовая генерация."); Random random = new Random(); string fullName = ""; string[] fullNames = GenerateFullName(whoToGenerate).ToArray(); for (int i = 0; i < fullNames.Length; i++) { fullName = ""; fullName = fullNames[random.Next(0, 7)]; fullName += fullNames[random.Next(8, 15)]; fullName += fullNames[random.Next(16, 23)]; // textBoxGenerate.Text = "\n" + fullName ; } if (tableName == null && isInsert || tableName == "" && isInsert) { return; } if (isInsert) { textBoxGenerate.Text += "INSERT INTO " + tableName + " VALUES (" + fullName + "' , '" + GenerateNumber() + "'" + " , " + "'" + GenerateAddress() + "'" + " , " + GenerateBirthDate() + " , " + random.Next(100000, 999999) + ")\n"; } else { textBoxGenerate.Text += fullName + "' , '" + GenerateAddress() + "'" + " , " + "'" + GenerateNumber() + "'" + " , " + GenerateBirthDate() + " , " + random.Next(100000, 999999) + ")\n"; } } }