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

📄 form1.cs

📁 java基础方面的一些实例代码
💻 CS
📖 第 1 页 / 共 3 页
字号:
			this.TName.TabIndex = 1;
			this.TName.Text = "Name";
			// 
			// textBox3
			// 
			this.textBox3.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.textBox3.Enabled = false;
			this.textBox3.Location = new System.Drawing.Point(72, 32);
			this.textBox3.Name = "textBox3";
			this.textBox3.ReadOnly = true;
			this.textBox3.Size = new System.Drawing.Size(56, 14);
			this.textBox3.TabIndex = 0;
			this.textBox3.TabStop = false;
			this.textBox3.Text = "所开课程";
			// 
			// PrevT
			// 
			this.PrevT.Location = new System.Drawing.Point(8, 128);
			this.PrevT.Name = "PrevT";
			this.PrevT.Size = new System.Drawing.Size(56, 24);
			this.PrevT.TabIndex = 1;
			this.PrevT.Text = "上一个";
			this.PrevT.Click += new System.EventHandler(this.PrevT_Click);
			// 
			// TNext
			// 
			this.TNext.Location = new System.Drawing.Point(80, 128);
			this.TNext.Name = "TNext";
			this.TNext.Size = new System.Drawing.Size(56, 24);
			this.TNext.TabIndex = 1;
			this.TNext.Text = "下一个";
			this.TNext.Click += new System.EventHandler(this.TNext_Click);
			// 
			// groupBox3
			// 
			this.groupBox3.Controls.Add(this.listBox3);
			this.groupBox3.Controls.Add(this.MulQuery);
			this.groupBox3.Controls.Add(this.textBox4);
			this.groupBox3.Location = new System.Drawing.Point(384, 232);
			this.groupBox3.Name = "groupBox3";
			this.groupBox3.Size = new System.Drawing.Size(144, 160);
			this.groupBox3.TabIndex = 3;
			this.groupBox3.TabStop = false;
			this.groupBox3.Text = "多表查询例";
			// 
			// listBox3
			// 
			this.listBox3.ItemHeight = 12;
			this.listBox3.Location = new System.Drawing.Point(8, 96);
			this.listBox3.Name = "listBox3";
			this.listBox3.Size = new System.Drawing.Size(128, 52);
			this.listBox3.TabIndex = 1;
			// 
			// MulQuery
			// 
			this.MulQuery.AllowDrop = true;
			this.MulQuery.Items.AddRange(new object[] {
														  "有教授参与授课的所有课程",
														  "有副教授参与授课的所有课程",
														  "所有选择教授所授课程的学生",
														  "王心怡老师的所有学生",
														  "所有有课程冲突的学生"});
			this.MulQuery.Location = new System.Drawing.Point(16, 24);
			this.MulQuery.Name = "MulQuery";
			this.MulQuery.Size = new System.Drawing.Size(120, 20);
			this.MulQuery.TabIndex = 0;
			this.MulQuery.SelectedIndexChanged += new System.EventHandler(this.MulQuery_SelectedIndexChanged);
			// 
			// textBox4
			// 
			this.textBox4.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.textBox4.Enabled = false;
			this.textBox4.Location = new System.Drawing.Point(8, 72);
			this.textBox4.Name = "textBox4";
			this.textBox4.ReadOnly = true;
			this.textBox4.Size = new System.Drawing.Size(56, 14);
			this.textBox4.TabIndex = 0;
			this.textBox4.TabStop = false;
			this.textBox4.Text = "查询结果";
			// 
			// DeleteB
			// 
			this.DeleteB.Location = new System.Drawing.Point(536, 224);
			this.DeleteB.Name = "DeleteB";
			this.DeleteB.Size = new System.Drawing.Size(64, 24);
			this.DeleteB.TabIndex = 1;
			this.DeleteB.Text = "删除记录";
			this.DeleteB.Click += new System.EventHandler(this.DeleteB_Click);
			// 
			// InsertB
			// 
			this.InsertB.Location = new System.Drawing.Point(536, 252);
			this.InsertB.Name = "InsertB";
			this.InsertB.Size = new System.Drawing.Size(64, 24);
			this.InsertB.TabIndex = 1;
			this.InsertB.Text = "添加记录";
			this.InsertB.Click += new System.EventHandler(this.InsertB_Click);
			// 
			// ModifyB
			// 
			this.ModifyB.Location = new System.Drawing.Point(536, 280);
			this.ModifyB.Name = "ModifyB";
			this.ModifyB.Size = new System.Drawing.Size(64, 24);
			this.ModifyB.TabIndex = 1;
			this.ModifyB.Text = "修改张萍";
			this.ModifyB.Click += new System.EventHandler(this.ModifyB_Click);
			// 
			// ReceiveB
			// 
			this.ReceiveB.Location = new System.Drawing.Point(536, 308);
			this.ReceiveB.Name = "ReceiveB";
			this.ReceiveB.Size = new System.Drawing.Size(64, 24);
			this.ReceiveB.TabIndex = 1;
			this.ReceiveB.Text = "接受修改";
			this.ReceiveB.Click += new System.EventHandler(this.ReceiveB_Click);
			// 
			// RejectB
			// 
			this.RejectB.Location = new System.Drawing.Point(536, 336);
			this.RejectB.Name = "RejectB";
			this.RejectB.Size = new System.Drawing.Size(64, 24);
			this.RejectB.TabIndex = 1;
			this.RejectB.Text = "拒绝修改";
			this.RejectB.Click += new System.EventHandler(this.RejectB_Click);
			// 
			// ResultB
			// 
			this.ResultB.Location = new System.Drawing.Point(536, 366);
			this.ResultB.Name = "ResultB";
			this.ResultB.Size = new System.Drawing.Size(64, 24);
			this.ResultB.TabIndex = 1;
			this.ResultB.Text = "结果入库";
			this.ResultB.Click += new System.EventHandler(this.ResultB_Click);
			// 
			// DataReaderB
			// 
			this.DataReaderB.Location = new System.Drawing.Point(8, 382);
			this.DataReaderB.Name = "DataReaderB";
			this.DataReaderB.Size = new System.Drawing.Size(80, 48);
			this.DataReaderB.TabIndex = 1;
			this.DataReaderB.Text = "Command和DataReader使用例子";
			this.DataReaderB.Click += new System.EventHandler(this.DataReaderB_Click);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(608, 437);
			this.Controls.Add(this.groupBox2);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.SqlConn);
			this.Controls.Add(this.dataGrid1);
			this.Controls.Add(this.OleDBConn);
			this.Controls.Add(this.IsConn);
			this.Controls.Add(this.DisConn);
			this.Controls.Add(this.ReadData);
			this.Controls.Add(this.XmlBuild);
			this.Controls.Add(this.NewTable);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.groupBox3);
			this.Controls.Add(this.DeleteB);
			this.Controls.Add(this.InsertB);
			this.Controls.Add(this.ModifyB);
			this.Controls.Add(this.ReceiveB);
			this.Controls.Add(this.RejectB);
			this.Controls.Add(this.ResultB);
			this.Controls.Add(this.DataReaderB);
			this.Name = "Form1";
			this.Text = "Form1";
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			this.groupBox1.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.groupBox3.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void OleDBConn_Click(object sender, System.EventArgs e)
		{			
			try 
			{
				string ConStr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Current\doc\CSharp教程计划\SourceCode\Chap20\mcaoTest.mdb";
				//string ConStr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\mcaoTest.mdb";
				MyOleConn = new OleDbConnection(ConStr);				
				MyOleConn.Open( );
			}
			catch 
			{
				MessageBox.Show("目前没有连接任何数据库");
			}
		}

		private void ReadData_Click(object sender, System.EventArgs e)
		{
			string [] ReadStr = {"SELECT * FROM teacherinfo", "SELECT * FROM studentinfo",
									"SELECT * FROM classinfo", "SELECT * FROM teacherclass"};
			string [] TableNameStr = {"teacherinfo", "studentinfo", "classinfo", "teacherclass"};
			MyDataSet = new DataSet( );

			for (int i = 0; i < 4; i++)
			{
				MyDataAdapter = new OleDbDataAdapter(ReadStr[i],MyOleConn);
				MyDataAdapter.Fill(MyDataSet,TableNameStr[i]);  //获取数据
				MyComm = new OleDbCommand(ReadStr[i],MyOleConn);
				MyDataReader = MyComm.ExecuteReader(); //用DataReader

				MyDataTable[i] = MyDataReader.GetSchemaTable( );  //获取每个表的每一列的所有属性		
				MyDataReader.Close();
			}
			bIsConnected = true;
		}

		private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if (bIsConnected == false) 
			{
				MessageBox.Show("目前没有连接任何数据库或者没有读取数据库数据");
				return;
			}
			int CurrentIndex = listBox1.SelectedIndex;	
			dataGrid1.SetDataBinding(MyDataSet.Tables[CurrentIndex], null);	
			//dataGrid1.SetDataBinding(MyDataTable[CurrentIndex], null);
		}

		private void TID_TextChanged(object sender, System.EventArgs e)
		{
			if (bIsConnected == false) 
			{
				MessageBox.Show("目前没有连接任何数据库或者没有读取数据库数据");
				return;
			}
			int CurrentID = Int32.Parse(TID.Text)-1;
			QueryTeacher(CurrentID);
		}

		private void TNext_Click(object sender, System.EventArgs e)
		{
			if (bIsConnected == false) 
			{
				MessageBox.Show("目前没有连接任何数据库或者没有读取数据库数据");
				return;
			}
			int CurrentID = Int32.Parse(TID.Text);
			QueryTeacher(CurrentID);	
		}

		private void PrevT_Click(object sender, System.EventArgs e)
		{
			if (bIsConnected == false) 
			{
				MessageBox.Show("目前没有连接任何数据库或者没有读取数据库数据");
				return;
			}
			int CurrentID = Int32.Parse(TID.Text)-2;
			QueryTeacher(CurrentID);
		}

		private void QueryTeacher(int index)
		{
			string NameStr;
			string [] CourseStr = {"","","","",""};
			DataTable CurrentTable = MyDataSet.Tables[0];
			DataTable CourseTable = MyDataSet.Tables[3];
			//DataRow [] foundRow = CurrentTable.Select("SELECT 'TID = 1'", "");
			try 
			{
				DataRow foundRow = CurrentTable.Rows[index];
				NameStr = foundRow.ItemArray[3].ToString()+foundRow.ItemArray[2].ToString();
				TID.DataBindings.Clear();
				TID.DataBindings.Add("Text", (index+1).ToString(), null);
				TName.DataBindings.Clear();
				TName.DataBindings.Add("Text", NameStr, null);
				foundRow = CourseTable.Rows[index];
				for (int i = 0; i< 5; i++) 
				{
					CourseStr[i] = foundRow.ItemArray[i+1].ToString();
				}
				listBox2.DataSource = CourseStr;		
			}
			catch 
			{
			}
		}

		private void IsConn_Click(object sender, System.EventArgs e)
		{
			try 
			{
				string str = MyOleConn.DataSource;
				if (str.Equals(""))
					MessageBox.Show("目前没有连接任何数据库");
				else
					MessageBox.Show("已经连接的数据库为:"+"\n"+MyOleConn.DataSource);
			}
			catch 

⌨️ 快捷键说明

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