⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 admindata.aspx.cs

📁 前台首页:users/index.aspx 后台首页:login.aspx 这是一个有关宠物的电子商务网站 注:后台的“售后服务” 和“数据统计”这两块由于时间原因暂时 没完成。由于技术问
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class admindata : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        DataTable tab =new DataTable();
        DataColumn col2 = new DataColumn("产品编号", System.Type.GetType("System.Int32"));
        DataColumn col3 = new DataColumn("产品名称", System.Type.GetType("System.String"));
        DataColumn col4 = new DataColumn("库存", System.Type.GetType("System.Int32"));
        DataColumn col5 = new DataColumn("已售出", System.Type.GetType("System.Int32"));

        tab.Columns.Add(col2);
        tab.Columns.Add(col3);
        tab.Columns.Add(col4);
        tab.Columns.Add(col5);

        SqlConnection con = new SqlConnection("data source=localhost;uid=sa;pwd=;database=Ebusiness");
        con.Open();
        SqlCommand comm = new SqlCommand("select count(*) from product_info", con);
        SqlDataReader reader = comm.ExecuteReader();
        int m=0;
        if (reader.Read())
        {
            m=reader.GetInt32(0);
            reader.Close();
        }
        for (int i = 0; i < m; i++)
        { 
            DataRow dr = tab.NewRow();
            
            SqlCommand objcomm = new SqlCommand("select a.id,a.petname,a.num,sum(b.[count]) from product_info as a ,orderinfo as b where a.id=" + i + " and b.id="+i+" group by a.id,a.petname,a.num", con);
            SqlDataReader objreader = objcomm.ExecuteReader();
            if (objreader.Read())
            {

                dr["产品编号"] = objreader.GetInt32(0).ToString();
                dr["产品名称"] = objreader.GetString(1);
                dr["库存"] = objreader.GetInt32(2).ToString();
                dr["已售出"] = objreader.GetInt32(3).ToString();
               
            }

          
            objreader.Close();
            
            SqlCommand objcomm0 = new SqlCommand("select a.id,a.petname,a.num from product_info as a  where a.id not in( select id from orderinfo as b) and a.id="+i+"", con);
            SqlDataReader objreader0 = objcomm0.ExecuteReader();
            if (objreader0.Read())
            {

                dr["产品编号"] = objreader0.GetInt32(0).ToString();
                dr["产品名称"] = objreader0.GetString(1);
                dr["库存"] = objreader0.GetInt32(2).ToString();
                dr["已售出"] =0;

            }
            objreader0.Close();
            tab.Rows.Add(dr);
            SqlCommand objcomm1 = new SqlCommand("select max(b.[count]),b.id,a.petname from product_info as a,orderinfo as b where b.id="+i+" group by b.id,a.petname ", con);
            SqlDataReader objreader1 = objcomm1.ExecuteReader();
            if (objreader1.Read())
            {
                Label1.Text= objreader1.GetString(2) + "、";
            }
            objreader1.Close();

        }
        GridView1.DataSource = tab;
        GridView1.DataBind();

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -