完整的基于泛形、SOA设计思想的.net 框架 CS客户端(七)之三,这个生成的代码改动最小,只删除了一个控件,改变了一下文本框的位置与大小。 namespace Unie2e.Yuking.Forms { using System; using System.Collections.Generic; using System.Text; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Windows.Forms; using Unie2e.Common.Configuration; using Unie2e.Common.Model; using Unie2e.Common; using Unie2e.Win; using Unie2e.Yuking.SDO; using Unie2e.Yuking.Proxy; [E2EFormAttribute("CurrencySDO")] public partial class CurrencySDODLForm : E2EForm { 提示#region 提示 private const string E_NONEINIT = "请先赋值或新建"; private const string S_SAVEOK = "保存成功"; private const string S_DELETEOK = "删除成功"; private const string E_NONECHANGE = "数据没有改变"; private const string E_NONEDATA = "请选择数据"; private const string S_LOADED = "数据加载完毕"; #endregion 绑定控件#region 绑定控件 private Label LB_CurrencyName; private TextBox TB_CurrencyName; private Label LB_CurrencyComment; private TextBox TB_CurrencyComment; #endregion 基本控件#region 基本控件 private System.ComponentModel.IContainer components = null; private TableLayoutPanel tableLayoutPanel; private Panel panel; private ToolStripContainer toolStripContainer; private UserToolStrip userToolStrip; private DataGridView dataGridView; private GridViewExtender gridViewExtender; private BindingSource bindingSource; #endregion private DataGridViewTextBoxColumn currencyIdDataGridViewTextBoxColumn; private DataGridViewTextBoxColumn currencyNameDataGridViewTextBoxColumn; private DataGridViewTextBoxColumn currencyCommentDataGridViewTextBoxColumn; private DataGridViewTextBoxColumn ownerDataGridViewTextBoxColumn; private CurrencyServiceSO currencyServiceSO; public CurrencySDODLForm() { this.InitializeComponent(); this.BindStrip(); this.BindData(); this.BindExtender(); this.BindCreateNew(); // 绑定数据错误不提示 this.dataGridView.DataError += delegate(object sender, DataGridViewDataErrorEventArgs e) { }; } 输入参数Input#region 输入参数Input public DataCollection<CurrencySDO> Input { get { if (!(this.bindingSource.DataSource is DataCollection<CurrencySDO>)) { bindingSource.DataSource = new DataCollection<CurrencySDO>(); } return ((DataCollection<CurrencySDO>)(bindingSource.DataSource)); } set { if (!(value is DataCollection<CurrencySDO>)) { value = new DataCollection<CurrencySDO>(); } bindingSource.DataSource = value; } } #endregion public event EventHandler<E2ETEventArgs<DataCollection<Unie2e.Yuking.SDO.CurrencySDO>>> OnSavedBatch; public event EventHandler<E2ETEventArgs<DataCollection<Unie2e.Yuking.SDO.CurrencySDO>>> OnDataLoad; public event EventHandler<E2ETEventArgs<Unie2e.Yuking.SDO.CurrencySDO>> OnCreated; public event EventHandler<E2ETEventArgs<Unie2e.Yuking.SDO.CurrencySDO>> OnDeleted; 初始化#region 初始化 protected override void Dispose(bool disposing) { if ((disposing == true)) { if ((components != null)) { components.Dispose(); } } base.Dispose(disposing); } private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.toolStripContainer = new System.Windows.Forms.ToolStripContainer(); this.tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); this.panel = new System.Windows.Forms.Panel(); this.LB_CurrencyName = new System.Windows.Forms.Label(); this.TB_CurrencyName = new System.Windows.Forms.TextBox(); this.LB_CurrencyComment = new System.Windows.Forms.Label(); this.TB_CurrencyComment = new System.Windows.Forms.TextBox(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.currencyIdDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.currencyNameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.currencyCommentDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.bindingSource = new System.Windows.Forms.BindingSource(this.components); this.userToolStrip = new Unie2e.Win.UserToolStrip(); this.toolStripContainer.ContentPanel.SuspendLayout(); this.toolStripContainer.TopToolStripPanel.SuspendLayout(); this.toolStripContainer.SuspendLayout(); this.tableLayoutPanel.SuspendLayout(); this.panel.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.bindingSource)).BeginInit(); this.SuspendLayout(); // // toolStripContainer // this.toolStripContainer.BottomToolStripPanelVisible = false; // // toolStripContainer.ContentPanel // this.toolStripContainer.ContentPanel.Controls.Add(this.tableLayoutPanel); this.toolStripContainer.ContentPanel.Size = new System.Drawing.Size(792, 548); this.toolStripContainer.Dock = System.Windows.Forms.DockStyle.Fill; this.toolStripContainer.LeftToolStripPanelVisible = false; this.toolStripContainer.Location = new System.Drawing.Point(0, 0); this.toolStripContainer.Name = "toolStripContainer"; this.toolStripContainer.RightToolStripPanelVisible = false; this.toolStripContainer.Size = new System.Drawing.Size(792, 573); this.toolStripContainer.TabIndex = 0; this.toolStripContainer.Text = "toolStripContainer"; // // toolStripContainer.TopToolStripPanel // this.toolStripContainer.TopToolStripPanel.Controls.Add(this.userToolStrip); // // tableLayoutPanel // this.tableLayoutPanel.ColumnCount = 1; this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel.Controls.Add(this.panel, 0, 0); this.tableLayoutPanel.Controls.Add(this.dataGridView, 0, 1); this.tableLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill; this.tableLayoutPanel.Location = new System.Drawing.Point(0, 0); this.tableLayoutPanel.Name = "tableLayoutPanel"; this.tableLayoutPanel.RowCount = 2; this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 38.68613F)); this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 61.31387F)); this.tableLayoutPanel.Size = new System.Drawing.Size(792, 548); this.tableLayoutPanel.TabIndex = 0; // // panel // this.panel.Controls.Add(this.LB_CurrencyName); this.panel.Controls.Add(this.TB_CurrencyName); this.panel.Controls.Add(this.LB_CurrencyComment); this.panel.Controls.Add(this.TB_CurrencyComment); this.panel.Dock = System.Windows.Forms.DockStyle.Fill; this.panel.Location = new System.Drawing.Point(3, 3); this.panel.Name = "panel"; this.panel.Size = new System.Drawing.Size(786, 205); this.panel.TabIndex = 0; // // LB_CurrencyName // this.LB_CurrencyName.AutoSize = true; this.LB_CurrencyName.Location = new System.Drawing.Point(20, 15); this.LB_CurrencyName.Name = "LB_CurrencyName"; this.LB_CurrencyName.Size = new System.Drawing.Size(29, 12); this.LB_CurrencyName.TabIndex = 2; this.LB_CurrencyName.Text = "币种"; // // TB_CurrencyName // this.TB_CurrencyName.Location = new System.Drawing.Point(82, 11); this.TB_CurrencyName.Name = "TB_CurrencyName"; this.TB_CurrencyName.Size = new System.Drawing.Size(110, 21); this.TB_CurrencyName.TabIndex = 3; // // LB_CurrencyComment // this.LB_CurrencyComment.AutoSize = true; this.LB_CurrencyComment.Location = new System.Drawing.Point(20, 56); this.LB_CurrencyComment.Name = "LB_CurrencyComment"; this.LB_CurrencyComment.Size = new System.Drawing.Size(29, 12); this.LB_CurrencyComment.TabIndex = 4; this.LB_CurrencyComment.Text = "备注"; // // TB_CurrencyComment // this.TB_CurrencyComment.Location = new System.Drawing.Point(82, 52); this.TB_CurrencyComment.Multiline = true; this.TB_CurrencyComment.Name = "TB_CurrencyComment"; this.TB_CurrencyComment.Size = new System.Drawing.Size(462, 102); this.TB_CurrencyComment.TabIndex = 5; // // dataGridView // this.dataGridView.AllowUserToOrderColumns = true; this.dataGridView.AutoGenerateColumns = false; this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.currencyIdDataGridViewTextBoxColumn, this.currencyNameDataGridViewTextBoxColumn, this.currencyCommentDataGridViewTextBoxColumn}); this.dataGridView.DataSource = this.bindingSource; this.dataGridView.Dock = System.Windows.Forms.DockStyle.Fill; this.dataGridView.Location = new System.Drawing.Point(3, 214); this.dataGridView.Name = "dataGridView"; this.dataGridView.RowTemplate.Height = 23; this.dataGridView.Size = new System.Drawing.Size(786, 331); this.dataGridView.TabIndex = 1; // // currencyIdDataGridViewTextBoxColumn // this.currencyIdDataGridViewTextBoxColumn.DataPropertyName = "CurrencyId"; this.currencyIdDataGridViewTextBoxColumn.HeaderText = "CurrencyId"; this.currencyIdDataGridViewTextBoxColumn.Name = "currencyIdDataGridViewTextBoxColumn"; // // currencyNameDataGridViewTextBoxColumn // this.currencyNameDataGridViewTextBoxColumn.DataPropertyName = "CurrencyName"; this.currencyNameDataGridViewTextBoxColumn.HeaderText = "CurrencyName"; this.currencyNameDataGridViewTextBoxColumn.Name = "currencyNameDataGridViewTextBoxColumn"; // // currencyCommentDataGridViewTextBoxColumn // this.currencyCommentDataGridViewTextBoxColumn.DataPropertyName = "CurrencyComment"; this.currencyCommentDataGridViewTextBoxColumn.HeaderText = "CurrencyComment"; this.currencyCommentDataGridViewTextBoxColumn.Name = "currencyCommentDataGridViewTextBoxColumn"; // // bindingSource // this.bindingSource.DataSource = typeof(Unie2e.Yuking.SDO.CurrencySDO); // // userToolStrip // this.userToolStrip.Dock = System.Windows.Forms.DockStyle.None; this.userToolStrip.EnabledCancel = true; this.userToolStrip.EnabledClose = true; this.userToolStrip.EnabledDelete = true; this.userToolStrip.EnabledLoad = true; this.userToolStrip.EnabledNew = true; this.userToolStrip.EnabledSave = true; this.userToolStrip.EnabledView = true; this.userToolStrip.Location = new System.Drawing.Point(3, 0); this.userToolStrip.Name = "userToolStrip"; this.userToolStrip.Size = new System.Drawing.Size(241, 25); this.userToolStrip.TabIndex = 0; this.userToolStrip.VisibleCancel = true; this.userToolStrip.VisibleClose = true; this.userToolStrip.VisibleDelete = true; this.userToolStrip.VisibleLoad = true; this.userToolStrip.VisibleNew = true; this.userToolStrip.VisibleSave = true; this.userToolStrip.VisibleView = true; // // CurrencySDODLForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(792, 573); this.Controls.Add(this.toolStripContainer); this.Name = "CurrencySDODLForm"; this.Load += new System.EventHandler(this.CurrencySDODLForm_Load); this.toolStripContainer.ContentPanel.ResumeLayout(false); this.toolStripContainer.TopToolStripPanel.ResumeLayout(false); this.toolStripContainer.TopToolStripPanel.PerformLayout(); this.toolStripContainer.ResumeLayout(false); this.toolStripContainer.PerformLayout(); this.tableLayoutPanel.ResumeLayout(false); this.panel.ResumeLayout(false); this.panel.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.bindingSource)).EndInit(); this.ResumeLayout(false); } #endregion 数据绑定#region 数据绑定 // 数据绑定 private void BindData() { // 请在上面添加额外的绑定数据源 gridViewExtender = new GridViewExtender(this.dataGridView); //this.TB_CurrencyId.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.bindingSource, "CurrencyId", true)); this.TB_CurrencyName.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.bindingSource, "CurrencyName", true)); this.TB_CurrencyComment.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.bindingSource, "CurrencyComment", true)); // 上面为控件绑定 gridViewExtender.CfgFileName ="CurrencySDO.xml"; gridViewExtender.BindColumn(); } void BindStrip() { userToolStrip.OnCancel+=DataCancel; userToolStrip.OnClose+=delegate(object sender, EventArgs e) { this.Close(); }; userToolStrip.OnCreateNew+=DataCreateNew; userToolStrip.OnLoad+=DataLoad; userToolStrip.OnSave+=DataSave; userToolStrip.OnDelete+=DataDelete; userToolStrip.VisibleView = false; } private void BindExtender() { } private void BindCreateNew() { DataCollection<CurrencySDO> source = this.Input; source.AddingNew += DataCreateNew; source.AddingNewBefore += AddingNewBefore; } #endregion private CurrencyServiceSO getProxy() { if ((currencyServiceSO == null)) { currencyServiceSO = new CurrencyServiceSO(); } return currencyServiceSO; } 基本操作#region 基本操作 // 新建对象 private void DataCreateNew(object sender, System.ComponentModel.AddingNewEventArgs e) { CurrencySDO data = CurrencySDO.CreateNew(); data.BeginInit(); // 更多的初始化 // 结束初始化 data.EndInit(); e.NewObject = data; if ((this.OnCreated != null)) { this.OnCreated(this, new E2ETEventArgs<CurrencySDO>(data)); } } private CurrencySDO AddingNewBefore() { return ((CurrencySDO)(this.bindingSource.AddNew())); } private void DataCreateNew(object sender, System.EventArgs e) { this.DataCreateNew(); } // 新建并显示明细 private void DataCreateNew() { DataCollection<CurrencySDO> source = this.Input; CurrencySDO data = source.AddNew(); } // 加载数据,这儿要根据实现的情况进行更改 private void DataLoad() { DataCollection<CurrencySDO> source = this.Input; try { DataCollection<CurrencySDO> rlt = this.getProxy().FindByAll(); source.Load(rlt); if ((OnDataLoad != null)) { this.OnDataLoad(this, new E2ETEventArgs<DataCollection<CurrencySDO>>(rlt)); } //MessageBox.Show(S_LOADED); } catch (E2EException ex) { MessageBox.Show(ex.Message); } catch (Exception ex) { MessageBox.Show(ex.Message); } } // 加载数据 private void DataLoad(object sender, System.EventArgs e) { this.DataLoad(); } private void DataSave() { this.Validate(); DataCollection<CurrencySDO> source = this.Input; DataCollection<CurrencySDO> collection = source.GetChanges(); if ((collection.Count == 0)) { MessageBox.Show(E_NONECHANGE); return; } try { DataCollection<CurrencySDO> rlt = this.getProxy().SavedBatch(collection); source.Merage(rlt); source.AcceptChange(); if ((OnSavedBatch != null)) { this.OnSavedBatch(this, new E2ETEventArgs<DataCollection<CurrencySDO>>(rlt)); } MessageBox.Show(S_SAVEOK); } catch (E2EException ex) { MessageBox.Show(ex.Message); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void DataSave(object sender, System.EventArgs e) { this.DataSave(); } private void DataDelete() { this.Validate(); CurrencySDO data = this.bindingSource.Current as CurrencySDO; if (data is CurrencySDO) { if (data.IsCreated()) { data.DirectDelete(); } else { try { CurrencySDO rlt = getProxy().Deleted(data); MessageBox.Show(S_DELETEOK); if ((OnDeleted != null)) { this.OnDeleted(this, new E2ETEventArgs<CurrencySDO>(data)); } data.DirectDelete(); } catch (E2EException ex) { MessageBox.Show(ex.Message); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } else { MessageBox.Show(E_NONEDATA); } } private void DataDelete(object sender, System.EventArgs e) { this.DataDelete(); } private void DataCancel() { this.Validate(); DataCollection<CurrencySDO> source = this.Input; source.RejectChange(); } private void DataCancel(object sender, System.EventArgs e) { this.DataCancel(); } #endregion private void CurrencySDODLForm_Load(object sender, EventArgs e) { DataLoad(); } }}