Advertisement
Pavle_nis

slagalica-kviz-2

Dec 8th, 2016
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.43 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. using System.Data.SqlClient;
  12.  
  13. namespace Test_slagalica
  14. {
  15.     public partial class Form1 : Form
  16.     {
  17.         public Form1()
  18.         {
  19.             InitializeComponent();
  20.         }
  21.         string cs = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename= C:\Users\Pavle\Documents\Visual Studio 2015\Projects\Test slagalica\Test slagalica\Slagalica-DB.mdf;Integrated Security=True";
  22.         string queryString = "SELECT * FROM table1 WHERE LEN(Reci) >=10 AND LEN(Reci) <=12 ORDER BY NEWID()";
  23.         int i;
  24.         Random random = new Random();
  25.         string word;
  26.         string promesana_rec;
  27.         private void Form1_Load(object sender, EventArgs e)
  28.         {
  29.             Label[] label = new Label[] { label2, label3, label4, label5, label6, label7, label8, label9, label10, label11, label12, label13 };
  30.  
  31.             button1.Text = "Start";
  32.             textBox1.Text = "";
  33.             textBox2.Text = "";
  34.             textBox1.Enabled = false;
  35.  
  36.             using (SqlConnection connection = new SqlConnection(cs))
  37.             {
  38.                 SqlCommand mycommand = new SqlCommand(queryString, connection);
  39.                 try
  40.                 {
  41.                     connection.Open();
  42.                     string word = (string)mycommand.ExecuteScalar();
  43.                     promesana_rec = new string(word.OrderBy(r => random.Next()).ToArray());
  44.                 }
  45.                 catch (Exception ex)
  46.                 {
  47.                     MessageBox.Show(ex.Message);
  48.                 }
  49.             }
  50.         }
  51.         private void button1_Click(object sender, EventArgs e)
  52.         {
  53.             Label[] label = new Label[] { label2, label3, label4, label5, label6, label7, label8, label9, label10, label11, label12, label13 };
  54.  
  55.             timer1.Start();
  56.  
  57.                 if (!button1.Enabled)
  58.                     return;
  59.                 if (button1.Text == "Start")
  60.                 {
  61.                     i = 0;
  62.                     timer1.Enabled = true;
  63.                     button1.Text = "Stop";
  64.                     button1.Enabled = true;
  65.                 }
  66.                 else
  67.                 {
  68.                 label[i].Text = Convert.ToString(promesana_rec[i]);
  69.                 i = i + 1;
  70.                     if (i == 12)
  71.                     {
  72.                         textBox1.Enabled = true;
  73.                         button1.Enabled = false;
  74.                         button1.Text = "Start";
  75.                         timer1.Enabled = false;
  76.                         textBox1.Focus();
  77.                     }
  78.                 }
  79.             }
  80.         private void timer1_Tick(object sender, EventArgs e)
  81.         {
  82.             //char[] letters = "AБВГДЂЕЖЗИЈКЛЉМНЊОПРСТЋУФХЦЧЏШ".ToCharArray();
  83.             char[] letters = new char[30] { 'A', 'Б', 'В', 'Г', 'Д', 'Ђ', 'Е', 'Ж', 'З', 'И', 'Ј', 'К', 'Л', 'Љ', 'М', 'Н', 'Њ', 'О', 'П', 'Р', 'С', 'Т', 'Ћ', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Џ', 'Ш' };
  84.             Label[] label = new Label[] { label2, label3, label4, label5, label6, label7, label8, label9, label10, label11, label12, label13 };
  85.             string randomString = "";
  86.             randomString += letters[random.Next(0, 30)].ToString();
  87.         }
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement