⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addfriend.cs

📁 问题定义 随着生活水平的日益提高
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 通讯录
{
	/// <summary>
	/// 添加新通讯录信息
	/// </summary>
	public class addfriend : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		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.PictureBox pictureBox1;
		private System.Windows.Forms.TextBox txtname;
		private System.Windows.Forms.TextBox txtimages;
		private System.Windows.Forms.TextBox txtmobilephone;
		private System.Windows.Forms.TextBox txtqq;
		private System.Windows.Forms.TextBox txtnowaddress;
		private System.Windows.Forms.TextBox txtfamilyaddress;
		private System.Windows.Forms.TextBox txtothers;
		private System.Windows.Forms.Button btnok;
		private System.Windows.Forms.Button btnexit;
		private System.Windows.Forms.TextBox txtemail;
		private System.Windows.Forms.Label label56;
		private System.Windows.Forms.TextBox txttelephone;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public addfriend()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			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()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(addfriend));
			this.label1 = new System.Windows.Forms.Label();
			this.label56 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.label6 = new System.Windows.Forms.Label();
			this.label7 = new System.Windows.Forms.Label();
			this.label8 = new System.Windows.Forms.Label();
			this.label9 = new System.Windows.Forms.Label();
			this.pictureBox1 = new System.Windows.Forms.PictureBox();
			this.txtname = new System.Windows.Forms.TextBox();
			this.txttelephone = new System.Windows.Forms.TextBox();
			this.txtimages = new System.Windows.Forms.TextBox();
			this.txtmobilephone = new System.Windows.Forms.TextBox();
			this.txtqq = new System.Windows.Forms.TextBox();
			this.txtemail = new System.Windows.Forms.TextBox();
			this.txtnowaddress = new System.Windows.Forms.TextBox();
			this.txtfamilyaddress = new System.Windows.Forms.TextBox();
			this.txtothers = new System.Windows.Forms.TextBox();
			this.btnok = new System.Windows.Forms.Button();
			this.btnexit = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label1.Location = new System.Drawing.Point(16, 16);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(64, 23);
			this.label1.TabIndex = 0;
			this.label1.Text = "姓名:";
			// 
			// label56
			// 
			this.label56.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label56.Location = new System.Drawing.Point(272, 16);
			this.label56.Name = "label56";
			this.label56.TabIndex = 1;
			this.label56.Text = "固定电话:";
			// 
			// label3
			// 
			this.label3.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label3.Location = new System.Drawing.Point(272, 64);
			this.label3.Name = "label3";
			this.label3.TabIndex = 2;
			this.label3.Text = "手机:";
			// 
			// label4
			// 
			this.label4.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label4.Location = new System.Drawing.Point(272, 112);
			this.label4.Name = "label4";
			this.label4.TabIndex = 3;
			this.label4.Text = "QQ:";
			// 
			// label5
			// 
			this.label5.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label5.Location = new System.Drawing.Point(272, 160);
			this.label5.Name = "label5";
			this.label5.TabIndex = 4;
			this.label5.Text = "email:";
			// 
			// label6
			// 
			this.label6.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label6.Location = new System.Drawing.Point(16, 56);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(64, 23);
			this.label6.TabIndex = 5;
			this.label6.Text = "照片:";
			// 
			// label7
			// 
			this.label7.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label7.Location = new System.Drawing.Point(16, 200);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(64, 23);
			this.label7.TabIndex = 6;
			this.label7.Text = "现居地:";
			// 
			// label8
			// 
			this.label8.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label8.Location = new System.Drawing.Point(16, 232);
			this.label8.Name = "label8";
			this.label8.TabIndex = 7;
			this.label8.Text = "家庭住址:";
			// 
			// label9
			// 
			this.label9.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label9.Location = new System.Drawing.Point(16, 272);
			this.label9.Name = "label9";
			this.label9.Size = new System.Drawing.Size(80, 23);
			this.label9.TabIndex = 8;
			this.label9.Text = "其他信息:";
			// 
			// pictureBox1
			// 
			this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
			this.pictureBox1.Location = new System.Drawing.Point(120, 96);
			this.pictureBox1.Name = "pictureBox1";
			this.pictureBox1.Size = new System.Drawing.Size(112, 88);
			this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
			this.pictureBox1.TabIndex = 10;
			this.pictureBox1.TabStop = false;
			// 
			// txtname
			// 
			this.txtname.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.txtname.Location = new System.Drawing.Point(120, 16);
			this.txtname.Name = "txtname";
			this.txtname.TabIndex = 11;
			this.txtname.Text = "";
			// 
			// txttelephone
			// 
			this.txttelephone.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.txttelephone.Location = new System.Drawing.Point(392, 16);
			this.txttelephone.Name = "txttelephone";
			this.txttelephone.TabIndex = 12;
			this.txttelephone.Text = "";
			// 
			// txtimages
			// 
			this.txtimages.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.txtimages.Location = new System.Drawing.Point(120, 56);
			this.txtimages.Name = "txtimages";
			this.txtimages.TabIndex = 13;
			this.txtimages.Text = "images\\no.gif";
			this.txtimages.Leave += new System.EventHandler(this.txtimages_Leave);
			// 
			// txtmobilephone
			// 
			this.txtmobilephone.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.txtmobilephone.Location = new System.Drawing.Point(392, 64);
			this.txtmobilephone.Name = "txtmobilephone";
			this.txtmobilephone.TabIndex = 14;
			this.txtmobilephone.Text = "";
			// 
			// txtqq
			// 
			this.txtqq.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.txtqq.Location = new System.Drawing.Point(392, 112);
			this.txtqq.Name = "txtqq";
			this.txtqq.TabIndex = 15;
			this.txtqq.Text = "";
			// 
			// txtemail
			// 
			this.txtemail.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.txtemail.Location = new System.Drawing.Point(392, 160);
			this.txtemail.Name = "txtemail";
			this.txtemail.TabIndex = 16;
			this.txtemail.Text = "";
			// 
			// txtnowaddress
			// 
			this.txtnowaddress.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.txtnowaddress.Location = new System.Drawing.Point(118, 194);
			this.txtnowaddress.Name = "txtnowaddress";
			this.txtnowaddress.Size = new System.Drawing.Size(378, 23);
			this.txtnowaddress.TabIndex = 17;
			this.txtnowaddress.Text = "";
			// 
			// txtfamilyaddress
			// 
			this.txtfamilyaddress.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.txtfamilyaddress.Location = new System.Drawing.Point(118, 232);
			this.txtfamilyaddress.Name = "txtfamilyaddress";
			this.txtfamilyaddress.Size = new System.Drawing.Size(378, 23);
			this.txtfamilyaddress.TabIndex = 18;
			this.txtfamilyaddress.Text = "";
			// 
			// txtothers
			// 
			this.txtothers.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.txtothers.Location = new System.Drawing.Point(117, 271);
			this.txtothers.Multiline = true;
			this.txtothers.Name = "txtothers";
			this.txtothers.Size = new System.Drawing.Size(379, 65);
			this.txtothers.TabIndex = 19;
			this.txtothers.Text = "";
			// 
			// btnok
			// 
			this.btnok.Location = new System.Drawing.Point(280, 352);
			this.btnok.Name = "btnok";
			this.btnok.Size = new System.Drawing.Size(104, 32);
			this.btnok.TabIndex = 20;
			this.btnok.Text = "确认添加";
			this.btnok.Click += new System.EventHandler(this.btnok_Click);
			// 
			// btnexit
			// 
			this.btnexit.Location = new System.Drawing.Point(416, 352);
			this.btnexit.Name = "btnexit";
			this.btnexit.Size = new System.Drawing.Size(112, 32);
			this.btnexit.TabIndex = 21;
			this.btnexit.Text = "退出";
			this.btnexit.Click += new System.EventHandler(this.btnexit_Click);
			// 
			// addfriend
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(544, 397);
			this.Controls.Add(this.btnexit);
			this.Controls.Add(this.btnok);
			this.Controls.Add(this.txtothers);
			this.Controls.Add(this.txtfamilyaddress);
			this.Controls.Add(this.txtnowaddress);
			this.Controls.Add(this.txtemail);
			this.Controls.Add(this.txtqq);
			this.Controls.Add(this.txtmobilephone);
			this.Controls.Add(this.txtimages);
			this.Controls.Add(this.txttelephone);
			this.Controls.Add(this.txtname);
			this.Controls.Add(this.pictureBox1);
			this.Controls.Add(this.label9);
			this.Controls.Add(this.label8);
			this.Controls.Add(this.label7);
			this.Controls.Add(this.label6);
			this.Controls.Add(this.label5);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.label56);
			this.Controls.Add(this.label1);
			this.Name = "addfriend";
			this.Text = "添加信息";
			this.ResumeLayout(false);

		}
		#endregion

		private void btnok_Click(object sender, System.EventArgs e)
		{
			string insertfriend="insert into stuinf(name,telephone,mobilepho,qq,email,nowaddress,familyaddress,images,others,adddate) values('";
		//定义插入SQL语句
			insertfriend +=txtname.Text;
			insertfriend +="','";
			insertfriend +=txttelephone.Text;
			insertfriend +="','";
			insertfriend +=txtmobilephone.Text;
			insertfriend +="','";
			insertfriend +=txtqq.Text;
			insertfriend +="','";
			insertfriend +=txtemail.Text;
			insertfriend +="','";
			insertfriend +=txtnowaddress.Text;
			insertfriend +="','";
			insertfriend +=txtfamilyaddress.Text;
			insertfriend +="','";
			insertfriend +=txtimages.Text;
			insertfriend +="','";
			insertfriend +=txtothers.Text;
			insertfriend +="',";
			insertfriend += System.DateTime.Now.ToShortDateString();
			insertfriend +=")";
			Classdb insertdb=new Classdb();
			SqlConnection insertcon=insertdb.conds();
			SqlCommand insertcom=new SqlCommand(insertfriend,insertcon);
		//	MessageBox.Show(insertfriend);
			try
			{
				int i;
				insertcon.Open();
				i=insertcom.ExecuteNonQuery();
				if (i!=0) 
				{
					MessageBox.Show("插入成功!");
				}
				else
				{
					MessageBox.Show("insert failed1!");
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show("insert failed2!\n" + ex.ToString());
			}
			finally
			{
			insertcom.Dispose();
			insertcon.Dispose();
			}
		}


		private void txtimages_Leave(object sender, System.EventArgs e)
		{
			if (txtimages.Text=="")
			{
				pictureBox1.Image=Image.FromFile("images\no.gif");
			}
			else
			{
				pictureBox1.Image=Image.FromFile(txtimages.Text);//动态初始化照片信息
			}
		}


		private void btnexit_Click(object sender, System.EventArgs e)
		{
			this.Dispose();//退出
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -