• bindingSource具体使用案例


    界面如下:

    using DevExpress.XtraBars.Docking; using DevExpress.XtraEditors; using NewPwrDY.DBEntity; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;

    namespace NewPwrDY {     public partial class Frm_WorkOrder : XtraForm     {         public Frm_WorkOrder()         {             InitializeComponent();             this.bindingSource.DataSource = this._WorkOrderList;             this.gridView.OptionsBehavior.Editable = false;             this.gridView.OptionsView.ColumnAutoWidth = true;             this.gridView.OptionsView.ShowColumnHeaders = true;             this.gridView.OptionsView.ColumnHeaderAutoHeight = DevExpress.Utils.DefaultBoolean.True;         }

            List<mes_work_order> _WorkOrderList = new List<mes_work_order>();

            protected override void OnShown(EventArgs e)         {             base.OnShown(e);             this.dockPanel.Dock = DockingStyle.Float;             int x = 500;             int y = 250;             Point p = new Point(x, y);             this.dockPanel.FloatLocation = p;         }

            private void Frm_WorkOrder_Load(object sender, EventArgs e)         {             this.backgroundWorker.RunWorkerAsync();         }

            private void tsmiSearch_Click(object sender, EventArgs e)         {             this.gridView.ShowFindPanel();         }

            private void tsmiAdd_Click(object sender, EventArgs e)         {             if (this.dockPanel.Visibility == DockVisibility.Hidden)             {                 this.dockPanel.Show();             }             MessageBox.Show("新增", "提示:");         }

            private void tsmiDelete_Click(object sender, EventArgs e)         {             MessageBox.Show("删除", "提示:");         }

            private void tsmiEdit_Click(object sender, EventArgs e)         {             MessageBox.Show("编辑", "提示:");         }

            private void tsmiSave_Click(object sender, EventArgs e)         {             MessageBox.Show("保存", "提示:");         }

            private void tsmiCancel_Click(object sender, EventArgs e)         {             MessageBox.Show("取消", "提示:");         }

            private void btnSave_Click(object sender, EventArgs e)         {             List<mes_work_order> WorkOrderList = this._WorkOrderList;             MessageBox.Show("保存", "提示:");         }

            private void btnCancel_Click(object sender, EventArgs e)         {             MessageBox.Show("取消", "提示:");         }

            private void gridView_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)         {             if (e.Clicks == 2 && this.dockPanel.Visibility == DockVisibility.Hidden)             {                 this.dockPanel.Show();             }         }

            private void dockPanel_DockChanged(object sender, EventArgs e)         {             if (dockPanel.Dock.Equals(DockingStyle.Float))             {                 this.dockPanel.FloatForm.MinimumSize = new Size(623, 401);             }         }

            private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)         {             //DB_DYFDEntities _DbContext = new DB_DYFDEntities();             //Dictionary<string, object> dic = new Dictionary<string, object>();             //dic.Add(nameof(mes_work_order), _DbContext.mes_work_order.ToList());             //e.Result = dic;         }

            private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)         {             if (this.IsDisposed || e.Cancelled || e.Error != null)             {                 return;             }             //Dictionary<string, object> dic = e.Result as Dictionary<string, object>;             //if (dic != null)             //{             //    this._WorkOrderList = dic[nameof(mes_work_order)] as List<mes_work_order>;             //}

                mes_work_order wo;             for (int i = 0; i < 60; i++)             {                 wo = new mes_work_order();                 wo.WorkOrderNo = DateTime.Now.ToString("yyyyMMddHHmmss")+i.ToString();                 wo.Seq = i;                 wo.ProductName = "产品" + (i + 1).ToString();                 wo.ProductSpec = "规格" + (i + 1).ToString(); ;                 wo.Qty = i + 1;                 wo.FinishQty = i;                 wo.WorkDate = DateTime.Now;                 this._WorkOrderList.Add(wo);

                }             this.bindingSource.DataSource = this._WorkOrderList;             //不加下面这句话,bindingSource的Position始终未-1             this.bindingSource.ResetBindings(false);             this.gridView.RefreshData();         }

            private void bindingSource_CurrentChanged(object sender, EventArgs e)         {             mes_work_order mes_work_order=  this.bindingSource.Current as mes_work_order;

                this.tbxWorkOrderNo.DataBindings.Clear();             this.tbxWorkOrderNo.DataBindings.Add(nameof(tbxWorkOrderNo.Text), mes_work_order, nameof(mes_work_order.WorkOrderNo));

                this.tbxSeq.DataBindings.Clear();             this.tbxSeq.DataBindings.Add(nameof(tbxSeq.Text), mes_work_order, nameof(mes_work_order.Seq));

                this.tbxProductName.DataBindings.Clear();             this.tbxProductName.DataBindings.Add(nameof(tbxProductName.Text), mes_work_order, nameof(mes_work_order.ProductName));

                this.tbxProductSpec.DataBindings.Clear();             this.tbxProductSpec.DataBindings.Add(nameof(tbxProductSpec.Text), mes_work_order, nameof(mes_work_order.ProductSpec));

                this.tbxQty.DataBindings.Clear();             this.tbxQty.DataBindings.Add(nameof(tbxQty.Text), mes_work_order, nameof(mes_work_order.Qty));

                this.tbxFinishQty.DataBindings.Clear();             this.tbxFinishQty.DataBindings.Add(nameof(tbxFinishQty.Text), mes_work_order, nameof(mes_work_order.FinishQty));

                this.dpiWorkDate.DataBindings.Clear();             this.dpiWorkDate.DataBindings.Add(nameof(dpiWorkDate.Value), mes_work_order, nameof(mes_work_order.WorkDate));

                this.tbxWorkOrderNo.DataBindings.Clear();             this.tbxWorkOrderNo.DataBindings.Add(nameof(tbxWorkOrderNo.Text), mes_work_order, nameof(mes_work_order.WorkOrderNo));

            }     } }

  • 相关阅读:
    android ndk通过遍历和删除文件
    SVN提交忽略*.class、.classpath、.mymetadata、.project、.settings、.myeclipse和其他非版本控制文件
    JDBC加载过程
    JVMTI 中间JNI系列功能,线程安全和故障排除技巧
    【Python】Python与文本处理langid工具包的文本语言检测和歧视
    SQL 存储过程 分页
    Android:仿手机QQ朋友动态ListView
    再说Java EE
    辛星与您解读PHP页面跳转的几种实现方式
    VS2010 使用TeeChart画图控件
  • 原文地址:https://www.cnblogs.com/1175429393wljblog/p/6845158.html
Copyright © 2020-2023  润新知