Поиск по этому блогу

пятница, 18 марта 2016 г.

DocsVision 4.5 - Алгоритм поиска в каком подразделении находится сотрудник

Столкнулся с задачей, как определить, в каком подразделении числится сотрудник в DocsVision.
Поиски по форумам особого результата не дали. Немного полазил по DVExplorer и подумал. В итоге алгоритм не очень сложный. Но придется по ходу работы учитывать разные нюансы. Например пользователей может быть два с одинаковым полем данных. Тогда нужно осуществлять поиск по уникальному полю.



Суть такова:

1 Делаем запрос через  FindRows, чтобы получить все поля пользователя.
2 Ищем в справочнике сотрудников нужное нам подразделение, которое содержит нашего пользователя. Тут есть один нюанс у сотрудника свойство ParentRowID соответствует  свойству ID у подразделения.
Скрипт не упрощал для наглядности, чтобы показать что происходит.
В общем сам скрипт


using System;
using System.Xml;

// подключение библиотек СУБП
using DocsVision.Platform.ObjectManager;
using DocsVision.Workflow.Objects;
using DocsVision.Workflow.Runtime;
using DocsVision.Workflow.Gates;


using ProcessInfo = DocsVision.Workflow.Runtime.ProcessInfo;
using System.Collections.Generic;
using System.Collections;

namespace DVScriptHost
{
    class DVScript
    {
        const string cPartners = "65FF9382-17DC-4E9F-8E93-84D6D3D8FE8C";
        const string cCompanies = "C78ABDED-DB1C-4217-AE0D-51A400546923";
        const string cProperties = "156CE04E-A0A0-4003-B068-709992035FA7";

        const string cEmployeerDirectory = "6710B92A-E148-4363-8A6F-1AA0EB18936C";//справочник сотрудников
        const string cEmployeers = "DBC8AE9D-C1D2-4D5E-978B-339D22B32482";// секция сотрудники
        const string cStaffUnits = "7473F07F-11ED-4762-9F1E-7FF10808DDD1";//секция Подразделения справочника сотрудников
        public void Execute(ProcessInfo process, PassState passInfo)
        {

            try
            {
                ProcessVariable pAuthor = process.GetVariableByName("ПользовательДляТеста");
                ProcessVariable pCard = process.GetVariableByName("Карточка");


                DVGate gate = (DVGate)process.Gates[DVGate.GateID];
                UserSession session = gate.Session;

                session.LockManager.get_LockableResource(pCard.ID).ForceUnlock();
                CardData card = session.CardManager.get_CardData(pCard.Value.ToString());
                RowData cardMain = card.Sections[card.Type.Sections.GetByAlias("MainInfo").ID].FirstRow;

                CardData StaffCatalog = session.CardManager.get_DictionaryData(cEmployeerDirectory);
                SectionData oUnits = StaffCatalog.Sections[cStaffUnits];

                DVPrincipal Author = (DVPrincipal)pAuthor.Value;
                //process.LogMessage("--->>>Author " + pAuthor.Value);
                SectionData section = StaffCatalog.Sections[cEmployeers];
                SectionQuery query = new SectionQuery();
                Condition condition = query.ConditionGroup.Conditions.AddNew("DisplayString", FieldTypeEnum.FIELD_UNISTRING,
                    ConditionOperationEnum.CONDITION_OPERATION_EQUALS, Author.DisplayString);

                condition = query.ConditionGroup.Conditions.AddNew("Email", FieldTypeEnum.FIELD_STRING,
                    ConditionOperationEnum.CONDITION_OPERATION_EQUALS, Author.Email);
                RowDataCollection result = section.FindRows(query.GetText(true, null));
                process.LogMessage("result Count" + result.Count);
                process.LogMessage(query.GetText(true, null));
                //process.LogMessage("pAuthor " + Author.DisplayString);
                //process.LogMessage("pAuthor " + Author.DisplayValue);
                //process.LogMessage("pAuthor " + Author.ID);
                string abc = "";
                if (result.Count > 0)
                {
                    for (int i = 0; i < result.Count; i++)
                    {
                        process.LogMessage("result " + i + " " + result[i].get_Value("ParentRowID").ToString());
                        process.LogMessage("result " + i + " " + result[i].get_Value("ParentTreeRowID").ToString());
                        DVPrincipal principal = (DVPrincipal)gate.GetVariable((long)DVVariableType.PRINCIPAL, result[i].ID);
                        process.LogMessage("principal FirstName " + principal.FirstName);
                        process.LogMessage("principal LastName " + principal.LastName);
                        process.LogMessage("principal Email " + principal.Email);
                        abc = result[i].get_Value("ParentRowID").ToString();
                        if (abc.Length > 0) break;
                    }
                }
                process.LogMessage("abc " + abc);



                if (oUnits.Rows.Count > 0)
                {
                    DVPrincipal principal = (DVPrincipal)gate.GetVariable((long)DVVariableType.PRINCIPAL, result[0].ID);//result[i].ID
                    process.LogMessage("principal ParentRowID " + result[0].get_Value("ParentRowID").ToString());
                    process.LogMessage("principal ParentTreeRowID " + result[0].get_Value("ParentTreeRowID").ToString());
                    foreach (RowData first in oUnits.Rows)
                    {
                        process.LogMessage("------------------------------");
                        string value1 = first.get_Value("Name").ToString();
                        if (value1 == null) value1 = "";
                        process.LogMessage(value1);
                        process.LogMessage("------------------------------");
                        
                        
                        #region основной цикл(переделан в метод)
                        foreach (RowData second in first.ChildRows)
                        {
                            process.LogMessage("second.ID " + second.ID);
                            string value1 = second.get_Value("Name").ToString();
                            if (value1 == null) value1 = "";
                            process.LogMessage(value1);
                            process.LogMessage("second ParentRowID " + second.get_Value("ParentRowID").ToString());
                            process.LogMessage("second ParentTreeRowID " + second.get_Value("ParentTreeRowID").ToString());
                            if (second.ID == abc)
                            {
                                process.LogMessage("BINGO!!!!!!");
                                process.LogMessage("THIS IS - "+value1);
                            }

                            foreach (RowData third in second.ChildRows)
                            {
                                process.LogMessage("third.ID " + third.ID);
                                string value2 = third.get_Value("Name").ToString();
                                if (value2 == null) value2 = "";
                                process.LogMessage(value2);
                                process.LogMessage("third AllChildRows.Count " + third.AllChildRows.Count);
                                process.LogMessage("third ChildRows.Count " + third.ChildRows.Count);
                                process.LogMessage("third ChildSections.Count " + third.ChildSections.Count);
                                process.LogMessage("third ParentRowID " + third.get_Value("ParentRowID").ToString());
                                process.LogMessage("third ParentTreeRowID " + third.get_Value("ParentTreeRowID").ToString());
                                if (third.ID == abc || third.get_Value("ParentTreeRowID").ToString() == abc)
                                {
                                    process.LogMessage("BINGO!!!!!!");
                                    process.LogMessage("THIS IS - " + value2);
                                }
                                    if (third.SubSection != null)
                                {
                                    if (third.SubSection.Rows != null)
                                    {
                                        process.LogMessage("third.Section.Rows " + third.SubSection.Rows.Count);
                                    }
                                }

                                foreach (RowData fourth in third.ChildRows)
                                {
                                    process.LogMessage("fourth.ID " + fourth.ID);
                                    string value3 = fourth.get_Value("FirstName").ToString();
                                    if (value3 == null) value3 = "";
                                    process.LogMessage(value3);
                                    if (fourth.Section != null)
                                    {
                                        if (fourth.Section.Rows != null)
                                        {
                                            process.LogMessage("fourth.Section.Rows " + fourth.Section.Rows.Count);
                                        }
                                    }
                                }
                            }
                        }
                        #endregion
                    }
                }
                process.LogMessage("------------------------------");
                process.LogMessage("------------------------------");
                process.LogMessage("------------------------------");
            }
            catch (Exception ex)
            {
                // запись в журнал ошибки исполнения
                process.LogMessage("Ошибка выполнения скрипта:" + ex.ToString());
                process.LogMessage("------------------------------");
                process.LogMessage("------------------------------");
                process.LogMessage("------------------------------");
            }
            return;
        }
    }
}

Комментариев нет:

Отправить комментарий