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

📄 frmcustomeradd.cs

📁 北大青鸟内部资料
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;

namespace AddCustomToFile
{
	/// <summary>
	/// Summary description for frmCustomerDetails
	/// </summary>
	public class frmCustomerDetails : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label lblName;
		private System.Windows.Forms.Label lblAddress;
		private System.Windows.Forms.Label lblPhone;
		private System.Windows.Forms.TextBox txtName;
		private System.Windows.Forms.TextBox txtAddress;
		private System.Windows.Forms.TextBox txtPhone;
		private System.Windows.Forms.Button btnDone;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.Button btnAdd;
        private Hashtable hash;
		private System.Windows.Forms.Button btnSearch;
		private System.Windows.Forms.GroupBox sep; 
	    private StreamWriter writer;

		public frmCustomerDetails()
		{
			InitializeComponent();
	        if (!File.Exists(@"C:\Customer.txt")) 
			{
				// 创建文件并将流指向该文件
				writer = File.CreateText(@"C:\Customer.txt"); 
			}
			else
			{   
				//设置流以追加到该文件
				writer = File.AppendText(@"C:\Customer.txt");
			}
		}

		/// <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.lblName = new System.Windows.Forms.Label();
			this.lblAddress = new System.Windows.Forms.Label();
			this.lblPhone = new System.Windows.Forms.Label();
			this.txtName = new System.Windows.Forms.TextBox();
			this.txtAddress = new System.Windows.Forms.TextBox();
			this.txtPhone = new System.Windows.Forms.TextBox();
			this.btnDone = new System.Windows.Forms.Button();
			this.btnAdd = new System.Windows.Forms.Button();
			this.btnSearch = new System.Windows.Forms.Button();
			this.sep = new System.Windows.Forms.GroupBox();
			this.SuspendLayout();
			// 
			// lblName
			// 
			this.lblName.Location = new System.Drawing.Point(10, 26);
			this.lblName.Name = "lblName";
			this.lblName.Size = new System.Drawing.Size(102, 14);
			this.lblName.TabIndex = 0;
			this.lblName.Text = "输入客户姓名:";
			// 
			// lblAddress
			// 
			this.lblAddress.Location = new System.Drawing.Point(10, 60);
			this.lblAddress.Name = "lblAddress";
			this.lblAddress.Size = new System.Drawing.Size(110, 12);
			this.lblAddress.TabIndex = 1;
			this.lblAddress.Text = "输入客户地址:";
			// 
			// lblPhone
			// 
			this.lblPhone.Location = new System.Drawing.Point(10, 129);
			this.lblPhone.Name = "lblPhone";
			this.lblPhone.Size = new System.Drawing.Size(126, 15);
			this.lblPhone.TabIndex = 2;
			this.lblPhone.Text = "输入客户电话号码:";
			// 
			// txtName
			// 
			this.txtName.Location = new System.Drawing.Point(202, 26);
			this.txtName.Name = "txtName";
			this.txtName.Size = new System.Drawing.Size(172, 21);
			this.txtName.TabIndex = 3;
			this.txtName.Text = "";
			// 
			// txtAddress
			// 
			this.txtAddress.Location = new System.Drawing.Point(202, 60);
			this.txtAddress.Multiline = true;
			this.txtAddress.Name = "txtAddress";
			this.txtAddress.Size = new System.Drawing.Size(172, 61);
			this.txtAddress.TabIndex = 4;
			this.txtAddress.Text = "";
			// 
			// txtPhone
			// 
			this.txtPhone.Location = new System.Drawing.Point(202, 129);
			this.txtPhone.Name = "txtPhone";
			this.txtPhone.Size = new System.Drawing.Size(172, 21);
			this.txtPhone.TabIndex = 5;
			this.txtPhone.Text = "";
			// 
			// btnDone
			// 
			this.btnDone.Location = new System.Drawing.Point(296, 168);
			this.btnDone.Name = "btnDone";
			this.btnDone.Size = new System.Drawing.Size(80, 25);
			this.btnDone.TabIndex = 6;
			this.btnDone.Text = "退出(&E)";
			this.btnDone.Click += new System.EventHandler(this.btnDone_Click);
			// 
			// btnAdd
			// 
			this.btnAdd.Location = new System.Drawing.Point(208, 168);
			this.btnAdd.Name = "btnAdd";
			this.btnAdd.Size = new System.Drawing.Size(80, 25);
			this.btnAdd.TabIndex = 7;
			this.btnAdd.Text = "添加(&A)";
			this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
			// 
			// btnSearch
			// 
			this.btnSearch.Location = new System.Drawing.Point(120, 168);
			this.btnSearch.Name = "btnSearch";
			this.btnSearch.Size = new System.Drawing.Size(80, 24);
			this.btnSearch.TabIndex = 8;
			this.btnSearch.Text = "查找(&S)";
			this.btnSearch.Click += new System.EventHandler(this.button1_Click);
			// 
			// sep
			// 
			this.sep.Location = new System.Drawing.Point(8, 152);
			this.sep.Name = "sep";
			this.sep.Size = new System.Drawing.Size(376, 8);
			this.sep.TabIndex = 9;
			this.sep.TabStop = false;
			// 
			// frmCustomerDetails
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(384, 205);
			this.Controls.Add(this.sep);
			this.Controls.Add(this.btnSearch);
			this.Controls.Add(this.btnAdd);
			this.Controls.Add(this.btnDone);
			this.Controls.Add(this.txtPhone);
			this.Controls.Add(this.txtAddress);
			this.Controls.Add(this.txtName);
			this.Controls.Add(this.lblPhone);
			this.Controls.Add(this.lblAddress);
			this.Controls.Add(this.lblName);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
			this.MaximizeBox = false;
			this.Name = "frmCustomerDetails";
			this.Text = "客户详情";
			this.Load += new System.EventHandler(this.frmCustomerDetails_Load);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new frmCustomerDetails());
		}

		private void btnDone_Click(object sender, System.EventArgs e)
		{
            //将流中的数据写入文件
 			writer.Flush();
			Application.Exit ();
		}

		private void btnAdd_Click(object sender, System.EventArgs e)
		{
		    hash = new Hashtable();
			hash.Add("姓名",txtName.Text.ToString ());
			hash.Add("地址", txtAddress.Text.ToString ());
			hash.Add("电话",txtPhone.Text.ToString ());
 			foreach(DictionaryEntry customer in hash)
			{
			    writer.WriteLine(" {0} : {1}",customer.Key.ToString (),customer.Value.ToString ());
				writer.WriteLine();
			}
 			btnDone.Enabled =true;
			txtName.Text ="";
			txtAddress.Text ="";
			txtPhone.Text ="";
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			/*
			//create a byte array to read the data 
			byte[] arr = new byte[100];
			UTF8Encoding data = new UTF8Encoding(true);
        
			//go on reading as long as there is data in the file
			while (fstream.Read(arr,0,arr.Length) > 0) 
			{
				MessageBox.Show(data.GetString(arr));
			}
			fstream.Close ();
		*/
		}

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

⌨️ 快捷键说明

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