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

📄 updata_book.cs

📁 因本人正在学习中
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;
using System.Data;
using System.Data.SqlClient;

namespace 图书
{
	/// <summary>
	/// updata_book 的摘要说明。
	/// </summary>
	public class updata_book : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TextBox txt_lx;
		private System.Windows.Forms.Label lbl_lx;
		private System.Windows.Forms.TextBox txt_bz;
		private System.Windows.Forms.TextBox txt_gjc;
		private System.Windows.Forms.TextBox txt_zs;
		private System.Windows.Forms.TextBox txtID;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Button btn_cancel;
		private System.Windows.Forms.Button btn_sure;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.DataGrid dataGrid1;
		private System.Windows.Forms.ToolBar toolBar3;
		private System.Windows.Forms.ToolBarButton tobtnupdata;
		private System.Windows.Forms.ToolBarButton toolBarButton13;
		private System.Windows.Forms.ImageList imageList1;
		private System.ComponentModel.IContainer components;
public static DataSet ds;
		public updata_book()
		{
			//
			// 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.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(updata_book));
			this.txt_lx = new System.Windows.Forms.TextBox();
			this.lbl_lx = new System.Windows.Forms.Label();
			this.txt_bz = new System.Windows.Forms.TextBox();
			this.txt_gjc = new System.Windows.Forms.TextBox();
			this.txt_zs = new System.Windows.Forms.TextBox();
			this.txtID = new System.Windows.Forms.TextBox();
			this.label7 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.btn_cancel = new System.Windows.Forms.Button();
			this.btn_sure = new System.Windows.Forms.Button();
			this.label3 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.dataGrid1 = new System.Windows.Forms.DataGrid();
			this.toolBar3 = new System.Windows.Forms.ToolBar();
			this.tobtnupdata = new System.Windows.Forms.ToolBarButton();
			this.toolBarButton13 = new System.Windows.Forms.ToolBarButton();
			this.imageList1 = new System.Windows.Forms.ImageList(this.components);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
			this.SuspendLayout();
			// 
			// txt_lx
			// 
			this.txt_lx.Location = new System.Drawing.Point(456, 56);
			this.txt_lx.Name = "txt_lx";
			this.txt_lx.Size = new System.Drawing.Size(88, 21);
			this.txt_lx.TabIndex = 78;
			this.txt_lx.Text = "";
			// 
			// lbl_lx
			// 
			this.lbl_lx.Location = new System.Drawing.Point(368, 56);
			this.lbl_lx.Name = "lbl_lx";
			this.lbl_lx.Size = new System.Drawing.Size(80, 32);
			this.lbl_lx.TabIndex = 77;
			this.lbl_lx.Text = "书籍类型:";
			this.lbl_lx.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// txt_bz
			// 
			this.txt_bz.Location = new System.Drawing.Point(232, 136);
			this.txt_bz.Multiline = true;
			this.txt_bz.Name = "txt_bz";
			this.txt_bz.Size = new System.Drawing.Size(288, 104);
			this.txt_bz.TabIndex = 75;
			this.txt_bz.Text = "";
			// 
			// txt_gjc
			// 
			this.txt_gjc.Location = new System.Drawing.Point(456, 96);
			this.txt_gjc.Name = "txt_gjc";
			this.txt_gjc.Size = new System.Drawing.Size(88, 21);
			this.txt_gjc.TabIndex = 74;
			this.txt_gjc.Text = "";
			// 
			// txt_zs
			// 
			this.txt_zs.Location = new System.Drawing.Point(232, 96);
			this.txt_zs.Name = "txt_zs";
			this.txt_zs.Size = new System.Drawing.Size(112, 21);
			this.txt_zs.TabIndex = 73;
			this.txt_zs.Text = "";
			// 
			// txtID
			// 
			this.txtID.Location = new System.Drawing.Point(232, 56);
			this.txtID.Name = "txtID";
			this.txtID.Size = new System.Drawing.Size(112, 21);
			this.txtID.TabIndex = 69;
			this.txtID.Text = "";
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(184, 128);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(48, 32);
			this.label7.TabIndex = 72;
			this.label7.Text = "备注:";
			this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(376, 96);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(72, 23);
			this.label5.TabIndex = 71;
			this.label5.Text = "关键词:";
			this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// btn_cancel
			// 
			this.btn_cancel.Location = new System.Drawing.Point(448, 512);
			this.btn_cancel.Name = "btn_cancel";
			this.btn_cancel.Size = new System.Drawing.Size(72, 24);
			this.btn_cancel.TabIndex = 70;
			this.btn_cancel.Text = "取消(&C)";
			this.btn_cancel.TextAlign = System.Drawing.ContentAlignment.TopCenter;
			this.btn_cancel.Click += new System.EventHandler(this.btn_cancel_Click);
			// 
			// btn_sure
			// 
			this.btn_sure.Location = new System.Drawing.Point(272, 512);
			this.btn_sure.Name = "btn_sure";
			this.btn_sure.Size = new System.Drawing.Size(72, 23);
			this.btn_sure.TabIndex = 68;
			this.btn_sure.Text = "刷新";
			this.btn_sure.TextAlign = System.Drawing.ContentAlignment.TopCenter;
			this.btn_sure.Click += new System.EventHandler(this.btn_sure_Click);
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(152, 96);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(80, 24);
			this.label3.TabIndex = 67;
			this.label3.Text = "书籍总数:";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(120, 56);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(112, 24);
			this.label1.TabIndex = 66;
			this.label1.Text = "书籍编号:";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// dataGrid1
			// 
			this.dataGrid1.DataMember = "";
			this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGrid1.Location = new System.Drawing.Point(72, 248);
			this.dataGrid1.Name = "dataGrid1";
			this.dataGrid1.Size = new System.Drawing.Size(640, 232);
			this.dataGrid1.TabIndex = 79;
			this.dataGrid1.Click += new System.EventHandler(this.dataGrid1_Click);
			// 
			// toolBar3
			// 
			this.toolBar3.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
																						this.tobtnupdata,
																						this.toolBarButton13});
			this.toolBar3.DropDownArrows = true;
			this.toolBar3.ImageList = this.imageList1;
			this.toolBar3.Location = new System.Drawing.Point(0, 0);
			this.toolBar3.Name = "toolBar3";
			this.toolBar3.ShowToolTips = true;
			this.toolBar3.Size = new System.Drawing.Size(776, 41);
			this.toolBar3.TabIndex = 80;
			this.toolBar3.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar3_ButtonClick);
			// 
			// tobtnupdata
			// 
			this.tobtnupdata.ImageIndex = 1;
			this.tobtnupdata.Text = "修改";
			this.tobtnupdata.ToolTipText = "修改";
			// 
			// toolBarButton13
			// 
			this.toolBarButton13.ImageIndex = 2;
			this.toolBarButton13.Text = "保存";
			this.toolBarButton13.ToolTipText = "保存";
			// 
			// imageList1
			// 
			this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
			this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
			this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// updata_book
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackColor = System.Drawing.Color.Aquamarine;
			this.ClientSize = new System.Drawing.Size(776, 557);
			this.Controls.Add(this.toolBar3);
			this.Controls.Add(this.dataGrid1);
			this.Controls.Add(this.txt_lx);
			this.Controls.Add(this.txt_bz);
			this.Controls.Add(this.txt_gjc);
			this.Controls.Add(this.txt_zs);
			this.Controls.Add(this.txtID);
			this.Controls.Add(this.lbl_lx);
			this.Controls.Add(this.label7);
			this.Controls.Add(this.label5);
			this.Controls.Add(this.btn_cancel);
			this.Controls.Add(this.btn_sure);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.label1);
			this.ForeColor = System.Drawing.Color.Blue;
			this.Name = "updata_book";
			this.Text = "书籍信息修改界面";
			this.Load += new System.EventHandler(this.updata_book_Load);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void ClearFields()
		{
			this.txtID.Text="";
			this.txt_lx.Text="";
			this.txt_gjc.Text="";
			this.txt_zs.Text="";
			this.txt_bz.Text="";
			
			
		}
		private void toolBar3_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
		{
			if(e.Button.Text=="保存")
			{
				StreamReader sr=new StreamReader("ts.ini",System.Text.Encoding.Default);
				string sn=sr.ReadLine();	
				SqlConnection conn=new SqlConnection(sn);
				try
				{
					SqlCommand comm=new SqlCommand("update_sjxxb",conn);
					comm.CommandType=CommandType.StoredProcedure;	
					comm.Parameters.Add("@sjbh",(this.txtID.Text));
					comm.Parameters.Add("@sjlx",(this.txt_lx.Text));
					comm.Parameters.Add("@gjc",(this.txt_gjc.Text));
					comm.Parameters.Add("@sjzs",(this.txt_zs.Text));
					comm.Parameters.Add("@bz",(this.txt_bz.Text));
					conn.Open();
					comm.ExecuteNonQuery();
					ds.Tables["sjxxb"].Rows[this.dataGrid1.CurrentCell.RowNumber][2]=(this.txt_gjc.Text);
					ds.Tables["sjxxb"].Rows[this.dataGrid1.CurrentCell.RowNumber][1]=(this.txt_lx.Text);
					MessageBox.Show("已经成功更新");
					ClearFields();
				}
				catch(SqlException ex)
				{
					MessageBox.Show(ex.Message);
				}
				finally
				{
					conn.Close();
				}

			}
			
		
			if(e.Button.Text=="修改")
			{	
				
				this.txt_gjc.ReadOnly=false;
				this.txt_lx.ReadOnly=false;
				this.txt_zs.ReadOnly=false;
				this.txt_bz.ReadOnly=false;
				this.txtID.Focus();	
				StreamReader sr=new StreamReader("ts.ini",System.Text.Encoding.Default);
				string sn=sr.ReadLine();	
				SqlConnection conn=new SqlConnection(sn);
			
				SqlCommand comm=new SqlCommand("update_sjxxb",conn);
				comm.CommandType=CommandType.StoredProcedure;	
				comm.Parameters.Add("@sjbh",(this.txtID.Text));
				comm.Parameters.Add("@sjlx",(this.txt_lx.Text));
				comm.Parameters.Add("@gjc",(this.txt_gjc.Text));
				comm.Parameters.Add("@sjzs",(this.txt_zs.Text));
				comm.Parameters.Add("@bz",(this.txt_bz.Text));
				
				
			}
		}
		private void SetModifyMode()
		{
			this.txtID.ReadOnly=true;
			this.txt_gjc.ReadOnly=true;
			this.txt_lx.ReadOnly=true;
			this.txt_zs.ReadOnly=true;
			this.txt_bz.ReadOnly=true;
		}

		private void updata_book_Load(object sender, System.EventArgs e)
		{
			StreamReader sr=new StreamReader("ts.ini",System.Text.Encoding.Default);
			string sn=sr.ReadLine();	
			SqlConnection conn=new SqlConnection(sn);	
			string  sql="select * from sjxxb "; 
			SqlDataAdapter da=new SqlDataAdapter(sql,conn);
			ds=new DataSet();
			da.Fill(ds,"sjxxb");
			this.dataGrid1.DataSource=ds.Tables["sjxxb"].DefaultView;
			SetModifyMode();
		}

		private void dataGrid1_Click(object sender, System.EventArgs e)
		{
			int curRow=this.dataGrid1.CurrentCell.RowNumber;
			this.txtID.Text=this.dataGrid1[this.dataGrid1.CurrentRowIndex,0].ToString();
			this.txt_lx.Text=this.dataGrid1[this.dataGrid1.CurrentCell.RowNumber,1].ToString();
			this.txt_gjc.Text=this.dataGrid1[this.dataGrid1.CurrentCell.RowNumber,2].ToString();
			this.txt_zs.Text=this.dataGrid1[this.dataGrid1.CurrentCell.RowNumber,3].ToString();
			this.txt_bz.Text=this.dataGrid1[this.dataGrid1.CurrentCell.RowNumber,4].ToString();
		}

		private void btn_sure_Click(object sender, System.EventArgs e)
		{
			StreamReader sr=new StreamReader("ts.ini",System.Text.Encoding.Default);
			string sn=sr.ReadLine();	
			SqlConnection conn=new SqlConnection(sn);	
			SqlDataAdapter da=new SqlDataAdapter("select * from sjxxb",conn);
			DataSet ds=new DataSet();
			da.Fill(ds,"sjxxb");
			this.dataGrid1.SetDataBinding(ds,"sjxxb");
		}

		private void btn_cancel_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}
		
	}
}

⌨️ 快捷键说明

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