Пример #1
0
    /// <summary>
    /// 保存按钮事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ButtonSave_Click(object sender, EventArgs e)
    {
        if (String.IsNullOrEmpty(TextBoxAccount.Text.Trim()) || String.IsNullOrEmpty(TextBoxUserName.Text.Trim()))
        {
            return;
        }
        if (RadioButtonListBan.SelectedItem == null)
        {
            return;
        }
        UserDataModel userDataModel = new UserDataModel
        {
            GUID     = String.IsNullOrEmpty(UserGuid)?Guid.NewGuid().ToString():UserGuid,
            Account  = TextBoxAccount.Text.Trim(),
            UserName = TextBoxUserName.Text.Trim(),
            Password = "******",
            Ban      = RadioButtonListBan.SelectedItem.Value == "0"
        };

        try
        {
            WebBean bean = WebBean.GetInstance();
            bean.AddOrUpdateUser(userDataModel, string.IsNullOrEmpty(UserGuid)?"add":"update");

            //如果用户组信息
            bean.AddUserToUserGroup(UserGuid, string.Empty, false);
            foreach (ListItem item in CheckBoxListUserGroups.Items)
            {
                if (item.Selected)
                {
                    bean.AddUserToUserGroup(userDataModel.GUID, item.Value, true);
                }
            }
            //if (CheckBoxListUserGroups.SelectedItem != null && DropDownListUserGroup.SelectedValue != "0")
            //{
            //    bean.AddUserToUserGroup(userDataModel.GUID, DropDownListUserGroup.SelectedValue, true);
            //}
        }
        catch (Exception ex)
        {
            WriteLog.WriteExceptionLog(ex.ToString());
        }
    }