unit ole1c; interface uses Classes, ComCtrls, Grids, Variants, StrUtils, SysUtils, Windows, Dialogs; Const ACT_VIEW = 'Просмотреть'; ACT_VIEWOFNUM = 'ПросмотретьПоНомеру'; ACT_EDIT = 'Просмотреть в развёрнутом виде'; ACT_ENTRY = 'Провести'; ACT_DELENTRY = 'Отменить проводку'; ACT_MARKDEL = 'Пометить на удаление'; ACT_NOMARKDEL = 'Снять пометку на удаление'; ACT_DELETE = 'Удалить'; ACT_GETTABLE = 'Получить табличную часть'; ACT_ADD = 'Добавить элемент'; ACT_ADDGROUP = 'Добавить группу'; ACT_GETTURN = 'Получить обороты'; ACT_GETREST = 'Получить остаток'; ACT_EXECQUERY = 'Выполнить запрос'; MD_OBJTYPEDATA= 'Объектный тип данных'; MD_CONST = 0; MD_PREFERENCE = 1; MD_DOCUMENT = 2; MD_ENUM = 3; MD_REGISTER = 4; MD_BOOKTOTALS = 5; str_SEP='|+|+|+|+|'; type TDateInterval=array[0..1] of TDateTime; TTypeDataObject = (tdUnknown,tdNumber,tdString,tdDate,tdEnum, tdReference,tdDocument,tdCalendar, tdCalculationKind{ВидРасчета},tdAccount{Счет}, tdSubcontoKind{ВидСубконто}, tdChartOfAccounts{ПланСчетов},tdOthers, tdNumPD,tdStrPD,tdDtPD); type TServer1C = class(TComponent) protected FOLEServer:OleVariant; tmpOLE:OleVariant; tmpItem:TListItem; procedure ClearVariable; public constructor Create(AOwner: TComponent); override; function BegOfYear(ADate:TDateTime=0):TDateTime; function EndOfYear(ADate:TDateTime=0):TDateTime; function GetTypePeriodicData(const pObject:String; var tdTypeData:TTypeDataObject):String; function FindIdentifierObject(const Present,TypeObject:String; const IndexTypeObject:Integer; var IndexObject:Integer):String; function GetAttrib_(TDO:TTypeDataObject;Attrib:OleVariant):String; function GetAttribut_(const pObject:String; const pPresent,IndexAttr:Integer; var Periodic:Boolean):OleVariant; function GetCountAttributs(const pObject:String; const pPresent:Integer):Integer; function GetCountObjects(const pObject:String):Integer; function GetMetaDataObject(const IndexTypeObject,IndexObject:Integer):OleVariant; function GetTypeDataObject(const pObject:String;var TypeStr:String):TTypeDataObject; function GetValueTypeData(IDAttr:String;var TypeStr:String):String; function ExecuteActionDocument(const _Object:String; var List:TListView;ObjectAction:String; DateQuery:TDateInterval;p:TStatusBar):TStrings; function ExecuteActionPreference(const _Object:String; var List:TListView;ObjectAction:String; DateQuery:TDateInterval;p:TStatusBar):TStrings; function SetInterval(DateBeg,DateEnd:TDateTime):TDateInterval; procedure ExecuteActionConst(const _Object:String; var Grid:TStringGrid;ObjectAction:String; DateQuery:TDateInterval); procedure ExecuteActionEnum(const _Object:String;var Grid:TStringGrid;ObjectAction:String); published property OLEServer:OleVariant read FOLEServer write FOLEServer; end; var TypeObjects : array [0..5,0..1] of String; implementation constructor TServer1C.Create(AOwner: TComponent); begin inherited Create(AOwner); TypeObjects[0,0]:='Константа';TypeObjects[1,0]:='Справочник'; TypeObjects[2,0]:='Документ';TypeObjects[3,0]:='Перечисление'; TypeObjects[4,0]:='Регистр';TypeObjects[5,0]:='БухгалтерскиеИтоги'; TypeObjects[0,1]:='Const';TypeObjects[1,1]:='Reference'; TypeObjects[2,1]:='Document';TypeObjects[3,1]:='Enum'; TypeObjects[4,1]:='Register';TypeObjects[5,1]:='BookkeepingTotals'; end; procedure TServer1C.ClearVariable; begin tmpOLE:=UnAssigned; Pointer(tmpItem):=nil; end; function TServer1C.BegOfYear(ADate:TDateTime=0):TDateTime; begin Result:=FOLEServer.EvalExpr(IfThen(ADate<>0,Format('НачГода(Дата("%s"))', [DateToStr(ADate)]),'НачалоПериодаБИ()')); end; function TServer1C.EndOfYear(ADate:TDateTime=0):TDateTime; begin Result:=FOLEServer.EvalExpr(IfThen(ADate<>0,Format('КонГода(Дата("%s"))', [DateToStr(ADate)]),'КонецПериодаБИ()')); end; function TServer1C.GetTypePeriodicData(const pObject:String; var tdTypeData:TTypeDataObject):String; var CallBackDate : TDateTime; CallBackValue : String; CallBackNumber : Extended; begin try CallBackValue:=FOLEServer.EvalExpr(Format('%s.Получить(ТекущаяДата())',[pObject])); try CallBackNumber:=StrToFloat(CallBackValue); CallBackValue:=FloatToStr(CallBackNumber); Result:='Число (периодический реквизит)'; tdTypeData:=tdNumPD; except try if CallBackValue = '0:00:00' then Result:='Дата (периодический реквизит)' else begin CallBackDate:=StrToDate(CallBackValue); CallBackValue:=DateToStr(CallBackDate); Result:='Дата (периодический реквизит)' end; tdTypeData:=tdDtPD; except try Result:='Строка (периодический реквизит)'; tdTypeData:=tdStrPD; except end; end; end; except Result:='Внешний тип'; tdTypeData:=tdOthers; end; end; function TServer1C.GetAttrib_(TDO:TTypeDataObject;Attrib:OleVariant):String; begin case TDO of tdEnum : Result:='[Перечисление]'; tdReference : Result:='[Справочник]'; tdDocument : Result:='[Документ]'; tdCalendar : Result:='[Календарь]'; tdCalculationKind: Result:='[Вид расчета]'; tdAccount : Result:='[Счет]'; else Result:=Format('[%s]',[MD_OBJTYPEDATA]); end; end; function TServer1C.GetAttribut_(const pObject:String; const pPresent,IndexAttr:Integer; var Periodic:Boolean):OleVariant; begin Result:=FOLEServer.EvalExpr(Format('Метаданные.%s("%s").Реквизит(%d)', [TypeObjects[pPresent,0],pObject,IndexAttr])); Periodic:=(FOLEServer.EvalExpr(Format('Метаданные.%s("%s").Реквизит(%d).Периодический', [TypeObjects[pPresent,0],pObject,IndexAttr])) = 1); end; function TServer1C.GetCountAttributs(const pObject:String; const pPresent:Integer):Integer; begin Result:=FOLEServer.EvalExpr(Format('Метаданные.%s("%s").Реквизит()', [TypeObjects[pPresent,0],pObject])); end; function TServer1C.GetCountObjects(const pObject:String):Integer; begin try Result:=FOLEServer.EvalExpr(Format('Метаданные.%s()',[pObject])); except Result:=-1; end; end; function TServer1C.GetMetaDataObject(const IndexTypeObject, IndexObject:Integer):OleVariant; begin Case IndexTypeObject of 0 : Result:=FOLEServer.MetaData.Const(IndexObject); 1 : Result:=FOLEServer.MetaData.Reference(IndexObject); 2 : Result:=FOLEServer.MetaData.Document(IndexObject); 3 : Result:=FOLEServer.MetaData.Enum(IndexObject); 4 : Result:=FOLEServer.MetaData.Register(IndexObject); 5 : Result:=FOLEServer.MetaData.BookkeepingTotals(IndexObject); else Result:=UnAssigned; end; end; function TServer1C.GetTypeDataObject(const pObject:String; var TypeStr:String):TTypeDataObject; var TypeData:Byte; begin TypeData:=FOLEServer.EvalExpr(Format('ТипЗначения(%s)',[pObject])); Case TypeData of 0 : begin Result:=tdUnknown; TypeStr:='Unknown'; end; 1 : begin Result:=tdNumber; TypeStr:='Число'; end; 2 : begin Result:=tdString; TypeStr:='Строка'; end; 3 : begin Result:=tdDate; TypeStr:='Дата'; end; 10 : begin Result:=tdEnum; TypeStr:='Перечисление'; end; 11 : begin Result:=tdReference; TypeStr:='Справочник'; end; 12 : begin Result:=tdDocument; TypeStr:='Документ'; end; 13 : begin Result:=tdCalendar; TypeStr:='Календарь'; end; 14 : begin Result:=tdCalculationKind; TypeStr:='ВидРасчета'; end; 15 : begin Result:=tdAccount; TypeStr:='Счет'; end; 16 : begin Result:=tdSubcontoKind; TypeStr:='ВмдСубконто'; end; 17 : begin Result:=tdChartOfAccounts; TypeStr:='ПланСчетов'; end; 100 : begin TypeStr:=GetTypePeriodicData(pObject,Result); end; else Result:=tdUnknown; TypeStr:='Unknown'; end; end; function TServer1C.GetValueTypeData(IDAttr:String;var TypeStr:String):String; var tmpX:String; xOLE:OleVariant; begin xOLE:=tmpOLE; Result:=EmptyStr; try tmpX:=xOLE.GetAttrib(IDAttr).IsAmount; TypeStr:=Format('(%s) %s',[xOLE.GetAttrib(IDAttr).Code, xOLE.GetAttrib(IDAttr).Description]); Result:='[A]'; except try tmpX:=IntToStr(xOLE.GetAttrib(IDAttr).IsGroup); TypeStr:=Format('%s',[xOLE.GetAttrib(IDAttr).Description]); Result:='[P]'; except try tmpX:=IntToStr(xOLE.GetAttrib(IDAttr).IsTransacted(1)); TypeStr:=Format('%s №%s от %s',[xOLE.GetAttrib(IDAttr).KindPresent, xOLE.GetAttrib(IDAttr).DocNum, DateToStr(xOLE.GetAttrib(IDAttr).DocDate)]); Result:='[D]'; except try tmpX:=IfThen(xOLE.GetAttrib(IDAttr).Number=0,'1', IntToStr(xOLE.GetAttrib(IDAttr).Number)); TypeStr:=FOLEServer.EvalExpr(Format( 'Перечисление.%s.ЗначениеПоНомеру(%s)', [xOLE.GetAttrib(IDAttr).Kind, tmpX])).Identifier; TypeStr:=IfThen(xOLE.GetAttrib(IDAttr).Number=0,EmptyStr,TypeStr); Result:='[E]'; except try TypeStr:=Trim(xOLE.GetAttrib(IDAttr)); except TypeStr:=MD_OBJTYPEDATA; Result:='[X]'; end; end; end; end; end; xOLE:=UnAssigned; end; function TServer1C.FindIdentifierObject(const Present,TypeObject:String; const IndexTypeObject:Integer; var IndexObject:Integer):String; var Counter,CountObj:Integer; begin Result:=EmptyStr;CountObj:=GetCountObjects(TypeObject); for Counter:=1 to CountObj do if GetMetaDataObject(IndexTypeObject,Counter).Present = Present then begin IndexObject:=Counter; Result:=GetMetaDataObject(IndexTypeObject,Counter).Identifier; Break; end; end; procedure TServer1C.ExecuteActionConst(const _Object:String; var Grid:TStringGrid; ObjectAction:String; DateQuery:TDateInterval); const GetValue = '%s.ПолучитьАтрибут("%s")'; GetDateValue = '%s.ПолучитьАтрибут("%s").Получить(Дата("%s"))'; var Identifier,TypeStr:String; I,J:Integer; CallBackType:TTypeDataObject; begin if (Length(Trim(_Object)) = 0) or (Length(Trim(ObjectAction)) = 0) then Exit; Identifier:=FindIdentifierObject(_Object,TypeObjects[MD_CONST,0],MD_CONST,I); CallBackType:=GetTypeDataObject(TypeObjects[MD_CONST,0]+'.'+Identifier,TypeStr); tmpOLE:=GetMetaDataObject(MD_CONST,I); if ObjectAction = ACT_VIEW then begin for I := 0 to Grid.RowCount - 1 do for J:=0 to Grid.ColCount - 1 do Grid.Cells[J,I]:=EmptyStr; Grid.Cells[1,0]:='Значение';Grid.Cells[2,0]:='Тип'; Grid.Cells[2,1]:=TypeStr; case CallBackType of tdUnknown : Grid.Cells[1,1]:='Объект неопределённого типа'; tdOthers : Grid.Cells[1,1]:='<...>'; tdNumber : Grid.Cells[1,1]:=FloatToStr(FOLEServer.EvalExpr( Format(GetValue,[TypeObjects[MD_CONST,0],Identifier]))); tdString : Grid.Cells[1,1]:=FOLEServer.EvalExpr( Format(GetValue,[TypeObjects[MD_CONST,0],Identifier])); tdDate : Grid.Cells[1,1]:=DateToStr(FOLEServer.EvalExpr( Format(GetValue,[TypeObjects[MD_CONST,0],Identifier]))); tdNumPD : Grid.Cells[1,1]:=FloatToStr(FOLEServer.EvalExpr( Format(GetDateValue,[TypeObjects[MD_CONST,0],Identifier,DateToStr(DateQuery[0])]))); tdStrPD : Grid.Cells[1,1]:=FOLEServer.EvalExpr( Format(GetDateValue,[TypeObjects[MD_CONST,0],Identifier,DateToStr(DateQuery[0])])); tdDtPD : Grid.Cells[1,1]:=DateToStr(FOLEServer.EvalExpr( Format(GetDateValue,[TypeObjects[MD_CONST,0],Identifier,DateToStr(DateQuery[0])]))); tdEnum : Grid.Cells[1,1]:=tmpOLE.Description; tdReference : Grid.Cells[1,1]:=tmpOLE.Description; tdDocument : Grid.Cells[1,1]:=tmpOLE.Description; tdCalendar : Grid.Cells[1,1]:=tmpOLE.Description; tdCalculationKind : Grid.Cells[1,1]:=tmpOLE.Description; tdAccount : Grid.Cells[1,1]:=tmpOLE.Description; tdSubcontoKind : Grid.Cells[1,1]:=tmpOLE.Description; tdChartOfAccounts : Grid.Cells[1,1]:=tmpOLE.Description; end; end; end; procedure TServer1C.ExecuteActionEnum(const _Object:String; var Grid:TStringGrid; ObjectAction:String); var Identifier:String; I,countEnum:Integer; begin if (Length(Trim(_Object)) = 0) or (Length(Trim(ObjectAction)) = 0) then Exit; Identifier:=FindIdentifierObject(_Object,TypeObjects[MD_ENUM,0],MD_ENUM,I); if ObjectAction = ACT_VIEW then begin for I := 0 to Grid.RowCount - 1 do for countEnum:=0 to Grid.ColCount - 1 do Grid.Cells[countEnum,I]:=EmptyStr; countEnum:=FOLEServer.EvalExpr(Format('Перечисление.%s.КоличествоЗначений()',[Identifier])); Grid.RowCount:=countEnum+1; Grid.Cells[1,0]:='Идентификатор'; for I:=1 to countEnum do Grid.Cells[1,I]:=FOLEServer.EvalExpr(Format( 'Перечисление.%s.ЗначениеПоНомеру(%d)',[Identifier,I])).Identifier; end; end; function TServer1C.ExecuteActionDocument(const _Object:String; var List:TListView; ObjectAction:String; DateQuery:TDateInterval; p:TStatusBar):TStrings; var Identifier,IdentifierAttribut,tmpSTR,vType:String; IndexObject:Integer; Counter,Index:Integer; tmpDI:TDateInterval; countHeader,countTable, countGlobal:Integer; begin Result:=TStringList.Create; Result.Clear; if (Length(Trim(_Object)) = 0) or (Length(Trim(ObjectAction)) = 0) then Exit;Counter:=1; Identifier:=FindIdentifierObject(_Object,TypeObjects[MD_DOCUMENT,0], MD_DOCUMENT,IndexObject); tmpOLE:=FOLEServer.CreateObject(Format('%s.%s',[TypeObjects[MD_DOCUMENT,0],Identifier])); if (ObjectAction = ACT_VIEW) or (ObjectAction = ACT_VIEWOFNUM) then begin tmpOLE.SelectDocuments(DateQuery[0],DateQuery[1]); if ObjectAction = ACT_VIEW then begin List.Clear;p.Panels[0].Text:='Документов за выбранный период нет'; while tmpOLE.GetDocument(1) > 0 do //Выбираем все документы begin tmpItem:=List.Items.Add; Index:=tmpOLE.IsTransacted(1)+4; if tmpOLE.DeleteMark=0 then tmpItem.ImageIndex:=Index else tmpItem.ImageIndex:=6; tmpItem.SubItems.Add(tmpOLE.DocNum); tmpItem.SubItems.Add(DateToStr(tmpOLE.DocDate)); p.Panels[0].Text:=Format('Обработано %d документов',[Counter]); Inc(Counter); UpdateWindow(p.Handle); end; end else begin tmpItem:=List.Items[List.ItemIndex]; while tmpOLE.GetDocument(1) > 0 do //Выбираем все документы if tmpOLE.DocNum = tmpItem.SubItems[0] then begin Index:=tmpOLE.IsTransacted(1)+4; if tmpOLE.DeleteMark=0 then tmpItem.ImageIndex:=Index else tmpItem.ImageIndex:=6; Break; end; end; ClearVariable; Exit; end; if (ObjectAction = ACT_DELETE) or (ObjectAction = ACT_MARKDEL) or (ObjectAction = ACT_NOMARKDEL) then begin tmpDI:=SetInterval(StrToDate(List.Items[List.ItemIndex].SubItems[1]), StrToDate(List.Items[List.ItemIndex].SubItems[1])); tmpOLE.SelectDocuments(tmpDI[0],tmpDI[1]); while tmpOLE.GetDocument(1) > 0 do //Выбираем все документы if tmpOLE.DocNum = List.Items[List.ItemIndex].SubItems[0] then begin if ObjectAction <> ACT_NOMARKDEL then tmpOLE.Delete(StrToInt(IfThen(ObjectAction = ACT_DELETE,'1','0'))) else tmpOLE.ClearDeleteMark; Break; end; ClearVariable; Exit; end; if (ObjectAction = ACT_ENTRY) or (ObjectAction = ACT_DELENTRY) then begin tmpDI:=SetInterval(StrToDate(List.Items[List.ItemIndex].SubItems[1]), StrToDate(List.Items[List.ItemIndex].SubItems[1])); tmpOLE.SelectDocuments(tmpDI[0],tmpDI[1]); while tmpOLE.GetDocument(1) > 0 do //Выбираем все документы if tmpOLE.DocNum = List.Items[List.ItemIndex].SubItems[0] then begin if ObjectAction = ACT_ENTRY then tmpOLE.MakeActions else tmpOLE.UnPost; Break; end; ClearVariable; ExecuteActionDocument(_Object,List,ACT_VIEWOFNUM,tmpDI,p); Exit; end; if (ObjectAction = ACT_EDIT) or (ObjectAction = ACT_GETTABLE) then begin if (List.Items.Count=0) or (List.ItemIndex < 0) then Exit; tmpDI:=SetInterval(StrToDate(List.Items[List.ItemIndex].SubItems[1]), StrToDate(List.Items[List.ItemIndex].SubItems[1])); tmpOLE.SelectDocuments(tmpDI[0],tmpDI[1]); while tmpOLE.GetDocument(1) > 0 do //Выбираем все документы if tmpOLE.DocNum = List.Items[List.ItemIndex].SubItems[0] then Break; countTable := FOLEServer.EvalExpr(Format('Метаданные.Документ("%s").РеквизитТабличнойЧасти()',[Identifier])); if ObjectAction = ACT_GETTABLE then begin if tmpOLE.SelectLines(1) <> 1 then begin ClearVariable; Exit; end; while tmpOLE.GetLine(1) > 0 do begin //Выбираем все строки документа for Index:=1 to countTable do begin IdentifierAttribut:=FOLEServer.EvalExpr(Format( 'Метаданные.Документ("%s").РеквизитТабличнойЧасти(%d).Идентификатор', [Identifier,Index])); vType:=GetValueTypeData(IdentifierAttribut,tmpSTR); Result.Add(Format('%s%s%s%s%s',[FOLEServer.EvalExpr(Format( 'Метаданные.Документ("%s").РеквизитТабличнойЧасти(%d).Представление()', [Identifier,Index])),str_SEP,vType,str_SEP,tmpSTR])); end; end; ClearVariable; Exit; end; countHeader := FOLEServer.EvalExpr(Format('Метаданные.Документ("%s").РеквизитШапки()',[Identifier])); countGlobal := FOLEServer.EvalExpr('Метаданные.ОбщийРеквизитДокумента()'); for Index:=1 to countHeader do begin IdentifierAttribut:=FOLEServer.EvalExpr(Format( 'Метаданные.Документ("%s").РеквизитШапки(%d).Идентификатор', [Identifier,Index])); vType:=GetValueTypeData(IdentifierAttribut,tmpSTR); Result.Add(Format('HEAD%s%s%s%s%s%s%s',[vType,str_SEP,IdentifierAttribut,str_SEP, tmpSTR,str_SEP,FOLEServer.EvalExpr(Format( 'Метаданные.Документ("%s").РеквизитШапки(%d).Представление()', [Identifier,Index]))])); end; for Index:=1 to countTable do begin IdentifierAttribut:=FOLEServer.EvalExpr(Format( 'Метаданные.Документ("%s").РеквизитТабличнойЧасти(%d).Идентификатор', [Identifier,Index])); vType:=GetValueTypeData(IdentifierAttribut,tmpSTR); Result.Add(Format('TABL%s%s%s%s%s%s%s',[vType,str_SEP,IdentifierAttribut,str_SEP, tmpSTR,str_SEP,FOLEServer.EvalExpr(Format( 'Метаданные.Документ("%s").РеквизитТабличнойЧасти(%d).Представление()', [Identifier,Index]))])); end; for Index:=1 to countGlobal do begin IdentifierAttribut:=FOLEServer.EvalExpr(Format( 'Метаданные.ОбщийРеквизитДокумента(%d).Идентификатор', [Index])); vType:=GetValueTypeData(IdentifierAttribut,tmpSTR); Result.Add(Format('GLOB%s%s%s%s%s%s%s',[vType,str_SEP,IdentifierAttribut,str_SEP, tmpSTR,str_SEP,FOLEServer.EvalExpr(Format( 'Метаданные.ОбщийРеквизитДокумента(%d).Представление()', [Index]))])); end; ClearVariable; end; end; function TServer1C.ExecuteActionPreference(const _Object:String; var List:TListView; ObjectAction:String; DateQuery:TDateInterval; p:TStatusBar):TStrings; const ENTER_NAME_ELEMENT = 'Введите наименование нового элемента справочника'; ENTER_KOD_ELEMENT = 'Введите код нового элемента справочника'; ENTER_NAME_GROUP = 'Введите наименование новой группы'; ENTER_KOD_GROUP = 'Введите код новой группы'; NEW_ELEMENT = 'Новый элемент'; NEW_GROUP = 'Новая группа'; var Identifier,vType,tmpSTR1,tmpSTR2,tmpSTR3:String; IndexObject,CountAttr:Integer; PeriodAttr:Boolean; Counter,Index:Integer; begin Result:=TStringList.Create; Result.Clear; if (Length(Trim(_Object)) = 0) or (Length(Trim(ObjectAction)) = 0) then Exit; Counter:=1; Identifier:=FindIdentifierObject(_Object,TypeObjects[MD_PREFERENCE,0], MD_PREFERENCE,IndexObject); tmpOLE:=FOLEServer.CreateObject(Format('%s.%s',[TypeObjects[MD_PREFERENCE,0],Identifier])); if (ObjectAction = ACT_VIEW) or (ObjectAction = ACT_VIEWOFNUM) then begin if ObjectAction = ACT_VIEW then begin List.Clear;p.Panels[0].Text:='Справочник пуст'; tmpOLE.SelectItems(1); //Открываем выборку элементов справочника while tmpOLE.GetItem(1) > 0 do //Выбираем все элементы begin tmpItem:=List.Items.Add; Index:=Round(ABS(tmpOLE.IsGroup(1)-1)); tmpItem.ImageIndex:=StrToInt(IfThen(tmpOLE.DeleteMark=0,IntToStr(Index),IntToStr(Index+2))); tmpItem.SubItems.Add(tmpOLE.FullCode); tmpItem.SubItems.Add(tmpOLE.Description); p.Panels[0].Text:=Format('Обработано %d элементов',[Counter]); Inc(Counter);UpdateWindow(p.Handle); end; end else begin tmpOLE.FindByCode(Trim(List.Items[List.ItemIndex].SubItems[0]),2); tmpItem:=List.Items[List.ItemIndex]; Index:=Round(ABS(tmpOLE.IsGroup(1)-1)); tmpItem.ImageIndex:=StrToInt(IfThen(tmpOLE.DeleteMark=0,IntToStr(Index),IntToStr(Index+2))); tmpItem.SubItems[0]:=tmpOLE.FullCode; tmpItem.SubItems[1]:=tmpOLE.Description; end; ClearVariable; Exit; end; if (ObjectAction = ACT_EDIT) then begin if (List.Items.Count=0) or (List.ItemIndex < 0) then Exit; if Length(Trim(List.Items[List.ItemIndex].SubItems[0])) > 0 then begin tmpOLE.FindByCode(Trim(List.Items[List.ItemIndex].SubItems[0]),2); tmpOLE.UseDate(DateQuery[0],1); CountAttr:=GetCountAttributs(Identifier,MD_PREFERENCE);Result.Clear; Result.Add(Format('%s%s%s%s%s%s%s',['Наименование',str_SEP,EmptyStr,str_SEP, tmpOLE.Description,str_SEP,'Наименование'])); Result.Add(Format('%s%s%s%s%s%s%s',['Код',str_SEP,EmptyStr,str_SEP, tmpOLE.FullCode,str_SEP,'Код'])); if tmpOLE.IsGroup(1) = 1 Then Exit; for Counter:=1 to CountAttr do begin tmpSTR1:=GetAttribut_(Identifier,MD_PREFERENCE,Counter,PeriodAttr).Identifier; tmpSTR2:=GetAttribut_(Identifier,MD_PREFERENCE,Counter,PeriodAttr).Present; try tmpSTR3:=IfThen(PeriodAttr, Trim(tmpOLE.GetAttrib(tmpSTR1).GetValue(DateQuery[0])), Trim(tmpOLE.GetAttrib(tmpSTR1))); except vType:=GetValueTypeData(tmpSTR1,tmpSTR3); end; Result.Add(Format('%s%s%s%s%s%s%s',[tmpSTR1,str_SEP, IfThen(PeriodAttr,'*',EmptyStr)+vType,str_SEP,tmpSTR3,str_SEP,tmpSTR2])); end; ClearVariable; ExecuteActionPreference(_Object,List,ACT_VIEWOFNUM,DateQuery,p); Exit; end; end; if (ObjectAction = ACT_DELETE) or (ObjectAction = ACT_MARKDEL) or (ObjectAction = ACT_NOMARKDEL) then begin if Length(Trim(List.Items[List.ItemIndex].SubItems[0])) > 0 then begin tmpOLE.FindByCode(Trim(List.Items[List.ItemIndex].SubItems[0]),2); if ObjectAction <> ACT_NOMARKDEL then tmpOLE.Delete(IfThen(ObjectAction = ACT_DELETE,'1','0')) else tmpOLE.ClearDeleteMark; ClearVariable; end; ExecuteActionPreference(_Object,List,IfThen(ObjectAction = ACT_DELETE, ACT_VIEW,ACT_VIEWOFNUM), DateQuery,p); Exit; end; if (ObjectAction = ACT_ADD) or (ObjectAction = ACT_ADDGROUP) then begin if ObjectAction = ACT_ADD then tmpOLE.New else tmpOLE.NewGroup; tmpSTR1:=IfThen((ObjectAction = ACT_ADD),NEW_ELEMENT,NEW_GROUP); tmpSTR2:='Код'; if not InputQuery(IfThen((ObjectAction = ACT_ADD), ENTER_NAME_ELEMENT,ENTER_NAME_GROUP), tmpSTR1,tmpSTR1) then begin ClearVariable; Exit; end; if not InputQuery(IfThen((ObjectAction = ACT_ADD), ENTER_KOD_ELEMENT,ENTER_KOD_GROUP), tmpSTR2,tmpSTR2) then begin ClearVariable; Exit; end; tmpOLE.Description:=tmpSTR1; tmpOLE.Code:=tmpSTR2; tmpOLE.Write; tmpItem:=List.Items.Add; tmpItem.ImageIndex:=Round(ABS(tmpOLE.IsGroup(1)-1)); tmpItem.SubItems.Add(tmpOLE.FullCode); tmpItem.SubItems.Add(tmpOLE.Description); ClearVariable; Exit; end; end; function TServer1C.SetInterval(DateBeg,DateEnd:TDateTime):TDateInterval; begin Result[0]:=DateBeg; Result[1]:=DateEnd; end; end.