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

OA系统

开发平台:

ASP/ASPX

  1. using System;
  2. using Microsoft.Reporting.WebForms;
  3. using System.Data;
  4. using System.Data.SqlClient;
  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 DataTable = System.Data.DataTable;
  14. public partial class web_pos_pos_baobiao : System.Web.UI.Page
  15. {
  16.     DataTable dt = new DataTable("dataname");
  17.     string last_date = "";
  18.     string last_time = "";
  19.     string last_d = "";
  20.     string last_t = "";
  21.     double sum_1 = 0;
  22.     double sum_2 = 0;
  23.     double sum = 0;
  24.     int num_1 = 0;
  25.     int num_2 = 0;
  26.     protected void Page_Load(object sender, EventArgs e)
  27.     {
  28.         dt.Columns.Add("date", typeof(string));
  29.         dt.Columns.Add("shop_id", typeof(string));
  30.         dt.Columns.Add("shop_name", typeof(string));
  31.         dt.Columns.Add("total_money", typeof(double));
  32.         dt.Columns.Add("cancel_money", typeof(double));
  33.         dt.Columns.Add("cancel_num", typeof(Int32));
  34.         dt.Columns.Add("back_money", typeof(double));
  35.         dt.Columns.Add("back_num", typeof(Int32));
  36.         dt.Columns.Add("cancel_total", typeof(string));
  37.         ReportViewer1.Visible = false;
  38.     }
  39.     public void bind()
  40.     {
  41.         SqlConnection conn = dbConnection.getConnection();
  42.         conn.Open();
  43.         DataRow row = dt.NewRow();
  44.         SqlCommand sqlcom = new SqlCommand("select distinct shop as shop from SPECREC order by shop", conn);
  45.         SqlDataReader dr = sqlcom.ExecuteReader();
  46.         if (dr.HasRows)
  47.         {
  48.             while (dr.Read())
  49.             {
  50.                 SqlConnection conn1 = dbConnection.getConnection();
  51.                 conn1.Open();
  52.                 SqlCommand sqlcom2 = new SqlCommand("select distinct DATE as DATE from SPECREC where DATE between'" + b_date.Text.Trim().ToString() + "' and '" + e_date.Text.Trim().ToString() + "' order by DATE", conn1);
  53.                 SqlDataReader dr2 = sqlcom2.ExecuteReader();
  54.                 if (dr2.HasRows)
  55.                 {
  56.                     while (dr2.Read())
  57.                     {
  58.                         sum_1 = 0;
  59.                         sum_2 = 0;
  60.                         num_1 = 0;
  61.                         num_2 = 0;
  62.                         sum = 0;
  63.                         row = dt.NewRow();
  64.                         last_d = "";
  65.                         last_date = "";
  66.                         last_t = "";
  67.                         last_time = "";
  68.                         row["shop_id"] = dr["shop"].ToString();
  69.                         row["date"] = dr2["DATE"].ToString();
  70.                         SqlConnection conn2 = dbConnection.getConnection();
  71.                         conn2.Open();
  72.                         SqlCommand sqlcom5 = new SqlCommand("select sum(QTY*UNITPRICE) as sum from CTI where shop='" + dr["shop"].ToString() + "' and DATE='" + dr2["DATE"].ToString() + "'", conn2);
  73.                         sqlcom5.CommandTimeout = 432000;
  74.                         SqlDataReader dr5 = sqlcom5.ExecuteReader();
  75.                         if (dr5.HasRows)
  76.                         {
  77.                             while (dr5.Read())
  78.                             {
  79.                                 if (dr5["sum"].ToString().Equals(""))
  80.                                 {
  81.                                 }
  82.                                 else
  83.                                 {
  84.                                     row["total_money"] = Round(Convert.ToDouble(dr5["sum"]), 2);
  85.                                     sum = Round(Convert.ToDouble(dr5["sum"]), 2);
  86.                                 }
  87.                             }
  88.                         }
  89.                         dr5.Close();
  90.                         SqlCommand sqlcom4 = new SqlCommand("select name from POS_SHOP where NO='" + dr["shop"].ToString() + "'", conn2);
  91.                         SqlDataReader dr4 = sqlcom4.ExecuteReader();
  92.                         if (dr4.HasRows)
  93.                         {
  94.                             while (dr4.Read())
  95.                             {
  96.                                 row["shop_name"] = dr4["name"].ToString();
  97.                             }
  98.                         }
  99.                         dr4.Close();
  100.                         SqlCommand sqlcom1 = new SqlCommand("select QTY,UNITPRICE,TDATE,TTIME from SPECREC where shop='" + dr["shop"].ToString() + "' and TDATE ='" + dr2["DATE"].ToString() + "' and REMARK='V' AND MANAGER='' ORDER BY TIME", conn2);
  101.                         SqlDataReader dr1 = sqlcom1.ExecuteReader();
  102.                         if (dr1.HasRows)
  103.                         {
  104.                             while (dr1.Read())
  105.                             {
  106.                                 sum_1 = sum_1 + Convert.ToDouble(dr1["UNITPRICE"])*Convert.ToInt32(dr1["QTY"]);
  107.                                 if (dr1["TDATE"].ToString().Equals(last_date) && dr1["TTIME"].ToString().Equals(last_time))
  108.                                 {
  109.                                 }
  110.                                 else
  111.                                 {
  112.                                     num_1 = num_1 + 1;
  113.                                 }
  114.                                 last_date = dr1["TDATE"].ToString();
  115.                                 last_time = dr1["TTIME"].ToString();
  116.                             }
  117.                         }
  118.                         dr1.Close();
  119.                         row["cancel_num"] = num_1;
  120.                         row["cancel_money"] = sum_1;
  121.                         SqlCommand sqlcom3 = new SqlCommand("select QTY,UNITPRICE,TDATE,TTIME from SPECREC where shop='" + dr["shop"].ToString() + "' and TDATE ='" + dr2["DATE"].ToString() + "' and REMARK='R'  ORDER BY TIME", conn2);
  122.                         SqlDataReader dr3 = sqlcom3.ExecuteReader();
  123.                         if (dr3.HasRows)
  124.                         {
  125.                             while (dr3.Read())
  126.                             {
  127.                                 sum_2 = sum_2 + Convert.ToDouble(dr3["UNITPRICE"]) * Convert.ToInt32(dr3["QTY"]);
  128.                                 if (dr3["TDATE"].ToString().Equals(last_d) && dr3["TTIME"].ToString().Equals(last_t))
  129.                                 {
  130.                                 }
  131.                                 else
  132.                                 {
  133.                                     num_2 = num_2 + 1;
  134.                                 }
  135.                                 last_d = dr3["TDATE"].ToString();
  136.                                 last_t = dr3["TTIME"].ToString();
  137.                             }
  138.                         }
  139.                         dr3.Close();
  140.                         conn2.Close();
  141.                         row["back_num"] = num_2;
  142.                         row["back_money"] = sum_2;
  143.                         row["cancel_total"] = Round(100 * sum_1 / sum, 2).ToString() + "%";
  144.                     dt.Rows.Add(row);
  145.                     }
  146.                 }
  147.                 dr2.Close();
  148.                 conn1.Close();
  149.             }
  150.         }
  151.         dr.Close();
  152.         conn.Close();
  153.         ReportDataSource rds = new ReportDataSource("DataSet3_DataTable1", dt);
  154.         ReportViewer1.LocalReport.DataSources.Clear();
  155.         ReportViewer1.LocalReport.DataSources.Add(rds);
  156.         ReportViewer1.LocalReport.Refresh();
  157.     }
  158.     protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
  159.     {
  160.         if (Begindate.Visible == true)
  161.         {
  162.             Begindate.Visible = false;
  163.             Begindate.Focus();
  164.         }
  165.         else
  166.         {
  167.             Begindate.Visible = true;
  168.             Begindate.Focus();
  169.         }
  170.     }
  171.     protected void Begindate_SelectionChanged(object sender, EventArgs e)
  172.     {
  173.         Begindate.Visible = false;
  174.         string year = Begindate.SelectedDate.Year.ToString();
  175.         string month = Begindate.SelectedDate.Month.ToString();
  176.         if (month.Length == 1)
  177.         {
  178.             month = "0" + month;
  179.         }
  180.         string day = Begindate.SelectedDate.Day.ToString();
  181.         if (day.Length == 1)
  182.         {
  183.             day = "0" + day;
  184.         }
  185.         b_date.Text = year + "-" + month + "-" + day;
  186.         b_date.Focus();
  187.     }
  188.     protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
  189.     {
  190.         if (Enddate.Visible == true)
  191.         {
  192.             Enddate.Visible = false;
  193.             Enddate.Focus();
  194.         }
  195.         else
  196.         {
  197.             Enddate.Visible = true;
  198.             Enddate.Focus();
  199.         }
  200.     }
  201.     protected void Enddate_SelectionChanged(object sender, EventArgs e)
  202.     {
  203.         Enddate.Visible = false;
  204.         string year = Enddate.SelectedDate.Year.ToString();
  205.         string month = Enddate.SelectedDate.Month.ToString();
  206.         if (month.Length == 1)
  207.         {
  208.             month = "0" + month;
  209.         }
  210.         string day = Enddate.SelectedDate.Day.ToString();
  211.         if (day.Length == 1)
  212.         {
  213.             day = "0" + day;
  214.         }
  215.         e_date.Text = year + "-" + month + "-" + day;
  216.         e_date.Focus();
  217.     }
  218.     protected void ShowMessageBox(string strMessage)
  219.     {
  220.         Response.Write(string.Format("<script>alert('{0}')</script>", strMessage));
  221.     }
  222.     protected void Button1_Click(object sender, EventArgs e)
  223.     {
  224.         if (b_date.Text.Trim().Equals("") || e_date.Text.Trim().Equals(""))
  225.         {
  226.             ShowMessageBox("请选择日期");
  227.         }
  228.         else
  229.         {
  230.             ReportViewer1.Visible = true;
  231.             bind();
  232.         }
  233.     }
  234.     public double Round(double v, int x)
  235.     {
  236.         bool flat = false;
  237.         if (v < 0)
  238.         {
  239.             flat = true;
  240.             v = -v;
  241.         }
  242.         int ivalue = 1;
  243.         for (int i = 1; i <= x; i++)
  244.         {
  245.             ivalue = 10 * ivalue;
  246.         }
  247.         double num = Math.Round(v * ivalue + 0.5, 0);
  248.         v = num / ivalue;
  249.         if (flat)
  250.         {
  251.             v = -v;
  252.         }
  253.         return v;
  254.     }
  255. }