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

📄 editing.cs

📁 东软内部材料(六)ado .net相关
💻 CS
📖 第 1 页 / 共 2 页
字号:
			this.btnFirst.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnFirst.Location = new System.Drawing.Point(8, 272);
			this.btnFirst.Name = "btnFirst";
			this.btnFirst.Size = new System.Drawing.Size(32, 23);
			this.btnFirst.TabIndex = 7;
			this.btnFirst.Text = "<<";
			this.btnFirst.Click += new System.EventHandler(this.btnFirst_Click);
			// 
			// btnPrevious
			// 
			this.btnPrevious.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnPrevious.Location = new System.Drawing.Point(48, 272);
			this.btnPrevious.Name = "btnPrevious";
			this.btnPrevious.Size = new System.Drawing.Size(32, 23);
			this.btnPrevious.TabIndex = 8;
			this.btnPrevious.Text = "<";
			this.btnPrevious.Click += new System.EventHandler(this.btnPrevious_Click);
			// 
			// btnNext
			// 
			this.btnNext.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnNext.Location = new System.Drawing.Point(264, 272);
			this.btnNext.Name = "btnNext";
			this.btnNext.Size = new System.Drawing.Size(32, 23);
			this.btnNext.TabIndex = 9;
			this.btnNext.Text = ">";
			this.btnNext.Click += new System.EventHandler(this.btnNext_Click);
			// 
			// btnLast
			// 
			this.btnLast.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnLast.Location = new System.Drawing.Point(304, 272);
			this.btnLast.Name = "btnLast";
			this.btnLast.Size = new System.Drawing.Size(32, 23);
			this.btnLast.TabIndex = 10;
			this.btnLast.Text = ">>";
			this.btnLast.Click += new System.EventHandler(this.btnLast_Click);
			// 
			// txtPosition
			// 
			this.txtPosition.Location = new System.Drawing.Point(88, 272);
			this.txtPosition.Name = "txtPosition";
			this.txtPosition.Size = new System.Drawing.Size(168, 20);
			this.txtPosition.TabIndex = 11;
			this.txtPosition.Text = "Position";
			// 
			// btnSave
			// 
			this.btnSave.Location = new System.Drawing.Point(360, 6);
			this.btnSave.Name = "btnSave";
			this.btnSave.TabIndex = 12;
			this.btnSave.Text = "Save";
			this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
			// 
			// btnAdd
			// 
			this.btnAdd.Location = new System.Drawing.Point(360, 36);
			this.btnAdd.Name = "btnAdd";
			this.btnAdd.TabIndex = 13;
			this.btnAdd.Text = "Add";
			// 
			// btnDelete
			// 
			this.btnDelete.Location = new System.Drawing.Point(360, 66);
			this.btnDelete.Name = "btnDelete";
			this.btnDelete.TabIndex = 14;
			this.btnDelete.Text = "Delete";
			// 
			// btnEdit
			// 
			this.btnEdit.Location = new System.Drawing.Point(360, 96);
			this.btnEdit.Name = "btnEdit";
			this.btnEdit.TabIndex = 15;
			this.btnEdit.Text = "Edit";
			// 
			// btnDefer
			// 
			this.btnDefer.Location = new System.Drawing.Point(360, 126);
			this.btnDefer.Name = "btnDefer";
			this.btnDefer.TabIndex = 16;
			this.btnDefer.Text = "Defer";
			// 
			// btnUpdate
			// 
			this.btnUpdate.Location = new System.Drawing.Point(360, 156);
			this.btnUpdate.Name = "btnUpdate";
			this.btnUpdate.TabIndex = 17;
			this.btnUpdate.Text = "Update";
			// 
			// btnCmd
			// 
			this.btnCmd.Location = new System.Drawing.Point(360, 186);
			this.btnCmd.Name = "btnCmd";
			this.btnCmd.TabIndex = 18;
			this.btnCmd.Text = "Command";
			// 
			// btnFill
			// 
			this.btnFill.Location = new System.Drawing.Point(360, 216);
			this.btnFill.Name = "btnFill";
			this.btnFill.TabIndex = 19;
			this.btnFill.Text = "Fill";
			// 
			// btnAccept
			// 
			this.btnAccept.Location = new System.Drawing.Point(360, 246);
			this.btnAccept.Name = "btnAccept";
			this.btnAccept.TabIndex = 20;
			this.btnAccept.Text = "Accept";
			this.btnAccept.Click += new System.EventHandler(this.btnAccept_Click);
			// 
			// btnReject
			// 
			this.btnReject.Location = new System.Drawing.Point(360, 276);
			this.btnReject.Name = "btnReject";
			this.btnReject.TabIndex = 21;
			this.btnReject.Text = "Reject";
			// 
			// daEmployeeList
			// 
			this.daEmployeeList.DeleteCommand = this.cmdDeleteEmployees;
			this.daEmployeeList.InsertCommand = this.cmdInsertEmployees;
			this.daEmployeeList.SelectCommand = this.cmdSelectEmployees;
			this.daEmployeeList.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
																									 new System.Data.Common.DataTableMapping("Table", "Employees", new System.Data.Common.DataColumnMapping[] {
																																																				  new System.Data.Common.DataColumnMapping("EmployeeID", "EmployeeID"),
																																																				  new System.Data.Common.DataColumnMapping("FirstName", "FirstName"),
																																																				  new System.Data.Common.DataColumnMapping("LastName", "LastName")})});
			this.daEmployeeList.UpdateCommand = this.cmdUpdateEmployees;
			// 
			// cmdDeleteEmployees
			// 
			this.cmdDeleteEmployees.CommandText = "DELETE FROM Employees WHERE (EmployeeID = @Original_EmployeeID) AND (FirstName = " +
				"@Original_FirstName) AND (LastName = @Original_LastName)";
			this.cmdDeleteEmployees.Connection = this.cnNorthwind;
			this.cmdDeleteEmployees.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_EmployeeID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "EmployeeID", System.Data.DataRowVersion.Original, null));
			this.cmdDeleteEmployees.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_FirstName", System.Data.SqlDbType.NVarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "FirstName", System.Data.DataRowVersion.Original, null));
			this.cmdDeleteEmployees.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_LastName", System.Data.SqlDbType.NVarChar, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "LastName", System.Data.DataRowVersion.Original, null));
			// 
			// cnNorthwind
			// 
			this.cnNorthwind.ConnectionString = "data source=localhost;initial catalog=nwind;integrated security=SSPI;persist " +
				"security info=False;packet size=4096";
			// 
			// cmdInsertEmployees
			// 
			this.cmdInsertEmployees.CommandText = "INSERT INTO Employees(FirstName, LastName) VALUES (@FirstName, @LastName); SELECT" +
				" EmployeeID, FirstName, LastName FROM Employees WHERE (EmployeeID = @@IDENTITY) " +
				"ORDER BY LastName";
			this.cmdInsertEmployees.Connection = this.cnNorthwind;
			this.cmdInsertEmployees.Parameters.Add(new System.Data.SqlClient.SqlParameter("@FirstName", System.Data.SqlDbType.NVarChar, 10, "FirstName"));
			this.cmdInsertEmployees.Parameters.Add(new System.Data.SqlClient.SqlParameter("@LastName", System.Data.SqlDbType.NVarChar, 20, "LastName"));
			// 
			// cmdSelectEmployees
			// 
			this.cmdSelectEmployees.CommandText = "SELECT EmployeeID, FirstName, LastName FROM Employees ORDER BY LastName";
			this.cmdSelectEmployees.Connection = this.cnNorthwind;
			// 
			// cmdUpdateEmployees
			// 
			this.cmdUpdateEmployees.CommandText = "UPDATE Employees SET FirstName = @first, LastName = @last WHERE (EmployeeID = @em" +
				"pID)";
			this.cmdUpdateEmployees.Connection = this.cnNorthwind;
			this.cmdUpdateEmployees.Parameters.Add(new System.Data.SqlClient.SqlParameter("@first", System.Data.SqlDbType.NVarChar, 10, "FirstName"));
			this.cmdUpdateEmployees.Parameters.Add(new System.Data.SqlClient.SqlParameter("@last", System.Data.SqlDbType.NVarChar, 20, "LastName"));
			this.cmdUpdateEmployees.Parameters.Add(new System.Data.SqlClient.SqlParameter("@empID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "EmployeeID", System.Data.DataRowVersion.Original, null));
			// 
			// frmEditing
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(442, 303);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.btnReject,
																		  this.btnAccept,
																		  this.btnFill,
																		  this.btnCmd,
																		  this.btnUpdate,
																		  this.btnDefer,
																		  this.btnEdit,
																		  this.btnDelete,
																		  this.btnAdd,
																		  this.btnSave,
																		  this.txtPosition,
																		  this.btnLast,
																		  this.btnNext,
																		  this.btnPrevious,
																		  this.btnFirst,
																		  this.groupBox1,
																		  this.txtWorkingLastName,
																		  this.txtWorkingFirstName,
																		  this.txtWorkingID,
																		  this.label3,
																		  this.label2,
																		  this.label1});
			this.Name = "frmEditing";
			this.Text = "Editing";
			((System.ComponentModel.ISupportInitialize)(this.dsEmployeeList1)).EndInit();
			this.groupBox1.ResumeLayout(false);
			this.gbRowStatus.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new frmEditing());
		}

		
		#region Navigation Buttons
		private void btnFirst_Click(object sender, System.EventArgs e)
		{
			this.BindingContext[this.dsEmployeeList1, "Employees"].Position = 0;

		}

		private void btnPrevious_Click(object sender, System.EventArgs e)
		{
			System.Windows.Forms.CurrencyManager bc;

			bc = (CurrencyManager) this.BindingContext[this.dsEmployeeList1, "Employees"];
			bc.Position -= 1;
			UpdateDisplay();
		}

		private void btnNext_Click(object sender, System.EventArgs e)
		{
			System.Windows.Forms.CurrencyManager bc;

			bc = (CurrencyManager) this.BindingContext[this.dsEmployeeList1, "Employees"];
			bc.Position += 1;
			UpdateDisplay();
		}

		private void btnLast_Click(object sender, System.EventArgs e)
		{
			System.Windows.Forms.CurrencyManager bc;

			bc = (CurrencyManager) this.BindingContext[this.dsEmployeeList1, "Employees"];
			bc.Position = bc.Count - 1;
			UpdateDisplay();
		}
		#endregion

		#region Utility Functions

		private void btnSave_Click(object sender, System.EventArgs e)
		{
			BindingManagerBase bm;
			DataRowView drv;

			bm = this.BindingContext[this.dsEmployeeList1, "Employees"];
			drv = (DataRowView) bm.Current;
			drv.EndEdit();
			UpdateDisplay();			
		}


		private void UpdateDisplay()
		{
			//display original values
			DataRow drv;
			drv = this.dsEmployeeList1.Employees.Rows[this.BindingContext[this.dsEmployeeList1, "Employees"].Position];

			this.txtCurrentID.Text = drv["EmployeeID"].ToString();
			this.txtCurrentFirstName.Text = drv["FirstName"].ToString();
			this.txtCurrentLastName.Text = drv["LastName"].ToString();

			if (drv.HasVersion(DataRowVersion.Original)) 
			{
				this.txtOriginalID.Text = drv["EmployeeID", DataRowVersion.Original].ToString();
				this.txtOriginalFirstName.Text = drv["FirstName", DataRowVersion.Original].ToString();
				this.txtOriginalLastName.Text = drv["LastName", DataRowVersion.Original].ToString();
			}
			else
			{
				this.txtOriginalID.Text = "";
				this.txtOriginalFirstName.Text = "";
				this.txtOriginalLastName.Text = "";
			}

			switch (drv.RowState)
			{
				case DataRowState.Added:
					this.rbNew.Checked = true;
					break;
				case DataRowState.Modified:
					this.rbChanged.Checked = true;
					break;
				case DataRowState.Unchanged:
					this.rbUnchanged.Checked = true;				
					break;
			}

			this.txtPosition.Text = "Employee " + 
				(this.BindingContext[this.dsEmployeeList1, "Employees"].Position + 1).ToString() +
				" of " + this.BindingContext[this.dsEmployeeList1, "Employees"].Count.ToString();
		}


		private System.Data.DataRow GetRow() 
		{
			System.Windows.Forms.BindingManagerBase bm;
			System.Data.DataRowView drv;

			bm = this.BindingContext[this.dsEmployeeList1, "Employees"];
			drv = (System.Data.DataRowView) bm.Current;
			return drv.Row;
		}


		private void btnAccept_Click(object sender, System.EventArgs e)
		{
			this.dsEmployeeList1.AcceptChanges();
			UpdateDisplay();
		}

		#endregion

	}

}

⌨️ 快捷键说明

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