report.aspx.cs
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:6k
源码类别:

OA系统

开发平台:

ASP/ASPX

  1. using System;
  2. using System.Data;
  3. using System.Data.SqlClient;
  4. using Microsoft.Reporting.WebForms;
  5. using System.Configuration;
  6. using System.Collections;
  7. using System.Web;
  8. using System.Web.Security;
  9. using System.Web.UI;
  10. using System.Web.UI.WebControls;
  11. using System.Web.UI.WebControls.WebParts;
  12. using System.Web.UI.HtmlControls;
  13. using CrystalDecisions.CrystalReports.Engine;
  14. public partial class web_pos_report : System.Web.UI.Page
  15. {
  16.     protected void Page_Load(object sender, EventArgs e)
  17.     {
  18.     }
  19.    /* protected void Button1_Click(object sender, EventArgs e)
  20.     {
  21.         string year = DropDownList1.SelectedItem.ToString();
  22.         string month = DropDownList2.SelectedItem.ToString();
  23.         string date = "";
  24.         if (month.Length == 1)
  25.         {
  26.             month = "0" + month;
  27.         }
  28.         date = year + "-" + month;
  29.         SqlConnection conn = dbConnection.getConnection();
  30.         conn.Open();
  31.         DataSet DataSet2 = new DataSet();
  32.         DataTable DataTable1 = new DataTable();
  33.         DataTable1.Columns.Add("date", typeof(string));
  34.         DataTable1.Columns.Add("shop", typeof(string));
  35.         DataTable1.Columns.Add("money", typeof(double));
  36.         SqlCommand sqlcom = new SqlCommand("select NO,name from POS_SHOP", conn);
  37.         SqlDataReader dr = sqlcom.ExecuteReader();
  38.         if (dr.HasRows)
  39.         {
  40.             while (dr.Read())
  41.             {
  42.                 SqlConnection conn1 = dbConnection.getConnection();
  43.                 conn1.Open();
  44.                 SqlCommand sqlcom1 = new SqlCommand("select DATE,QTY*UNITPRICE as money from CTI where SUBSTRING(DATE,0,8)='" + date + "' and shop='" + dr["NO"].ToString() + "'", conn1);
  45.                 SqlDataReader dr1 = sqlcom1.ExecuteReader();
  46.                 if (dr1.HasRows)
  47.                 {
  48.                     while (dr1.Read())
  49.                     {
  50.                         DataRow row = DataTable1.NewRow();
  51.                         row["shop"] = dr["name"].ToString();
  52.                         row["date"] = dr1["DATE"].ToString();
  53.                         row["money"] = Convert.ToInt32(dr1["money"]);
  54.                         DataTable1.Rows.Add(row);
  55.                     }
  56.                 }
  57.                 dr1.Close();
  58.                 conn1.Close();
  59.             }
  60.         }
  61.         DataSet2.Tables.Add(DataTable1);
  62.         dr.Close();
  63.         conn.Close();
  64.         
  65.         CrystalReportSource1.ReportDocument.Load(Server.MapPath("~/web/pos/CrystalReport.rpt"));
  66.         CrystalReportSource1.ReportDocument.SetDataSource(DataSet2);
  67.         CrystalReportSource1.DataBind();
  68.         CrystalReportViewer1.ReportSource = CrystalReportSource1;
  69.         CrystalReportViewer1.DataBind();
  70.         CrystalReportViewer1.Visible = true;
  71.     }*/
  72.     protected void Button1_Click(object sender, EventArgs e)
  73.     {
  74.         string year = DropDownList1.SelectedItem.ToString();
  75.         string month = DropDownList2.SelectedItem.ToString();
  76.         string date = "";
  77.         if (month.Length == 1)
  78.         {
  79.             month = "0" + month;
  80.         }
  81.         date = year + "-" + month;
  82.         SqlConnection conn = dbConnection.getConnection();
  83.         conn.Open();
  84.         DataSet4 ds = new DataSet4();
  85.         SqlCommand sqlcom = new SqlCommand("select NO,name from POS_SHOP", conn);
  86.         SqlDataReader dr = sqlcom.ExecuteReader();
  87.         if (dr.HasRows)
  88.         {
  89.             while (dr.Read())
  90.             {
  91.                 SqlConnection conn1 = dbConnection.getConnection();
  92.                 conn1.Open();
  93.                 SqlCommand sqlcom1 = new SqlCommand("select distinct DATE from CTI where SUBSTRING(DATE,0,8)='" + date + "' order by DATE", conn1);
  94.                 SqlDataReader dr1 = sqlcom1.ExecuteReader();
  95.                 if (dr1.HasRows)
  96.                 {
  97.                     while (dr1.Read())
  98.                     {
  99.                          DataRow row = ds.CTI.NewRow();
  100.                             row["shop"] = dr["name"].ToString();
  101.                             row["date"] = dr1["DATE"].ToString();
  102.                         SqlConnection conn2 = dbConnection.getConnection();
  103.                         conn2.Open();
  104.                         SqlCommand sqlcom2 = new SqlCommand("select sum(QTY*UNITPRICE) as money from CTI where DATE='" + dr1["DATE"] + "' and shop='" + dr["NO"].ToString() + "'", conn2);
  105.                         SqlDataReader dr2 = sqlcom2.ExecuteReader();
  106.                         if (dr2.HasRows)
  107.                         {
  108.                             while (dr2.Read())
  109.                             {
  110.                                 if (!dr2["money"].ToString().Equals(""))
  111.                                 {
  112.                                     row["QTY*UNITPRICE"] = Convert.ToInt32(dr2["money"]);
  113.                                 }
  114.                                 else
  115.                                 {
  116.                                     row["QTY*UNITPRICE"] = 0;
  117.                                 }
  118.                             }
  119.                         }
  120.                         ds.CTI.Rows.Add(row);
  121.                         dr2.Close();
  122.                         conn2.Close();
  123.                     }
  124.                 }
  125.                 dr1.Close();
  126.                 conn1.Close();
  127.             }
  128.         }
  129.         dr.Close();
  130.         conn.Close();
  131.         CrystalReportSource1.ReportDocument.Load(Server.MapPath("~/web/pos/CrystalReport.rpt"));
  132.         CrystalReportSource1.ReportDocument.SetDataSource(ds);
  133.         CrystalReportSource1.DataBind();
  134.         CrystalReportViewer1.ReportSource = CrystalReportSource1;
  135.         CrystalReportViewer1.DataBind();
  136.         CrystalReportViewer1.Visible = true;
  137.        
  138.     }
  139. }