/// <summary>
/// 创建时间段
/// </summary>
/// <param name="dtFrom"></param>
/// <param name="dtTo"></param>
/// <returns></returns>
public Dictionary<string, string> CreateDictionaryDateTime
(
DateTime dtFrom,
DateTime dtTo
)
{
Dictionary<string, string> theResult = new Dictionary<string, string>();
DateTime dtFromMonth = DateTime.Parse(dtFrom.ToString("yyyy-MM") + "-01");
DateTime dtToMonth = DateTime.Parse(dtTo.ToString("yyyy-MM") + "-01");
int idx = 0;
DateTime dt = DateTime.Now;
while (true)
{
if (idx == 0)
dt = dtFromMonth;
else
dt = dtFromMonth.AddMonths(idx);
if (dt > dtToMonth)
break;
theResult.Add(dt.ToString("yyyyMM"), dt.ToString("yyyy年MM月"));
++idx;
}
return theResult;
}
/// <summary>
/// 创建时间段
/// </summary>
/// <param name="dtFrom"></param>
/// <param name="dtTo"></param>
/// <returns></returns>
public List<StatisticItemOne> CreateListStatisticItemOne
(
DateTime dtFrom,
DateTime dtTo
)
{
List<StatisticItemOne> theResult = new List<StatisticItemOne>();
DateTime dtFromMonth = DateTime.Parse(dtFrom.ToString("yyyy-MM") + "-01");
DateTime dtToMonth = DateTime.Parse(dtTo.ToString("yyyy-MM") + "-01");
StatisticItemOne itemOne = null;
int idx = 0;
DateTime dt = DateTime.Now;
while (true)
{
if (idx == 0)
dt = dtFromMonth;
else
dt = dtFromMonth.AddMonths(idx);
if (dt > dtToMonth)
break;
itemOne = new StatisticItemOne();
itemOne.TheName = dt.ToString("yyyy年MM月");
itemOne.TheNumber = 0;
itemOne.ID = dt.ToString("yyyyMM");
theResult.Add(itemOne);
++idx;
}
return theResult;
}
/// <summary>
/// 填充DIV
/// </summary>
/// <param name="divHeight"></param>
/// <param name="htmlValue"></param>
/// <returns></returns>
public string CommonFillDivOverflowAuto(int divHeight, string htmlValue)
{
if (htmlValue == null)
htmlValue = "";
return "<div id=\"div_View\" style=\" padding-top:5px; text-align:center; width:100%;height:" + divHeight.ToString() + "px; overflow:auto;\">" + htmlValue + "</div>";
}
/// <summary>
/// 绘制统计图表
/// </summary>
/// <param name="totalTitle"></param>
/// <param name="title"></param>
/// <param name="theList"></param>
/// <returns></returns>
public string CommonDrawStatTable
(
string totalTitle,
string title,
List<StatisticItemOne> theList
)
{
if (theList == null)
return "";
int iCount = theList.Count;
if (iCount <= 7)
return CommonDrawStatHorizontalTable(totalTitle, title, theList);
else
return CommonDrawStatVerticalTable(totalTitle, title, theList);
}
/// <summary>
/// 绘制统计图表
/// </summary>
/// <param name="showPercentage"></param>
/// <param name="totalTitle"></param>
/// <param name="title"></param>
/// <param name="theList"></param>
/// <returns></returns>
public string CommonDrawStatTable
(
bool showPercentage,
string totalTitle,
string title,
List<StatisticItemOne> theList
)
{
if (theList == null)
return "";
int iCount = theList.Count;
if (iCount <= 7)
return CommonDrawStatHorizontalTable(showPercentage, totalTitle, title, theList);
else
return CommonDrawStatVerticalTable(showPercentage, totalTitle, title, theList);
}
/// <summary>
/// 绘制统计图表
/// </summary>
/// <param name="theList"></param>
/// <returns></returns>
public string CommonDrawStatVerticalTable
(
string totalTitle,
string title,
List<StatisticItemOne> theList
)
{
if (theList == null)
return "";
StringBuilder theResult = new StringBuilder();
theResult.Append("<table class=\"tableItem\" width=\"98%\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" align=\"center\">");
theResult.Append("<tr class=\"trItem\">");
theResult.Append("<td class=\"tdLeftItem\" align=\"right\" height=\"30px\" width=\"50%\">" + title + "</td>");
theResult.Append("<td class=\"tdRightItem\" align=\"left\" height=\"30px\" width=\"50%\">统计数</td>");
theResult.Append("</tr>");
foreach (StatisticItemOne item in theList)
{
theResult.Append("<tr class=\"trItem\">");
theResult.Append("<td class=\"tdLeftItem\" align=\"right\" height=\"30px\" width=\"50%\">" + item.TheName + "</td>");
theResult.Append("<td class=\"tdRightItem\" align=\"left\" height=\"30px\" width=\"50%\">" + item.TheNumber.ToString() + "</td>");
theResult.Append("</tr>");
}
if (totalTitle != null)
{
decimal totalValue = 0;
foreach (StatisticItemOne item in theList)
{
totalValue += item.TheNumber;
}
theResult.Append("<tr class=\"trItem\">");
theResult.Append("<td class=\"tdLeftItem\" align=\"right\" height=\"30px\" width=\"50%\">" + totalTitle + "</td>");
theResult.Append("<td class=\"tdRightItem\" align=\"left\" height=\"30px\" width=\"50%\">" + totalValue.ToString() + "</td>");
theResult.Append("</tr>");
}
theResult.Append("</table>");
return CommonFillDivOverflowAuto(500, theResult.ToString());
}
/// <summary>
/// 绘制统计图表
/// </summary>
/// <param name="theList"></param>
/// <returns></returns>
public string CommonDrawStatHorizontalTable
(
string totalTitle,
string title,
List<StatisticItemOne> theList
)
{
if (theList == null)
return "";
int iCount = theList.Count + 1;
if (totalTitle != null)
iCount = iCount + 1;
int rate = 100 / iCount;
StringBuilder theResult = new StringBuilder();
theResult.Append("<table class=\"tableItem\" width=\"98%\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" align=\"center\">");
theResult.Append("<tr class=\"trItem\">");
theResult.Append("<td class=\"tdLeftItem\" align=\"center\" height=\"30px\" width=\"" + rate.ToString() + "%\">" + title + "</td>");
foreach (StatisticItemOne item in theList)
{
theResult.Append("<td class=\"tdLeftItem\" align=\"center\" height=\"30px\" width=\"" + rate.ToString() + "%\">" + item.TheName + "</td>");
}
if (totalTitle != null)
theResult.Append("<td class=\"tdLeftItem\" align=\"center\" height=\"30px\" width=\"" + rate.ToString() + "%\">" + totalTitle + "</td>");
theResult.Append("</tr>");
theResult.Append("<tr class=\"trItem\">");
theResult.Append("<td class=\"tdStatTextItem\" align=\"center\" height=\"30px\">统计数</td>");
foreach (StatisticItemOne item in theList)
{
theResult.Append("<td class=\"tdStatTextItem\" align=\"center\" height=\"30px\" >" + item.TheNumber.ToString() + "</td>");
}
if (totalTitle != null)
{
decimal totalValue = 0;
foreach (StatisticItemOne item in theList)
{
totalValue += item.TheNumber;
}
theResult.Append("<td class=\"tdStatTextItem\" align=\"center\" height=\"30px\" >" + totalValue.ToString() + "</td>");
}
theResult.Append("</tr>");
theResult.Append("</table>");
return CommonFillDivOverflowAuto(500, theResult.ToString());
}
/// <summary>
/// 绘制统计图表
/// </summary>
/// <param name="theList"></param>
/// <returns></returns>
public string CommonDrawStatVerticalTable
(
bool showPercentage,
string totalTitle,
string title,
List<StatisticItemOne> theList
)
{
if (theList == null)
return "";
StringBuilder theResult = new StringBuilder();
theResult.Append("<table class=\"tableItem\" width=\"98%\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" align=\"center\">");
theResult.Append("<tr class=\"trItem\">");
theResult.Append("<td class=\"tdLeftItem\" align=\"right\" height=\"30px\" width=\"50%\">" + title + "</td>");
theResult.Append("<td class=\"tdRightItem\" align=\"left\" height=\"30px\" width=\"50%\">统计数</td>");
theResult.Append("</tr>");
decimal totalValue = 0;
if (showPercentage || totalTitle != null)
{
foreach (StatisticItemOne item in theList)
{
totalValue += item.TheNumber;
}
}
if (showPercentage && totalValue != 0)
{
string strPercentage = "";
decimal percentageValue = 0;
foreach (StatisticItemOne item in theList)
{
percentageValue = (item.TheNumber * 100) / totalValue;
strPercentage = MathSlowXFunctions.GetMathRoundShowString(percentageValue, 2);
theResult.Append("<tr class=\"trItem\">");
theResult.Append("<td class=\"tdLeftItem\" align=\"right\" height=\"30px\" width=\"50%\">" + item.TheName + "</td>");
theResult.Append("<td class=\"tdRightItem\" align=\"left\" height=\"30px\" width=\"50%\">"
+ item.TheNumber.ToString() + " (" + strPercentage + "%)"
+ "</td>");
theResult.Append("</tr>");
}
}
else
{
foreach (StatisticItemOne item in theList)
{
theResult.Append("<tr class=\"trItem\">");
theResult.Append("<td class=\"tdLeftItem\" align=\"right\" height=\"30px\" width=\"50%\">" + item.TheName + "</td>");
theResult.Append("<td class=\"tdRightItem\" align=\"left\" height=\"30px\" width=\"50%\">" + item.TheNumber.ToString() + "</td>");
theResult.Append("</tr>");
}
}
if (totalTitle != null)
{
theResult.Append("<tr class=\"trItem\">");
theResult.Append("<td class=\"tdLeftItem\" align=\"right\" height=\"30px\" width=\"50%\">" + totalTitle + "</td>");
theResult.Append("<td class=\"tdRightItem\" align=\"left\" height=\"30px\" width=\"50%\">" + totalValue.ToString() + "</td>");
theResult.Append("</tr>");
}
theResult.Append("</table>");
return CommonFillDivOverflowAuto(500, theResult.ToString());
}
/// <summary>
/// 绘制二维统计图表
/// </summary>
/// <param name="xTotalTitle"></param>
/// <param name="yTotalTitle"></param>
/// <param name="title"></param>
/// <param name="statisticItemContainerValue"></param>
/// <returns></returns>
public string CommonDrawStatTwoTable
(
string xTotalTitle,
string yTotalTitle,
string title,
StatisticItemContainer statisticItemContainerValue
)
{
if (statisticItemContainerValue == null)
return "";
bool isFind = false;
bool xFillTotal = (xTotalTitle != null);
bool yFillTotal = (yTotalTitle != null);
StringBuilder theResult = new StringBuilder();
theResult.Append("<table class=\"tableItem\" width=\"98%\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" align=\"center\">");
// 绘制title //
theResult.Append("<tr class=\"trItem\">");
theResult.Append("<td class=\"tdLeftItem\" align=\"center\" height=\"30px\">" + title + "</td>");
Dictionary<string, string> dictionaryX = statisticItemContainerValue.dictionaryX;
Dictionary<string, string> dictionaryY = statisticItemContainerValue.dictionaryY;
List<StatisticItemTwo> theNumber = statisticItemContainerValue.TheNumber;
foreach (string xValue in dictionaryX.Values)
{
theResult.Append("<td class=\"tdLeftItem\" align=\"center\" height=\"30px\" >" + xValue + "</td>");
}
if (xFillTotal)
{
theResult.Append("<td class=\"tdLeftItem\" align=\"center\" height=\"30px\" >" + xTotalTitle + "</td>");
}
theResult.Append("</tr>");
decimal totalValue = 0;
foreach (string yKey in dictionaryY.Keys)
{
totalValue = 0;
theResult.Append("<tr class=\"trItem\">");
theResult.Append("<td class=\"tdStatTextItem\" align=\"center\" height=\"30px\">" + dictionaryY[yKey] + "</td>");
foreach (string xKey in dictionaryX.Keys)
{
isFind = false;
foreach (StatisticItemTwo item in theNumber)
{
if (item.xID == xKey && item.yID == yKey)
{
if (xFillTotal)
totalValue += item.TheNumber;
theResult.Append("<td class=\"tdStatTextItem\" align=\"center\" height=\"30px\" >" + item.TheNumber.ToString() + "</td>");
isFind = true;
break;
}
}
if (!isFind)
{
theResult.Append("<td class=\"tdStatTextItem\" align=\"center\" height=\"30px\" >0</td>");
}
}
if (xFillTotal)
theResult.Append("<td class=\"tdStatTextItem\" align=\"center\" height=\"30px\" >" + totalValue.ToString() + "</td>");
theResult.Append("</tr>");
}
if (yFillTotal)
{
decimal allValue = 0;
theResult.Append("<tr class=\"trItem\">");
theResult.Append("<td class=\"tdStatTextItem\" align=\"center\" height=\"30px\">" + yTotalTitle + "</td>");
foreach (string xKey in dictionaryX.Keys)
{
totalValue = 0;
foreach (StatisticItemTwo item in theNumber)
{
if (item.xID == xKey)
{
totalValue += item.TheNumber;
}
}
theResult.Append("<td class=\"tdStatTextItem\" align=\"center\" height=\"30px\" >" + totalValue.ToString() + "</td>");
allValue += totalValue;
}
if (xFillTotal)
theResult.Append("<td class=\"tdStatTextItem\" align=\"center\" height=\"30px\" >" + allValue.ToString() + "</td>");
theResult.Append("</tr>");
}
theResult.Append("</table>");
return CommonFillDivOverflowAuto(500, theResult.ToString());
}
/// <summary>
/// 绘制统计图表
/// </summary>
/// <param name="theList"></param>
/// <returns></returns>
public string CommonDrawStatHorizontalTable
(
bool showPercentage,
string totalTitle,
string title,
List<StatisticItemOne> theList
)
{
if (theList == null)
return "";
int iCount = theList.Count + 1;
if (totalTitle != null)
iCount = iCount + 1;
int rate = 100 / iCount;
StringBuilder theResult = new StringBuilder();
theResult.Append("<table class=\"tableItem\" width=\"98%\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" align=\"center\">");
theResult.Append("<tr class=\"trItem\">");
theResult.Append("<td class=\"tdLeftItem\" align=\"center\" height=\"30px\" width=\"" + rate.ToString() + "%\">" + title + "</td>");
decimal totalValue = 0;
if (showPercentage || totalTitle != null)
{
foreach (StatisticItemOne item in theList)
{
totalValue += item.TheNumber;
}
}
foreach (StatisticItemOne item in theList)
{
theResult.Append("<td class=\"tdLeftItem\" align=\"center\" height=\"30px\" width=\"" + rate.ToString() + "%\">" + item.TheName + "</td>");
}
if (totalTitle != null)
theResult.Append("<td class=\"tdLeftItem\" align=\"center\" height=\"30px\" width=\"" + rate.ToString() + "%\">" + totalTitle + "</td>");
theResult.Append("</tr>");
theResult.Append("<tr class=\"trItem\">");
theResult.Append("<td class=\"tdStatTextItem\" align=\"center\" height=\"30px\">统计数</td>");
if (showPercentage && totalValue != 0)
{
string strPercentage = "";
decimal percentageValue = 0;
foreach (StatisticItemOne item in theList)
{
percentageValue = (item.TheNumber * 100) / totalValue;
strPercentage = MathSlowXFunctions.GetMathRoundShowString(percentageValue, 2);
theResult.Append("<td class=\"tdStatTextItem\" align=\"center\" height=\"30px\" >"
+ item.TheNumber.ToString() + " (" + strPercentage + "%)"
+ "</td>");
}
}
else
{
foreach (StatisticItemOne item in theList)
{
theResult.Append("<td class=\"tdStatTextItem\" align=\"center\" height=\"30px\" >" + item.TheNumber.ToString() + "</td>");
}
}
if (totalTitle != null)
{
theResult.Append("<td class=\"tdStatTextItem\" align=\"center\" height=\"30px\" >" + totalValue.ToString() + "</td>");
}
theResult.Append("</tr>");
theResult.Append("</table>");
return CommonFillDivOverflowAuto(500, theResult.ToString());
}
/// <summary>
/// 获得DIV的HTML
/// </summary>
/// <returns></returns>
public string CommonGetDefaultChartDiv()
{
return "<div id=\"container\" style=\"width: 100%; height: 500px;\"></div>";
}
/// <summary>
/// 绘制统计图表
/// </summary>
/// <param name="theList"></param>
/// <returns></returns>
public string CommonDrawStatChartTable
(
string totalTitle,
string title,
int titleWidth,
int numberWidth,
int chartDivWidth,
string chartDiv,
List<StatisticItemOne> theList
)
{
StringBuilder theResult = new StringBuilder();
string titleWidthValue = "";
string numberWidthValue = "";
string chartDivWidthValue = "";
if (titleWidth > 0)
titleWidthValue = " width=\"" + titleWidth.ToString() + "px\"";
else if (titleWidth < 0)
titleWidthValue = " width=\"" + (-titleWidth).ToString() + "%\"";
if (numberWidth > 0)
numberWidthValue = " width=\"" + numberWidth.ToString() + "px\"";
else if (numberWidth < 0)
numberWidthValue = " width=\"" + (-numberWidth).ToString() + "%\"";
if (chartDivWidth > 0)
chartDivWidthValue = " width=\"" + chartDivWidth.ToString() + "px\"";
else if (chartDivWidth < 0)
chartDivWidthValue = " width=\"" + (-chartDivWidth).ToString() + "%\"";
int rowspan = theList.Count + 1;
if (totalTitle != null)
{
rowspan += 1;
}
theResult.Append("<table class=\"tableItem\" width=\"98%\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" align=\"center\">");
theResult.Append("<tr class=\"trItem\">");
theResult.Append("<td class=\"tdLeftItem\" align=\"right\" height=\"30px\"" + titleWidthValue + ">" + title + "</td>");
theResult.Append("<td class=\"tdRightItem\" align=\"left\" height=\"30px\"" + numberWidthValue + ">统计数</td>");
theResult.Append("<td class=\"tdRightItem\" align=\"center\" rowspan=\"" + rowspan.ToString() + "\"" + chartDivWidthValue + ">" + chartDiv + "</td>");
theResult.Append("</tr>");
foreach (StatisticItemOne item in theList)
{
theResult.Append("<tr class=\"trItem\">");
theResult.Append("<td class=\"tdLeftItem\" align=\"right\" height=\"30px\">" + item.TheName + "</td>");
theResult.Append("<td class=\"tdRightItem\" align=\"left\" height=\"30px\">" + item.TheNumber.ToString() + "</td>");
theResult.Append("</tr>");
}
if (totalTitle != null)
{
decimal totalValue = 0;
foreach (StatisticItemOne item in theList)
{
totalValue += item.TheNumber;
}
theResult.Append("<tr class=\"trItem\">");
theResult.Append("<td class=\"tdLeftItem\" align=\"right\" height=\"30px\"" + titleWidthValue + ">" + totalTitle + "</td>");
theResult.Append("<td class=\"tdRightItem\" align=\"left\" height=\"30px\"" + numberWidthValue + ">" + totalValue.ToString() + "</td>");
theResult.Append("</tr>");
}
theResult.Append("</table>");
return CommonFillDivOverflowAuto(500, theResult.ToString());
}