· 6 years ago · Oct 04, 2019, 12:54 PM
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using System.IO;
7
8namespace GenerateSQL
9{
10 class Program
11 {
12 static Random rnd = new Random();
13 static string GenerateName(ref List<string> names)
14 {
15 string name = "";
16 string[] firstnames = { "András", "László", "Ádám", "Béla", "József", "Sándor", "Anna", "Tamás", "Kata", "Andrea", "Dávid", "Dániel" };
17
18 string[] lastnames = { "Kovács", "Tóth", "Szabó", "Kiss", "Nagy", "Lakatos", "Molnár", "Vincze", "Papp", "Horváth", "Simon" };
19
20 do
21 {
22 name = "";
23 name += lastnames[rnd.Next(lastnames.Length)] + " " + firstnames[rnd.Next(firstnames.Length)];
24 }
25 while (names.Contains(name));
26 names.Add(name);
27 return name;
28 }
29 static string ToASCII(string accentedStr)
30 {
31
32 byte[] tempBytes;
33 tempBytes = System.Text.Encoding.GetEncoding("ISO-8859-8").GetBytes(accentedStr);
34 return System.Text.Encoding.UTF8.GetString(tempBytes);
35 }
36 static string GenerateEmail(string nev)
37 {
38
39 string first = ToASCII(nev.Split(' ')[0]);
40 string last = ToASCII(nev.Split(' ')[1]);
41 string[] mail = { "gmail.com", "freemail.hu", "hotmail.com", "uni-obuda.hu", "citromail.hu", "icloud.com", "outlook.com" };
42
43
44
45 return last + "." + first + "@" + mail[rnd.Next(mail.Length)];
46
47 }
48 static string GenerateCity()
49 {
50 string[] cities = { "Budapest", "Vác", "Dunakeszi", "Budaörs", "Gödöllő", "Gyál", "Budakeszi", "Budakalász", "Solymár", "Érd", "Mogyoród", "Szentendre", "Csömör", "Vecsés" };
51 return cities[rnd.Next(cities.Length)];
52 }
53 static string GenerateBirthDate()
54 {
55 return rnd.Next(1950, 2004).ToString() + "-" + rnd.Next(1, 13) + "-" + rnd.Next(1, 31);
56 }
57 static void GenerateINSERT()
58 {
59 List<string> names = new List<string>();
60 StreamWriter sw = new StreamWriter("insert.sql", true);
61 int i = 0;
62 while (names.Count < 50)
63 {
64
65 string nev = GenerateName(ref names);
66 string email = GenerateEmail(nev).ToLower();
67 string lakhely = GenerateCity();
68 string szuletes = GenerateBirthDate();
69 sw.WriteLine(String.Format("INSERT INTO Felhasznalok (id, nev, email, lakhely, szuletes) VALUES ({0}, {1}, {2}, {3}, TO_DATE({4}))", i++, nev, email, lakhely, szuletes));
70 }
71 sw.Close();
72 }
73
74 static void Main(string[] args)
75 {
76
77 GenerateINSERT();
78 }
79 }
80}