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

namespace WindowsApplication1
{
	/// <summary>
	/// Summary description for Form8.
	/// </summary>
	public class Form8 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.ComboBox comboBox1;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.DataGrid dataGrid1;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Panel panel2;
		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.TextBox textBox2;
		private System.Windows.Forms.TextBox textBox3;
		private System.Windows.Forms.TextBox textBox4;
		private System.Windows.Forms.TextBox textBox6;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.ComboBox comboBox2;
		private System.Windows.Forms.Button button3;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.Button button4;
        string s1,s2,s3;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.TextBox textBox5;
	
		public Form8()
		{
			//
			// 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(Form8));
			this.panel1 = new System.Windows.Forms.Panel();
			this.button3 = new System.Windows.Forms.Button();
			this.panel2 = new System.Windows.Forms.Panel();
			this.comboBox2 = new System.Windows.Forms.ComboBox();
			this.button2 = new System.Windows.Forms.Button();
			this.textBox6 = new System.Windows.Forms.TextBox();
			this.textBox4 = new System.Windows.Forms.TextBox();
			this.textBox3 = new System.Windows.Forms.TextBox();
			this.textBox2 = new System.Windows.Forms.TextBox();
			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.button1 = new System.Windows.Forms.Button();
			this.dataGrid1 = new System.Windows.Forms.DataGrid();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.comboBox1 = new System.Windows.Forms.ComboBox();
			this.label2 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.button4 = new System.Windows.Forms.Button();
			this.label8 = new System.Windows.Forms.Label();
			this.textBox5 = new System.Windows.Forms.TextBox();
			this.panel1.SuspendLayout();
			this.panel2.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
			this.SuspendLayout();
			// 
			// panel1
			// 
			this.panel1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("panel1.BackgroundImage")));
			this.panel1.Controls.Add(this.button3);
			this.panel1.Controls.Add(this.panel2);
			this.panel1.Controls.Add(this.button1);
			this.panel1.Controls.Add(this.dataGrid1);
			this.panel1.Controls.Add(this.textBox1);
			this.panel1.Controls.Add(this.comboBox1);
			this.panel1.Controls.Add(this.label2);
			this.panel1.Controls.Add(this.label1);
			this.panel1.Controls.Add(this.button4);
			this.panel1.Location = new System.Drawing.Point(0, 0);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(464, 360);
			this.panel1.TabIndex = 0;
			// 
			// button3
			// 
			this.button3.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.button3.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.button3.Location = new System.Drawing.Point(240, 168);
			this.button3.Name = "button3";
			this.button3.TabIndex = 8;
			this.button3.Text = "خروج";
			this.button3.Click += new System.EventHandler(this.button3_Click);
			// 
			// panel2
			// 
			this.panel2.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("panel2.BackgroundImage")));
			this.panel2.Controls.Add(this.textBox5);
			this.panel2.Controls.Add(this.label8);
			this.panel2.Controls.Add(this.comboBox2);
			this.panel2.Controls.Add(this.button2);
			this.panel2.Controls.Add(this.textBox6);
			this.panel2.Controls.Add(this.textBox4);
			this.panel2.Controls.Add(this.textBox3);
			this.panel2.Controls.Add(this.textBox2);
			this.panel2.Controls.Add(this.label7);
			this.panel2.Controls.Add(this.label6);
			this.panel2.Controls.Add(this.label5);
			this.panel2.Controls.Add(this.label4);
			this.panel2.Controls.Add(this.label3);
			this.panel2.Location = new System.Drawing.Point(8, 200);
			this.panel2.Name = "panel2";
			this.panel2.Size = new System.Drawing.Size(448, 144);
			this.panel2.TabIndex = 6;
			// 
			// comboBox2
			// 
			this.comboBox2.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.comboBox2.Items.AddRange(new object[] {
														   "مرد",
														   "زن"});
			this.comboBox2.Location = new System.Drawing.Point(8, 24);
			this.comboBox2.Name = "comboBox2";
			this.comboBox2.Size = new System.Drawing.Size(96, 21);
			this.comboBox2.TabIndex = 11;
			this.comboBox2.Text = "مرد";
			// 
			// button2
			// 
			this.button2.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.button2.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.button2.Location = new System.Drawing.Point(64, 120);
			this.button2.Name = "button2";
			this.button2.TabIndex = 10;
			this.button2.Text = "به روز رسانی";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// textBox6
			// 
			this.textBox6.Location = new System.Drawing.Point(8, 56);
			this.textBox6.Name = "textBox6";
			this.textBox6.Size = new System.Drawing.Size(96, 20);
			this.textBox6.TabIndex = 9;
			this.textBox6.Text = "";
			// 
			// textBox4
			// 
			this.textBox4.Location = new System.Drawing.Point(232, 88);
			this.textBox4.Name = "textBox4";
			this.textBox4.TabIndex = 7;
			this.textBox4.Text = "";
			// 
			// textBox3
			// 
			this.textBox3.Location = new System.Drawing.Point(232, 56);
			this.textBox3.Name = "textBox3";
			this.textBox3.TabIndex = 6;
			this.textBox3.Text = "";
			// 
			// textBox2
			// 
			this.textBox2.Location = new System.Drawing.Point(232, 24);
			this.textBox2.Name = "textBox2";
			this.textBox2.TabIndex = 5;
			this.textBox2.Text = "";
			this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged);
			this.textBox2.Leave += new System.EventHandler(this.textBox2_Leave);
			// 
			// label7
			// 
			this.label7.Font = new System.Drawing.Font("Tahoma", 13F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label7.Image = ((System.Drawing.Image)(resources.GetObject("label7.Image")));
			this.label7.Location = new System.Drawing.Point(120, 56);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(104, 23);
			this.label7.TabIndex = 4;
			this.label7.Text = "کد مشتری";
			this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label6
			// 
			this.label6.Font = new System.Drawing.Font("Tahoma", 13F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label6.Image = ((System.Drawing.Image)(resources.GetObject("label6.Image")));
			this.label6.Location = new System.Drawing.Point(120, 24);
			this.label6.Name = "label6";
			this.label6.TabIndex = 3;
			this.label6.Text = "نوع فروش";
			this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label5
			// 
			this.label5.Font = new System.Drawing.Font("Tahoma", 13F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label5.Image = ((System.Drawing.Image)(resources.GetObject("label5.Image")));
			this.label5.Location = new System.Drawing.Point(336, 88);
			this.label5.Name = "label5";
			this.label5.TabIndex = 2;
			this.label5.Text = "تاریخ فروش";
			this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label4
			// 
			this.label4.Font = new System.Drawing.Font("Tahoma", 13F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label4.Image = ((System.Drawing.Image)(resources.GetObject("label4.Image")));
			this.label4.Location = new System.Drawing.Point(336, 56);
			this.label4.Name = "label4";
			this.label4.TabIndex = 1;
			this.label4.Text = "تعداد کالا";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label3
			// 
			this.label3.Font = new System.Drawing.Font("Tahoma", 13F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label3.Image = ((System.Drawing.Image)(resources.GetObject("label3.Image")));
			this.label3.Location = new System.Drawing.Point(336, 24);
			this.label3.Name = "label3";
			this.label3.TabIndex = 0;
			this.label3.Text = "کد کالا";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// button1
			// 
			this.button1.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.button1.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.button1.Location = new System.Drawing.Point(128, 168);
			this.button1.Name = "button1";
			this.button1.TabIndex = 5;
			this.button1.Text = "حذف";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// dataGrid1
			// 
			this.dataGrid1.AlternatingBackColor = System.Drawing.Color.GhostWhite;
			this.dataGrid1.BackColor = System.Drawing.Color.GhostWhite;
			this.dataGrid1.BackgroundColor = System.Drawing.Color.Lavender;
			this.dataGrid1.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.dataGrid1.CaptionBackColor = System.Drawing.Color.RoyalBlue;
			this.dataGrid1.CaptionFont = new System.Drawing.Font("Microsoft Sans Serif", 8F);
			this.dataGrid1.CaptionForeColor = System.Drawing.Color.White;
			this.dataGrid1.DataMember = "";
			this.dataGrid1.FlatMode = true;
			this.dataGrid1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F);
			this.dataGrid1.ForeColor = System.Drawing.Color.MidnightBlue;
			this.dataGrid1.GridLineColor = System.Drawing.Color.RoyalBlue;
			this.dataGrid1.HeaderBackColor = System.Drawing.Color.MidnightBlue;
			this.dataGrid1.HeaderFont = new System.Drawing.Font("Microsoft Sans Serif", 8F);
			this.dataGrid1.HeaderForeColor = System.Drawing.Color.Lavender;
			this.dataGrid1.LinkColor = System.Drawing.Color.Teal;
			this.dataGrid1.Location = new System.Drawing.Point(8, 80);
			this.dataGrid1.Name = "dataGrid1";
			this.dataGrid1.ParentRowsBackColor = System.Drawing.Color.Lavender;
			this.dataGrid1.ParentRowsForeColor = System.Drawing.Color.MidnightBlue;
			this.dataGrid1.SelectionBackColor = System.Drawing.Color.Teal;
			this.dataGrid1.SelectionForeColor = System.Drawing.Color.PaleGreen;
			this.dataGrid1.Size = new System.Drawing.Size(448, 80);
			this.dataGrid1.TabIndex = 4;
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(64, 48);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(120, 20);
			this.textBox1.TabIndex = 3;
			this.textBox1.Text = "";
			this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
			// 
			// comboBox1
			// 
			this.comboBox1.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.comboBox1.Items.AddRange(new object[] {
														   "کد کالا",
														   "تعداد کالا",
														   "تاریخ فروش",
														   "نوع فروش",
														   "شماره مشتری"});
			this.comboBox1.Location = new System.Drawing.Point(64, 16);
			this.comboBox1.Name = "comboBox1";
			this.comboBox1.TabIndex = 2;
			this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
			// 
			// label2
			// 
			this.label2.Font = new System.Drawing.Font("Tahoma", 13F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label2.Image = ((System.Drawing.Image)(resources.GetObject("label2.Image")));
			this.label2.Location = new System.Drawing.Point(216, 48);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(152, 23);
			this.label2.TabIndex = 1;
			this.label2.Text = "با مقدار";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label1
			// 
			this.label1.Font = new System.Drawing.Font("Tahoma", 13F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label1.Image = ((System.Drawing.Image)(resources.GetObject("label1.Image")));
			this.label1.Location = new System.Drawing.Point(216, 16);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(152, 23);
			this.label1.TabIndex = 0;
			this.label1.Text = "جست وجو برحسب";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// button4
			// 
			this.button4.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.button4.Location = new System.Drawing.Point(376, 32);
			this.button4.Name = "button4";
			this.button4.TabIndex = 1;
			this.button4.Text = "جستجو";
			this.button4.Click += new System.EventHandler(this.button4_Click);
			// 
			// label8
			// 
			this.label8.Font = new System.Drawing.Font("Tahoma", 13F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label8.Image = ((System.Drawing.Image)(resources.GetObject("label8.Image")));
			this.label8.Location = new System.Drawing.Point(120, 88);
			this.label8.Name = "label8";
			this.label8.TabIndex = 12;
			this.label8.Text = "قیمت";
			this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// textBox5
			// 
			this.textBox5.Location = new System.Drawing.Point(8, 88);
			this.textBox5.Name = "textBox5";
			this.textBox5.ReadOnly = true;
			this.textBox5.TabIndex = 13;
			this.textBox5.Text = "";
			// 
			// Form8
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(464, 358);
			this.Controls.Add(this.panel1);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "Form8";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "جست وجو فروش";
			this.panel1.ResumeLayout(false);
			this.panel2.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

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

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

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

		private void button4_Click(object sender, System.EventArgs e)
		{
			
			SqlConnection con=new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=abzar;Data Source=MAHDI-59CA33515\\WINCC");
			if (comboBox1.SelectedIndex==0)
				s1="select * from sell where codekala='"+textBox1.Text+"'";
			if (comboBox1.SelectedIndex==1)
				s1="select * from sell where numberkala='"+textBox1.Text+"'";
			if (comboBox1.SelectedIndex==2)
				s1="select * from sell where datesell='"+textBox1.Text+"'";
			if (comboBox1.SelectedIndex==3)
				s1="select * from sell where typesell='"+textBox1.Text+"'";
			if (comboBox1.SelectedIndex==4)
				s1="select * from sell where customerid='"+textBox1.Text+"'";
			if (comboBox1.SelectedIndex==5)
				s1="select * from sell where allsum='"+textBox1.Text+"'";
			con.Open();
			SqlDataAdapter adp=new SqlDataAdapter(s1,con);
			DataSet dst=new DataSet();
			adp.Fill(dst,"a1");
			dataGrid1.DataSource=dst.Tables["a1"];
			con.Close();
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			SqlConnection con=new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=abzar;Data Source=MAHDI-59CA33515\\WINCC");
			if (comboBox1.SelectedIndex==0)
				s2="delete from sell where codekala='"+textBox1.Text+"'";
			if (comboBox1.SelectedIndex==1)
				s2="delete from sell where numberkala='"+textBox1.Text+"'";
			if (comboBox1.SelectedIndex==2)
				s2="delete from sell where datesell='"+textBox1.Text+"'";
			if (comboBox1.SelectedIndex==3)
				s2="delete from sell where typesell='"+textBox1.Text+"'";
			if (comboBox1.SelectedIndex==4)
				s2="delete from sell where customerid='"+textBox1.Text+"'";
			if (comboBox1.SelectedIndex==5)
				s2="delete from sell where allsum='"+textBox1.Text+"'";
			con.Open();
			SqlCommand com=new SqlCommand(s2,con);
			com.ExecuteNonQuery();
			con.Close();
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			SqlConnection con=new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=abzar;Data Source=MAHDI-59CA33515\\WINCC");
			if (comboBox1.SelectedIndex==0)
				s3="update sell set codekala=@a1,numberkala=@a2,datesell=@a3,typesell=@a4,customerid=@a5,allsum=@a6 where codekala='"+textBox1.Text+"'";
			if (comboBox1.SelectedIndex==1)
				s3="update sell set codekala=@a1,numberkala=@a2,datesell=@a3,typesell=@a4,customerid=@a5,allsum=@a6 where numberkala='"+textBox1.Text+"'";
			if (comboBox1.SelectedIndex==2)
				s3="update sell set codekala=@a1,numberkala=@a2,datesell=@a3,typesell=@a4,customerid=@a5,allsum=@a6 where datesell='"+textBox1.Text+"'";
			if (comboBox1.SelectedIndex==3)
				s3="update sell set codekala=@a1,numberkala=@a2,datesell=@a3,typesell=@a4,customerid=@a5,allsum=@a6 where typesell='"+textBox1.Text+"'";
			if (comboBox1.SelectedIndex==4)
				s3="update sell set codekala=@a1,numberkala=@a2,datesell=@a3,typesell=@a4,customerid=@a5,allsum=@a6 where customerid='"+textBox1.Text+"'";
			if (comboBox1.SelectedIndex==5)
				s3="update sell set codekala=@a1,numberkala=@a2,datesell=@a3,typesell=@a4,customerid=@a5,allsum=@a6 where allsum='"+textBox1.Text+"'";
			con.Open();
			SqlCommand com=new SqlCommand(s3,con);
			com.Parameters.Add("@a1",textBox2.Text);
			com.Parameters.Add("@a2",Convert.ToInt32(textBox3.Text));
			com.Parameters.Add("@a3",Convert.ToDateTime(textBox4.Text));
			com.Parameters.Add("@a4",Convert.ToString(comboBox1.SelectedItem));
			com.Parameters.Add("@a5",textBox6.Text);
			com.Parameters.Add("@a6",((Convert.ToInt32(textBox5.Text))*(Convert.ToInt32(textBox3.Text))));
			com.ExecuteNonQuery();
			con.Close();
		}

		private void textBox2_TextChanged(object sender, System.EventArgs e)
		{
			SqlConnection con=new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=abzar;Data Source=MAHDI-59CA33515\\WINCC");
			con.Open();
			SqlCommand com2=new SqlCommand("select * from kala where codekala='"+textBox2.Text+"'",con);
			SqlDataReader dr;
			dr=com2.ExecuteReader();
			if (dr.Read())
			{
				textBox5.Text=Convert.ToString(dr["pricesell"]);
			}
			else
			{
				textBox5.Text="0";
			}
			con.Close();
		}

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