private void comfirmClick(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrWhiteSpace(name.Text) || String.IsNullOrWhiteSpace(right.Text))
            {
                MessageBoxX.Show("提示", "角色名称、权限不能为空!");
            }
            else
            {
                dataAnadll.User us = new dataAnadll.User();
                us.Name       = name.Text;
                us.RoleID     = int.Parse(right.Text);
                us.Department = description.Text;
                userData.AddUser(us);//用户数据添加

                List <dataAnadll.User> list = new List <dataAnadll.User>();
                list = userData.GetAllUsers();
                SystemRole sr = new SystemRole
                {
                    ID          = RoleManagement.roleList.Count,
                    Code        = list[list.Count - 1].ID.ToString(),
                    Name        = list[list.Count - 1].Name,
                    Right       = list[list.Count - 1].RoleID.ToString(),
                    Description = list[list.Count - 1].Department,
                    ReadOnly    = true,
                };
                RoleManagement.roleList.Add(sr);
                this.Close();
            }
        }
        private void Edit_Click(object sender, RoutedEventArgs e)//列表右侧按钮-编辑
        {
            ToggleButton b  = sender as ToggleButton;
            int          id = Convert.ToInt32(b.CommandParameter);

            for (int i = UserListView.Items.Count - 1; i >= 0; i--)
            {
                if (userList[i].ID == id)
                {
                    if (!userList[i].ReadOnly)
                    {
                        ListViewItem lvi = this.UserListView.ItemContainerGenerator.ContainerFromIndex(i) as ListViewItem;
                        TextBox      tb  = FindVisualChild <TextBox>(lvi);
                        tb.Focus();
                        tb.SelectionStart = tb.Text.Length;
                    }
                    else
                    {
                        if (String.IsNullOrWhiteSpace(userList[i].UserName) || String.IsNullOrWhiteSpace(userList[i].Password) || String.IsNullOrWhiteSpace(userList[i].Role))
                        {
                            MessageBoxX.Show("提示", "用户名、密码、角色类型不能为空!");
                            userList[i].ReadOnly = !userList[i].ReadOnly;
                        }
                        else
                        {
                            try
                            {
                                dataAnadll.User us = new dataAnadll.User();
                                us.ID         = int.Parse(userList[i].UserID);
                                us.Name       = userList[i].UserName;
                                us.Password   = userList[i].Password;
                                us.RoleID     = int.Parse(userList[i].Role);
                                us.Department = userList[i].Department;
                                us.Level      = userList[i].Position;
                                us.Email      = userList[i].Mail;
                                us.Phone      = userList[i].Phone;
                                userData.UpdateUser(us);//用户数据更新
                            }
                            catch (Exception ex)
                            {
                                MessageBoxX.Show("警告", "存在非法的数据!");
                                userList[i].ReadOnly = !userList[i].ReadOnly;
                            }
                        }
                    }
                }
            }
        }
        private void comfirmClick(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrWhiteSpace(userName.Text) || String.IsNullOrWhiteSpace(password.Text) || String.IsNullOrWhiteSpace(role.Text))
            {
                MessageBoxX.Show("提示", "用户名、密码、角色类型不能为空!");
            }
            else
            {
                try
                {
                    dataAnadll.User us = new dataAnadll.User();
                    us.Name       = userName.Text;
                    us.Password   = password.Text;
                    us.RoleID     = role.SelectedIndex;
                    us.Department = department.Text;
                    us.Level      = position.Text;
                    us.Email      = mail.Text;
                    us.Phone      = phone.Text;
                    userData.AddUser(us);//用户数据添加

                    List <dataAnadll.User> list = new List <dataAnadll.User>();
                    list = userData.GetAllUsers();
                    SystemUser su = new SystemUser()
                    {
                        ID         = UserManagement.userList.Count,
                        UserID     = list[list.Count - 1].ID.ToString(),
                        UserName   = list[list.Count - 1].Name,
                        Password   = list[list.Count - 1].Password,
                        Role       = list[list.Count - 1].RoleID.ToString(),
                        Position   = list[list.Count - 1].Level,
                        Department = list[list.Count - 1].Department,
                        Phone      = list[list.Count - 1].Phone,
                        Mail       = list[list.Count - 1].Email,
                        ReadOnly   = true
                    };
                    UserManagement.userList.Add(su);
                    this.Close();
                }
                catch (Exception ex)
                {
                    MessageBoxX.Show("警告", "存在非法的数据!");
                }
            }
        }
        private void Edit_Click(object sender, RoutedEventArgs e)//列表编辑
        {
            ToggleButton b  = sender as ToggleButton;
            int          id = Convert.ToInt32(b.CommandParameter);

            for (int i = RoleListView.Items.Count - 1; i >= 0; i--)
            {
                if (roleList[i].ID == id)
                {
                    if (!roleList[i].ReadOnly)
                    {
                        ListViewItem lvi = this.RoleListView.ItemContainerGenerator.ContainerFromIndex(i) as ListViewItem;
                        TextBox      tb  = FindVisualChild <TextBox>(lvi);
                        tb.Focus();
                        tb.SelectionStart = tb.Text.Length;
                    }
                    else
                    {
                        if (String.IsNullOrWhiteSpace(roleList[i].Name) || String.IsNullOrWhiteSpace(roleList[i].Right))
                        {
                            MessageBoxX.Show("提示", "角色名称、权限不能为空!");
                            roleList[i].ReadOnly = !roleList[i].ReadOnly;
                        }
                        else
                        {
                            dataAnadll.User us = new dataAnadll.User();
                            us.ID         = int.Parse(roleList[i].Code);
                            us.Name       = roleList[i].Name;
                            us.RoleID     = int.Parse(roleList[i].Right);
                            us.Department = roleList[i].Description;

                            user.UpdateUser(us);//用户数据更新
                        }
                    }
                }
            }
        }
        private void LoginClick(object sender, RoutedEventArgs e)//登录按钮
        {
            //userName.Text = "1";
            //password.Password = "******";
            try
            {
                userInfor = loginData.Login(userName.Text.Trim(), password.Password.Trim());
            }
            catch
            {
                MessageBoxX.Show("警告", "数据库连接失败!");
                System.Windows.Application.Current.Shutdown();

                Environment.Exit(0);//强制退出
                GC.Collect();
            }
            //roleContrl需要数据库查询赋值
            if (userInfor != null)
            {
                roleContrl          = str[userInfor.RoleID];//用以权限赋值
                opeation.UserID     = userInfor.ID;
                opeation.OptionName = "登录";
                opeation.LogType    = 1;
                opeation.Result     = "成功";
                opeation.UserName   = userInfor.Name;
                opeation.IP         = deviceIP;
                opeation.OptionTime = GetTime(GetTimeStamp().ToString());
                OperationLogData.WriteOperationLog(opeation);

                if (!String.IsNullOrWhiteSpace(userName.Text) && IsUserNameNew(userName.Text))//更新用户名的配置文件
                {
                    if (userCount < maxCount)
                    {
                        sc.write_string("userName", "count" + userCount.ToString(), userName.Text);
                        userCount += 1;
                        sc.write_double("userCount", "max", userCount);
                    }
                    else
                    {
                        for (int i = 0; i < maxCount - 1; i++)
                        {
                            sc.write_string("userName", "count" + i.ToString(), sc.read_string("userName", "count" + (i + 1).ToString()));
                        }
                        sc.write_string("userName", "count" + (userCount - 1).ToString(), userName.Text);
                    }
                }

                if ((bool)rememberPassword.IsChecked && !String.IsNullOrWhiteSpace(password.Password))//更新密码的配置文件
                {
                    sc.write_string("password", "user_" + userName.Text, password.Password);
                }

                sc.write_bool("isRememberPassword", "value", (bool)rememberPassword.IsChecked);//更新是否记住密码


                if (extendScrean.IsChecked == true)    //判断是否启动扩展屏
                {
                    MonitoringInterface q = new MonitoringInterface();
                    System.Windows.Application.Current.MainWindow = q;
                    this.Close();
                    q.Show();

                    try
                    {
                        MainWindow.opeation.OptionName = "双屏显示";    //日志入库
                        MainWindow.opeation.LogType    = 2;
                        MainWindow.opeation.OptionTime = GetTime(GetTimeStampS().ToString());
                        MainWindow.OperationLogData.WriteOperationLog(MainWindow.opeation);

                        if (!MainWindow.doubleScreen)
                        {
                            MainWindow.doubles         = new DoubleScreen();
                            MainWindow.doubles.Closed += doubleScreenClosed;
                            System.Windows.Application.Current.MainWindow = MainWindow.doubles;
                            MainWindow.doubles.Show();

                            MainWindow.doubleScreen = true;
                            MonitoringX.MonitoringXObj.doubleScreen();    //修改主界面
                        }
                    }
                    catch (Exception eex)
                    {
                        MessageBoxX.Show("异常信息", "未检测到扩展屏。");    //显示异常信息
                        MainWindow.doubleScreen = false;
                    }
                }
                else
                {
                    MonitoringInterface q = new MonitoringInterface();
                    System.Windows.Application.Current.MainWindow = q;
                    this.Close();
                    q.Show();
                };
            }
            else
            {
                if (String.IsNullOrWhiteSpace(userName.Text) || String.IsNullOrWhiteSpace(password.Password))
                {
                    MessageBoxX.Show("警告", "登录名或者密码为空。");
                }
                else
                {
                    MessageBoxX.Show("警告", "登录名或者密码有误.。");
                }
            };
        }