/// <summary>
        /// 解析数据
        /// </summary>
        /// <param name="values">数据</param>
        /// <returns>用户和模块关系</returns>
        public UserModule Parse(object[] values)
        {
            UserModule result = new UserModule();

            try
            {
                result = DatabaseHibernate.ParseModule(result, values) as UserModule;

                result.UserId = DatabaseHibernate.ParseString(values[7]);
                result.ModuleCode = DatabaseHibernate.ParseString(values[8]);
            }
            catch (Exception exception)
            {
                result = null;
                EnvironmentalMonitor.Support.Resource.Variable.Logger.Log(exception);
            }

            return result;
        }
        /// <summary>
        /// 增加
        /// </summary>
        /// <param name="value">值</param>
        /// <returns>结果</returns>
        public bool Insert(UserModule value)
        {
            bool result = false;

            string sql = string.Format("insert into m_user_module ({0}) values (:guid, :insert_user_id, :insert_time, :update_user_id, :update_time, :remark, :validity, :user_id, :module_code)", this.Asterisk(""));
            List<Parameter> parameters = new List<Parameter>();

            parameters.Add(new Parameter("guid", DatabaseHibernate.Parameter(DatabaseHibernate.GUID())));
            parameters.Add(new Parameter("insert_user_id", DatabaseHibernate.Parameter(value.InsertUserId)));
            parameters.Add(new Parameter("insert_time", DatabaseHibernate.Parameter(value.InsertTime)));
            parameters.Add(new Parameter("update_user_id", DatabaseHibernate.Parameter(value.UpdateUserId)));
            parameters.Add(new Parameter("update_time", DatabaseHibernate.Parameter(value.UpdateTime)));
            parameters.Add(new Parameter("remark", DatabaseHibernate.Parameter(value.Remark)));
            parameters.Add(new Parameter("validity", DatabaseHibernate.Parameter(value.Validity)));
            parameters.Add(new Parameter("user_id", DatabaseHibernate.Parameter(value.UserId)));
            parameters.Add(new Parameter("module_code", DatabaseHibernate.Parameter(value.ModuleCode)));

            DatabaseHibernate hibernate = new DatabaseHibernate();

            result = hibernate.Write(Variable.Link, sql, parameters);

            return result;
        }
        protected void ButtonOK_Click(object sender, EventArgs e)
        {
            string guid = this.DropDownListUsers.SelectedValue;
            if (!string.IsNullOrEmpty(guid))
            {
                bool done = false;
                StringBuilder stringBuilder = new StringBuilder();

                UserBusiness business = new UserBusiness();
                User module = business.QueryByGuid(guid);

                this.InitializeUpdateModule(module);

                module.Name = this.TextBoxName.Text;
                module.Account = this.TextBoxAccount.Text;
                module.Password = this.TextBoxPassword.Text;
                module.Prerogative = false;

                User user = business.QueryByAccount(module.Account);

                if ((user == null) || (string.Equals(user.Guid, module.Guid, StringComparison.CurrentCulture)))
                {
                    done = business.Update(module);

                    if (done)
                    {
                        stringBuilder.Append("修改用户成功!");
                    }
                    else
                    {
                        stringBuilder.Append("修改用户失败!");
                    }
                }
                else
                {
                    stringBuilder.Append("用户已经存在(账户相同)!");
                }

                if (done)
                {
                    user = business.QueryByAccount(module.Account);
                    if ((user != null) && (user.Guid != null))
                    {
                        if (this.CheckBoxListRooms.Items != null)
                        {
                            List<UserRoom> userRooms = new List<UserRoom>();
                            for (int i = 0; i < this.CheckBoxListRooms.Items.Count; i++)
                            {
                                if (this.CheckBoxListRooms.Items[i].Selected)
                                {
                                    UserRoom userRoom = new UserRoom();
                                    this.InitializeInsertModule(userRoom);

                                    userRoom.UserId = user.Guid;
                                    userRoom.RoomId = this.CheckBoxListRooms.Items[i].Value;

                                    userRooms.Add(userRoom);
                                }
                            }
                            UserRoomBusiness userRoomBusiness = new UserRoomBusiness();
                            done = userRoomBusiness.Refresh(user.Guid, userRooms);

                            if (done)
                            {
                                stringBuilder.Append("更新机房成功!");
                            }
                            else
                            {
                                stringBuilder.Append("更新机房失败!");
                            }
                        }
                    }
                    if ((user != null) && (user.Guid != null))
                    {
                        if (this.CheckBoxListModules.Items != null)
                        {
                            List<UserModule> userModules = new List<UserModule>();
                            for (int i = 0; i < this.CheckBoxListModules.Items.Count; i++)
                            {
                                if (this.CheckBoxListModules.Items[i].Selected)
                                {
                                    UserModule userModule = new UserModule();
                                    this.InitializeInsertModule(userModule);

                                    userModule.UserId = user.Guid;
                                    userModule.ModuleCode = this.CheckBoxListModules.Items[i].Value;

                                    userModules.Add(userModule);
                                }
                            }
                            UserModuleBusiness userModuleBusiness = new UserModuleBusiness();
                            done = userModuleBusiness.Refresh(user.Guid, userModules);

                            if (done)
                            {
                                stringBuilder.Append("更新权限成功!");
                            }
                            else
                            {
                                stringBuilder.Append("更新权限失败!");
                            }
                        }
                    }
                }

                this.LabelMessage.Text = stringBuilder.ToString();

                this.InitializeBind();
            }
        }
        public List<UserModule> RefreshUserModules(User value)
        {
            List<UserModule> results = null;

            if (value.Prerogative)
            {
                results = new List<UserModule>();
                for (int i = 0; i < UserModule.Modules.Length; i++)
                {
                    UserModule userModule = new UserModule();
                    userModule.ModuleCode = UserModule.Modules[i];
                    results.Add(userModule);
                }
            }
            else
            {
                UserModuleBusiness business = new UserModuleBusiness();
                int total = 0;
                results = business.QueryByUser(1, int.MaxValue, ref total, value.Guid);
            }

            return results;
        }