Home > Net >  Consult, such data can be realized with code break up?
Consult, such data can be realized with code break up?

Time:11-07



 & lt; % @ Page Language="c #" AutoEventWireup="true" CodeFile="DataSplitDemo. Aspx. Cs" Inherits="Develop_BBS_DataSplitDemo % & gt;" 



<meta HTTP - equiv="content-type" Content="text/HTML. Charset=utf-8 "/& gt;


<body>




 
Introduction: with id 1001 Count to 1 (only the first line);
Id for 1002 Count for 2, 1 (first line) + 1 (the second line);
Id for the Count to 5, 1, 1003 (the first line) + 1 (line 2) + 3 (the third row);







 using System; 
using System.Collections.Generic;
using System.Data;
Using System. Linq;
Using System. The Web;
Using System. Web. UI.
Using System. Web. UI. WebControls;

Public partial class Develop_BBS_DataSplitDemo: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
Var dtSource=new DataTable ();
DtSource. Columns. The Add (" Id ", typeof (int));
DtSource. Columns. The Add (" Name ", typeof (string));
DtSource. Columns. The Add (" Count ", typeof (int));

Var drNew=dtSource. NewRow ();
DrNew (" Id ")=1001;
DrNew/" Name "=" apple ";
DrNew [" Count "]=1;
DtSource. Rows. The Add (drNew);

DrNew=dtSource. NewRow ();
DrNew (" Id ")=1002;
DrNew/" Name "=" banana ";
DrNew (" Count ")=2;
DtSource. Rows. The Add (drNew);

DrNew=dtSource. NewRow ();
DrNew (" Id ")=1003;
DrNew/" Name "=" orange ".
DrNew [" Count "]=5;
DtSource. Rows. The Add (drNew);
//... The actual number for the dynamic line

Enclosing gvSource. The DataSource=dtSource;
This. GvSource. DataBind ();

Var dtResult=new DataTable ();
DtResult. Columns. The Add (Ids, typeof (string));
DtResult. Columns. The Add (" Names ", typeof (string));
DtResult. Columns. The Add (" Count ", typeof (int));

Var drResult=dtResult. NewRow ();
DrResult [" Ids "]="3", 1001100, 2100;
DrResult [" Names "]="apples, bananas, oranges";
DrResult [" Count "]=1;
DtResult. Rows. The Add (drResult);

DrResult=dtResult. NewRow ();
DrResult [" Ids "]="1002100";
DrResult [" Names "]="bananas, oranges";
DrResult [" Count "]=1;
DtResult. Rows. The Add (drResult);

DrResult=dtResult. NewRow ();
DrResult [" Ids "]="1003";
DrResult [" Names "]="orange".
DrResult [" Count "]=3;
DtResult. Rows. The Add (drResult);

Enclosing gvResult. The DataSource=dtResult;
This. GvResult. DataBind ();
}
}


Don't know I clearly ~ ~, consult everybody how to use the code above that break up?

CodePudding user response:

https://segmentfault.com/q/1010000023720320

CodePudding user response:

 using System; 
using System.Collections.Generic;
Using System. Linq;

The namespace Console_Demo
{
Class Program
{
The static void Main (string [] args)
{
//read the database table
List Frults=new List
{
New Frult {Id="1001" and Name="apple," Count=1},
New Frult {Id="1002" and Name="banana", Count=2},
New Frult {Id="1003" and Name="orange," Count=5},
};

List FrultsRs=new List (a);
While (true)
{
Frults. RemoveAll (f=& gt; F. mount & lt;=0);
If (frults. Count==0) break;

Var doneIds=frults. Select (c=& gt; C.I d);
String id=string. Join (', 'doneIds);
Var frultGroup=frultsRs. FirstOrDefault (f=& gt; F.I d==id);
If (frultGroup==null) frultsRs. Add (new Frult
{
Id=Id,
Name=string. Join (', 'frults. Select (c=& gt; C.N ame)),
The Count=1
});
The else
{
FrultGroup. Count +=1;
}

Frults. ForEach (f=& gt; F. mount -=1);
}

The foreach (var d in frultsRs)
{
Console. WriteLine (the string. Format (" {0}, {1}, {2} ", d.I d, d.N ame,, dc mount));
}

Console.ReadKey();
}
}

Public class Frult
{
Public string Id {get; The set; }
Public string Name {get; The set; }
Public int Count {get; The set; }
}
}

CodePudding user response:

To tell you the truth, I didn't understand you what is the meaning of merger,,,
Feel the source of the database design should have a problem,

CodePudding user response:

refer to the third floor is nu month god reply:
to tell you the truth, I didn't understand you what is the meaning of merger,,,
Feel the source of the database design should have a problem,


Data sources, objective table would be all right, may be my words not clear enough, on the second floor of the code may be realized,

CodePudding user response:

nullnullnullnullnullnull