Ejemplo n.º 1
0
 private void InitLayerGridView()
 {
     this.gvLayer.AllowAddNewRow     = false;
     this.gvLayer.AllowEditRow       = false;
     this.gvLayer.AllowSearchRow     = true;
     this.gvLayer.EnableFiltering    = true;
     this.gvLayer.CurrentRowChanged += (s, e) => {
         var currentRow = e.CurrentRow;
         if (currentRow != null && !(currentRow is GridViewNewRowInfo))
         {
             if (e.OldRow != null && OriLayer != null)
             {
                 var oldData = e.OldRow.DataBoundItem as QuoLayer;
                 ObjectHelper.CopyAllField(OriLayer, oldData);
             }
             var curData = e.CurrentRow.DataBoundItem as QuoLayer;
             OriLayer = ObjectHelper.DeepClone(curData);
             this.deLayer.DataSource = curData;
             EditMode = Enums.EditFormMode.Edit;
         }
     };
 }
Ejemplo n.º 2
0
        //private bool isUpdate = false;
        //private ObservableCollection<BasLayer> layerData = new ObservableCollection<BasLayer>();
        public BaseParaSettingForm()
        {
            InitializeComponent();
            this.Text         = "基础参数设置";
            this.AutoValidate = AutoValidate.EnableAllowFocusChange;//控件验证时 validating e.cancel = true 时可以 切换焦点



            InitMaterialCostGridView();
            InitMaterialGridView();
            InitLayerDataEntry();
            InitLayerGridView();
            LoadLayerData();

            this.pvSetting.SelectedPageChanged += (s, e) => {
                switch (this.pvSetting.SelectedPage.Name)
                {
                case "pvpMaterialSetting":     //物料设置
                    //InitMaterialGridView();
                    LoadMaterialData();
                    break;

                case "pvpLayerSetting":    //层数设置
                    //InitLayerDataEntry();
                    //InitLayerGridView();
                    LoadLayerData();
                    break;

                default:
                    break;
                }
            };

            this.btnMaterialReload.Click += (s, e) => {
                LoadMaterialData();
            };
            this.btnMaterialDelete.Click += (s, e) => {
                if (RadMessageBox.Show(this, "确认删除所选行?", "", MessageBoxButtons.YesNo, RadMessageIcon.Question) == DialogResult.No)
                {
                    return;
                }
                var rows = this.gvMaterial.SelectedRows;
                if (rows.Count <= 0)
                {
                    RadMessageBox.Show(this, "请选择想删除的行!", "", MessageBoxButtons.OK, RadMessageIcon.Error);
                    return;
                }
                delIds.Clear();
                foreach (var row    in rows)
                {
                    var tmp = row.DataBoundItem as QuoMaterial;
                    if (tmp != null && tmp.Id > 0)
                    {
                        delIds.Add(tmp.Id);
                    }
                }
                if (delIds.Count > 0)
                {
                    Task.Factory.StartNew(() => {
                        bll.Delete <QuoMaterial>(delIds);
                    }).ContinueWith(t => {
                        if (t.IsFaulted)
                        {
                            LoadMaterialData();
                        }
                        syncContext.Post((state) => {
                            this.gvMaterial.BeginUpdate();
                            foreach (var i in rows)
                            {
                                this.gvMaterial.Rows.Remove(i);
                            }
                            this.gvMaterial.EndUpdate();
                        }, "");
                    });
                }
            };

            //取消按钮事件
            this.btnLayerCancel.Click += (s, e) => {
                if (EditMode == Enums.EditFormMode.Add)
                {
                    this.deLayer.DataSource = new QuoLayer();
                }
                else if (EditMode == Enums.EditFormMode.Edit)
                {
                    this.deLayer.DataSource = OriLayer;
                    var cur = this.gvLayer.CurrentRow.DataBoundItem as QuoLayer;
                    ObjectHelper.CopyAllField(OriLayer, cur);
                    //this.deLayer.DataSource = OriginalLayer ;
                }
            };
            //加载按钮事件
            this.btnReLoad.Click += (s, e) => { LoadLayerData(); };
            //新增按钮事件
            this.btnLayerAdd.Click += (s, e) => {
                EditMode = Enums.EditFormMode.Add;
                this.deLayer.DataSource = new QuoLayer();
            };
            //删除按钮事件
            this.btnLayerDelete.Click += (s, e) => {
                if (RadMessageBox.Show(this, "确认删除?", "", MessageBoxButtons.YesNo, RadMessageIcon.Question) == DialogResult.Yes)
                {
                    this.btnLayerDelete.Enabled = false;
                    Task.Factory.StartNew <QuoLayer>(() => {
                        var cur = this.gvLayer.CurrentRow.DataBoundItem as QuoLayer;
                        if (bll.Delete <QuoLayer>(cur.Id) > 0)
                        {
                            return(cur);
                        }
                        else
                        {
                            return(null);
                        }
                    }).ContinueWith(t => {
                        if (!t.IsFaulted && t.Result != null)
                        {
                            syncContext.Post((state) => {
                                this.gvLayer.BeginUpdate();
                                var layerData = this.gvLayer.DataSource as ObservableCollection <QuoLayer>;
                                layerData.Remove(t.Result);
                                this.gvLayer.EndUpdate();
                            }, "");
                        }
                        syncContext.Post((state) => {
                            this.btnLayerDelete.Enabled = true;
                        }, "");
                    });
                }
            };
            //保存按钮事件
            this.btnLayerSave.Click += (s, e) => {
                var t = ValidationHelper.hasValidationErrors(this.deLayer.Controls);

                if (t)
                {
                    return;
                }
                this.btnLayerSave.Enabled = false;
                Task.Factory.StartNew <QuoLayer>(() => {
                    QuoLayer re = null;
                    if (EditMode == Enums.EditFormMode.Add)
                    {
                        re = bll.Insert <QuoLayer>(this.deLayer.CurrentObject as QuoLayer);
                    }
                    else if (EditMode == Enums.EditFormMode.Edit)
                    {
                        re       = bll.Update(this.deLayer.CurrentObject as QuoLayer);
                        OriLayer = re;
                    }
                    return(re);
                }).ContinueWith(tt => {
                    if (!tt.IsFaulted)
                    {
                        syncContext.Post((state) => {
                            if (tt.Result != null)
                            {
                                this.gvLayer.BeginUpdate();
                                if (EditMode == Enums.EditFormMode.Add)
                                {
                                    var layerData = this.gvLayer.DataSource as ObservableCollection <QuoLayer>;
                                    layerData.Insert(0, tt.Result);
                                }
                                else if (EditMode == Enums.EditFormMode.Edit)
                                {
                                    var layerData = this.gvLayer.DataSource as ObservableCollection <QuoLayer>;
                                    var cur       = this.gvLayer.CurrentRow.DataBoundItem as QuoLayer;
                                    //cur = tt.Result;
                                    layerData[layerData.IndexOf(cur)] = tt.Result;
                                }

                                this.gvLayer.EndUpdate();

                                if (EditMode == Enums.EditFormMode.Add)
                                {
                                    this.gvLayer.Rows[0].IsCurrent = true;
                                }
                            }
                        }, "");
                    }
                    syncContext.Post((state) => {
                        this.btnLayerSave.Enabled = true;
                    }, "");
                });
            };
        }