Exemplo n.º 1
0
    protected void viewTop(object sender, EventArgs e)
    {
        string        connStr = ConfigurationManager.ConnectionStrings["MyDbConn"].ToString();
        SqlConnection conn    = new SqlConnection(connStr);

        SqlCommand cmd = new SqlCommand("ViewTop", conn);

        cmd.CommandType = CommandType.StoredProcedure;
        string MVT = MonthVT.Text;

        cmd.Parameters.Add(new SqlParameter("@HR", Session["Username"].ToString()));
        cmd.Parameters.Add(new SqlParameter("@month", MVT));
        conn.Open();
        cmd.ExecuteNonQuery();
        GridViewTop.EmptyDataText = "No Records Found";
        SqlDataAdapter adapter = new SqlDataAdapter(cmd);
        DataSet        ds      = new DataSet();

        adapter.Fill(ds);
        if (ds.Tables.Count == 0)
        {
            GridViewTop.Visible = false;
            Response.Write("no records");
        }
        else
        {
            GridViewTop.DataSource = ds;
            GridViewTop.DataBind();
            GridViewTop.Visible = true;
        }
        conn.Close();
    }
        protected void Button1_Click(object sender, EventArgs e)
        {
            //string host = HttpContext.Current.Request.Url.Host + ":" + HttpContext.Current.Request.Url.Port;
            //string CourseTimes = HttpGet("http://" + host + "/InterFace/custom.ashx?method=CourseTimesList&start="+ hidStartDate.Value+ "&end="+hidEndDate.Value, "application/json");
            //JArray CourseTimesJ = JsonConvert.DeserializeObject<JArray>(CourseTimes);
            DateTime StartTime = Convert.ToDateTime(hidStartDate.Value);
            DateTime EndTime   = Convert.ToDateTime(hidEndDate.Value);
            //string area = DDarea.SelectedValue;
            var ProjectModel = new ProjectCollection.WebUI.Models.ProjectCollectionEntities();
            var AllOrder     = (from o in ProjectModel.TempOrder
                                join c in ProjectModel.TempCourse on o.CourseId equals c.CourseId
                                where (c.type == "自筹") && (!string.IsNullOrEmpty(c.SourceCourseId)) &&
                                (c.SourceCourseId != "") && (c.CreateDate >= StartTime) && (c.CreateDate <= EndTime)
                                //&& o.TempCustomer.area == area
                                select new
            {
                name = c.title,
                sourceid = c.SourceCourseId,
                customid = o.CustomerId
            });
            var DistinctOrder = AllOrder.GroupBy(o => new { o.customid, o.sourceid })
                                .Select(g => g.FirstOrDefault());
            var OrderCount = from o in DistinctOrder
                             group o by new { o.sourceid } into oc
            orderby oc.Count() descending
            select new
            {
                id = oc.Key.sourceid,
                //title =(from c in ProjectModel.TempCourse where c.SourceCourseId == oc.Key.sourceid select c.title).Take(1),
                count = oc.Count()
            };
            var OrderGroup = from o in OrderCount
                             group o by new { o.count } into oc
            orderby oc.Key.count descending
                select new
            {
                订购次数 = oc.Key.count,
                课件数量 = oc.Count()
            };

            GridViewTop.DataSource = OrderGroup.ToList();
            GridViewTop.DataBind();
        }