Exemplo n.º 1
0
    private static void MoveExistEmployee(RowData employeeDocsvision, RowData department)
    {
        var newDepartmentCode     = department[RefStaff.Units.Code];
        var existedDepartmentCode = employeeDocsvision.SubSection.ParentRow[RefStaff.Units.Code];

        if (!newDepartmentCode.Equals(existedDepartmentCode))
        {
            employeeDocsvision.Move(Guid.Empty, department.Id);
        }
    }
Exemplo n.º 2
0
    //public string UpdateDepartment(string unitId, string unit, string unitFull, string ownerId, string chief, string curator)
    public object UpdateDepartment(string unitId, string unit, string unitFull, string ownerId, string chief, string curator)
    {
        if (string.IsNullOrEmpty(unit))
        {
            //logger.Info(string.Format(LogEmptyInfo, "Unit"));
            //return string.Format(LogEmptyInfo, "Unit");
            return(true);
        }

        CardData    refStaffData = Session.CardManager.GetDictionaryData(RefStaff.ID);
        SectionData unitsSection = refStaffData.Sections[RefStaff.Units.ID];

        //im RowData department = GetExistObject(RefStaff.Units.ID, RefStaff.Units.Code, unitId);
        RowDataCollection departmentColl = GetExistObject(RefStaff.Units.ID, RefStaff.Units.Code, unitId);
        RowData           department     = null;

        try{
            department = departmentColl[0];
        }
        catch {}

        if (department == null)
        {
            return(AddDepartment(unitId, unit, unitFull, ownerId, chief, curator));
        }

        refStaffData.BeginUpdate();

        //Родитель
        if (ownerId == unitId)
        {
            return(true);
        }
        var existedParentDepartmentCode = department.ParentRow[RefStaff.Units.Code];

        if (!(existedParentDepartmentCode == null && ownerId == null) && !ownerId.Equals(existedParentDepartmentCode))
        {
            SectionQuery sectionQueryParentDepartment = Session.CreateSectionQuery();
            sectionQueryParentDepartment.ConditionGroup.Conditions.AddNew(RefStaff.Units.Code, FieldType.Unistring,
                                                                          ConditionOperation.Equals, ownerId);

            RowDataCollection departmentParentCollection = unitsSection.FindRows(sectionQueryParentDepartment.GetXml());
            if (departmentParentCollection != null && departmentParentCollection.Count > 0)
            {
                department.Move(departmentParentCollection[0].Id, Guid.Empty);
            }
        }

        refStaffData.EndUpdate();

        refStaffData.BeginUpdate();
        try{
            var isFirstLoad = ConfigurationManager.AppSettings["FirstLoad"];
            if (isFirstLoad == "1")
            {
                department[RefStaff.Units.Name]     = unit;
                department[RefStaff.Units.FullName] = unitFull;
            }
            else
            {
                department[RefStaff.Units.Name]     = unit;
                department[RefStaff.Units.FullName] = unitFull;
            }
            department[RefStaff.Units.Code] = unitId;

            //Руководитель подразделения
            if (chief != string.Empty)
            {
                try{
                    UpdateDepartmentChief(department, refStaffData, chief);
                }
                catch {
                    refStaffData.EndUpdate();
                    return("Руководитель не найден.");
                }
            }

            //Куратор подразделения
            if (curator != string.Empty)
            {
                try{
                    UpdateDepartmentCurator(department, refStaffData, curator);
                }
                catch {
                    refStaffData.EndUpdate();
                    return("Куратор не найден.");
                }
            }

            refStaffData.EndUpdate();

            //return "Департамент обновлен";
            return(true);
        }
        catch {
            return("Ошибка при попытке обновить подразделение. Необходимо перезапустить сервис!");
        }
    }