Search This Blog

Wednesday, December 15, 2010

codes for a Quizzer I Created

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using IqTest;

namespace IqTest
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
  
    public partial class MainWindow : Window
    {
        BusinessLogicLayer bl = new BusinessLogicLayer();
        string selectedText;
        DateTime ticks = DateTime.Now;
        public MainWindow()
        {
            InitializeComponent();

            textBlock1.Text = bl.ShowQuestions();
            submitButton.IsEnabled = false;
            radioButton1.Checked += submitButton_Check;
            radioButton2.Checked += submitButton_Check;
            System.Windows.Forms.Timer t = new System.Windows.Forms.Timer();
            t.Start();
            t.Interval = 1000;
            t.Tick += new EventHandler(t_Tick);
          
        }

        void t_Tick(object sender, EventArgs e)
        {
           ticks=ticks.AddSeconds(1);
           txtTime.Text = ticks.ToLongTimeString();
        }
      
      
        private void button2_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("Your Quiz Score is "+bl.correctAnswers.ToString(),"",MessageBoxButton.OK,MessageBoxImage.Information);
            Close();
        }

        private void submitButton_Click(object sender, RoutedEventArgs e)
        {
          
          
            if (radioButton1.IsChecked==true)
            {
                selectedText = "A";
            }
            else if (radioButton2.IsChecked == true)
            {
                selectedText = "B";
            }
            if (bl.ShowAnswers() == selectedText)
            {
                bl.Increment();
            }
            textBlock1.Text = bl.ShowQuestions();
          
          
        }
        void submitButton_Check(object sender, RoutedEventArgs e)
        {
            submitButton.IsEnabled = true;
        }
      
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IqTest;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Data.Linq;
using System.Windows;
using System.Xaml;

namespace IqTest
{
    class DataAccessLayer
    {
       
        public string GetQuestions()
        {
            IQTestDataContext dc = new IQTestDataContext();
            var value = dc.ExecuteQuery<string>(@"SELECT TOP 1 Questions FROM QUSETIONS ORDER BY NewID()");
            string question = value.FirstOrDefault<string>();
            return question;
        }
        public string GetAnswers()
        {
            IQTestDataContext dd = new IQTestDataContext();
            string answer = "";
            var value = dd.ExecuteQuery<string>(@"SELECT TOP 1 Answers FROM QUSETIONS");
            answer = value.FirstOrDefault<string>();
            return answer;
        }
       
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Linq;
using System.Data.SqlClient;
using IqTest;

namespace IqTest
{
    class BusinessLogicLayer
    {
        DataAccessLayer da = new DataAccessLayer();
         public int correctAnswers;
        public string ShowQuestions()
        {
            return da.GetQuestions();
        }
        public string ShowAnswers()
        {
            return da.GetAnswers();
        }
        public int Increment()
        {
            return correctAnswers++;
        }
        public int ComputeIQ(int correctAnswers)
        {
            return (correctAnswers / 15) * 200;
        }
        
    }
}
//The code has a database file which you can create yourself with columns: Id,Questions,Answers.
//include a linq to sql class and use the given datasets.