www.pudn.com > classifier.rar > clearType.cs


using System; 
using System.Drawing; 
using System.Collections; 
using System.ComponentModel; 
using System.Windows.Forms; 
using System.Data.OleDb; 
using System.Data; 
 
namespace classifier 
{ 
	///  
	/// clearType 的摘要说明。 
	///  
	public class clearType : System.Windows.Forms.Form 
	{ 
		private System.Windows.Forms.Button button1; 
		private System.Windows.Forms.ComboBox comboBox1; 
		private System.Windows.Forms.Button button2; 
		///  
		/// 必需的设计器变量。 
		///  
		private System.ComponentModel.Container components = null; 
 
		public clearType() 
		{ 
			// 
			// Windows 窗体设计器支持所必需的 
			// 
			InitializeComponent(); 
 
			// 
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码 
			// 
		} 
 
		///  
		/// 清理所有正在使用的资源。 
		///  
		protected override void Dispose( bool disposing ) 
		{ 
			if( disposing ) 
			{ 
				if(components != null) 
				{ 
					components.Dispose(); 
				} 
			} 
			base.Dispose( disposing ); 
		} 
 
		#region Windows 窗体设计器生成的代码 
		///  
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改 
		/// 此方法的内容。 
		///  
		private void InitializeComponent() 
		{ 
			this.button1 = new System.Windows.Forms.Button(); 
			this.comboBox1 = new System.Windows.Forms.ComboBox(); 
			this.button2 = new System.Windows.Forms.Button(); 
			this.SuspendLayout(); 
			//  
			// button1 
			//  
			this.button1.Location = new System.Drawing.Point(312, 136); 
			this.button1.Name = "button1"; 
			this.button1.TabIndex = 1; 
			this.button1.Text = "重新统计汇总表"; 
			this.button1.Click += new System.EventHandler(this.button1_Click); 
			//  
			// comboBox1 
			//  
			this.comboBox1.Location = new System.Drawing.Point(120, 136); 
			this.comboBox1.Name = "comboBox1"; 
			this.comboBox1.Size = new System.Drawing.Size(121, 20); 
			this.comboBox1.TabIndex = 2; 
			this.comboBox1.Text = "comboBox1"; 
			//  
			// button2 
			//  
			this.button2.Location = new System.Drawing.Point(224, 64); 
			this.button2.Name = "button2"; 
			this.button2.TabIndex = 3; 
			this.button2.Text = "清空汇总表"; 
			this.button2.Click += new System.EventHandler(this.button2_Click); 
			//  
			// clearType 
			//  
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); 
			this.ClientSize = new System.Drawing.Size(568, 517); 
			this.Controls.Add(this.button2); 
			this.Controls.Add(this.comboBox1); 
			this.Controls.Add(this.button1); 
			this.Name = "clearType"; 
			this.Text = "clearType"; 
			this.Load += new System.EventHandler(this.clearType_Load); 
			this.ResumeLayout(false); 
 
		} 
		#endregion 
 
		private void clearType_Load(object sender, System.EventArgs e) 
		{ 
			OleDbConnection sqlCon=db.dbOpertation.getConnection(); 
 
			if(sqlCon.State==ConnectionState.Closed) 
			{ 
				sqlCon.Open(); 
			} 
 
			OleDbDataAdapter typeAd; 
			DataTable dt=new DataTable(); 
			string cmd="select * from typeTable"; 
			typeAd=new OleDbDataAdapter(cmd,sqlCon); 
			typeAd.Fill(dt); 
			for(int i=0;i0) 
						{ 
							sumTimes=Convert.ToInt32(drs[0]["times"]); 
							sumTimes=sumTimes+times; 
							drs[0]["times"]=sumTimes; 
						} 
						else 
						{ 
							dr2=ds.Tables["sumTable"].NewRow(); 
							dr2["word"]=word; 
							dr2["times"]=times; 
							ds.Tables["sumTable"].Rows.Add(dr2); 
						} 
 
					} 
 
					ds.Tables["classTable"].Clear(); 
					MessageBox.Show(comboBox1.Text+":处理完毕"); 
 
					cmd="insert into sumLearned(typeName) values(\'"+comboBox1.Text+"\')"; 
					sqlCom=new OleDbCommand(cmd,sqlCon); 
					sqlCom.ExecuteNonQuery(); 
				 
					sumAd.Update(ds,"sumTable"); 
					ds.Tables["sumTable"].AcceptChanges(); 
					MessageBox.Show("更新汇总表成功!"); 
					sqlCon.Close(); 
				 
				} 
				catch(Exception ex) 
				{ 
					sqlCon.Close(); 
					MessageBox.Show("出错:"+ex.Message); 
				} 
 
			 
			 
		} 
 
		private void button2_Click(object sender, System.EventArgs e) 
		{ 
			OleDbConnection sqlCon=db.dbOpertation.getConnection(); 
			 
			OleDbCommand sqlCom; 
			string cmd,word; 
			 
			cmd="delete * from wordSum2"; 
			if(sqlCon.State==ConnectionState.Closed) 
			{ 
				sqlCon.Open(); 
			} 
			sqlCom=new OleDbCommand(cmd,sqlCon); 
			try 
			{ 
				sqlCom.ExecuteNonQuery(); 
				MessageBox.Show("删除汇总表成功!"); 
			} 
			catch(Exception ex) 
			{ 
				MessageBox.Show("删除汇总表失败!"+ex.Message); 
			} 
		} 
	} 
}