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

namespace KelimeEzber
{
	/// <summary>
	/// Summary description for DataGiris.
	/// </summary>
	public class Form_DataGiris : System.Windows.Forms.Form
	{
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Button button_FirstRecord;
		private System.Windows.Forms.Button button_prev;
		private System.Windows.Forms.Button button_next;
		private System.Windows.Forms.Button button_last;
		private System.Windows.Forms.Button button_kaydet;
		private System.Windows.Forms.Button button_sil;
		private System.Windows.Forms.Button button_temizle;
		private System.Windows.Forms.TextBox textBox_RecordId;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		private General.DataManager myDm = null;
		private System.Windows.Forms.TextBox textBox_English;
		private System.Windows.Forms.RichTextBox TextBox_Examples;
		private System.Windows.Forms.TextBox textBox_Definition;
		private System.Windows.Forms.TextBox textBox_Okunusu;
		private System.Windows.Forms.TextBox textBox_Turkce;
		private System.Windows.Forms.Button button_HizliGiris;
		private General.Sozluk mySozlukRecord = null;

		public Form_DataGiris()
		{
			//
			// 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()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form_DataGiris));
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.textBox_English = new System.Windows.Forms.TextBox();
			this.label5 = new System.Windows.Forms.Label();
			this.TextBox_Examples = new System.Windows.Forms.RichTextBox();
			this.textBox_Definition = new System.Windows.Forms.TextBox();
			this.textBox_Okunusu = new System.Windows.Forms.TextBox();
			this.textBox_Turkce = new System.Windows.Forms.TextBox();
			this.label4 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.textBox_RecordId = new System.Windows.Forms.TextBox();
			this.button_FirstRecord = new System.Windows.Forms.Button();
			this.button_prev = new System.Windows.Forms.Button();
			this.button_next = new System.Windows.Forms.Button();
			this.button_last = new System.Windows.Forms.Button();
			this.button_kaydet = new System.Windows.Forms.Button();
			this.button_sil = new System.Windows.Forms.Button();
			this.button_temizle = new System.Windows.Forms.Button();
			this.button_HizliGiris = new System.Windows.Forms.Button();
			this.groupBox1.SuspendLayout();
			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.textBox_English);
			this.groupBox1.Controls.Add(this.label5);
			this.groupBox1.Controls.Add(this.TextBox_Examples);
			this.groupBox1.Controls.Add(this.textBox_Definition);
			this.groupBox1.Controls.Add(this.textBox_Okunusu);
			this.groupBox1.Controls.Add(this.textBox_Turkce);
			this.groupBox1.Controls.Add(this.label4);
			this.groupBox1.Controls.Add(this.label3);
			this.groupBox1.Controls.Add(this.label2);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Location = new System.Drawing.Point(0, 0);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(728, 216);
			this.groupBox1.TabIndex = 0;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Kelime (Word)";
			// 
			// textBox_English
			// 
			this.textBox_English.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.textBox_English.Location = new System.Drawing.Point(168, 24);
			this.textBox_English.Name = "textBox_English";
			this.textBox_English.Size = new System.Drawing.Size(336, 20);
			this.textBox_English.TabIndex = 1;
			this.textBox_English.Text = "textBox_English";
			// 
			// label5
			// 
			this.label5.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.label5.Location = new System.Drawing.Point(13, 24);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(152, 23);
			this.label5.TabIndex = 9;
			this.label5.Text = "İngilizce Kelime :";
			this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// TextBox_Examples
			// 
			this.TextBox_Examples.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.TextBox_Examples.Location = new System.Drawing.Point(168, 136);
			this.TextBox_Examples.Name = "TextBox_Examples";
			this.TextBox_Examples.Size = new System.Drawing.Size(552, 72);
			this.TextBox_Examples.TabIndex = 5;
			this.TextBox_Examples.Text = "TextBox_Examples";
			// 
			// textBox_Definition
			// 
			this.textBox_Definition.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.textBox_Definition.Location = new System.Drawing.Point(168, 108);
			this.textBox_Definition.Name = "textBox_Definition";
			this.textBox_Definition.Size = new System.Drawing.Size(336, 20);
			this.textBox_Definition.TabIndex = 4;
			this.textBox_Definition.Text = "textBox_Definition";
			// 
			// textBox_Okunusu
			// 
			this.textBox_Okunusu.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.textBox_Okunusu.Location = new System.Drawing.Point(168, 80);
			this.textBox_Okunusu.Name = "textBox_Okunusu";
			this.textBox_Okunusu.Size = new System.Drawing.Size(336, 20);
			this.textBox_Okunusu.TabIndex = 3;
			this.textBox_Okunusu.Text = "textBox_Okunusu";
			// 
			// textBox_Turkce
			// 
			this.textBox_Turkce.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.textBox_Turkce.Location = new System.Drawing.Point(168, 52);
			this.textBox_Turkce.Name = "textBox_Turkce";
			this.textBox_Turkce.Size = new System.Drawing.Size(336, 20);
			this.textBox_Turkce.TabIndex = 2;
			this.textBox_Turkce.Text = "textBox_Turkce";
			// 
			// label4
			// 
			this.label4.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.label4.Location = new System.Drawing.Point(13, 136);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(152, 23);
			this.label4.TabIndex = 4;
			this.label4.Text = "Examples :";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label3
			// 
			this.label3.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.label3.Location = new System.Drawing.Point(13, 108);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(152, 23);
			this.label3.TabIndex = 3;
			this.label3.Text = "Definition :";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label2
			// 
			this.label2.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.label2.Location = new System.Drawing.Point(13, 80);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(152, 23);
			this.label2.TabIndex = 2;
			this.label2.Text = "Türkçe Okunus :";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label1
			// 
			this.label1.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.label1.Location = new System.Drawing.Point(13, 52);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(152, 23);
			this.label1.TabIndex = 1;
			this.label1.Text = "Türkçe Karşılık :";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// textBox_RecordId
			// 
			this.textBox_RecordId.Location = new System.Drawing.Point(0, 0);
			this.textBox_RecordId.Name = "textBox_RecordId";
			this.textBox_RecordId.TabIndex = 0;
			this.textBox_RecordId.Text = "";
			// 
			// button_FirstRecord
			// 
			this.button_FirstRecord.AccessibleDescription = "İlk Kayıt";
			this.button_FirstRecord.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.button_FirstRecord.Location = new System.Drawing.Point(7, 224);
			this.button_FirstRecord.Name = "button_FirstRecord";
			this.button_FirstRecord.Size = new System.Drawing.Size(57, 23);
			this.button_FirstRecord.TabIndex = 9;
			this.button_FirstRecord.Text = "<<";
			this.button_FirstRecord.Click += new System.EventHandler(this.button_FirstRecord_Click);
			// 
			// button_prev
			// 
			this.button_prev.AccessibleDescription = "Önceki Kayıt";
			this.button_prev.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.button_prev.Location = new System.Drawing.Point(67, 224);
			this.button_prev.Name = "button_prev";
			this.button_prev.Size = new System.Drawing.Size(57, 23);
			this.button_prev.TabIndex = 10;
			this.button_prev.Text = "<";
			this.button_prev.Click += new System.EventHandler(this.button_prev_Click);
			// 
			// button_next
			// 
			this.button_next.AccessibleDescription = "Sonraki Kayıt";
			this.button_next.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.button_next.Location = new System.Drawing.Point(127, 224);
			this.button_next.Name = "button_next";
			this.button_next.Size = new System.Drawing.Size(57, 23);
			this.button_next.TabIndex = 11;
			this.button_next.Text = ">";
			this.button_next.Click += new System.EventHandler(this.button_next_Click);
			// 
			// button_last
			// 
			this.button_last.AccessibleDescription = "Son Kayıt";
			this.button_last.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.button_last.Location = new System.Drawing.Point(189, 224);
			this.button_last.Name = "button_last";
			this.button_last.Size = new System.Drawing.Size(57, 23);
			this.button_last.TabIndex = 12;
			this.button_last.Text = ">>";
			this.button_last.Click += new System.EventHandler(this.button_last_Click);
			// 
			// button_kaydet
			// 
			this.button_kaydet.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.button_kaydet.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(162)));
			this.button_kaydet.Location = new System.Drawing.Point(440, 224);
			this.button_kaydet.Name = "button_kaydet";
			this.button_kaydet.TabIndex = 6;
			this.button_kaydet.Text = "&Kaydet";
			this.button_kaydet.Click += new System.EventHandler(this.button_kaydet_Click);
			// 
			// button_sil
			// 
			this.button_sil.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.button_sil.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(162)));
			this.button_sil.Location = new System.Drawing.Point(632, 224);
			this.button_sil.Name = "button_sil";
			this.button_sil.TabIndex = 8;
			this.button_sil.Text = "&Sil";
			this.button_sil.Click += new System.EventHandler(this.button_sil_Click);
			// 
			// button_temizle
			// 
			this.button_temizle.AccessibleDescription = "Bilgileri Temizle";
			this.button_temizle.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.button_temizle.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(162)));
			this.button_temizle.Location = new System.Drawing.Point(519, 224);
			this.button_temizle.Name = "button_temizle";
			this.button_temizle.TabIndex = 7;
			this.button_temizle.Text = "&Temizle";
			this.button_temizle.Click += new System.EventHandler(this.button_temizle_Click);
			// 
			// button_HizliGiris
			// 
			this.button_HizliGiris.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.button_HizliGiris.Enabled = false;
			this.button_HizliGiris.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(162)));
			this.button_HizliGiris.Location = new System.Drawing.Point(272, 224);
			this.button_HizliGiris.Name = "button_HizliGiris";
			this.button_HizliGiris.Size = new System.Drawing.Size(128, 24);
			this.button_HizliGiris.TabIndex = 13;
			this.button_HizliGiris.Text = "&Hızlı Giriş";
			this.button_HizliGiris.Click += new System.EventHandler(this.button_HizliGiris_Click);
			// 
			// Form_DataGiris
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(728, 253);
			this.Controls.Add(this.button_HizliGiris);
			this.Controls.Add(this.button_temizle);
			this.Controls.Add(this.button_sil);
			this.Controls.Add(this.button_kaydet);
			this.Controls.Add(this.button_last);
			this.Controls.Add(this.button_next);
			this.Controls.Add(this.button_prev);
			this.Controls.Add(this.button_FirstRecord);
			this.Controls.Add(this.groupBox1);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.KeyPreview = true;
			this.Name = "Form_DataGiris";
			this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show;
			this.Text = "Data Giriş";
			this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.DataGiris_KeyPress);
			this.Load += new System.EventHandler(this.Form_DataGiris_Load);
			this.Closed += new System.EventHandler(this.Form_DataGiris_Closed);
			this.Activated += new System.EventHandler(this.Form_DataGiris_Activated);
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

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

		private void button_temizle_Click(object sender, System.EventArgs e)
		{
			string str;
			foreach(Control ctrl in this.groupBox1.Controls)
			{
				str = Convert.ToString(ctrl.GetType());
				if ((str == "System.Windows.Forms.TextBox") || (str == "System.Windows.Forms.RichTextBox"))
				{
					ctrl.Text = "";
				}
			}
		}

		private void RecordDisplay() 
		{
			if ((mySozlukRecord != null)) 
			{
				this.textBox_RecordId.Text = Convert.ToString(mySozlukRecord.RecordId);
				this.textBox_English.Text = mySozlukRecord.English;
				this.textBox_Turkce.Text = mySozlukRecord.Turkce;
				this.textBox_Okunusu.Text = mySozlukRecord.Okunusu;
				this.textBox_Definition.Text = mySozlukRecord.Definition;
				this.TextBox_Examples.Text = mySozlukRecord.Example;
				this.button_HizliGiris.Enabled=true;
			} 
			else {
				this.button_HizliGiris.Enabled=false;
				this.textBox_RecordId.Text = 
				this.textBox_English.Text = 
				this.textBox_Turkce.Text = 
				this.textBox_Okunusu.Text =
				this.textBox_Definition.Text = 
				this.TextBox_Examples.Text = "";
			}
		}

		private void button_FirstRecord_Click(object sender, System.EventArgs e)
		{
			mySozlukRecord = new General.Sozluk();
			mySozlukRecord = myDm.FirstRecord(mySozlukRecord);
			RecordDisplay();
			mySozlukRecord = null;
		}

		private void button_prev_Click(object sender, System.EventArgs e)
		{
			if (this.textBox_RecordId.Text.Length > 0 ) 
			{
				mySozlukRecord = new General.Sozluk();
				mySozlukRecord.RecordId = Convert.ToInt32(this.textBox_RecordId.Text);
				mySozlukRecord.English = this.textBox_English.Text;
				mySozlukRecord = myDm.PrevRecord(mySozlukRecord);
				if ((mySozlukRecord != null))
					RecordDisplay();
				mySozlukRecord = null;
			}
		}

		private void button_next_Click(object sender, System.EventArgs e)
		{
			if (this.textBox_RecordId.Text.Length > 0 ) 
			{
				mySozlukRecord = new General.Sozluk();
				mySozlukRecord.RecordId = Convert.ToInt32(this.textBox_RecordId.Text);
				mySozlukRecord.English = this.textBox_English.Text;
				mySozlukRecord = myDm.NextRecord(mySozlukRecord);
				if ((mySozlukRecord != null))
					RecordDisplay();
				mySozlukRecord = null;
			}
		}

		private void button_last_Click(object sender, System.EventArgs e)
		{
			mySozlukRecord = myDm.LastRecord(mySozlukRecord);
			RecordDisplay();
			mySozlukRecord = null;
		}

		private void button_kaydet_Click(object sender, System.EventArgs e)
		{
			mySozlukRecord = new General.Sozluk();
			mySozlukRecord.English = this.textBox_English.Text;
			mySozlukRecord.Turkce = this.textBox_Turkce.Text;
			mySozlukRecord.Okunusu = this.textBox_Okunusu.Text;
			mySozlukRecord.Definition = this.textBox_Definition.Text;
			mySozlukRecord.Example = this.TextBox_Examples.Text;
			myDm.Kaydet(mySozlukRecord);
			mySozlukRecord = null;
		}

		private void button_sil_Click(object sender, System.EventArgs e)
		{
			if (this.textBox_RecordId.Text == "") 
			{
				return;
			}
			DialogResult dr = MessageBox.Show("Kaydı Silmek İstediğinizden emin misiniz?","Çıkış",
				MessageBoxButtons.YesNoCancel,MessageBoxIcon.Information);
			//DialogResult dr = MessageBox.Show("Su tamare" + 
			//    " aa program bandh karvo chhe..?","Conformation",
			//    MessageBoxButtons.YesNo,MessageBoxIcon.Stop);
			if(Convert.ToString(dr)!="Yes")
			{
				return;
			}

			mySozlukRecord = new General.Sozluk();
			mySozlukRecord.RecordId = Convert.ToInt32(this.textBox_RecordId.Text);
			myDm.Sil(mySozlukRecord);
			RecordDisplay();
		}

		private void button_HizliGiris_Click(object sender, System.EventArgs e)
		{
			Form_HizliDataGiris yeniWindow = new Form_HizliDataGiris();
			yeniWindow.MdiParent = this.MdiParent;
			yeniWindow.Show();
		}

		private void Form_DataGiris_Load(object sender, System.EventArgs e)
		{
			myDm = new General.DataManager();			
			this.button_temizle.PerformClick(); //On _Click(button_temizle,e);
		}

		private void Form_DataGiris_Closed(object sender, System.EventArgs e)
		{
			myDm.Dispose();
			myDm = null;
		}

		private void Form_DataGiris_Activated(object sender, System.EventArgs e)
		{
			if (this.textBox_RecordId.Text=="") this.button_FirstRecord.PerformClick(); //_Click(this.button_FirstRecord,e);
		}
	}
}
