protected Table GetOrgObjectTable(OrgObject.enObjectType SAPObjTyp) { string sTabName; //--- Get the table name dependend on the SAP object type if (SAPObjTyp == OrgObject.enObjectType.Unit) { sTabName = TabName_Unit; } else if (SAPObjTyp == OrgObject.enObjectType.Position) { sTabName = TabName_Pos; } else if (SAPObjTyp == OrgObject.enObjectType.Person) { sTabName = TabName_Per; } else if (SAPObjTyp == OrgObject.enObjectType.CostCenter) { sTabName = TabName_CosCen; } else { throw new Exception(ErrMsg_InvSAPObjTyp.Replace("%typ%", SAPObjTyp.GetType().Name)); } //--- Get the table return(GetSBMTable(sTabName)); }
protected void SetChartObjects(ChartObjectList SAPChaObjLst, ChartObject SAPLeadPos, AuxiliaryItem ChaObjItem) { ChartObject SAPChaObj = null; AuxiliaryItem OrgObjItem = null; string sFldName = null; ItemIdentList IdentLst = null; ItemField Fld = null; //--- Clear the chart object references fields ClearChartObjectReferences(ChaObjItem, FldName_ChaObj_Units); ClearChartObjectReferences(ChaObjItem, FldName_ChaObj_Poss); ClearChartObjectReferences(ChaObjItem, FldName_ChaObj_Pers); ClearChartObjectReferences(ChaObjItem, FldName_ChaObj_CosCens); //--- Import the SAP objects for (int nIdx = 0; nIdx < SAPChaObjLst.Count; nIdx++) { //--- Get the SAP chart object and the tagged org-object item SAPChaObj = SAPChaObjLst[nIdx]; OrgObjItem = (AuxiliaryItem)SAPChaObj.OrgObject.Tag; //--- Get the chart object field name with the SAP object type if (SAPChaObj.OrgObject.ObjectType == OrgObject.enObjectType.Unit) { sFldName = FldName_ChaObj_Units; } else if (SAPChaObj.OrgObject.ObjectType == OrgObject.enObjectType.Position) { sFldName = FldName_ChaObj_Poss; } else if (SAPChaObj.OrgObject.ObjectType == OrgObject.enObjectType.Person) { sFldName = FldName_ChaObj_Pers; } else if (SAPChaObj.OrgObject.ObjectType == OrgObject.enObjectType.CostCenter) { sFldName = FldName_ChaObj_CosCens; } else { throw new Exception(ErrMsg_InvSAPObjTyp.Replace("%typ%", SAPChaObj.OrgObject.ObjectType.ToString())); } //--- Get the field and the items idents Fld = GetSBMItemFieldByDatabaseName(ChaObjItem, sFldName); IdentLst = Fld.GetItemIdentValues(); //--- Add the chart object item ident and set the item idents IdentLst.Add(new ItemIdent(OrgObjItem)); Fld.SetItemIdentValues(IdentLst); /* * //--- Set the lead position item if exists * if (SAPLeadPos != null) * GetSBMItemFieldByDatabaseName(ChaObjItem, FldName_ChaObj_LeadPos).SetItemIdentValue(new ItemIdent((AuxiliaryItem)SAPChaObj.LeadPosition.Tag)); */ //--- Set the item references SetChartObjects(SAPChaObj.ChartObjects, SAPChaObj.LeadPosition, OrgObjItem); } }
public override void Run() { /*TEST * Library.Windows.Windows.Pause(20000); * return; */ OrgChart SAPOrgCha = null; OrgObject SAPOrgObj = null; Table Tab = null; AuxiliaryItem OrgChaItem = null, OrgObjItem = null; UserList UsrLst = null; User Usr = null; Hashtable UsrTab = null; ItemList OrgChaItemLst = null, UnitItemLst = null, PosItemLst = null, PerItemLst = null, CosCenItemLst = null, OrgObjItemLst = null; int nPerNum = Global.IntegerNull, nProgIdx = Global.IntegerNull, nAllCnt = Global.IntegerNull; //--- Create a new start import message CreateMessage(ProgressMessage.enMessageState.Info, ProgMsg_StartImpSAPOrgCha); //--- Read the SAP org-chart SAPOrgCha = new OrgChart(); SAPOrgCha = OrgChart.FromSAPFiles(ObjectFileWatcher.FileName, ReferenceFileWatcher.FileName); //--- Create a new read server users message CreateMessage(ProgressMessage.enMessageState.Info, ProgMsg_ReadOrgObjsSvr.Replace("%svr%", GetServer().ServerName)); //--- Read the users UsrLst = ReadAllSBMUsers(); //--- Init the user table and the AD user info UsrTab = new Hashtable(); //--- Add the user to the user table for (int nIdx = 0; nIdx < UsrLst.Count; nIdx++) { //--- Get the user and the personnel number Usr = UsrLst[nIdx]; nPerNum = String.IsNullOrEmpty(Usr.GetEmailCC()) ? 0 : Convert.ToInt32(Usr.GetEmailCC()); //--- Check personnel number not exists if (nPerNum == 0) { continue; } //--- Check user exists in the user table else if (UsrTab[nPerNum] == null) { UsrTab.Add(nPerNum, Usr); } else { //--- Create a new start import message CreateMessage ( ProgressMessage.enMessageState.Warning, ProgMsg_UsrPerNumExi .Replace("%usr%", Usr.GetDisplayName()) .Replace("%num%", nPerNum.ToString()) ); } } //--- Read the orag objects OrgChaItemLst = ReadSBMItems(TabName_OrgCha, SQLWhere_OrgCha_NumSky.Replace("%num%", FldVal_OrgCha_Num_Sky.ToString())); UnitItemLst = ReadSBMItems(TabName_Unit); PosItemLst = ReadSBMItems(TabName_Pos); PerItemLst = ReadSBMItems(TabName_Per); CosCenItemLst = ReadSBMItems(TabName_CosCen); //--- Find the org-chart item wit the Sky number OrgChaItem = (AuxiliaryItem)OrgChaItemLst.FindByItemFieldValue(FldName_OrgCha_Num, FieldList.enFieldIdent.DatabaseName, FldVal_OrgCha_Num_Sky); //--- Check org-chart item exists if (OrgChaItem == null) { //--- Init the Sky org-chart and add to the org-chart items OrgChaItem = GetSBMTable(TabName_OrgCha).NewAuxiliaryItem(); OrgChaItemLst.Add(OrgChaItem); //--- Tag the org-chart item for create OrgChaItem.Tag = enAction.Create; } //--- Tag the org-chart item for update else { OrgChaItem.Tag = enAction.Update; } //--- Update the org-chart item values GetSBMItemFieldByDatabaseName(OrgChaItem, FldName_OrgCha_Num).SetIntegerValue(FldVal_OrgCha_Num_Sky); OrgChaItem.SetActive(true); //--- Create a new read AD users message CreateMessage(ProgressMessage.enMessageState.Info, ProgMsg_ImpSAPOrgObjs); //--- Import the SAP org-objects for (int nIdx = 0; nIdx < SAPOrgCha.OrgObjects.Count; nIdx++) { //--- Get the SAP object and the table SAPOrgObj = SAPOrgCha.OrgObjects[nIdx]; Tab = GetOrgObjectTable(SAPOrgObj.ObjectType); //--- Get the table name dependend on the SAP object type if (SAPOrgObj.ObjectType == OrgObject.enObjectType.Unit) { OrgObjItemLst = UnitItemLst; } else if (SAPOrgObj.ObjectType == OrgObject.enObjectType.Position) { OrgObjItemLst = PosItemLst; } else if (SAPOrgObj.ObjectType == OrgObject.enObjectType.Person) { OrgObjItemLst = PerItemLst; } else if (SAPOrgObj.ObjectType == OrgObject.enObjectType.CostCenter) { OrgObjItemLst = CosCenItemLst; } else { throw new Exception(ErrMsg_InvSAPObjTyp.Replace("%typ%", SAPOrgObj.ObjectType.ToString())); } //--- Find the orga object item OrgObjItem = (AuxiliaryItem)OrgObjItemLst.FindByItemFieldValue(FldName_OrgObj_Num, FieldList.enFieldIdent.DatabaseName, SAPOrgObj.ObjectNumber); //--- Check org-object item exists if (OrgObjItem == null) { //--- Init the orga object and add to the org-object items OrgObjItem = Tab.NewAuxiliaryItem(); OrgObjItemLst.Add(OrgObjItem); //--- Tag the org-object item with the crsate action OrgObjItem.Tag = enAction.Create; } //--- Tag the org-object item with the update action else { OrgObjItem.Tag = enAction.Update; } //--- Set the values OrgObjItem.SetTitle(SAPOrgObj.LongName); OrgObjItem.SetActive(SAPOrgObj.IsActiveNow()); GetSBMItemFieldByDatabaseName(OrgObjItem, FldName_OrgObj_Num).SetIntegerValue(SAPOrgObj.ObjectNumber); SetOrgObjectItemDate(OrgObjItem, FldName_OrgObj_StartDat, SAPOrgObj.StartDate); SetOrgObjectItemDate(OrgObjItem, FldName_OrgObj_EndDat, SAPOrgObj.EndDate); //--- Check position obejct type if (SAPOrgObj.ObjectType == OrgObject.enObjectType.Position) { GetSBMItemFieldByDatabaseName(OrgObjItem, FldName_Pos_JobID).SetTextValue(SAPOrgObj.ShortName); } //--- Check person object type else if (SAPOrgObj.ObjectType == OrgObject.enObjectType.Person) { //--- Get the user Usr = (User)UsrTab[SAPOrgObj.ObjectNumber]; //--- Set the user in the person item if (Usr == null) { GetSBMItemFieldByDatabaseName(OrgObjItem, FldName_Per_Usr).SetNullValue(); } else { GetSBMItemFieldByDatabaseName(OrgObjItem, FldName_Per_Usr).SetRelationalID(Usr.GetID()); } //--- Set the user active dependend if the user exists and is active OrgObjItem.SetActive(Usr != null ? !Usr.IsDeleted() : false); } //--- Tag the SAP org-object with the org-object item SAPOrgObj.Tag = OrgObjItem; } //--- Set the chart objects of the org-chart SetChartObjects(SAPOrgCha.ChartObjects, null, OrgChaItem); //--- Activate and tag the item lists ActivateOrgObjectItems(UnitItemLst, false, enAction.Delete); ActivateOrgObjectItems(PosItemLst, false, enAction.Delete); ActivateOrgObjectItems(PerItemLst, false, enAction.Delete); ActivateOrgObjectItems(CosCenItemLst, true, enAction.None); //--- Create a new read AD users message CreateMessage(ProgressMessage.enMessageState.Info, ProgMsg_AddOrUpdSAPOrgObjs); //--- Init the progress index and calculate the all count nProgIdx = 0; nAllCnt = OrgChaItemLst.Count + UnitItemLst.Count + PosItemLst.Count + PerItemLst.Count + CosCenItemLst.Count; //--- Add or update the org-objects AddOrUpdateOrgObjItems(OrgChaItemLst, ObjTypStr_OrgCha, ref nProgIdx, nAllCnt); AddOrUpdateOrgObjItems(UnitItemLst, OrgObject.enObjectType.Unit.ToString(), ref nProgIdx, nAllCnt); AddOrUpdateOrgObjItems(PosItemLst, OrgObject.enObjectType.Position.ToString(), ref nProgIdx, nAllCnt); AddOrUpdateOrgObjItems(PerItemLst, OrgObject.enObjectType.Person.ToString(), ref nProgIdx, nAllCnt); AddOrUpdateOrgObjItems(CosCenItemLst, OrgObject.enObjectType.CostCenter.ToString(), ref nProgIdx, nAllCnt); //--- Create a new message CreateMessage(ProgressMessage.enMessageState.Info, ProgMsg_FinImpADUsrs, nAllCnt, nAllCnt); }