Advertisement
myname0

Generator

Apr 22nd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.68 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace db_fill
  8. {
  9.     class Program
  10.     {
  11.         static int PostId(ref Random rand)
  12.         {
  13.             return rand.Next(1, 3);
  14.         }
  15.  
  16.         static string GetGraph(ref Random rand)
  17.         {
  18.             return (rand.Next(1, 7)).ToString() + '/' + (rand.Next(1, 7)).ToString();
  19.         }
  20.  
  21.         static int GetDepart(ref Random rand)
  22.         {
  23.             return rand.Next(1, 11);
  24.         }
  25.  
  26.         static string BirthDate(ref Random rand)
  27.         {
  28.             string date;
  29.             date = String.Format("{0}-{1}-{2}", rand.Next(1940, 2016), rand.Next(1, 12), rand.Next(1, 28));
  30.             return date;
  31.         }
  32.  
  33.         static void Main(string[] args)
  34.         {
  35.             //using (StreamWriter sw = new StreamWriter("output.txt", false))
  36.             //{
  37.             //    sw.WriteLine("insert into Staff (postId, name, DOB, graph, deptId) values ");
  38.             //    using (StreamReader sr = new StreamReader("input.txt"))
  39.             //    {
  40.             //        for (int i = 0; i < 5000; i++)
  41.             //        {
  42.             //            Random rand = new Random();
  43.             //            string stringName = sr.ReadLine();
  44.             //            int postId = PostId(ref rand);
  45.             //            if (postId == 2)
  46.             //            {
  47.             //                sw.WriteLine("('{0}', '{1}', '{2}', '{3}', '{4}'),",
  48.             //                postId, stringName, BirthDate(ref rand), GetGraph(ref rand), GetDepart(ref rand));
  49.             //            }
  50.             //            else
  51.             //            {
  52.             //                sw.WriteLine("('{0}', '{1}', '{2}', '{3}', null),",
  53.             //                postId, stringName, BirthDate(ref rand), GetGraph(ref rand));
  54.             //            }
  55.             //            System.Threading.Thread.Sleep(50);
  56.             //        }
  57.             //    }
  58.  
  59.             //}
  60.             using (StreamWriter sw2 = new StreamWriter("output2.txt", false))
  61.             {
  62.                 Random rand = new Random();
  63.                 //sw2.WriteLine("insert into Products (productName, productCost) values ");
  64.                 //for (int i = 0; i < 5000; i++)
  65.                 //    sw2.WriteLine("( {0}, {1} ),", i, rand.Next(1, 10000));
  66.                 sw2.WriteLine("insert into Products (staffId, discountId, orderPrice, dateOrder) values");
  67.                 for (int i = 0; i < 2000; i++)
  68.                     sw2.WriteLine("( {0}, null, {1}, '{2}' ),", rand.Next(2, 4500), rand.Next(50, 15000), BirthDate(ref rand));
  69.             }
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement