123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585 |
- using System;
- using System.IO;
- using System.Text;
- using System.Threading;
- using System.Windows.Forms;
- using System.Web.Services.Protocols;
- using SamplesCommon;
- using cognosdotnet_10_2;
- using System.Xml;
- namespace CreateReport
- {
- public class TableData
- {
- public TableData m_tableNameColumnMap;
- public string m_tableName = "";
- public XmlNodeWrapper[] m_columns = null;
- public TableData()
- {
- m_tableName = "";
- m_columns = null;
- }
- public TableData(string tbName, XmlNodeWrapper[] cols)
- {
- m_tableName = tbName;
- int nbCols = cols.GetLength(0);
- m_columns = new XmlNodeWrapper[nbCols];
- m_columns = cols;
- }
- public string getTableName()
- {
- return m_tableName;
- }
- public XmlNodeWrapper[] getColumns()
- {
- return m_columns;
- }
- }
-
-
-
- class CreateReport
- {
- public CreateReport(){}
-
- static void Main(string[] args)
- {
- SamplesConnect connectDlg = new SamplesConnect();
- CreateReportDlg createReportDlgObject = new CreateReportDlg();
- if (args.GetLength(0) == 0 )
- {
-
- connectDlg.ShowDialog();
- if (connectDlg.IsConnectedToCBI() == true)
- {
- createReportDlgObject.setConnection(connectDlg);
- createReportDlgObject.ShowDialog();
- }
- }
- }
- public string getPackageName(SamplesConnect connection)
- {
- string packageName = "";
- try
- {
-
- PackageNameDlg packageNameDlg = new PackageNameDlg();
- packageNameDlg.setConnection(connection);
-
- sort[] sortOptions = { new sort() };
- sortOptions[0].order = orderEnum.ascending;
- sortOptions[0].propName = propEnum.defaultName;
- propEnum[] props = new propEnum[] { propEnum.searchPath, propEnum.defaultName };
- searchPathMultipleObject packagesPath = new searchPathMultipleObject();
- packagesPath.Value = "/content//package";
- baseClass[] bc = connection.CBICMS.query(packagesPath, props, sortOptions, new queryOptions());
-
-
- string[] packageNames = new string[bc.GetLength(0)];
- for (int i = 0; i < bc.GetLength(0); i++)
- {
- packageNames[i] = bc[i].defaultName.value;
- }
- packageNameDlg.setPackageNames(packageNames);
- packageNameDlg.setSelectedPackage(1);
- packageNameDlg.ShowDialog();
- if (packageNameDlg.isOKed)
- {
- packageName = packageNameDlg.getSelectedPackageName();
- }
- else
- {
- return "";
- }
- }
- catch(SoapException ex)
- {
- SamplesException.ShowExceptionMessage( ex, true, "Create Report Sample - getPackageName" );
- return "";
- }
- catch(System.Exception ex)
- {
- SamplesException.ShowExceptionMessage( ex.Message, true, "Create Report Sample - getPackageName" );
- return "";
- }
- return packageName;
- }
- public string getReportName()
- {
- try
- {
- string reportName = "";
-
-
- ReportNameDlg reportNameDlg = new ReportNameDlg();
- reportNameDlg.ShowDialog();
- if (reportNameDlg.isOKed)
- {
-
- reportName = reportNameDlg.getReportName();
- }
- else
- {
- return "";
- }
- return reportName;
- }
- catch(SoapException ex)
- {
- SamplesException.ShowExceptionMessage( ex, true, "Create Report Sample - getReportName" );
- return "";
- }
- catch(System.Exception ex)
- {
- SamplesException.ShowExceptionMessage( ex.Message, true, "Create Report Sample - getReportName" );
- return "";
- }
- }
- public XmlNode buildListColumnNode(XmlDocument xmlDoc, string myNameSpace, string columnLabel, string columnValue)
- {
- XmlNode nextNode, currentNode, listColumnNode, styleNode, currentStyleNode;
- XmlAttribute attribNode;
- listColumnNode = xmlDoc.CreateNode(XmlNodeType.Element, "listColumn", myNameSpace);
-
-
-
- currentNode = xmlDoc.CreateNode(XmlNodeType.Element, "dataItemLabel", myNameSpace);
- attribNode = xmlDoc.CreateAttribute("refDataItem");
- attribNode.Value = columnLabel;
- currentNode.Attributes.Append(attribNode);
-
-
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element, "dataSource", myNameSpace);
- nextNode.AppendChild(currentNode);
- currentNode = nextNode;
-
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element, "textItem", myNameSpace);
- nextNode.AppendChild(currentNode);
- currentNode = nextNode;
-
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element, "contents", myNameSpace);
- nextNode.AppendChild(currentNode);
- currentNode = nextNode;
-
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element, "defaultStyle", myNameSpace);
- attribNode = xmlDoc.CreateAttribute("refStyle");
- attribNode.Value = "lt";
- nextNode.Attributes.Append(attribNode);
- currentStyleNode = nextNode;
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element, "defaultStyles", myNameSpace);
- nextNode.AppendChild(currentStyleNode);
- currentStyleNode = nextNode;
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element, "style", myNameSpace);
- nextNode.AppendChild(currentStyleNode);
- styleNode = nextNode;
-
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element,"listColumnTitle", myNameSpace);
- nextNode.AppendChild(styleNode);
- nextNode.AppendChild(currentNode);
-
- listColumnNode.AppendChild(nextNode);
-
-
-
- currentNode = xmlDoc.CreateNode(XmlNodeType.Element, "dataItemValue", myNameSpace);
- attribNode = xmlDoc.CreateAttribute("refDataItem");
- attribNode.Value = columnValue;
- currentNode.Attributes.Append(attribNode);
-
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element, "dataSource", myNameSpace);
- nextNode.AppendChild(currentNode);
- currentNode = nextNode;
-
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element, "textItem", myNameSpace);
- nextNode.AppendChild(currentNode);
- currentNode = nextNode;
-
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element, "contents", myNameSpace);
- nextNode.AppendChild(currentNode);
- currentNode = nextNode;
-
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element, "defaultStyle", myNameSpace);
- attribNode = xmlDoc.CreateAttribute("refStyle");
- attribNode.Value = "lc";
- nextNode.Attributes.Append(attribNode);
- currentStyleNode = nextNode;
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element, "defaultStyles", myNameSpace);
- nextNode.AppendChild(currentStyleNode);
- currentStyleNode = nextNode;
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element, "style", myNameSpace);
- nextNode.AppendChild(currentStyleNode);
- styleNode = nextNode;
-
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element, "listColumnBody", myNameSpace);
- nextNode.AppendChild(styleNode);
- nextNode.AppendChild(currentNode);
-
- listColumnNode.AppendChild(nextNode);
- return listColumnNode;
- }
- public XmlNode buildDataItemNode(XmlDocument xmlDoc, string myNameSpace, string name, string expression)
- {
- XmlNode expressionNode, dataItemNode;
- XmlAttribute attribNode;
-
- expressionNode = xmlDoc.CreateNode(XmlNodeType.Element, "expression", myNameSpace);
- expressionNode.InnerText = expression;
-
- dataItemNode = xmlDoc.CreateNode(XmlNodeType.Element, "dataItem", myNameSpace);
- attribNode = xmlDoc.CreateAttribute("name");
- attribNode.Value = name;
- dataItemNode.Attributes.Append(attribNode);
- attribNode = xmlDoc.CreateAttribute("aggregate");
- attribNode.Value = "none";
- dataItemNode.Attributes.Append(attribNode);
- dataItemNode.AppendChild(expressionNode);
- return dataItemNode;
- }
- public reportServiceSpecification createReportSpec(SamplesConnect connection, string packageName, string targetLocation, string newReportName, string tableName, XmlNodeWrapper[] selectedColumns)
- {
- try
- {
-
- XmlDocument xmlDoc = new XmlDocument();
- XmlNode root,
- currentNode,
- nextNode,
- listColumnsNode,
- cssNode,
- currentStyleNode,
- styleNode,
- selectionNode;
- XmlAttribute attribNode;
- string defaultPackageName, strName, strReportXML;
- report reportName = new report();
- addOptions addOptions = new addOptions();
- tokenProp tokenName = new tokenProp();
- anyTypeProp anyTypeName = new anyTypeProp();
- reportServiceReportSpecification rspecReport = new reportServiceReportSpecification();
-
- string myNS = "http://developer.cognos.com/schemas/report/15.0/";
-
-
-
- root = xmlDoc.CreateNode(XmlNodeType.Element, "report", myNS);
- attribNode = xmlDoc.CreateAttribute("expressionLocale");
- attribNode.Value = "en-us";
- root.Attributes.Append(attribNode);
- xmlDoc.AppendChild(root);
-
-
-
- currentNode = xmlDoc.CreateComment("RS:8.1");
- root.AppendChild(currentNode);
-
- defaultPackageName = "/content/folder[@name='Samples']/folder[@name='Models']/package[@name='"
- + packageName
- + "']/model[@name='model']";
- currentNode = xmlDoc.CreateNode(XmlNodeType.Element, "modelPath", myNS);
- currentNode.InnerText = defaultPackageName;
- root.AppendChild(currentNode);
-
-
-
-
- currentNode = xmlDoc.CreateNode(XmlNodeType.Element, "model", myNS);
-
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element, "source", myNS);
- nextNode.AppendChild(currentNode);
- currentNode = nextNode;
-
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element, "query", myNS);
- attribNode = xmlDoc.CreateAttribute("name");
- attribNode.Value = "Query1";
- nextNode.Attributes.Append(attribNode);
- nextNode.AppendChild(currentNode);
-
-
-
- selectionNode = xmlDoc.CreateNode(XmlNodeType.Element, "selection", myNS);
- nextNode.AppendChild(selectionNode);
- currentNode = nextNode;
-
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element, "queries", myNS);
- nextNode.AppendChild(currentNode);
- currentNode = nextNode;
-
- root.AppendChild(currentNode);
-
-
-
-
- cssNode = xmlDoc.CreateNode(XmlNodeType.Element, "CSS", myNS);
- attribNode = xmlDoc.CreateAttribute("value");
- attribNode.Value = "border-collapse:collapse";
- cssNode.Attributes.Append(attribNode);
-
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element, "defaultStyle", myNS);
- attribNode = xmlDoc.CreateAttribute("refStyle");
- attribNode.Value = "ls";
- nextNode.Attributes.Append(attribNode);
- currentStyleNode = nextNode;
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element, "defaultStyles", myNS);
- nextNode.AppendChild(currentStyleNode);
- currentStyleNode = nextNode;
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element, "style", myNS);
- nextNode.AppendChild(currentStyleNode);
- nextNode.AppendChild(cssNode);
- styleNode = nextNode;
-
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element, "list", myNS);
- attribNode = xmlDoc.CreateAttribute("refQuery");
- attribNode.Value = "Query1";
- nextNode.Attributes.Append(attribNode);
- nextNode.AppendChild(styleNode);
-
-
-
- listColumnsNode = xmlDoc.CreateNode(XmlNodeType.Element, "listColumns", myNS);
- nextNode.AppendChild(listColumnsNode);
- currentNode = nextNode;
-
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element, "defaultStyle", myNS);
- attribNode = xmlDoc.CreateAttribute("refStyle");
- attribNode.Value = "pb";
- nextNode.Attributes.Append(attribNode);
- currentStyleNode = nextNode;
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element, "defaultStyles", myNS);
- nextNode.AppendChild(currentStyleNode);
- currentStyleNode = nextNode;
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element, "style", myNS);
- nextNode.AppendChild(currentStyleNode);
- styleNode = nextNode;
-
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element, "contents", myNS);
- nextNode.AppendChild(currentNode);
- currentNode = nextNode;
-
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element, "pageBody", myNS);
- nextNode.AppendChild(styleNode);
- nextNode.AppendChild(currentNode);
- currentNode = nextNode;
-
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element, "defaultStyle", myNS);
- attribNode = xmlDoc.CreateAttribute("refStyle");
- attribNode.Value = "pg";
- nextNode.Attributes.Append(attribNode);
- currentStyleNode = nextNode;
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element, "defaultStyles", myNS);
- nextNode.AppendChild(currentStyleNode);
- currentStyleNode = nextNode;
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element, "style", myNS);
- nextNode.AppendChild(currentStyleNode);
- styleNode = nextNode;
-
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element, "page", myNS);
- attribNode = xmlDoc.CreateAttribute("name");
- attribNode.Value = "Page1";
- nextNode.Attributes.Append(attribNode);
- nextNode.AppendChild(styleNode);
- nextNode.AppendChild(currentNode);
- currentNode = nextNode;
-
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element, "reportPages", myNS);
- nextNode.AppendChild(currentNode);
- currentNode = nextNode;
-
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element, "layout", myNS);
- nextNode.AppendChild(currentNode);
- currentNode = nextNode;
-
- nextNode = xmlDoc.CreateNode(XmlNodeType.Element, "layouts", myNS);
- nextNode.AppendChild(currentNode);
- root.AppendChild(nextNode);
-
-
-
- int nbSelectedColumns = selectedColumns.GetLength(0);
- for (int i=0; i<nbSelectedColumns; i++)
- {
-
- selectionNode.AppendChild(buildDataItemNode(xmlDoc, myNS, selectedColumns[i].ToString(), selectedColumns[i].PATH));
-
- listColumnsNode.AppendChild(buildListColumnNode(xmlDoc, myNS, selectedColumns[i].ToString(), selectedColumns[i].ToString()));
- }
-
-
-
-
- strReportXML = root.OuterXml;
- strName = newReportName;
-
-
- tokenName.value = strName;
- anyTypeName.value = strReportXML;
-
- reportName.defaultName = tokenName;
- reportName.specification = anyTypeName;
- addOptions.updateAction = updateActionEnum.replace;
- reportName.specification.value = strReportXML;
- searchPathSingleObject targetPath = new searchPathSingleObject();
- targetPath.Value = targetLocation;
- connection.CBIRS.add(targetPath, reportName, addOptions);
-
- rspecReport.value = new specification();
- rspecReport.value.Value = reportName.specification.value;
-
- return rspecReport;
- }
- catch(SoapException ex)
- {
- SamplesException.ShowExceptionMessage( ex, true, "Create Report Sample - createReportSpec" );
- return null;
- }
- catch(System.Exception ex)
- {
- SamplesException.ShowExceptionMessage( ex.Message, true, "Create Report Sample - createReportSpec" );
- return null;
- }
- }
- public bool executeReportSpec(SamplesConnect connection, reportServiceSpecification reportSpec)
- {
- try
- {
-
- option[] runOptions = new option[0];
- asynchReply executeResponse = new asynchReply();
- executeResponse = connection.CBIRS.runSpecification(reportSpec, new parameterValue[] {} , runOptions);
-
- while ( executeResponse.status != asynchReplyStatusEnum.complete )
- {
- executeResponse = connection.CBIRS.wait(executeResponse.primaryRequest,new parameterValue[] {}, new option[] {});
- }
- return true;
- }
- catch(SoapException ex)
- {
- SamplesException.ShowExceptionMessage( ex, true, "Create Report Sample - executeReportSpec" );
- return false;
- }
- catch(System.Exception ex)
- {
- SamplesException.ShowExceptionMessage( ex.Message, true, "Create Report Sample - executeReportSpec" );
- return false;
- }
- }
- }
- }
|