using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Text;
using System.Collections.Generic;
[Serializable]
[Microsoft.SqlServer.Server.SqlUserDefinedAggregate(Format.UserDefined,
IsInvariantToDuplicates = false,
IsInvariantToNulls = true,
IsInvariantToOrder = false,
IsNullIfEmpty = true,
MaxByteSize = 8000
)]
public struct SumPart : IBinarySerialize
{
private StringBuilder _reuslt;
//private List<string> _li ;
public void Init()
{
// 在此处放置代码
_reuslt = new StringBuilder();
//_li = new List<string>();
}
public void Accumulate(SqlString Value)
{
// 在此处放置代码
if (Value.IsNull)
{
return;
}
else
{
//_li.Add(Value.Value);
if (_reuslt.Length > 0)
{
_reuslt.Append("$");
}
_reuslt.Append(Value.Value);
}
}
public void Merge(SumPart Group)
{
// 在此处放置代码
_reuslt.Append(Group._reuslt);
}
public SqlString Terminate()
{
// 在此处放置代码
//if(li.Count>0) 为什么li老是==null????
//if (_li == null)
//{
// return new SqlString("");
//}
if (_reuslt.Length > 0)
{
string strReturn = "";
string[] arrayStr = _reuslt.ToString().Split('$');
List<string> li = new List<string>();
for (int i = 0; i < arrayStr.Length; i++)
{
li.Add(arrayStr[i]);
}
li.Sort();
foreach (string item in li)
{
strReturn += "$"+item ;
}
return new SqlString(strReturn);
//return new SqlString(_reuslt.ToString());
}
return new SqlString("");
}
// 这是占位符成员字段
private int var1;
#region IBinarySerialize 成员
public void Read(System.IO.BinaryReader r)
{
_reuslt = new StringBuilder(r.ReadString());
}
public void Write(System.IO.BinaryWriter w)
{
w.Write(_reuslt.ToString());
}
#endregion
}