Snippets
Created by
Suhail Akhtar
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | #region Get XML From Report object
/*==================================================
= Get XML From Report object =
==================================================*/
private string getReportInXML(Report report)
{
string strreport = "";
strreport += "<Report xmlns=\"http://schema.intuit.com/finance/v3\">";
strreport += getReportHeader(report.Header);
strreport += getReportColumns(report.Columns);
strreport += getRows(report.Rows);
strreport += "</Report>";
return strreport;
}
private string getReportHeader(ReportHeader header)
{
string strheader = "";
strheader += "<Header>";
strheader += "<Time>" + String.Format("{0:yyyy-MM-ddTH:mm:sszzz}", header.Time) + "</Time>";
strheader += "<ReportName>" + header.ReportName + "</ReportName>";
strheader += "<DateMacro>" + header.DateMacro + "</DateMacro>";
strheader += "<ReportBasis>" + header.ReportBasis + "</ReportBasis>";
strheader += "<StartPeriod>" + header.StartPeriod + "</StartPeriod>";
strheader += "<EndPeriod>" + header.EndPeriod + "</EndPeriod>";
strheader += "<SummarizeColumnsBy>" + header.SummarizeColumnsBy + "</SummarizeColumnsBy>";
strheader += "<Currency>" + header.Currency + "</Currency>";
foreach (var option in header.Option)
{
strheader += "<Option>";
strheader += "<Name>" + option.Name + "</Name>";
strheader += "<Value>" + option.Value + "</Value>";
strheader += "</Option>";
}
strheader += "</Header>";
return strheader;
}
private string getReportColumns(Column[] columns)
{
string strcolumn = "";
strcolumn += "<Columns>";
foreach (Column column in columns)
{
strcolumn += "<Column>";
strcolumn += " <ColTitle>" + Convert.ToString(column.ColTitle) + "</ColTitle>";
strcolumn += " <ColType>" + column.ColType + "</ColType>";
foreach (var meta in column.MetaData)
{
strcolumn += "<MetaData>";
strcolumn += "<Name>" + meta.Name + "</Name>";
strcolumn += "<Value>" + meta.Value + "</Value>";
strcolumn += "</MetaData>";
}
strcolumn += "</Column>";
}
strcolumn += "</Columns>";
return strcolumn;
}
private string getRows(Row[] rows)
{
string strrows = "";
strrows += " <Rows>";
foreach (Row row in rows)
{
if (row.type.ToString() == "Section") ///It contains more Rows
{
// if type of row is data then call it
strrows += getRowSection(row);
}
else if (row.type.ToString() == "Data")
{
//Otherwise call getRowSection
strrows += getRowData(row);
}
}
strrows += " </Rows>";
return strrows;
}
private string getRowSection(Row row)
{
string strrowsection = "";
strrowsection += " <Row type=\"Section\"";
if (row.group != null)
{
strrowsection += " group=\"" + row.group + "\"";
}
strrowsection += ">";
string type = row.AnyIntuitObjects[0].GetType().ToString();
object[] objs = (object[])row.AnyIntuitObjects;
foreach (var obj in objs)
{
string objtype = obj.GetType().ToString();
switch (objtype)
{
case "Intuit.Ipp.Data.Header":
Header header = (Header)obj;
strrowsection += getHeader(header);
break;
case "Intuit.Ipp.Data.Rows":
Rows rows = (Rows)obj;
strrowsection += getRows(rows.Row);
break;
case "Intuit.Ipp.Data.Summary":
Summary summary = (Summary)obj;
strrowsection += getSummary(summary);
break;
}
}
strrowsection += " </Row>";
return strrowsection;
}
private string getSummary(Summary summary)
{
string strsummary = "";
strsummary += "<Summary>";
ColData[] coldata = (ColData[])summary.ColData;
strsummary += getColData(coldata);
strsummary += "</Summary>";
return strsummary;
}
private string getRowData(Row row)
{
string strrowdata = "";
strrowdata += " <Row type=\"Data\">";
ColData[] coldata = (ColData[])row.AnyIntuitObjects[0];
strrowdata += getColData(coldata);
strrowdata += "</Row>";
return strrowdata;
}
private string getHeader(Header header)
{
string strheader = "";
strheader += " <Header>";
ColData[] coldata = (ColData[])header.ColData;
strheader += getColData(coldata);
strheader += " </Header>";
return strheader;
}
private string getColData(ColData[] coldata)
{
string strcoldata = "";
foreach (ColData col in coldata)
{
//Generate the coldata string here.
string value = col.value;
value = value.Replace("&", "&");
strcoldata += "<ColData value=\"" + value + "\"";
if (col.id != null)
{
strcoldata += " id=\"" + col.id + "\"";
}
strcoldata += " /> ";
}
return strcoldata;
}
/*===== End of Get XML From Report object ======*/
#endregion End of Get XML From Report object
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.