using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.OleDb ;
namespace bank
{
	/// <summary>
	/// Summary description for Form2.
	/// </summary>
	public class Form2 : System.Windows.Forms.Form
	{
		OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data source=bank.mdb");
		private System.Windows.Forms.Panel panel1;
		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.Label label6;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.Label label10;
		private System.Windows.Forms.Label label11;
		private System.Windows.Forms.Panel panel2;
		private System.Windows.Forms.Label label12;
		private System.Windows.Forms.Button Bclose;
		private System.Windows.Forms.Button Button1;
		private System.Windows.Forms.Button Button4;
		private System.Windows.Forms.Button bsave;
		private System.Windows.Forms.Button Bnew;
		private System.Windows.Forms.Button button3;
		private System.Windows.Forms.TextBox t1;
		private System.Windows.Forms.TextBox t2;
		private System.Windows.Forms.TextBox t4;
		private System.Windows.Forms.TextBox t3;
		private System.Windows.Forms.TextBox t5;
		private System.Windows.Forms.TextBox t7;
		private System.Windows.Forms.TextBox t6;
		private System.Windows.Forms.TextBox t8;
		private System.Windows.Forms.TextBox txtpass;
		private System.Windows.Forms.TextBox txtuser;
		private System.Windows.Forms.TextBox textBox1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form2()
		{
			//
			// 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.panel1 = new System.Windows.Forms.Panel();
            this.label10 = new System.Windows.Forms.Label();
            this.label9 = new System.Windows.Forms.Label();
            this.label8 = new System.Windows.Forms.Label();
            this.label7 = new System.Windows.Forms.Label();
            this.label6 = new System.Windows.Forms.Label();
            this.label5 = new System.Windows.Forms.Label();
            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.txtuser = new System.Windows.Forms.TextBox();
            this.txtpass = new System.Windows.Forms.TextBox();
            this.t8 = new System.Windows.Forms.TextBox();
            this.t6 = new System.Windows.Forms.TextBox();
            this.t7 = new System.Windows.Forms.TextBox();
            this.t5 = new System.Windows.Forms.TextBox();
            this.t3 = new System.Windows.Forms.TextBox();
            this.t4 = new System.Windows.Forms.TextBox();
            this.t2 = new System.Windows.Forms.TextBox();
            this.t1 = new System.Windows.Forms.TextBox();
            this.label11 = new System.Windows.Forms.Label();
            this.panel2 = new System.Windows.Forms.Panel();
            this.label12 = new System.Windows.Forms.Label();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.Bclose = new System.Windows.Forms.Button();
            this.Button1 = new System.Windows.Forms.Button();
            this.Button4 = new System.Windows.Forms.Button();
            this.bsave = new System.Windows.Forms.Button();
            this.Bnew = new System.Windows.Forms.Button();
            this.button3 = new System.Windows.Forms.Button();
            this.panel1.SuspendLayout();
            this.panel2.SuspendLayout();
            this.SuspendLayout();
            // 
            // panel1
            // 
            this.panel1.BackColor = System.Drawing.Color.CadetBlue;
            this.panel1.Controls.Add(this.label10);
            this.panel1.Controls.Add(this.label9);
            this.panel1.Controls.Add(this.label8);
            this.panel1.Controls.Add(this.label7);
            this.panel1.Controls.Add(this.label6);
            this.panel1.Controls.Add(this.label5);
            this.panel1.Controls.Add(this.label4);
            this.panel1.Controls.Add(this.label3);
            this.panel1.Controls.Add(this.label2);
            this.panel1.Controls.Add(this.label1);
            this.panel1.Controls.Add(this.txtuser);
            this.panel1.Controls.Add(this.txtpass);
            this.panel1.Controls.Add(this.t8);
            this.panel1.Controls.Add(this.t6);
            this.panel1.Controls.Add(this.t7);
            this.panel1.Controls.Add(this.t5);
            this.panel1.Controls.Add(this.t3);
            this.panel1.Controls.Add(this.t4);
            this.panel1.Controls.Add(this.t2);
            this.panel1.Controls.Add(this.t1);
            this.panel1.Location = new System.Drawing.Point(48, 56);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(416, 272);
            this.panel1.TabIndex = 0;
            // 
            // label10
            // 
            this.label10.Location = new System.Drawing.Point(312, 232);
            this.label10.Name = "label10";
            this.label10.Size = new System.Drawing.Size(80, 23);
            this.label10.TabIndex = 19;
            this.label10.Text = " ";
            this.label10.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // label9
            // 
            this.label9.Location = new System.Drawing.Point(120, 232);
            this.label9.Name = "label9";
            this.label9.Size = new System.Drawing.Size(72, 23);
            this.label9.TabIndex = 18;
            this.label9.Text = " ";
            this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // label8
            // 
            this.label8.Location = new System.Drawing.Point(302, 192);
            this.label8.Name = "label8";
            this.label8.Size = new System.Drawing.Size(100, 23);
            this.label8.TabIndex = 17;
            this.label8.Text = " ";
            this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // label7
            // 
            this.label7.Location = new System.Drawing.Point(302, 152);
            this.label7.Name = "label7";
            this.label7.Size = new System.Drawing.Size(100, 23);
            this.label7.TabIndex = 16;
            this.label7.Text = "";
            this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // label6
            // 
            this.label6.Location = new System.Drawing.Point(120, 152);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(72, 23);
            this.label6.TabIndex = 15;
            this.label6.Text = "";
            this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // label5
            // 
            this.label5.Location = new System.Drawing.Point(302, 112);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(100, 23);
            this.label5.TabIndex = 14;
            this.label5.Text = "";
            this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // label4
            // 
            this.label4.Location = new System.Drawing.Point(302, 80);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(100, 23);
            this.label4.TabIndex = 13;
            this.label4.Text = "";
            this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // label3
            // 
            this.label3.Location = new System.Drawing.Point(120, 80);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(72, 23);
            this.label3.TabIndex = 12;
            this.label3.Text = "";
            this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // label2
            // 
            this.label2.Location = new System.Drawing.Point(302, 48);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(100, 23);
            this.label2.TabIndex = 11;
            this.label2.Text = "";
            this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(302, 16);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(100, 23);
            this.label1.TabIndex = 10;
            this.label1.Text = " ";
            this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // txtuser
            // 
            this.txtuser.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.txtuser.Location = new System.Drawing.Point(200, 232);
            this.txtuser.Name = "txtuser";
            this.txtuser.Size = new System.Drawing.Size(100, 26);
            this.txtuser.TabIndex = 9;
            // 
            // txtpass
            // 
            this.txtpass.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.txtpass.Location = new System.Drawing.Point(20, 232);
            this.txtpass.Name = "txtpass";
            this.txtpass.Size = new System.Drawing.Size(100, 26);
            this.txtpass.TabIndex = 8;
            // 
            // t8
            // 
            this.t8.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.t8.Location = new System.Drawing.Point(20, 192);
            this.t8.Name = "t8";
            this.t8.Size = new System.Drawing.Size(280, 26);
            this.t8.TabIndex = 7;
            // 
            // t6
            // 
            this.t6.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.t6.Location = new System.Drawing.Point(200, 152);
            this.t6.Name = "t6";
            this.t6.Size = new System.Drawing.Size(100, 26);
            this.t6.TabIndex = 6;
            this.t6.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.t6_KeyPress);
            // 
            // t7
            // 
            this.t7.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.t7.Location = new System.Drawing.Point(20, 152);
            this.t7.Name = "t7";
            this.t7.Size = new System.Drawing.Size(100, 26);
            this.t7.TabIndex = 5;
            this.t7.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.t7_KeyPress);
            // 
            // t5
            // 
            this.t5.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.t5.Location = new System.Drawing.Point(20, 112);
            this.t5.Name = "t5";
            this.t5.Size = new System.Drawing.Size(280, 26);
            this.t5.TabIndex = 4;
            // 
            // t3
            // 
            this.t3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.t3.Location = new System.Drawing.Point(200, 80);
            this.t3.Name = "t3";
            this.t3.Size = new System.Drawing.Size(100, 26);
            this.t3.TabIndex = 3;
            this.t3.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.t3_KeyPress);
            // 
            // t4
            // 
            this.t4.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.t4.Location = new System.Drawing.Point(20, 80);
            this.t4.Name = "t4";
            this.t4.Size = new System.Drawing.Size(100, 26);
            this.t4.TabIndex = 2;
            // 
            // t2
            // 
            this.t2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.t2.Location = new System.Drawing.Point(20, 48);
            this.t2.Name = "t2";
            this.t2.Size = new System.Drawing.Size(280, 26);
            this.t2.TabIndex = 1;
            // 
            // t1
            // 
            this.t1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.t1.Location = new System.Drawing.Point(200, 16);
            this.t1.Name = "t1";
            this.t1.Size = new System.Drawing.Size(100, 26);
            this.t1.TabIndex = 0;
            // 
            // label11
            // 
            this.label11.Font = new System.Drawing.Font("Arabic Transparent", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(178)));
            this.label11.ForeColor = System.Drawing.Color.White;
            this.label11.Location = new System.Drawing.Point(168, 24);
            this.label11.Name = "label11";
            this.label11.Size = new System.Drawing.Size(128, 23);
            this.label11.TabIndex = 11;
            this.label11.Text = "";
            this.label11.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // panel2
            // 
            this.panel2.BackColor = System.Drawing.Color.CadetBlue;
            this.panel2.Controls.Add(this.label12);
            this.panel2.Controls.Add(this.textBox1);
            this.panel2.Location = new System.Drawing.Point(48, 336);
            this.panel2.Name = "panel2";
            this.panel2.Size = new System.Drawing.Size(416, 48);
            this.panel2.TabIndex = 12;
            // 
            // label12
            // 
            this.label12.Location = new System.Drawing.Point(256, 8);
            this.label12.Name = "label12";
            this.label12.Size = new System.Drawing.Size(136, 23);
            this.label12.TabIndex = 19;
            this.label12.Text = " /  ";
            this.label12.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // textBox1
            // 
            this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.textBox1.Location = new System.Drawing.Point(16, 8);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(240, 26);
            this.textBox1.TabIndex = 18;
            this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
            // 
            // Bclose
            // 
            this.Bclose.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
            this.Bclose.Location = new System.Drawing.Point(76, 392);
            this.Bclose.Name = "Bclose";
            this.Bclose.Size = new System.Drawing.Size(57, 23);
            this.Bclose.TabIndex = 14;
            this.Bclose.Text = "";
            this.Bclose.UseVisualStyleBackColor = false;
            this.Bclose.Click += new System.EventHandler(this.Bclose_Click);
            // 
            // Button1
            // 
            this.Button1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
            this.Button1.Location = new System.Drawing.Point(190, 392);
            this.Button1.Name = "Button1";
            this.Button1.Size = new System.Drawing.Size(57, 23);
            this.Button1.TabIndex = 15;
            this.Button1.Text = "";
            this.Button1.UseVisualStyleBackColor = false;
            this.Button1.Click += new System.EventHandler(this.Button1_Click);
            // 
            // Button4
            // 
            this.Button4.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
            this.Button4.Location = new System.Drawing.Point(247, 392);
            this.Button4.Name = "Button4";
            this.Button4.Size = new System.Drawing.Size(57, 23);
            this.Button4.TabIndex = 16;
            this.Button4.Text = "";
            this.Button4.UseVisualStyleBackColor = false;
            this.Button4.Click += new System.EventHandler(this.Button4_Click);
            // 
            // bsave
            // 
            this.bsave.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
            this.bsave.Location = new System.Drawing.Point(304, 392);
            this.bsave.Name = "bsave";
            this.bsave.Size = new System.Drawing.Size(57, 23);
            this.bsave.TabIndex = 17;
            this.bsave.Text = "";
            this.bsave.UseVisualStyleBackColor = false;
            this.bsave.Click += new System.EventHandler(this.bsave_Click);
            // 
            // Bnew
            // 
            this.Bnew.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
            this.Bnew.Location = new System.Drawing.Point(361, 392);
            this.Bnew.Name = "Bnew";
            this.Bnew.Size = new System.Drawing.Size(57, 23);
            this.Bnew.TabIndex = 18;
            this.Bnew.Text = "";
            this.Bnew.UseVisualStyleBackColor = false;
            this.Bnew.Click += new System.EventHandler(this.Bnew_Click);
            // 
            // button3
            // 
            this.button3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
            this.button3.Location = new System.Drawing.Point(133, 392);
            this.button3.Name = "button3";
            this.button3.Size = new System.Drawing.Size(57, 23);
            this.button3.TabIndex = 19;
            this.button3.Text = "";
            this.button3.UseVisualStyleBackColor = false;
            this.button3.Click += new System.EventHandler(this.button3_Click);
            // 
            // Form2
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(7, 19);
            this.BackColor = System.Drawing.Color.Teal;
            this.ClientSize = new System.Drawing.Size(510, 428);
            this.ControlBox = false;
            this.Controls.Add(this.button3);
            this.Controls.Add(this.Bnew);
            this.Controls.Add(this.bsave);
            this.Controls.Add(this.Button4);
            this.Controls.Add(this.Button1);
            this.Controls.Add(this.Bclose);
            this.Controls.Add(this.panel2);
            this.Controls.Add(this.label11);
            this.Controls.Add(this.panel1);
            this.Font = new System.Drawing.Font("Arabic Transparent", 12F);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
            this.Name = "Form2";
            this.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "                                                        ";
            this.panel1.ResumeLayout(false);
            this.panel1.PerformLayout();
            this.panel2.ResumeLayout(false);
            this.panel2.PerformLayout();
            this.ResumeLayout(false);

		}
		#endregion

		private void bsave_Click(object sender, System.EventArgs e)
		{
			if (t3.Text.Trim() == "")
				t3.Text = "0";
			if (t6.Text.Trim() == "")
				t6.Text = "0";
			if (t7.Text.Trim() == "")
				t7.Text = "0";
			OleDbCommand cmd = new OleDbCommand("insert into Customers Values('" + Convert.ToInt32(t1.Text.Trim()) + "','" + t2.Text.Trim() + "' , '" + Convert.ToInt32(t3.Text.Trim()) + "','" + t4.Text.Trim() + "','" + t5.Text.Trim() + "','" + Convert.ToInt32(t6.Text.Trim()) + "','" + Convert.ToInt32(t7.Text.Trim()) + "','" + t8.Text.Trim() + "','" + txtuser.Text.Trim() + "','" + txtpass.Text.Trim() + "')", con);
			con.Open();
			cmd.ExecuteNonQuery();
			con.Close();
          
			bsave.Enabled = false;
		}

		private void Bnew_Click(object sender, System.EventArgs e)
		{
			cls();;
			OleDbCommand cmd = new OleDbCommand("select Max(Id) From customers", con);
			con.Open();

			OleDbDataReader  Dr= cmd.ExecuteReader();

			if (Dr.Read() == true)
			{
				if (Dr.GetValue(0).ToString() == "")
					t1.Text = "1";
				else
					t1.Text = Convert.ToString(Convert.ToInt32(Dr.GetValue(0).ToString())+1);

			}
			else
				t1.Text = "1";
        
			con.Close();
			Dr.Close();
			t2.Focus();
			bsave.Enabled = true ;
		}

		private void Bclose_Click(object sender, System.EventArgs e)
		{
			 this.Close();
		}

		private void button3_Click(object sender, System.EventArgs e)
		{
			cls();
			bsave.Enabled = false;
			t1.Focus();
		}

		private void Button1_Click(object sender, System.EventArgs e)
		{
			OleDbCommand cmd =new OleDbCommand("Delete  From Customers Where Id like'" +t1.Text.Trim() + "'", con);
			con.Open();
			cmd.ExecuteNonQuery();
			con.Close();

			OleDbCommand cmd2 = new OleDbCommand("Delete  From Accounts Where Id like'" + t1.Text.Trim()+ "'", con);
			con.Open();
			cmd2.ExecuteNonQuery();
			con.Close();
			cls();
		}
		private void cls()
		{
			t1.Text = "";
			t2.Text = "";
			t3.Text = "";
			t4.Text = "";
			t5.Text = "";
			t6.Text = "";
			t7.Text = "";
			t8.Text = "";
			txtuser.Text = "";
			txtpass.Text = "";
		}

		private void textBox1_TextChanged(object sender, System.EventArgs e)
		{
			bsave.Enabled = false;
			OleDbCommand cmd = new OleDbCommand("select * from customers where Name='" + textBox1.Text + "' or Ident like '"+textBox1.Text.Trim()+"'", con);

			con.Open();
			OleDbDataReader dr = cmd.ExecuteReader();
			if (dr.Read() == true)
			{
				t1.Text = dr.GetValue(0).ToString();
				t2.Text = dr.GetValue(1).ToString();
				t3.Text = dr.GetValue(2).ToString();
				t4.Text = dr.GetValue(3).ToString();
				t5.Text = dr.GetValue(4).ToString();
				t6.Text = dr.GetValue(5).ToString();
				t7.Text = dr.GetValue(6).ToString();
				t8.Text = dr.GetValue(7).ToString();
				txtuser.Text = dr.GetValue(8).ToString();
				txtpass.Text = dr.GetValue(9).ToString();

			}
			else
			{
				cls(); 
			}
			dr.Close();
			con.Close();
		}

		private void t3_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			if (!char.IsDigit(e.KeyChar))
			{
				e.Handled = true;
			}

			base.OnKeyPress(e);
		}

		private void t6_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			if (!char.IsDigit(e.KeyChar))
			{
				e.Handled = true;
			}

			base.OnKeyPress(e);
		}

		private void t7_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			if (!char.IsDigit(e.KeyChar))
			{
				e.Handled = true;
			}

			base.OnKeyPress(e);
		}

        private void Button4_Click(object sender, EventArgs e)
        {
           
        }
	}
}
