Ejemplo n.º 1
0
    protected void rptAccounts_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        switch (e.CommandName)
        {
        case "Del":
            string[] args       = e.CommandArgument.ToString().Split(',');
            int      empId      = Convert.ToInt32(args[0]);
            string   empAccount = args[1];

            bool result = empAuth.DeleteEmployeeData(empId);

            //新增後端操作記錄
            empAuth.InsertBackEndLogData(new BackEndLogData()
            {
                EmpAccount  = c.GetEmpAccount(),
                Description = string.Format(".刪除帳號/Delete account .代碼/id[{0}] 帳號/account[{1}] 結果/result[{2}]", empId, empAccount, result),
                IP          = c.GetClientIP()
            });

            // log to file
            c.LoggerOfUI.InfoFormat("{0} deletes {1}, result: {2}", c.GetEmpAccount(), "Emp-" + empId.ToString() + "-" + empAccount, result);

            if (result)
            {
                DisplayAccounts();
            }
            else
            {
                Master.ShowErrorMsg(Resources.Lang.ErrMsg_DeleteAccountFailed);
            }

            break;
        }
    }
Ejemplo n.º 2
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (!IsValid)
        {
            return;
        }

        try
        {
            txtEmpAccount.Text = txtEmpAccount.Text.Trim();
            txtPsw.Text        = txtPsw.Text.Trim();
            string passwordValue  = hidEmpPasswordOri.Text;
            bool   passwordHashed = Convert.ToBoolean(hidPasswordHashed.Text);

            if (txtPsw.Text != "")
            {
                passwordValue  = HashUtility.GetPasswordHash(txtPsw.Text);
                passwordHashed = true;
            }

            txtEmpName.Text      = txtEmpName.Text.Trim();
            txtEmail.Text        = txtEmail.Text.Trim();
            txtRemarks.Text      = txtRemarks.Text.Trim();
            txtOwnerAccount.Text = txtOwnerAccount.Text.Trim();

            AccountParams param = new AccountParams()
            {
                EmpAccount            = txtEmpAccount.Text,
                EmpPassword           = passwordValue,
                EmpName               = txtEmpName.Text,
                Email                 = txtEmail.Text,
                Remarks               = txtRemarks.Text,
                DeptId                = Convert.ToInt32(ddlDept.SelectedValue),
                RoleId                = Convert.ToInt32(ddlRoles.SelectedValue),
                IsAccessDenied        = chkIsAccessDenied.Checked,
                StartDate             = Convert.ToDateTime(txtStartDate.Text),
                EndDate               = Convert.ToDateTime(txtEndDate.Text),
                OwnerAccount          = txtOwnerAccount.Text,
                PasswordHashed        = passwordHashed,
                DefaultRandomPassword = hidDefaultRandomPassword.Text,
                PostAccount           = c.GetEmpAccount()
            };

            bool result = false;

            if (c.qsAct == ConfigFormAction.add)
            {
                result = empAuth.InsertEmployeeData(param);

                if (!result)
                {
                    if (param.HasAccountBeenUsed)
                    {
                        Master.ShowErrorMsg(Resources.Lang.ErrMsg_AccountHasBeenUsed);
                    }
                    else
                    {
                        Master.ShowErrorMsg(Resources.Lang.ErrMsg_AddFailed);
                    }
                }
            }
            else if (c.qsAct == ConfigFormAction.edit)
            {
                param.EmpId = c.qsEmpId;
                result      = empAuth.UpdateEmployeeData(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 account[{1}] EmpId[{2}] 結果/result[{3}]", Title, txtEmpAccount.Text, param.EmpId, result),
                IP          = c.GetClientIP()
            });
        }
        catch (Exception ex)
        {
            c.LoggerOfUI.Error("", ex);
            Master.ShowErrorMsg(ex.Message);
        }
    }