Пример #1
0
        public UserRolesAddEditForm()
        {
            InitializeComponent();
            this.AcceptButton = this.btnSubmit;
            this.CancelButton = this.btnCanel;

            this.FormClosed += (s, e) => {
                //释放 资源
                if (bll != null)
                {
                    bll.Dispose();
                    bll = null;
                }
            };

            //设置dataentity
            this.deUserRole.FitToParentWidth    = true;
            this.deUserRole.ShowValidationPanel = true;
            this.deUserRole.EditorInitializing += (s, e) => {
                e.Editor.Name = e.Property.Name;
            };
            this.deUserRole.ItemValidating += (s, e) => {
                Models.AppRole role = this.deUserRole.CurrentObject as Models.AppRole;
                switch (e.Label.Text)
                {
                case "角色名称":
                    if (string.IsNullOrWhiteSpace(role.RoleName))
                    {
                        string errorMessage = "角色名称不能为空!";
                        e.ErrorProvider.SetError(s as Control, errorMessage);
                        e.Cancel = true;
                        AddErrorLabel(this.deUserRole, e.Label.Text, errorMessage);
                    }
                    else
                    {
                        e.ErrorProvider.Clear();
                        this.deUserRole.ValidationPanel.PanelContainer.Controls.RemoveByKey(e.Label.Text);
                    }
                    break;

                default:
                    break;
                }
            };

            this.Shown += (s, e) => {
                //设置窗体title
                switch (EditMode)
                {
                case Enums.EditFormMode.Add:
                    this.Text = "新增";
                    UserRole  = new Models.AppRole();
                    break;

                case Enums.EditFormMode.Edit:
                    this.Text = "编辑";
                    break;

                case Enums.EditFormMode.Delete:
                    this.Text = "删除";
                    break;

                default:
                    this.Text = "新增/编辑";
                    break;
                }
                if (UserRole != null)
                {
                    this.deUserRole.DataSource = this.UserRole;
                    this.UserRole.BeginEdit();
                }
            };

            this.btnCanel.Click += (s, e) => {
                //this.UserRole.CancelEdit();
                this.DialogResult = DialogResult.Cancel;
            };

            this.btnSubmit.Click += (s, e) => {
                var t = ValidationHelper.hasValidationErrors(this.deUserRole.Controls);
                if (t)
                {
                    return;
                }

                this.btnSubmit.Enabled = false;
                Task.Factory.StartNew(() => {
                    Models.AppRole re = null;
                    if (EditMode == Enums.EditFormMode.Add)
                    {
                        re = bll.Insert <Models.AppRole>(this.UserRole);
                    }
                    else if (EditMode == Enums.EditFormMode.Edit)
                    {
                        re = bll.Update <Models.AppRole>(this.UserRole);
                    }

                    syncContext.Post((state) => {
                        this.btnSubmit.Enabled = true;
                        Models.AppRole sta     = (Models.AppRole)state;
                        if (sta != null)
                        {
                            this.UserRole     = sta;
                            this.DialogResult = DialogResult.OK;
                            //this.SubmitSucess = true;
                        }
                        else
                        {
                            RadMessageBox.Show(this, "保存失败!", "", MessageBoxButtons.OK, RadMessageIcon.Error);
                        }
                    }, re);
                });
            };
        }
Пример #2
0
        public AppUserAddEditForm()
        {
            InitializeComponent();
            this.AcceptButton = this.btnOk;
            this.CancelButton = this.btnCancel;
            this.FormClosed  += (s, e) => {
                //释放 资源
                if (bll != null)
                {
                    bll.Dispose();
                    bll = null;
                }
            };
            //设置dataentity
            this.deMain.FitToParentWidth    = true;
            this.deMain.ShowValidationPanel = true;
            this.deMain.EditorInitializing += (s, e) => {
                e.Editor.Name = e.Property.Name;
                if (e.Property.Name == "UserName" && EditMode == Enums.EditFormMode.Edit)
                {
                    e.Editor.Enabled = false;
                }
                else if (e.Property.Name == "Email")
                {
                    RadMaskedEditBox editor = new RadMaskedEditBox();
                    editor.MaskType = MaskType.EMail;
                    editor.MaskedEditBoxElement.StretchVertically = true;
                    e.Editor = editor;
                }
                //else if (e.Property.Name == "Tel")
                //{
                //    RadMaskedEditBox editor = new RadMaskedEditBox();
                //    editor.MaskType = MaskType.Regex;
                //    editor.MaskedEditBoxElement.StretchVertically = true;
                //    //editor.Mask = "9";
                //    e.Editor = editor;
                //}
            };
            this.deMain.ItemValidating += (s, e) => {
                Models.AppUser user = this.deMain.CurrentObject as Models.AppUser;
                switch (e.Label.Text)
                {
                case "用户名":
                    if (string.IsNullOrWhiteSpace(user.UserName))
                    {
                        string errorMessage = "用户名不能为空!";
                        e.ErrorProvider.SetError(s as Control, errorMessage);
                        e.Cancel = true;
                        AddErrorLabel(this.deMain, e.Label.Text, errorMessage);
                    }
                    else
                    {
                        e.ErrorProvider.Clear();
                        this.deMain.ValidationPanel.PanelContainer.Controls.RemoveByKey(e.Label.Text);
                    }
                    break;

                default:
                    break;
                }
            };

            this.Shown += (s, e) => {
                //设置窗体title
                switch (EditMode)
                {
                case Enums.EditFormMode.Add:
                    this.Text = "新增";
                    DataEntry = new Models.AppUser()
                    {
                        Password = Helpers.EncryptDecryptHelper.GetStringMD5("888888")
                    };                                                                                                   //新增用户默认密码
                    break;

                case Enums.EditFormMode.Edit:
                    this.Text = "编辑";
                    break;

                case Enums.EditFormMode.Delete:
                    this.Text = "删除";
                    break;

                default:
                    this.Text = "新增/编辑";
                    break;
                }
                if (DataEntry != null)
                {
                    this.deMain.DataSource = this.DataEntry;
                }
            };

            this.btnCancel.Click += (s, e) => {
                //this.UserRole.CancelEdit();
                this.DialogResult = DialogResult.Cancel;
            };

            this.btnOk.Click += (s, e) => {
                var t = ValidationHelper.hasValidationErrors(this.deMain.Controls);
                if (t)
                {
                    return;
                }

                this.btnOk.Enabled = false;

                Task.Factory.StartNew <AppUser>(() => {
                    Models.AppUser re = null;
                    if (EditMode == Enums.EditFormMode.Add)
                    {
                        re = bll.Insert <Models.AppUser>(this.DataEntry);
                    }
                    else if (EditMode == Enums.EditFormMode.Edit)
                    {
                        re = bll.Update <Models.AppUser>(this.DataEntry);
                    }


                    return(re);
                }).ContinueWith(tt => {
                    if (!tt.IsFaulted)
                    {
                        syncContext.Post((state) => {
                            Models.AppUser sta = (Models.AppUser)state;
                            if (sta != null)
                            {
                                this.DataEntry    = sta;
                                this.DialogResult = DialogResult.OK;
                                //this.SubmitSucess = true;
                            }
                            else
                            {
                                RadMessageBox.Show(this, "保存失败!", "", MessageBoxButtons.OK, RadMessageIcon.Error);
                            }
                        }, tt.Result);
                    }
                    syncContext.Post((state) => {
                        this.btnOk.Enabled = true;
                    }, tt.Result);
                });
            };
        }
Пример #3
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;
                    }, "");
                });
            };
        }