Esempio n. 1
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (!IsValid)
        {
            return;
        }

        try
        {
            txtRoleName.Text        = txtRoleName.Text.Trim();
            txtRoleDisplayName.Text = txtRoleDisplayName.Text.Trim();

            RoleParams param = new RoleParams()
            {
                RoleName        = txtRoleName.Text,
                RoleDisplayName = txtRoleDisplayName.Text,
                SortNo          = Convert.ToInt32(txtSortNo.Text.Trim()),
                PostAccount     = c.GetEmpAccount()
            };

            bool result = false;

            if (c.qsAct == ConfigFormAction.add)
            {
                if (ddlCopyPrivilegeFrom.SelectedIndex > 0)
                {
                    param.CopyPrivilegeFromRoleName = ddlCopyPrivilegeFrom.SelectedValue;
                }

                result = empAuth.InsertEmployeeRoleData(param);

                if (!result)
                {
                    if (param.HasRoleBeenUsed)
                    {
                        Master.ShowErrorMsg(Resources.Lang.ErrMsg_RoleNameHasBeenUsed);
                    }
                    else
                    {
                        Master.ShowErrorMsg(Resources.Lang.ErrMsg_AddFailed);
                    }
                }
            }
            else if (c.qsAct == ConfigFormAction.edit)
            {
                param.RoleId = c.qsRoleId;
                result       = empAuth.UpdateEmployeeRoleData(param);

                if (!result)
                {
                    Master.ShowErrorMsg(Resources.Lang.ErrMsg_UpdateFailed);
                }
            }

            if (result)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", StringUtility.GetNoticeOpenerJs("Config"), true);
            }

            //新增後端操作記錄
            empAuth.InsertBackEndLogData(new BackEndLogData()
            {
                EmpAccount  = c.GetEmpAccount(),
                Description = string.Format(".{0} .儲存身分/Save role[{1}] RoleId[{2}] 結果/result[{3}]", Title, txtRoleName.Text, param.RoleId, result),
                IP          = c.GetClientIP()
            });
        }
        catch (Exception ex)
        {
            c.LoggerOfUI.Error("", ex);
            Master.ShowErrorMsg(ex.Message);
        }
    }