示例#1
0
        /// <summary>
        /// 删除方法
        /// </summary>
        private void DeleteEntry()
        {
            var cell = this.vgMainGrid.CurrentCell;

            if (cell == null)
            {
                RadMessageBox.Show(this, "请选择一行!", "", MessageBoxButtons.OK, RadMessageIcon.Error);
                return;
            }
            if (cell.RowIndex < 0)
            {
                return;
            }
            var dr = RadMessageBox.Show(this, "确认删除?", "确认?", MessageBoxButtons.YesNo, RadMessageIcon.Question);

            if (dr == DialogResult.No)
            {
                return;
            }
            var current = data.Data[cell.RowIndex];
            var re      = bll.Delete <Models.AppRole>(current.Id);

            if (re > 0)
            {
                this.vgMainGrid.BeginUpdate();
                data.Data.RemoveAt(cell.RowIndex);
                this.vgMainGrid.RowCount--;
                this.vgMainGrid.EndUpdate();
                //if (cell.RowIndex>0)
                //{
                //    this.vgUserRoles.SelectCell();
                //}
            }
            //ObservableCollection<Models.UserRole> adf = new ObservableCollection<UserRole>();
            //this.vgUserRoles.MultiSelect = true; e.RowIndices 如果允许多选,可以使用前面的属性遍历选中的行号,此处我采用单行删除
        }
示例#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;
                    }, "");
                });
            };
        }