using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace KelimeEzber
{
	/// <summary>
	/// Summary description for Form_KelimeTekrar.
	/// </summary>
	public class Form_KelimeTekrar : System.Windows.Forms.Form
	{
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Label label_Ingilizce;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label_Turkce;
		private System.Windows.Forms.Label label_Okunusu;
		private System.Windows.Forms.Label label_Definition;
		private System.Windows.Forms.Label label_Example;
		private System.Windows.Forms.NumericUpDown numericUpDown2;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Timer timer1;
		private System.Windows.Forms.Label label_RecordID;
		private System.Windows.Forms.CheckBox checkBox_Sirali;
		private System.ComponentModel.IContainer components;

		private General.Sozluk mySozlukRecord = null;
		private string sAnaPencereTitle = "";
		private System.Windows.Forms.CheckBox checkBox_Sesli;
		private General.Mp3Play myMp3Play=null;
		private General.GenelAyarlar myAyarlar = null;
		public Form_KelimeTekrar()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form_KelimeTekrar));
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.checkBox_Sesli = new System.Windows.Forms.CheckBox();
			this.checkBox_Sirali = new System.Windows.Forms.CheckBox();
			this.label_RecordID = new System.Windows.Forms.Label();
			this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
			this.label6 = new System.Windows.Forms.Label();
			this.label_Example = new System.Windows.Forms.Label();
			this.label_Definition = new System.Windows.Forms.Label();
			this.label_Okunusu = new System.Windows.Forms.Label();
			this.label_Turkce = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.label_Ingilizce = new System.Windows.Forms.Label();
			this.timer1 = new System.Windows.Forms.Timer(this.components);
			this.groupBox1.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
			this.SuspendLayout();
			// 
			// groupBox1
			// 
			this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.groupBox1.Controls.Add(this.checkBox_Sesli);
			this.groupBox1.Controls.Add(this.checkBox_Sirali);
			this.groupBox1.Controls.Add(this.label_RecordID);
			this.groupBox1.Controls.Add(this.numericUpDown2);
			this.groupBox1.Controls.Add(this.label6);
			this.groupBox1.Controls.Add(this.label_Example);
			this.groupBox1.Controls.Add(this.label_Definition);
			this.groupBox1.Controls.Add(this.label_Okunusu);
			this.groupBox1.Controls.Add(this.label_Turkce);
			this.groupBox1.Controls.Add(this.label4);
			this.groupBox1.Controls.Add(this.label3);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Controls.Add(this.label_Ingilizce);
			this.groupBox1.Location = new System.Drawing.Point(7, 9);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(416, 368);
			this.groupBox1.TabIndex = 0;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Kelime";
			// 
			// checkBox_Sesli
			// 
			this.checkBox_Sesli.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
			this.checkBox_Sesli.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(162)));
			this.checkBox_Sesli.Location = new System.Drawing.Point(165, 336);
			this.checkBox_Sesli.Name = "checkBox_Sesli";
			this.checkBox_Sesli.Size = new System.Drawing.Size(59, 24);
			this.checkBox_Sesli.TabIndex = 17;
			this.checkBox_Sesli.Text = "Sesli";
			// 
			// checkBox_Sirali
			// 
			this.checkBox_Sirali.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.checkBox_Sirali.Location = new System.Drawing.Point(8, 335);
			this.checkBox_Sirali.Name = "checkBox_Sirali";
			this.checkBox_Sirali.TabIndex = 16;
			this.checkBox_Sirali.Text = "Sıralı Kelimeler";
			// 
			// label_RecordID
			// 
			this.label_RecordID.Location = new System.Drawing.Point(16, 175);
			this.label_RecordID.Name = "label_RecordID";
			this.label_RecordID.TabIndex = 15;
			this.label_RecordID.Text = "label_RecordID";
			this.label_RecordID.Visible = false;
			// 
			// numericUpDown2
			// 
			this.numericUpDown2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.numericUpDown2.Location = new System.Drawing.Point(345, 335);
			this.numericUpDown2.Maximum = new System.Decimal(new int[] {
																		   1000,
																		   0,
																		   0,
																		   0});
			this.numericUpDown2.Minimum = new System.Decimal(new int[] {
																		   1,
																		   0,
																		   0,
																		   0});
			this.numericUpDown2.Name = "numericUpDown2";
			this.numericUpDown2.Size = new System.Drawing.Size(53, 20);
			this.numericUpDown2.TabIndex = 13;
			this.numericUpDown2.Value = new System.Decimal(new int[] {
																		 1,
																		 0,
																		 0,
																		 0});
			this.numericUpDown2.ValueChanged += new System.EventHandler(this.numericUpDown2_ValueChanged);
			// 
			// label6
			// 
			this.label6.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.label6.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.label6.Location = new System.Drawing.Point(257, 335);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(80, 23);
			this.label6.TabIndex = 12;
			this.label6.Text = "Süre :";
			this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label_Example
			// 
			this.label_Example.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.label_Example.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(162)));
			this.label_Example.Location = new System.Drawing.Point(135, 151);
			this.label_Example.Name = "label_Example";
			this.label_Example.Size = new System.Drawing.Size(272, 177);
			this.label_Example.TabIndex = 8;
			this.label_Example.Text = "label_Example";
			// 
			// label_Definition
			// 
			this.label_Definition.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.label_Definition.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(162)));
			this.label_Definition.Location = new System.Drawing.Point(134, 127);
			this.label_Definition.Name = "label_Definition";
			this.label_Definition.Size = new System.Drawing.Size(272, 23);
			this.label_Definition.TabIndex = 7;
			this.label_Definition.Text = "label_Definition";
			this.label_Definition.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// label_Okunusu
			// 
			this.label_Okunusu.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.label_Okunusu.BackColor = System.Drawing.Color.Black;
			this.label_Okunusu.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(162)));
			this.label_Okunusu.ForeColor = System.Drawing.Color.Blue;
			this.label_Okunusu.Location = new System.Drawing.Point(144, 19);
			this.label_Okunusu.Name = "label_Okunusu";
			this.label_Okunusu.Size = new System.Drawing.Size(264, 23);
			this.label_Okunusu.TabIndex = 6;
			this.label_Okunusu.Text = "label_Okunusu";
			this.label_Okunusu.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// label_Turkce
			// 
			this.label_Turkce.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.label_Turkce.BackColor = System.Drawing.Color.Black;
			this.label_Turkce.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(162)));
			this.label_Turkce.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(128)), ((System.Byte)(128)));
			this.label_Turkce.Location = new System.Drawing.Point(8, 72);
			this.label_Turkce.Name = "label_Turkce";
			this.label_Turkce.Size = new System.Drawing.Size(400, 48);
			this.label_Turkce.TabIndex = 5;
			this.label_Turkce.Text = "label_Turkce";
			this.label_Turkce.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label4
			// 
			this.label4.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.label4.Location = new System.Drawing.Point(6, 151);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(120, 23);
			this.label4.TabIndex = 4;
			this.label4.Text = "Example :";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label3
			// 
			this.label3.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.label3.Location = new System.Drawing.Point(7, 127);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(120, 23);
			this.label3.TabIndex = 3;
			this.label3.Text = "Definition :";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label1
			// 
			this.label1.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.label1.Location = new System.Drawing.Point(36, 16);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(102, 23);
			this.label1.TabIndex = 2;
			this.label1.Text = "Türkçe Okunuşu :";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label_Ingilizce
			// 
			this.label_Ingilizce.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.label_Ingilizce.BackColor = System.Drawing.Color.Black;
			this.label_Ingilizce.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(162)));
			this.label_Ingilizce.ForeColor = System.Drawing.Color.Lime;
			this.label_Ingilizce.Location = new System.Drawing.Point(8, 42);
			this.label_Ingilizce.Name = "label_Ingilizce";
			this.label_Ingilizce.Size = new System.Drawing.Size(400, 32);
			this.label_Ingilizce.TabIndex = 0;
			this.label_Ingilizce.Text = "label_Ingilizce";
			this.label_Ingilizce.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// timer1
			// 
			this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
			// 
			// Form_KelimeTekrar
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(432, 389);
			this.Controls.Add(this.groupBox1);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "Form_KelimeTekrar";
			this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show;
			this.Text = "Kelime Tekrar";
			this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.Form_KelimeTekrar_KeyPress);
			this.Load += new System.EventHandler(this.Form_KelimeTekrar_Load);
			this.Closed += new System.EventHandler(this.Form_KelimeTekrar_Closed);
			this.groupBox1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void Form_KelimeTekrar_Load(object sender, System.EventArgs e)
		{
			sAnaPencereTitle = this.MdiParent.Text;
			myAyarlar = new KelimeEzber.General.GenelAyarlar();
			checkBox_Sirali.Visible=false;
			checkBox_Sirali.Checked = myAyarlar.bSiraliKelimeGoster;
			checkBox_Sirali.Visible=true;
			numericUpDown2.Visible=false;
			this.label_Ingilizce.Text = myAyarlar.sSonKelime;
			this.checkBox_Sesli.Checked = myAyarlar.bSes;
			if (Convert.ToDecimal(myAyarlar.iHiz) > 0)
				numericUpDown2.Value = Convert.ToDecimal(myAyarlar.iHiz);
			numericUpDown2.Visible=true;
			myMp3Play = new KelimeEzber.General.Mp3Play();
			this.timer1.Interval = Convert.ToInt32(100 * numericUpDown2.Value);
			this.timer1.Start();
			timer1_Tick(this.timer1,e);
		}

		private void numericUpDown1_Leave(object sender, System.EventArgs e)
		{
		}

		private bool RecordDisplay() 
		{
			if ((mySozlukRecord != null)) 
			{
				this.label_RecordID.Text = Convert.ToString(mySozlukRecord.RecordId);
				this.label_Ingilizce.Text = mySozlukRecord.English;
				this.label_Turkce.Text = mySozlukRecord.Turkce;
				this.label_Okunusu.Text = mySozlukRecord.Okunusu;
				this.label_Definition.Text = mySozlukRecord.Definition;
				this.label_Example.Text = mySozlukRecord.Example;
				this.MdiParent.Text = this.label_Ingilizce.Text + " = " + this.label_Turkce.Text;
				if (this.checkBox_Sesli.Checked)
					myMp3Play.sPlayWord = mySozlukRecord.English;
				return false;
			} 
			else 
			{
				this.label_RecordID.Text = 
				this.label_Ingilizce.Text = 
				this.label_Turkce.Text = 
				this.label_Okunusu.Text =
				this.label_Definition.Text = 
				this.label_Example.Text = "";
				return true;
			}
		}

		private void timer1_Tick(object sender, System.EventArgs e)
		{
			General.DataManager myDm = new KelimeEzber.General.DataManager();
			if (this.checkBox_Sirali.Checked == true) 
			{
				mySozlukRecord = new General.Sozluk();
				if (this.label_Ingilizce.Text.Length==0)
					mySozlukRecord = myDm.FirstRecord(mySozlukRecord);
				else 
				{
					mySozlukRecord.English = this.label_Ingilizce.Text;
					mySozlukRecord = myDm.NextRecord(mySozlukRecord);
				}
				if (RecordDisplay()) 
				{
					mySozlukRecord = myDm.FirstRecord(mySozlukRecord);
					RecordDisplay();
				}
			}
			else 
			{
				Random random = new Random();

				myDm.sQuery = "Select * from SOZLUK Order By English";
				myDm.sTableName = "SOZLUK";
				DataTable myTable = new DataTable();
				myTable = myDm.ExecuteQuery();
				int iRastgeleBirSayi = random.Next(0, myTable.Rows.Count); 
				DataRow myTableRow = myTable.Rows[iRastgeleBirSayi];
				mySozlukRecord = new General.Sozluk(myTableRow);
				RecordDisplay();
				myTable.Dispose();
			}
		}

		private void numericUpDown2_ValueChanged(object sender, System.EventArgs e)
		{
			if (numericUpDown2.Visible==true)
			{
				this.timer1.Stop();
				this.timer1.Interval = Convert.ToInt32(100 * numericUpDown2.Value);
				this.timer1.Start();
			}
		}

		private void Form_KelimeTekrar_Closed(object sender, System.EventArgs e)
		{
			this.MdiParent.Text = sAnaPencereTitle;
			myAyarlar.sSonKelime = this.label_Ingilizce.Text;
			myAyarlar.bSiraliKelimeGoster = checkBox_Sirali.Checked;
			myAyarlar.iHiz = Convert.ToInt32(numericUpDown2.Value);
			myAyarlar.bSes = this.checkBox_Sesli.Checked;
			myAyarlar.Dispose();
			myAyarlar = null;
		}

		private void Form_KelimeTekrar_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			if (e.KeyChar == 27) 
			{
				this.Close();
			}
		}

	}
}
