##基于xml 和sql 实现自定义报表查询


private Report report;
private string strFunctionCode = string.Empty;
DataTable dtdata;
//
private ImportXMLHelper _XmlHelper;
private string ImportXMLPath;
private string InputType;
public ImportXMLHelper XmlHelper
{
get
{
if (this._XmlHelper == null)
{
this._XmlHelper = new ImportXMLHelper(this.ImportXMLPath);
}
return this._XmlHelper;
}
}
public FCustomerReport()
{
InitializeComponent();
ImportXMLPath = AppDomain.CurrentDomain.BaseDirectory + "/XML/PACK.XML";
}
private void FCustomerReport_Load(object sender, EventArgs e)
{
BuildDataTypeDDL();
}
private void cmbInputType_SelectedIndexChanged(object sender, EventArgs e)
{
InputType = this.cmbInputType.SelectedItemValue.ToString();
XmlHelper.SelectedImportType = InputType;
if (InputType.Length == 0)
{
}
else
{
InitGrid();
// this.UploadedFileName = string.Format(@"{0}download\{1}.xls", AppDomain.CurrentDomain.BaseDirectory, InputType);
// this.GetData();
strFunctionCode = InputType;
report = new Report(strFunctionCode);
string file = System.AppDomain.CurrentDomain.BaseDirectory + "/XML/PACK.XML";
ReportXml.FillReport(file, report);
}
}
private void btnQuery_Click(object sender, EventArgs e)
{
BindData();
}
private void BindData()
{
if (this.ucLabelMOCode.Value.Equals("") && this.ucLabelEdit1.Value.Equals("") && this.ucLabelEdit2.Value.Equals(""))
{
MessageBox.Show("选择输入一个以上的查询条件!");
return;
}
getCondition();
report.TransformSQL();
OracleHelper sqlHelper = new OracleHelper("");
dtdata = sqlHelper.ExecReport(report);
if (dtdata != null && dtdata.Rows.Count > 0)
{
pageNavigation1.Init(dtdata.Rows.Count);
//ultraGridMain.DataSource = dtdata;
btnExport.Enabled = true;
}
else
{
btnExport.Enabled = false;
MessageBox.Show("没有数据!");
}
}
private void getCondition()
{
if (!this.ucLabelMOCode.Value.Trim().Equals(string.Empty))
report.AddValue(0, this.ucLabelMOCode.Value.ToUpper().Trim());
if (!this.ucLabelEdit1.Value.Trim().Equals(string.Empty) && !this.ucLabelEdit2.Value.Trim().Equals(string.Empty))
{
report.AddValue(1, this.ucLabelEdit1.Value.ToUpper().Trim());
report.AddValue(2, this.ucLabelEdit2.Value.ToUpper().Trim());
}
}
private void btnExport_Click(object sender, EventArgs e)
{
string name = cmbInputType.SelectedItemText.ToString();
if (string.IsNullOrEmpty(name))
{
name = "导出数据";
}
new ExportExcelForm(dtdata, name).ShowDialog();
}
private void BuildDataTypeDDL()
{
this.cmbInputType.Clear();
ArrayList importType = this.XmlHelper.GetImportType();
if (importType.Count > 0)
{
foreach (DictionaryEntry entry in importType)
{
string text = entry.Value.ToString();
this.cmbInputType.AddItem(text, entry.Key.ToString());
}
}
}
private void InitGrid()
{
ArrayList gridBuilder = this.XmlHelper.GetGridBuilder();
if (gridBuilder.Count > 0)
{
ultraGridMain.DataSource = null;
foreach (DictionaryEntry entry in gridBuilder)
{
string key = entry.Key.ToString();
this.ultraGridMain.Rows.Band.Columns.Add(key, entry.Value.ToString());
}
}
}
xml
csharp
<?xml version="1.0" encoding="utf-8" ?>
<reports>
<report id="PACK_01">
<datatype name="PACK_01" text="出货">
<field>
<add key="ROWNUM" value="序号" Match="false" AllowNull="false"></add>
<add key="SN" value="SN" Match="false" AllowNull="true"></add>
<add key="IMEI" value="IMEI" Match="true" AllowNull="false" MatchType="MType"></add>
<add key="ICCID" value="ICCID" Match="true" AllowNull="false" MatchType="ItemControl"></add>
<add key="CARTONNO" value="箱号" Match="true" AllowNull="true" MatchType="BoolType"></add>
<add key="PALLETCODE" value="栈板" Match="true" AllowNull="true" MatchType="BoolType"></add>
</field>
</datatype>
<type>SQL</type>
<title>出货信息查询</title>
<sql>
SELECT ROWNUM,A.* FROM (
SELECT B.IMEI1 SN,B.IMEI2 IMEI, B.MEID ICCID,A.CARTONNO,PALL.PALLETCODE
FROM TBLCarton2RCARD a
left join tblmo2imei b on a.rcard=b.imei1 AND A.MOCODE=B.MOCODE
left join tblpallet2rcard pall on a.rcard=pall.rcard AND A.MOCODE=pall.MOCODE ORDER BY b.imei1
)a WHERE 1=1
STRPO STRpallet1 STRpallet2
</sql>
<fields>
<field name="mocode" flag="0" alias=":po" type="STRING" size="128" operator="=" location="STRPO" />
<field name="PALLETCODE" flag="0" alias=":po1" type="STRING" size="128" operator="RANG_START" location="STRpallet1" />
<field name="PALLETCODE" flag="0" alias=":po2" type="STRING" size="128" operator="RANG_END" location="STRpallet2" />
</fields>
</report>
<report id="PACK_02">
<datatype name="PACK_02" text="出货分页">
<field>
<add key="NUM" value="序号" Match="false" AllowNull="false"></add>
<add key="SN" value="SN" Match="false" AllowNull="true"></add>
<add key="SN1" value="SN1" Match="false" AllowNull="true"></add>
<add key="IMEI" value="IMEI" Match="true" AllowNull="false" MatchType="MType"></add>
<add key="ICCID" value="ICCID" Match="true" AllowNull="false" MatchType="ItemControl"></add>
<add key="CARTONNO" value="箱号" Match="true" AllowNull="true" MatchType="BoolType"></add>
</field>
</datatype>
<type>SQL</type>
<title>出货分页信息查询</title>
<sql>
SELECT ROW_NUMBER() OVER (PARTITION by A.cartonno ORDER BY b.imei1) as NUM,b.imei1 SN,'*'||b.imei1||'*' SN1,b.imei2 IMEI, B.MEID ICCID,a.cartonno
FROM TBLCarton2RCARD a left join tblmo2imei b on a.rcard=b.imei1
left join tblpallet2rcard pall on a.rcard=pall.rcard
WHERE 1=1
STRPO STRpallet1 STRpallet2
</sql>
<fields>
<field name="B.MOCODE" flag="0" alias=":po" type="STRING" size="128" operator="=" location="STRPO" />
<field name="pall.palletcode" flag="0" alias=":po1" type="STRING" size="128" operator="RANG_START" location="STRpallet1" />
<field name="pall.palletcode" flag="0" alias=":po2" type="STRING" size="128" operator="RANG_END" location="STRpallet2" />
</fields>
</report>
<report id="PACK_03">
<datatype name="PACK_03" text="出货(TUSN)">
<field>
<add key="ROWNUM" value="序号" Match="false" AllowNull="false"></add>
<add key="SN" value="SN" Match="false" AllowNull="true"></add>
<add key="IMEI" value="IMEI" Match="true" AllowNull="false" MatchType="MType"></add>
<add key="ICCID" value="ICCID" Match="true" AllowNull="false" MatchType="ItemControl"></add>
<add key="CARTONNO" value="箱号" Match="true" AllowNull="true" MatchType="BoolType"></add>
<add key="PALLETCODE" value="栈板" Match="true" AllowNull="true" MatchType="BoolType"></add>
</field>
</datatype>
<type>SQL</type>
<title>出货信息查询(TUSN)</title>
<sql>
SELECT ROWNUM,A.* FROM (
SELECT B.IMEI1 SN,B.PSN TUSN,B.IMEI2 IMEI, B.MEID ICCID,A.CARTONNO,PALL.PALLETCODE
FROM TBLCarton2RCARD a left join tblmo2imei b on a.rcard=b.imei1 left join tblpallet2rcard pall on a.rcard=pall.rcard ORDER BY b.imei1
)a WHERE 1=1
STRPO STRpallet1 STRpallet2
</sql>
<fields>
<field name="mocode" flag="0" alias=":po" type="STRING" size="128" operator="=" location="STRPO" />
<field name="PALLETCODE" flag="0" alias=":po1" type="STRING" size="128" operator="RANG_START" location="STRpallet1" />
<field name="PALLETCODE" flag="0" alias=":po2" type="STRING" size="128" operator="RANG_END" location="STRpallet2" />
</fields>
</report>
<report id="PACK_04">
<datatype name="PACK_04" text="出货明细">
<field>
<add key="NUM1" value="序号" Match="false" AllowNull="false"></add>
<add key="RECEIVEUSER" value="收件人" Match="false" AllowNull="true"></add>
<add key="TELEPHONE" value="电话" Match="true" AllowNull="false" MatchType="MType"></add>
<add key="ADDRESS" value="地址" Match="true" AllowNull="false" MatchType="ItemControl"></add>
<add key="NUM" value="台数" Match="true" AllowNull="true" MatchType="BoolType"></add>
<add key="CARTONQTY" value="箱数" Match="true" AllowNull="true" MatchType="BoolType"></add>
<add key="WEIGHT" value="重量(KG)" Match="false" AllowNull="true"></add>
<add key="CARTONNO" value="箱号" Match="false" AllowNull="true"></add>
<add key="RCARD" value="RCARD" Match="false" AllowNull="true"></add>
<add key="EXPRESSBILL" value="快递单" Match="false" AllowNull="true"></add>
<add key="PALLETCODE" value="栈板" Match="false" AllowNull="true"></add>
</field>
</datatype>
<type>SQL</type>
<title>出货明细</title>
<sql>
SELECT row_number()over(partition by a.EXPRESSBILL order by A.RCARD )NUM1,A.* FROM (
SELECT d.RECEIVEUSER,TELEPHONE ,ADDRESS , NUM , CARTONQTY , WEIGHT ,A.CARTONNO,PALL.RCARD ,d.EXPRESSBILL ,PALL.PALLETCODE
FROM TBLCarton2RCARD a
left join tblmo2imei b on a.rcard=b.imei1
left join tblpallet2rcard pall on a.rcard=pall.rcard
left join TBLQUSHIPBILL d on d.EXPRESSBILL=pall.eattribute1
)a WHERE 1=1
STRPO STRpallet1 STRpallet2 order by a.EXPRESSBILL,A.cartonno,a.RCARD
</sql>
<fields>
<field name="mocode" flag="0" alias=":po" type="STRING" size="128" operator="=" location="STRPO" />
<field name="PALLETCODE" flag="0" alias=":po1" type="STRING" size="128" operator="RANG_START" location="STRpallet1" />
<field name="PALLETCODE" flag="0" alias=":po2" type="STRING" size="128" operator="RANG_END" location="STRpallet2" />
</fields>
</report>
<report id="PACK_05">
<datatype name="PACK_05" text="P7W出货信息查询">
<field>
<add key="ROWNUM" value="序号" Match="false" AllowNull="false"></add>
<add key="SN" value="SN" Match="false" AllowNull="true"></add>
<add key="IMEI" value="IMEI" Match="true" AllowNull="false" MatchType="MType"></add>
<add key="ICCID" value="ICCID" Match="true" AllowNull="false" MatchType="ItemControl"></add>
<add key="CARTONNO" value="箱号" Match="true" AllowNull="true" MatchType="BoolType"></add>
<add key="PALLETCODE" value="栈板" Match="true" AllowNull="true" MatchType="BoolType"></add>
<add key="SSID" value="密钥" Match="true" AllowNull="true" MatchType="BoolType"></add>
<add key="WUBVERSION" value="版本" Match="true" AllowNull="true" MatchType="BoolType"></add>
</field>
</datatype>
<type>SQL</type>
<title>P7W出货信息查询</title>
<sql>
SELECT ROWNUM,A.* FROM (
SELECT B.IMEI1 SN,B.IMEI2 IMEI, B.MEID ICCID,A.CARTONNO,PALL.PALLETCODE,e.ssid,e.wubversion
FROM TBLCarton2RCARD a
left join tblmo2imei b on a.rcard=b.imei1
left join tblpallet2rcard pall on a.rcard=pall.rcard
left join TBLDXTESTDATA e on e.RCARD = pall.RCARD and e.mocode=pall.mocode
ORDER BY b.imei1
)a WHERE 1=1
STRPO STRpallet1 STRpallet2
</sql>
<fields>
<field name="mocode" flag="0" alias=":po" type="STRING" size="128" operator="=" location="STRPO" />
<field name="PALLETCODE" flag="0" alias=":po1" type="STRING" size="128" operator="RANG_START" location="STRpallet1" />
<field name="PALLETCODE" flag="0" alias=":po2" type="STRING" size="128" operator="RANG_END" location="STRpallet2" />
</fields>
</report>
<report id="PACK_06">
<datatype name="PACK_06" text="出货分页合集">
<field>
<add key="NUM" value="序号" Match="false" AllowNull="false"></add>
<add key="SN" value="SN" Match="false" AllowNull="true"></add>
<add key="SN1" value="SN1" Match="false" AllowNull="true"></add>
<add key="IMEI" value="IMEI" Match="true" AllowNull="false" MatchType="MType"></add>
<add key="ICCID" value="ICCID" Match="true" AllowNull="false" MatchType="ItemControl"></add>
<add key="CARTONNO" value="箱号" Match="true" AllowNull="true" MatchType="BoolType"></add>
</field>
</datatype>
<type>SQL</type>
<title>出货分页合集查询</title>
<sql>
SELECT ROW_NUMBER() OVER (PARTITION by b.mocode ORDER BY a.cartonno , b.imei1) as NUM,b.imei1 SN,'*'||b.imei1||'*' SN1,b.imei2 IMEI, B.MEID ICCID,a.cartonno
FROM TBLCarton2RCARD a left join tblmo2imei b on a.rcard=b.imei1
left join tblpallet2rcard pall on a.rcard=pall.rcard
WHERE 1=1
STRPO STRpallet1 STRpallet2
</sql>
<fields>
<field name="B.MOCODE" flag="0" alias=":po" type="STRING" size="128" operator="=" location="STRPO" />
<field name="pall.palletcode" flag="0" alias=":po1" type="STRING" size="128" operator="RANG_START" location="STRpallet1" />
<field name="pall.palletcode" flag="0" alias=":po2" type="STRING" size="128" operator="RANG_END" location="STRpallet2" />
</fields>
</report>
<report id="PACK_07">
<datatype name="PACK_07" text="iccid esim">
<field>
<add key="DA" value="日期" Match="true" AllowNull="true" MatchType="MType"></add>
<add key="NUM" value="序号" Match="false" AllowNull="false"></add>
<add key="ICCID" value="ICCID号" Match="true" AllowNull="false" MatchType="ItemControl"></add>
<add key="ESIM" value="esim卡号" Match="true" AllowNull="false" MatchType="MType"></add>
<add key="IMEI" value="IMEI号" Match="true" AllowNull="true" MatchType="MType"></add>
</field>
</datatype>
<type>SQL</type>
<title>iccid esim查询</title>
<sql>
SELECT to_char(sysdate,'YYYY-MM-DD HH24:MI:SS')DA,ROW_NUMBER() OVER (PARTITION by b.mocode ORDER BY a.cartonno , b.imei1) as NUM,
B.MEID ICCID,B.id1 ESIM, b.imei2 IMEI
FROM TBLCarton2RCARD a left join tblmo2imei b on a.rcard=b.imei1
left join tblpallet2rcard pall on a.rcard=pall.rcard
WHERE 1=1
STRPO STRpallet1 STRpallet2
</sql>
<fields>
<field name="B.MOCODE" flag="0" alias=":po" type="STRING" size="128" operator="=" location="STRPO" />
<field name="pall.palletcode" flag="0" alias=":po1" type="STRING" size="128" operator="RANG_START" location="STRpallet1" />
<field name="pall.palletcode" flag="0" alias=":po2" type="STRING" size="128" operator="RANG_END" location="STRpallet2" />
</fields>
</report>
</reports>
bs 类似 注意xml路径及不同xml 初始化

csharp
private void InitControls()
{
PageMg = new PageManage(this);
PageMg.GetStartTick();
PageMg.AuthorizeUser("WHS_01", this.TemplateSourceDirectory
+ "/WHS_01.aspx?" + Request.QueryString);
report = new Report("WHS_01");
fCommonDB = PageMg.GetCurrentDBInterface();
ReportXml.FillReport(Server.MapPath("../XML/WHS.xml"), report);
PageMD.Title = report.Title;
PageMD.IsSubPage = false;
ConLayer1.Title = report.Title;
ConLayer1.AddControl(Panel1);
ConLayer1.OnSubmitQuery += new ConLayer.OnSubmitQueryHandler(OnSubmitQuery);
PageMD.DataGridPageChange += new PageModule.DataGridPageChangeHandler(DataGridPageChange);
//PageMD.DataGridItemBound += new PageModule.DataGridItemBoundHandler(DataGridItemBound);
PageMD.OnFormatExcel += new System.EventHandler(OnFormatExcel);
}
存储过程
csharp
<report id="PACK_19">
<type>SP</type>
<title>PACK看板数据图</title>
<sql sp="存储过程名称不能有换行和回车">sp_KanbanPACK_Chart</sql>
<fields>
<field name="LineName" flag="0" alias="@LineCode" type="string" size="30" operator="SP" location="STRSQL_linename" />
</fields>
</report>
<report id="PACK_09">
<type>SP</type>
<title>栈板查询</title>
<sql sp="存储过程名称不能有换行和回车">SP_SHUNDI_DATA</sql>
<fields>
<field name="PO" flag="0" alias="@PO" type="STRING" size="128" operator="SP" location="STRPO" />
<field name="palletno_no" flag="0" alias="@palletno_no" type="STRING" size="128" operator="SP" location="STRPLTNO" />
</fields>
</report>