private void DisplayDepartments()
    {
        DeptListQueryParams param = new DeptListQueryParams()
        {
            Kw = c.qsKw
        };

        param.PagedParams = new PagedListQueryParams()
        {
            BeginNum   = 0,
            EndNum     = 0,
            SortField  = c.qsSortField,
            IsSortDesc = c.qsIsSortDesc
        };

        param.AuthParams = new AuthenticationQueryParams()
        {
            CanReadSubItemOfOthers = empAuth.CanReadSubItemOfOthers(),
            CanReadSubItemOfCrew   = empAuth.CanReadSubItemOfCrew(),
            CanReadSubItemOfSelf   = empAuth.CanReadSubItemOfSelf(),
            MyAccount = c.GetEmpAccount(),
            MyDeptId  = c.GetDeptId()
        };

        // get total of items
        empAuth.GetDepartmentList(param);

        // update pager and get begin end of item numbers
        int itemTotalCount = param.PagedParams.RowCount;

        ucDataPager.Initialize(itemTotalCount, c.qsPageCode);
        if (IsPostBack)
        {
            ucDataPager.RefreshPagerAfterPostBack();
        }

        param.PagedParams = new PagedListQueryParams()
        {
            BeginNum   = ucDataPager.BeginItemNumberOfPage,
            EndNum     = ucDataPager.EndItemNumberOfPage,
            SortField  = c.qsSortField,
            IsSortDesc = c.qsIsSortDesc
        };

        List <DepartmentForBackend> depts = empAuth.GetDepartmentList(param);

        if (depts != null)
        {
            rptDepartments.DataSource = depts;
            rptDepartments.DataBind();
        }

        if (c.qsPageCode > 1 || c.qsSortField != "")
        {
            ClientScript.RegisterStartupScript(this.GetType(), "isSearchPanelCollapsingAtBeginning", "isSearchPanelCollapsingAtBeginning = true;", true);
        }
    }
Example #2
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);
        }
    }