Пример #1
0
 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";
         //}
     }
 }
Пример #2
0
        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";
                }
            }
        }
Пример #3
0
        public static Person.Name getRandomPerson()
        {
            string url = "https://randomuser.me/api/";

            try {
                HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);

                HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();

                string response;

                using (StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream())) {
                    response = streamReader.ReadToEnd();
                }

                Person      person = JsonConvert.DeserializeObject <Person>(response);
                Person.Name name   = JsonConvert.DeserializeObject <Person.Name>(person);
                return(name);
            } catch (Exception) {
                return(null);
            }
        }