Пример #1
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (!IsValid)
        {
            return;
        }

        try
        {
            txtDeptName.Text = txtDeptName.Text.Trim();

            DeptParams param = new DeptParams()
            {
                DeptName    = txtDeptName.Text,
                SortNo      = Convert.ToInt32(txtSortNo.Text),
                PostAccount = c.GetEmpAccount()
            };

            bool result = false;

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

                if (!result)
                {
                    if (param.HasDeptNameBeenUsed)
                    {
                        Master.ShowErrorMsg(Resources.Lang.ErrMsg_DeptNameHasBeenUsed);
                    }
                    else
                    {
                        Master.ShowErrorMsg(Resources.Lang.ErrMsg_AddFailed);
                    }
                }
            }
            else if (c.qsAct == ConfigFormAction.edit)
            {
                param.DeptId = c.qsId;
                result       = empAuth.UpdateDepartmentData(param);

                if (!result)
                {
                    if (param.HasDeptNameBeenUsed)
                    {
                        Master.ShowErrorMsg(Resources.Lang.ErrMsg_DeptNameHasBeenUsed);
                    }
                    else
                    {
                        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 department[{1}] DeptId[{2}] 結果/result[{3}]", Title, txtDeptName.Text, param.DeptId, result),
                IP          = c.GetClientIP()
            });
        }
        catch (Exception ex)
        {
            c.LoggerOfUI.Error("", ex);
            Master.ShowErrorMsg(ex.Message);
        }
    }