Pavle_nis

Slagalica-kviz

Dec 8th, 2016
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.81 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.         int i;
  22.         string[] slova = new string[12];
  23.         Random random = new Random();
  24.         private void Form1_Load(object sender, EventArgs e)
  25.         {
  26.             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";
  27.         string queryString = "SELECT * FROM table1 WHERE LEN(Reci) >=10 AND LEN(Reci) <=12 ORDER BY NEWID()";
  28.  
  29. using (SqlConnection connection = new SqlConnection(cs))
  30.             {
  31.                 SqlCommand mycommand = new SqlCommand(queryString, connection);
  32.                 try
  33.                 {
  34.                     connection.Open();
  35.                     string word = (string)mycommand.ExecuteScalar();
  36.                     string promesana_rec = new string(word.OrderBy(r => random.Next()).ToArray());
  37.                 }
  38.                 catch (Exception ex)
  39.                 {
  40.                     MessageBox.Show(ex.Message);
  41.                 }
  42.             }
  43.  
  44.             Label[] label = new Label[] { label2, label3, label4, label5, label6, label7, label8, label9, label10, label11, label12, label13 };
  45.             for (int i = 0; i < 12; i++)
  46.                 slova[i] = label[i].Text;
  47.            
  48.             button1.Text = "Start";
  49.             textBox1.Text = "";
  50.             textBox2.Text = "";
  51.             textBox1.Enabled = false;
  52.         }
  53.         private void button1_Click(object sender, EventArgs e)
  54.         {
  55.             Label[] label = new Label[] { label2, label3, label4, label5, label6, label7, label8, label9, label10, label11, label12, label13 };
  56.             for (int i = 0; i < 12; i++)
  57.                 slova[i] = label[i].Text;
  58.          
  59.            timer1.Start();
  60.  
  61.             int counter = 0;
  62.                 if (!button1.Enabled)
  63.                     return;
  64.                 if (button1.Text == "Start")
  65.                 {
  66.                     i = 0;
  67.                     timer1.Enabled = true;
  68.                     button1.Text = "Stop";
  69.                     button1.Enabled = true;
  70.                 }
  71.                 else
  72.                 {
  73.                 //label[i].Text = slova[i];
  74.                 //label[i].Text = Convert.ToString(word[i]);
  75.                 label1.Text = Convert.ToString(word[counter]);
  76.                 //i = i + 1;
  77.                 counter++;
  78.                     if (i == 12)
  79.                     {
  80.                         textBox1.Enabled = true;
  81.                         button1.Enabled = false;
  82.                         button1.Text = "Start";
  83.                         timer1.Enabled = false;
  84.                         textBox1.Focus();
  85.                     }
  86.                 }
  87.             }
  88.         private void timer1_Tick(object sender, EventArgs e)
  89.         {
  90.             //char[] letters = "AБВГДЂЕЖЗИЈКЛЉМНЊОПРСТЋУФХЦЧЏШ".ToCharArray();
  91.             char[] letters = new char[30] { 'A', 'Б', 'В', 'Г', 'Д', 'Ђ', 'Е', 'Ж', 'З', 'И', 'Ј', 'К', 'Л', 'Љ', 'М', 'Н', 'Њ', 'О', 'П', 'Р', 'С', 'Т', 'Ћ', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Џ', 'Ш' };
  92.             Label[] label = new Label[] { label2, label3, label4, label5, label6, label7, label8, label9, label10, label11, label12, label13 };
  93.             string randomString = "";
  94.             randomString += letters[random.Next(0, 30)].ToString();
  95.             label[i].Text = randomString;
  96.         }
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment