Created
March 3, 2011 21:02
-
-
Save josht/853549 to your computer and use it in GitHub Desktop.
export to uda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var | |
exportType:String; | |
exportFormat:String; | |
extxt:String; | |
itemStr:string; | |
procedure csv; | |
begin | |
exportType := 'csv'; | |
End; | |
procedure excel; | |
begin | |
exportType := 'excel'; | |
End; | |
procedure cbrd; | |
begin | |
exportType := 'cbrd'; | |
end; | |
procedure getChildItems(itm:String; ItemsLst:TStringList); | |
begin | |
For cidx := 0 to ChildCount(itm) -1 do begin | |
citm := ChildItem(itm,cidx); | |
itemType := GetResultAsString(citm,'Type',''); | |
if (itemType = 'Part') OR (itemType = 'Material') OR (itemType = 'Labor') OR (itemType = 'Subcontract') OR (itemType = 'Equipment') OR (itemType = 'Other') then | |
ItemsLst.add(citm); | |
if ChildCount(citm) > 0 then | |
getChildItems(citm,ItemsLst); | |
End; | |
end; | |
var | |
clstbox :TlistBox; | |
begin | |
Form := Newform(170,120,'Export to UDA'); | |
Excelbtn := Newbutton(20,10,'Export To Excel',mrOk); | |
Excelbtn.Width := 120; | |
Excelbtn.height := 30; | |
Excelbtn.onClick := 'excel'; | |
Cancelbtn := Newbutton(20,50,'Cancel',mrCancel); | |
Cancelbtn.Width := 120; | |
Cancelbtn.height := 30; | |
if Form.ShowModal <> mrOk then Exit; | |
BeginUpdate; | |
//Get Job | |
job := Getitem('\Job'); | |
if job = '' then Exit; | |
Takeoff := Getitem(job +'\Takeoff'); | |
Category := GetResultAsString('\Settings\ACS - UDA','Category','Division'); | |
SubCategory := GetResultAsString('\Settings\ACS - UDA','Sub-Category','SubDivision'); | |
itemsLst := TStringList.Create; | |
if ExportType = 'excel' then begin | |
try | |
//load excel | |
xl := CreateoleObject('Excel.Application'); | |
wb := xl.workbooks.add; | |
ws := wb.worksheets.item(1); | |
xlRow := 1; | |
Except | |
xl := nil; | |
EndUpdate; | |
ShowMessage('An Error Occured') | |
exit; | |
End; | |
end else begin | |
XList := TStringList.Create; | |
end; | |
try | |
For idx := 0 to ChildCount(Takeoff) -1 do begin | |
citm := ChildItem(Takeoff,idx); | |
if childCount(citm) > 0 then | |
getChildItems(citm,itemsLst); | |
End; | |
if itemsLst.count <> 0 then begin | |
for nidx :=0 to itemsLst.Count - 1 do begin | |
itm := itemsLst.Strings[nidx]; | |
itemCategory := GetResultAsString(itm, Category, 'Unknown'); | |
itemSubCategory := GetResultAsString(itm, SubCategory, 'Unknown'); | |
itemName := GetResultAsString(itm,'Name'); | |
itemQty := GetResultAsString(itm, 'Qty'); | |
itemQtyUnit := GetPropertyAttribute(itm,'Qty','Units'); | |
itemPriceEach := GetResultAsString(itm, 'Price Each'); | |
itemStr := itemCategory + ':' + itemSubCategory + ':' + itemName + ':' + itemQty + ':' + itemQtyUnit + ':' + itemPriceEach; | |
if ExportType = 'excel' then begin | |
//ShowMessage('item: ' + getResultasString(itm,'Name','') + ' value: ' + floatToStr(tval)); | |
ws.Cells(xlRow,1).Value := itemStr; | |
inc(xlRow); | |
End else begin | |
xList.add(itemStr); | |
End; | |
End; | |
End; | |
itemsLst.clear; | |
itemsLst.free; | |
finally | |
if ExportType <> 'excel' then begin | |
if ExportType = 'csv' then begin | |
dia := TSaveDialog.Create(nil); | |
dia.title := 'Save as CSV'; | |
dia.initialDir := getCurrentDir; | |
dia.Filter := 'csv|*.csv'; | |
dia.DefaultExt := 'csv'; | |
Result := dia.Execute; | |
if Result then | |
Xlist.SavetoFile(dia.FileName); | |
dia.Free; | |
end | |
if ExportType = 'cbrd' then begin | |
Clipboard.AsText := XList.Text; | |
End; | |
XList.Free; | |
end else begin | |
ws.Columns('A:A').autofit; | |
xl.visible := True; | |
xl := nil; | |
End; | |
Endupdate; | |
end; | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment