friend.cs
资源名称:类似QQ聊天程序.rar [点击查看]
上传用户:yan_wy
上传日期:2007-06-09
资源大小:112k
文件大小:7k
源码类别:
ICQ/即时通讯
开发平台:
C#
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Data;
- namespace qq
- {
- /// <summary>
- /// friend 的摘要说明。
- /// </summary>
- public class friend : System.Windows.Forms.Form
- {
- Form1 form;
- private System.Windows.Forms.Button button1;
- private System.Windows.Forms.Button button2;
- private System.Windows.Forms.DataGrid dataGrid1;
- /// <summary>
- /// 必需的设计器变量。
- /// </summary>
- private System.ComponentModel.Container components = null;
- public friend(Form1 f)
- {
- //
- // Windows 窗体设计器支持所必需的
- //
- form=f;
- InitializeComponent();
- //
- // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
- //
- }
- /// <summary>
- /// 清理所有正在使用的资源。
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if(components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
- #region Windows 窗体设计器生成的代码
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器修改
- /// 此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- this.button1 = new System.Windows.Forms.Button();
- this.button2 = new System.Windows.Forms.Button();
- this.dataGrid1 = new System.Windows.Forms.DataGrid();
- ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
- this.SuspendLayout();
- //
- // button1
- //
- this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
- this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
- this.button1.Location = new System.Drawing.Point(128, 240);
- this.button1.Name = "button1";
- this.button1.Size = new System.Drawing.Size(72, 32);
- this.button1.TabIndex = 2;
- this.button1.Text = "加为好友";
- this.button1.Click += new System.EventHandler(this.button1_Click);
- //
- // button2
- //
- this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
- this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
- this.button2.Location = new System.Drawing.Point(24, 240);
- this.button2.Name = "button2";
- this.button2.Size = new System.Drawing.Size(72, 32);
- this.button2.TabIndex = 3;
- this.button2.Text = "取消";
- this.button2.Click += new System.EventHandler(this.button2_Click);
- //
- // dataGrid1
- //
- this.dataGrid1.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.dataGrid1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
- this.dataGrid1.CaptionBackColor = System.Drawing.SystemColors.ActiveBorder;
- this.dataGrid1.DataMember = "";
- this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
- this.dataGrid1.Location = new System.Drawing.Point(16, 32);
- this.dataGrid1.Name = "dataGrid1";
- this.dataGrid1.SelectionBackColor = System.Drawing.Color.Red;
- this.dataGrid1.SelectionForeColor = System.Drawing.Color.Black;
- this.dataGrid1.Size = new System.Drawing.Size(208, 184);
- this.dataGrid1.TabIndex = 4;
- this.dataGrid1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.dataGrid1_MouseDown);
- //
- // friend
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
- this.ClientSize = new System.Drawing.Size(240, 301);
- this.Controls.Add(this.dataGrid1);
- this.Controls.Add(this.button2);
- this.Controls.Add(this.button1);
- this.Name = "friend";
- this.Text = "friend";
- ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
- this.ResumeLayout(false);
- }
- #endregion
- public void startset(string a)
- {
- try
- {
- this.form.sdata.dataset.Tables.Clear();
- System.Data.SqlClient.SqlCommand sss=new System.Data.SqlClient.SqlCommand();
- if(a=="")
- sss.CommandText="SELECT id,name,sex,age from [user]";
- else
- sss.CommandText="SELECT id,name,sex,age from [user] where "+a;
- sss.Connection=this.form.sdata.sqlConnection1;
- this.form.sdata.sqlDataAdapter1.SelectCommand=sss;
- this.form.sdata.sqlDataAdapter1.Fill(this.form.sdata.dataset,"you");
- if(this.form.sdata.dataset.Tables["you"].Rows.Count!=0)
- {
- this.dataGrid1.SetDataBinding(this.form.sdata.dataset,"you");
- }
- }
- catch(Exception ee)
- {
- MessageBox.Show(ee.ToString());
- }
- }
- private void dataGrid1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
- {
- }
- private void button1_Click(object sender, System.EventArgs e)
- {
- int i=0;
- foreach(DataRow dt in this.form.sdata.dataset.Tables["you"].Rows)
- {
- if(i==this.dataGrid1.CurrentRowIndex)
- {
- try
- {
- int j=0;
- foreach(UserControl1 dt1 in form.userlist)
- {
- if(dt1.uid==dt[0].ToString())
- {
- MessageBox.Show("你已经加了这个用户");
- j=1;
- break;
- }
- }
- if(j==0)
- {
- System.Data.SqlClient.SqlCommand insert=new System.Data.SqlClient.SqlCommand();
- insert.CommandText = "INSERT INTO friends( uid, friendid) VALUES ("+form.userid+","+dt[0].ToString()+")";
- insert.Connection=this.form.sdata.sqlConnection1;
- this.form.sdata.sqlConnection1.Open();
- insert.ExecuteNonQuery();
- this.form.sdata.sqlConnection1.Close();
- System.Data.SqlClient.SqlCommand select=new System.Data.SqlClient.SqlCommand();
- select.CommandText= "SELECT [user].id,[user].name,[user].sex,[user].picture,[user].age,[user].jianjie,[user].state FROM [user] where id="+dt[0].ToString();
- select.Connection=this.form.sdata.sqlConnection1;
- this.form.sdata.sqlDataAdapter1.SelectCommand=select;
- this.form.sdata.dataset.Tables.Add("aa");
- this.form.sdata.sqlDataAdapter1.Fill(this.form.sdata.dataset,"aa");
- foreach(DataRow d in this.form.sdata.dataset.Tables["aa"].Rows)
- {
- UserControl1 userControl13=new UserControl1(form);
- userControl13.Dock=DockStyle.Top;
- userControl13.uid=d[0].ToString();
- userControl13.name=d[1].ToString();
- userControl13.sex=d[2].ToString();
- userControl13.picture=d[3].ToString();
- userControl13.age=d[4].ToString();
- userControl13.jianjie=d[5].ToString();
- userControl13.state=d[6].ToString();
- userControl13.setname(d[1].ToString());
- userControl13.setimage((d[3].ToString()).Trim());
- form.userlist.Add(userControl13);
- form.panel4.Controls.Add(userControl13);
- }
- this.form.sdata.dataset.Tables.Remove("aa");
- break;
- }
- }
- catch(Exception ee)
- {
- MessageBox.Show(ee.ToString());
- }
- }
- i++;
- }
- }
- private void button2_Click(object sender, System.EventArgs e)
- {
- this.Close();
- }
- }
- }