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

##基于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>
相关推荐
运维行者_3 小时前
PostgreSQL 十大性能问题及解决方案
运维·服务器·网络·数据库·postgresql·智能路由器·snmp
从零开始学习人工智能3 小时前
从反复报错到稳定运行:麒麟与Ubuntu时间同步服务部署全解析
服务器·数据库·ubuntu
xcLeigh3 小时前
数据库迁移:Oracle至KingbaseES迁移最佳实践
数据库·oracle·数据迁移·kingbasees·金仓数据库
nandao1583 小时前
Linux环境通过YUM仓库源码安装PostgreSQL 数据库
数据库
IT布道3 小时前
MongoDB性能调优之--关闭THP
数据库·mongodb
程序猿_极客3 小时前
MySQL 从入门到实战:DQL 查询语言详解(附案例 + 练习)
数据库·mysql·mysql入门
无奈笑天下5 小时前
银河麒麟桌面OS使用分区编辑器将/backup分区删除并扩容至根分区参考教程
linux·数据库·经验分享·编辑器
tzhou6445211 小时前
MySQL备份与恢复
数据库·mysql·adb
一过菜只因11 小时前
MySql Jdbc
android·数据库·mysql