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

📄 winmain.cs

📁 好的系统
💻 CS
📖 第 1 页 / 共 2 页
字号:
			}
			 dataGrid1.TableStyles.Add(ts); //增加一种自定义的表风格
			
		}
		private string ConvertTitle(string name)
		{
			switch (name)
			{
				case "stuid":
					return "学号";
				case "name":
					return "姓名";
				case "sex":
					return "性别";
				case "class":
					return "班级";
				case "tel":
					return "电话";
				case "address":
					return "家庭地址";
				case "btime":
					return "出生日期";
				case "password":
					return "密码";
				default:
					return "";

			}
		}

		private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
		{
			
			string str1="select * from student";
			System.Data.DataSet ds=data.GetDataSet(str1,"student");
			string st=ds.Tables[0].Rows[this.dataGrid1.CurrentRowIndex][0].ToString();
			if(e.Button==this.toolBarButton1)
			{
				
				NWST nwst=new NWST();
				
				if(nwst.ShowDialog()==DialogResult.OK)
				{
					string sqlStr="select * from student";
					dt=data.GetDataTable(sqlStr);
					dataGrid1.DataSource=dt;
			
				}
			}
			else if(e.Button==this.toolBarButton2)
			{
				XGST xgst=new XGST(st);
				if(xgst.ShowDialog()==DialogResult.OK)
				{
					string sqlStr="select * from student";
					dt=data.GetDataTable(sqlStr);
					dataGrid1.DataSource=dt;
			         

				}
			}
			else if(e.Button==this.toolBarButton3)
			{
				DialogBox dx=new DialogBox();
				if(dx.ShowDialog()==DialogResult.OK)
				{
					string deleteSql="delete student where stuid='"+st+"'";
					if(data.ExecuteSQL(deleteSql))
					{
						MessageBox.Show("删除成功");
						string sqlStr="select * from student";
						dt=data.GetDataTable(sqlStr);
						dataGrid1.DataSource=dt;
					}
					else 
					{
						MessageBox.Show("删除失败");
					}

				}
			}
			else if(e.Button==this.toolBarButton8)
			{
				
				SaveFileDialog df=new SaveFileDialog();
				df.Filter="所有文件|*.*|文本文件|*.txt";
				df.FilterIndex=1;
				df.InitialDirectory="D:\\Program Files\\Microsoft Visual Studio .NET 2003\\my projects\\CJGL";
				df.Title="将数据信息保存为文本文件";
				if(df.ShowDialog()==DialogResult.OK)
				{
					string fName=df.FileName;
					csFile cf=new csFile(fName);
					str1="select * from student";
					ds=data.GetDataSet(str1,"student");
					cf.OpenForWrite();
					for(int k=0;k<this.dt.Columns.Count;k++)
					{
						cf.write(this.dt.Columns[k].ColumnName+	"          ");
					}
					cf.writeLine("");
					for(int i=0;i<this.dt.Rows.Count;i++)
					{
						for(int j=0;j<this.dt.Columns.Count;j++)
						{
							cf.write(ds.Tables[0].Rows[i][j].ToString());
							for(int m=0;m<10+this.dt.Columns[j].ColumnName.Length-ds.Tables[0].Rows[i][j].ToString().Length;m++)
							{
								cf.write(" ");
							}
						}
						cf.writeLine("");
					
					}
					cf.close();
				}
			}
			else if(e.Button==this.toolBarButton7)
			{
				this.Close();
			   
			}
			else if(e.Button==this.toolBarButton6)
			{
				HELP help=new HELP();
				help.ShowDialog();
			}
			else
			{
			}
		     
		}
/// <summary>
/// 版本信息显示
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
		private void menuItem5_Click(object sender, System.EventArgs e)
		{
		  BBXY bbxy=new BBXY();
			bbxy.ShowDialog();
		}

	/// <summary>
	/// 产生dataGrid中的编号
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
		private void dataGrid1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
		{
			base.OnPaint(e);

			try

			{

				if(this.dataGrid1.DataSource!=null)

				{           

					int yDelta; 

					System.Drawing .Rectangle cell=this.dataGrid1.GetCellBounds(0,0);

					int y=cell.Top +2;

					e.Graphics.DrawString("编号", this.Font, new SolidBrush(Color.Black), 8, y-18); //

					if(this.dataGrid1.VisibleRowCount >0)//只在有记录集时在表格中显示序号

					{                   

						CurrencyManager cm;

						cm = (CurrencyManager) this.BindingContext[this.dataGrid1.DataSource, this.dataGrid1.DataMember]; 

						if(cm.Count >0)

						{                       

							int nRow=-1;

							y=30;           //为第一行默认高度

							while(nRow<0)

							{

								nRow=this.dataGrid1.HitTest (8,y).Row ;

								y++;

							}

							int nCount=0;

							while(y<this.Height && nCount<this.dataGrid1.VisibleRowCount )

							{

								string text = string.Format("{0}", nRow+nCount+1); 

								e.Graphics.DrawString(text, this.Font, new SolidBrush(Color.Black), 10, y); 

								yDelta = this.dataGrid1.GetCellBounds( nRow+nCount,0).Height + 1;//****表示一行高度的参数

								y += yDelta; 

								//如果下面有子行显示序号的区分显示   

								if(this.dataGrid1.IsExpanded (nRow+nCount)&& nRow+nCount+1<cm.Count )                                 
								{

									y+=this.dataGrid1.GetCellBounds (nRow+nCount+1,0).Height +3;

								}

								nCount++;       

							}

						}

					}

				}

			}

			catch

			{}

		}
		private void contextMenu1_Popup(object sender, System.EventArgs e)
		{
			this.contextMenu1.MenuItems.Clear();
			if(this.contextMenu1.SourceControl==this.dataGrid1)
			{
				this.contextMenu1.MenuItems.Add("增加档案  (Ctrl+A)",new System.EventHandler(this.menuItem2_Click));
				this.contextMenu1.MenuItems.Add("修改档案  (Ctrl+M)",new System.EventHandler(this.menuItem6_Click));
				this.contextMenu1.MenuItems.Add("删除档案  (Ctrl+D)",new System.EventHandler(this.menuItem7_Click));
			}
		}
		private void menuItem2_Click(object sender, System.EventArgs e)
		{
			NWST nwst=new NWST();
				
			if(nwst.ShowDialog()==DialogResult.OK)
			{
				string sqlStr="select * from student";
				dt=data.GetDataTable(sqlStr);
				dataGrid1.DataSource=dt;
			
			}
		}
        private void menuItem6_Click(object sender, System.EventArgs e)
		{
			string str1="select * from student";
			System.Data.DataSet ds=data.GetDataSet(str1,"student");
			string st=ds.Tables[0].Rows[this.dataGrid1.CurrentRowIndex][0].ToString();
			XGST xgst=new XGST(st);
			if(xgst.ShowDialog()==DialogResult.OK)
			{
				string sqlStr="select * from student";
				dt=data.GetDataTable(sqlStr);
				dataGrid1.DataSource=dt;
			         

			}
		}
		private void menuItem7_Click(object sender, System.EventArgs e)
		{
			string str1="select * from student";
			System.Data.DataSet ds=data.GetDataSet(str1,"student");
			string st=ds.Tables[0].Rows[this.dataGrid1.CurrentRowIndex][0].ToString();
			DialogBox dx=new DialogBox();
			if(dx.ShowDialog()==DialogResult.OK)
			{
				string deleteSql="delete student where stuid='"+st+"'";
				if(data.ExecuteSQL(deleteSql))
				{
					MessageBox.Show("删除成功");
					string sqlStr="select * from student";
					dt=data.GetDataTable(sqlStr);
					dataGrid1.DataSource=dt;
				}
				else 
				{
					MessageBox.Show("删除失败");
				}

			}
		}

		private void menuItem8_Click(object sender, System.EventArgs e)
		{
			SaveFileDialog df=new SaveFileDialog();
			df.Filter="所有文件|*.*|文本文件|*.txt";
			df.FilterIndex=1;
			df.InitialDirectory="D:\\Program Files\\Microsoft Visual Studio .NET 2003\\my projects\\CJGL";
			df.Title="将数据信息保存为文本文件";
			if(df.ShowDialog()==DialogResult.OK)
			{
				string fName=df.FileName;
				csFile cf=new csFile(fName);
				string str1="select * from student";
				System.Data.DataSet ds=data.GetDataSet(str1,"student");
				cf.OpenForWrite();
				for(int k=0;k<this.dt.Columns.Count;k++)
				{
					cf.write(this.dt.Columns[k].ColumnName+	"          ");
				}
				cf.writeLine("");
				for(int i=0;i<this.dt.Rows.Count;i++)
				{
					for(int j=0;j<this.dt.Columns.Count;j++)
					{
						cf.write(ds.Tables[0].Rows[i][j].ToString());
						for(int m=0;m<10+this.dt.Columns[j].ColumnName.Length-ds.Tables[0].Rows[i][j].ToString().Length;m++)
						{
							cf.write(" ");
						}
					}
					cf.writeLine("");
					
				}
				cf.close();
			}
		}

		private void menuItem1_Click(object sender, System.EventArgs e)
		{
			HELP help=new HELP();
			help.ShowDialog();
		}

		
	}
}

⌨️ 快捷键说明

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