• 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));

            }     } }

  • 相关阅读:
    2804 最大最小数质因数
    5429 多重背包
    1851 越狱
    Gvim使用
    3622 假期
    4906 删数问题
    2845 排序的代价
    poj 3352
    常用正则表达式汇总
    功能简单例子
  • 原文地址:https://www.cnblogs.com/1175429393wljblog/p/6845158.html
Copyright © 2020-2023  润新知