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

📄 form2.cs

📁 基于贝叶斯的数据挖掘算法的实现,使用visual stutio2005编程实现。
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
using System.Text;
using Microsoft.Office.Interop.Excel;
using Microsoft.Office.Core;
namespace DataMing
{
	/// <summary>
	/// Form2 的摘要说明。
	/// </summary>
	public class Form2 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TabControl tabControl1;
		private System.Windows.Forms.TabPage tabPage1;
		private System.Windows.Forms.TabPage tabPage2;
		private System.Windows.Forms.TabPage tabPage3;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.DataGrid dgSource;
		private System.Windows.Forms.Button btnShow;
		private System.Windows.Forms.DataGrid dgInfo;
		static private int kind = 0;//分类数目
		static private int feature = 0;
		private string path = null;
		static private DataSet ds = new DataSet();
		private System.Windows.Forms.DataGrid dgData;
		private System.Windows.Forms.Button btnCompute;
		private System.Windows.Forms.Button btnSave;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox tbResult;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form2()
		{
			//
			// 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()
		{
			this.tabControl1 = new System.Windows.Forms.TabControl();
			this.tabPage1 = new System.Windows.Forms.TabPage();
			this.dgInfo = new System.Windows.Forms.DataGrid();
			this.btnShow = new System.Windows.Forms.Button();
			this.button1 = new System.Windows.Forms.Button();
			this.dgSource = new System.Windows.Forms.DataGrid();
			this.tabPage2 = new System.Windows.Forms.TabPage();
			this.btnSave = new System.Windows.Forms.Button();
			this.btnCompute = new System.Windows.Forms.Button();
			this.dgData = new System.Windows.Forms.DataGrid();
			this.tabPage3 = new System.Windows.Forms.TabPage();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.tbResult = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.button2 = new System.Windows.Forms.Button();
			this.tabControl1.SuspendLayout();
			this.tabPage1.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.dgInfo)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.dgSource)).BeginInit();
			this.tabPage2.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.dgData)).BeginInit();
			this.tabPage3.SuspendLayout();
			this.groupBox2.SuspendLayout();
			this.SuspendLayout();
			// 
			// tabControl1
			// 
			this.tabControl1.Controls.Add(this.tabPage1);
			this.tabControl1.Controls.Add(this.tabPage2);
			this.tabControl1.Controls.Add(this.tabPage3);
			this.tabControl1.Location = new System.Drawing.Point(0, 0);
			this.tabControl1.Name = "tabControl1";
			this.tabControl1.SelectedIndex = 0;
			this.tabControl1.Size = new System.Drawing.Size(520, 400);
			this.tabControl1.TabIndex = 0;
			this.tabControl1.SelectedIndexChanged += new System.EventHandler(this.tabControl1_SelectedIndexChanged);
			// 
			// tabPage1
			// 
			this.tabPage1.Controls.Add(this.dgInfo);
			this.tabPage1.Controls.Add(this.btnShow);
			this.tabPage1.Controls.Add(this.button1);
			this.tabPage1.Controls.Add(this.dgSource);
			this.tabPage1.Location = new System.Drawing.Point(4, 21);
			this.tabPage1.Name = "tabPage1";
			this.tabPage1.Size = new System.Drawing.Size(512, 375);
			this.tabPage1.TabIndex = 0;
			this.tabPage1.Text = "训练数据";
			// 
			// dgInfo
			// 
			this.dgInfo.AlternatingBackColor = System.Drawing.Color.LightGray;
			this.dgInfo.BackColor = System.Drawing.Color.DarkGray;
			this.dgInfo.BackgroundColor = System.Drawing.Color.Ivory;
			this.dgInfo.CaptionBackColor = System.Drawing.Color.White;
			this.dgInfo.CaptionFont = new System.Drawing.Font("Verdana", 10F);
			this.dgInfo.CaptionForeColor = System.Drawing.Color.Navy;
			this.dgInfo.CaptionVisible = false;
			this.dgInfo.DataMember = "";
			this.dgInfo.ForeColor = System.Drawing.Color.Black;
			this.dgInfo.GridLineColor = System.Drawing.Color.Black;
			this.dgInfo.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None;
			this.dgInfo.HeaderBackColor = System.Drawing.Color.Silver;
			this.dgInfo.HeaderForeColor = System.Drawing.Color.Black;
			this.dgInfo.LinkColor = System.Drawing.Color.Navy;
			this.dgInfo.Location = new System.Drawing.Point(8, 232);
			this.dgInfo.Name = "dgInfo";
			this.dgInfo.ParentRowsBackColor = System.Drawing.Color.White;
			this.dgInfo.ParentRowsForeColor = System.Drawing.Color.Black;
			this.dgInfo.ReadOnly = true;
			this.dgInfo.SelectionBackColor = System.Drawing.Color.Navy;
			this.dgInfo.SelectionForeColor = System.Drawing.Color.White;
			this.dgInfo.Size = new System.Drawing.Size(496, 128);
			this.dgInfo.TabIndex = 3;
			this.dgInfo.Visible = false;
			// 
			// btnShow
			// 
			this.btnShow.Location = new System.Drawing.Point(288, 184);
			this.btnShow.Name = "btnShow";
			this.btnShow.Size = new System.Drawing.Size(136, 32);
			this.btnShow.TabIndex = 2;
			this.btnShow.Text = "显示特征值信息";
			this.btnShow.Click += new System.EventHandler(this.btnShow_Click);
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(72, 184);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(96, 32);
			this.button1.TabIndex = 1;
			this.button1.Text = "导入训练数据";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// dgSource
			// 
			this.dgSource.AlternatingBackColor = System.Drawing.Color.LightGray;
			this.dgSource.BackColor = System.Drawing.Color.DarkGray;
			this.dgSource.BackgroundColor = System.Drawing.Color.Ivory;
			this.dgSource.CaptionBackColor = System.Drawing.Color.White;
			this.dgSource.CaptionFont = new System.Drawing.Font("Verdana", 10F);
			this.dgSource.CaptionForeColor = System.Drawing.Color.Navy;
			this.dgSource.CaptionVisible = false;
			this.dgSource.DataMember = "";
			this.dgSource.ForeColor = System.Drawing.Color.Black;
			this.dgSource.GridLineColor = System.Drawing.Color.Black;
			this.dgSource.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None;
			this.dgSource.HeaderBackColor = System.Drawing.Color.Silver;
			this.dgSource.HeaderForeColor = System.Drawing.Color.Black;
			this.dgSource.LinkColor = System.Drawing.Color.Navy;
			this.dgSource.Location = new System.Drawing.Point(8, 16);
			this.dgSource.Name = "dgSource";
			this.dgSource.ParentRowsBackColor = System.Drawing.Color.White;
			this.dgSource.ParentRowsForeColor = System.Drawing.Color.Black;
			this.dgSource.ReadOnly = true;
			this.dgSource.SelectionBackColor = System.Drawing.Color.Navy;
			this.dgSource.SelectionForeColor = System.Drawing.Color.White;
			this.dgSource.Size = new System.Drawing.Size(472, 152);
			this.dgSource.TabIndex = 0;
			// 
			// tabPage2
			// 
			this.tabPage2.Controls.Add(this.btnSave);
			this.tabPage2.Controls.Add(this.btnCompute);
			this.tabPage2.Controls.Add(this.dgData);
			this.tabPage2.Location = new System.Drawing.Point(4, 21);
			this.tabPage2.Name = "tabPage2";
			this.tabPage2.Size = new System.Drawing.Size(512, 375);
			this.tabPage2.TabIndex = 1;
			this.tabPage2.Text = "数据分类";
			// 
			// btnSave
			// 
			this.btnSave.Location = new System.Drawing.Point(264, 328);
			this.btnSave.Name = "btnSave";
			this.btnSave.Size = new System.Drawing.Size(75, 32);
			this.btnSave.TabIndex = 2;
			this.btnSave.Text = "保存结果";
			this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
			// 
			// btnCompute
			// 
			this.btnCompute.Location = new System.Drawing.Point(72, 328);
			this.btnCompute.Name = "btnCompute";
			this.btnCompute.Size = new System.Drawing.Size(104, 32);
			this.btnCompute.TabIndex = 1;
			this.btnCompute.Text = "导入数据并分类";
			this.btnCompute.Click += new System.EventHandler(this.btnCompute_Click);
			// 
			// dgData
			// 
			this.dgData.AlternatingBackColor = System.Drawing.Color.LightGray;
			this.dgData.BackColor = System.Drawing.Color.DarkGray;
			this.dgData.CaptionBackColor = System.Drawing.Color.White;
			this.dgData.CaptionFont = new System.Drawing.Font("Verdana", 10F);
			this.dgData.CaptionForeColor = System.Drawing.Color.Navy;
			this.dgData.CaptionVisible = false;
			this.dgData.DataMember = "";
			this.dgData.ForeColor = System.Drawing.Color.Black;
			this.dgData.GridLineColor = System.Drawing.Color.Black;
			this.dgData.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None;
			this.dgData.HeaderBackColor = System.Drawing.Color.Silver;
			this.dgData.HeaderForeColor = System.Drawing.Color.Black;
			this.dgData.LinkColor = System.Drawing.Color.Navy;
			this.dgData.Location = new System.Drawing.Point(16, 24);
			this.dgData.Name = "dgData";
			this.dgData.ParentRowsBackColor = System.Drawing.Color.White;
			this.dgData.ParentRowsForeColor = System.Drawing.Color.Black;
			this.dgData.ReadOnly = true;
			this.dgData.SelectionBackColor = System.Drawing.Color.Navy;
			this.dgData.SelectionForeColor = System.Drawing.Color.White;
			this.dgData.Size = new System.Drawing.Size(472, 288);
			this.dgData.TabIndex = 0;
			// 
			// tabPage3
			// 
			this.tabPage3.Controls.Add(this.groupBox1);
			this.tabPage3.Controls.Add(this.groupBox2);
			this.tabPage3.Location = new System.Drawing.Point(4, 21);
			this.tabPage3.Name = "tabPage3";
			this.tabPage3.Size = new System.Drawing.Size(512, 375);
			this.tabPage3.TabIndex = 2;
			this.tabPage3.Text = "单个输入";
			// 
			// groupBox1
			// 
			this.groupBox1.Location = new System.Drawing.Point(8, 16);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(488, 240);
			this.groupBox1.TabIndex = 0;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "输入特征值";
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.Add(this.tbResult);
			this.groupBox2.Controls.Add(this.label1);
			this.groupBox2.Controls.Add(this.button2);
			this.groupBox2.Location = new System.Drawing.Point(8, 280);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(488, 72);
			this.groupBox2.TabIndex = 1;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "计算结果";
			// 
			// tbResult
			// 
			this.tbResult.Location = new System.Drawing.Point(256, 40);
			this.tbResult.Name = "tbResult";
			this.tbResult.TabIndex = 2;
			this.tbResult.Text = "";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(184, 40);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(72, 23);
			this.label1.TabIndex = 1;
			this.label1.Text = "所属分类:";
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(32, 32);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(72, 24);
			this.button2.TabIndex = 0;
			this.button2.Text = "计算结果";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// Form2
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(520, 405);
			this.Controls.Add(this.tabControl1);
			this.Name = "Form2";
			this.Text = "数据分类";
			this.tabControl1.ResumeLayout(false);
			this.tabPage1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.dgInfo)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.dgSource)).EndInit();
			this.tabPage2.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.dgData)).EndInit();
			this.tabPage3.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion
        

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			System.Windows.Forms.Application.Run(new Form2());
		}
        /// <summary>
        /// 抛出异常。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
		private void button1_Click(object sender, System.EventArgs e)
		{
			OpenFileDialog openFileDialog1 = new OpenFileDialog();

			openFileDialog1.InitialDirectory = "c:\\" ;
			openFileDialog1.Filter = "txt files (*.xls)|*.xls" ;
			openFileDialog1.FilterIndex = 1 ;
			openFileDialog1.RestoreDirectory = true ;

			if(openFileDialog1.ShowDialog() == DialogResult.OK)
			{
				path = openFileDialog1.FileName;
				dgSource.DataSource = GetDataTable(path);
				dgInfo.DataSource = GetDataSet(path,GetSchema(path));
			}

		}

		private void btnShow_Click(object sender, System.EventArgs e)
		{
		   dgInfo.Visible = !dgInfo.Visible;
		   btnShow.Text = dgInfo.Visible ?"隐藏特征值信息":"显示特征值信息";
		}

		/// <summary>
		/// 根据样本数据进行训练
		/// </summary>
		/// <param name="path">训练数据文件的路径</param>
		/// <param name="db" > 训练数据的元数据</param>

⌨️ 快捷键说明

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