예제 #1
0
        async Task NewUser()
        {
            string strError = "";

            UserDialog dlg = new UserDialog();

            dlg.Font = this.Font;
            dlg.ShowDialog(this);

            if (dlg.DialogResult == System.Windows.Forms.DialogResult.Cancel)
            {
                return;
            }
            List <User> users = new List <User>();
            User        user  = dlg.UserItem;

            users.Add(user);

            this.EnableControls(false);
            try
            {
                MessageResult result = await this.Connection.SetUsers("create", users);

                if (result.Value == -1)
                {
                    strError = result.ErrorInfo;
                    goto ERROR1;
                }
            }
            catch (AggregateException ex)
            {
                strError = MessageConnection.GetExceptionText(ex);
                goto ERROR1;
            }
            catch (Exception ex)
            {
                strError = ex.Message;
                goto ERROR1;
            }
            finally
            {
                this.EnableControls(true);
            }

            // 更新显示
            ListViewItem item = ChangeItem(null, user);

            this.listView1.SelectedItems.Clear();
            item.Selected = true;

            this.Changed = true;
            return;

ERROR1:
            this.Invoke((Action)(() =>
            {
                MessageBox.Show(this, strError);
            }
                                 ));
        }
예제 #2
0
        async Task ModifyUser()
        {
            string strError = "";

            if (this.listView1.SelectedItems.Count == 0)
            {
                strError = "尚未选定要修改的事项";
                goto ERROR1;
            }

            ListViewItem item = this.listView1.SelectedItems[0];
            UserDialog   dlg  = new UserDialog();

            dlg.Font       = this.Font;
            dlg.ChangeMode = true;
            dlg.UserItem   = (User)item.Tag;
            dlg.ShowDialog(this);

            if (dlg.DialogResult == System.Windows.Forms.DialogResult.Cancel)
            {
                return;
            }

            if (dlg.Changed == false && dlg.ChangePassword == false)
            {
                MessageBox.Show(this, "没有发生修改");
                return;
            }

            List <User> users = new List <User>();
            User        user  = dlg.UserItem;

            users.Add(user);

            this.EnableControls(false);
            try
            {
                if (dlg.Changed == true)
                {
                    MessageResult result = await this.Connection.SetUsers("change", users);

                    if (result.Value == -1)
                    {
                        strError = result.ErrorInfo;
                        // 如果这里返回出错仅仅是因为权限不够,还需要尝试继续执行后面的修改密码的操作
                        if (result.String != "Denied")
                        {
                            goto ERROR1;
                        }
                    }
                }

                if (dlg.ChangePassword)
                {
                    MessageResult result = await this.Connection.SetUsers("changePassword", users);

                    if (result.Value == -1)
                    {
                        if (string.IsNullOrEmpty(strError) == false)
                        {
                            strError += "; ";
                        }
                        strError += result.ErrorInfo;
                        goto ERROR1;
                    }
                }

                if (string.IsNullOrEmpty(strError) == false)
                {
                    goto ERROR1;
                }
            }
            catch (AggregateException ex)
            {
                strError = MessageConnection.GetExceptionText(ex);
                goto ERROR1;
            }
            catch (Exception ex)
            {
                strError = "ModifyUser() 出现异常: " + ex.Message;
                goto ERROR1;
            }
            finally
            {
                this.EnableControls(true);
            }

            ChangeItem(item, dlg.UserItem);

            this.Changed = true;
            return;

ERROR1:
            this.Invoke((Action)(() =>
            {
                MessageBox.Show(this, strError);
            }
                                 ));
        }
예제 #3
0
        void NewUser()
        {
            string strError = "";

            UserDialog dlg = new UserDialog();
            dlg.Font = this.Font;
            dlg.ShowDialog(this);

            if (dlg.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                return;
            List<User> users = new List<User>();
            User user = dlg.UserItem;
            users.Add(user);

            this.EnableControls(false);
            try
            {
                MessageResult result = this.Connection.SetUsers("create", users);
                if (result.Value == -1)
                {
                    strError = result.ErrorInfo;
                    goto ERROR1;
                }
            }
            catch (AggregateException ex)
            {
                strError = MessageConnection.GetExceptionText(ex);
                goto ERROR1;
            }
            catch (Exception ex)
            {
                strError = ex.Message;
                goto ERROR1;
            }
            finally
            {
                this.EnableControls(true);
            }

            // 更新显示
            ListViewItem item = ChangeItem(null, user);
            this.listView1.SelectedItems.Clear();
            item.Selected = true;

            this.Changed = true;
            return;
        ERROR1:
            MessageBox.Show(this, strError);
        }
예제 #4
0
        void ModifyUser()
        {
            string strError = "";

            if (this.listView1.SelectedItems.Count == 0)
            {
                strError = "尚未选定要修改的事项";
                goto ERROR1;
            }

            ListViewItem item = this.listView1.SelectedItems[0];
            UserDialog dlg = new UserDialog();
            dlg.Font = this.Font;
            dlg.ChangeMode = true;
            dlg.UserItem = (User)item.Tag;
            dlg.ShowDialog(this);

            if (dlg.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                return;

            if (dlg.Changed == false && dlg.ChangePassword == false)
            {
                MessageBox.Show(this, "没有发生修改");
                return;
            }

            List<User> users = new List<User>();
            User user = dlg.UserItem;
            users.Add(user);

            this.EnableControls(false);
            try
            {
                if (dlg.Changed == true)
                {
                    MessageResult result = this.Connection.SetUsers("change", users);
                    if (result.Value == -1)
                    {
                        strError = result.ErrorInfo;
                        // 如果这里返回出错仅仅是因为权限不够,还需要尝试继续执行后面的修改密码的操作
                        if (result.String != "Denied")
                            goto ERROR1;
                    }
                }

                if (dlg.ChangePassword)
                {
                    MessageResult result = this.Connection.SetUsers("changePassword", users);
                    if (result.Value == -1)
                    {
                        if (string.IsNullOrEmpty(strError) == false)
                            strError += "; ";
                        strError += result.ErrorInfo;
                        goto ERROR1;
                    }
                }

                if (string.IsNullOrEmpty(strError) == false)
                    goto ERROR1;
            }
            catch (AggregateException ex)
            {
                strError = MessageConnection.GetExceptionText(ex);
                goto ERROR1;
            }
            catch (Exception ex)
            {
                strError = ex.Message;
                goto ERROR1;
            }
            finally
            {
                this.EnableControls(true);
            }

            ChangeItem(item, dlg.UserItem);

            this.Changed = true;
            return;
        ERROR1:
            MessageBox.Show(this, strError);
        }