XWPFDocument doc = HtmlExport(Int32.Parse(ViewState["HidRecipwweekId"].ToString()), 0);//.Replace("
string wordFile = Server.MapPath("模板.docx");
FileInfo file = new FileInfo(wordFile);
if (file.Exists)
{
FileStream out1 = new FileStream(wordFile, FileMode.Create);
doc.Write(out1);
out1.Close();
openWindowExport(wordFile, "食谱.docx");
}
}
else
{
XWPFDocument doc = new XWPFDocument();
string wordFile = Server.MapPath("模板.docx");
FileInfo file = new FileInfo(wordFile);
if (file.Exists){
doc = tbGetReport(Int32.Parse(ViewState["HidRecipwweekId"].ToString()), doc);
FileStream out1 = new FileStream(wordFile, FileMode.Create);
doc.Write(out1);
out1.Close();
openWindowExport(wordFile, "食谱分析报告.docx");
}
}
}
}
public static string openWindowExport(string strFileName,string downfile)
{
string strReutrn = "";
try
{
FileInfo DownloadFile = new FileInfo(strFileName);
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.ClearHeaders();
System.Web.HttpContext.Current.Response.Buffer = false;
System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";
System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename="
+ System.Web.HttpUtility.UrlEncode(downfile, System.Text.Encoding.UTF8));
System.Web.HttpContext.Current.Response.AppendHeader("Content-Length",
DownloadFile.Length.ToString());
System.Web.HttpContext.Current.Response.WriteFile(DownloadFile.FullName);
}
catch (Exception Ex)
{
strReutrn = Ex.Message;
}
finally
{
System.Web.HttpContext.Current.Response.Flush();
System.Web.HttpContext.Current.Response.End();
}
return strReutrn;
}
#endregion
#region//导出食谱
private XWPFDocument HtmlExport(int recpweekId, int dispalyMaterial)
{
XWPFDocument doc = new XWPFDocument();
XWPFSettings set = new XWPFSettings();
StringBuilder str = new StringBuilder();
//星期
DataTable dtWeek = DAL.R_RecipeMeal.GetRecipeWeek(recpweekId).Tables[0];
DataTable dt = new DataTable();
DataTable dt_weekday = new DataTable();
dt = new CC.DAL.R_RecipeWeekMain().GetRecWeekDetailConnMealType(recpweekId).Tables[0];
dt = RCC(dt);
Hashtable hRQtable = new Hashtable();
string weekstart = "0";
string weekend = "0";
string strtitle = "周食谱";
if (dispalyMaterial == 1)
strtitle = "带量食谱";
dt_weekday = new CC.DAL.R_RecipeWeekMain().GetRecSevenDay(recpweekId).Tables[0];
if (dt_weekday.Rows.Count > 0)
{
//设置顶部title
weekstart = dt_weekday.Rows[0]["weekstart"].ToString();
weekend = dt_weekday.Rows[0]["weekend"].ToString();
//设置顶部title
XWPFParagraph p1 = doc.CreateParagraph();
XWPFRun r1 = p1.CreateRun();
r1.SetBold(true);
r1.SetText(dt_weekday.Rows[0]["name"].ToString() + strtitle);
r1.SetBold(true);
r1.SetFontFamily("Courier");
p1.SetAlignment(ParagraphAlignment.CENTER);
r1.SetFontSize(25);
p1 = doc.CreateParagraph();
p1.SetAlignment(ParagraphAlignment.CENTER);
r1.SetFontSize(15);
r1 = p1.CreateRun();
r1.SetBold(true);
r1.SetText("日期:" + weekstart.Replace('-', '.') + "—" + weekend.Replace('-', '.') + "周次:" + dt_weekday.Rows[0]["weekindex"].ToString());
r1.SetBold(true);
r1.SetFontFamily("Courier");
r1.SetTextPosition(20);
int dayCnt = 0;
//星期对应日期加入hashtable
for (DateTime t = DateTime.Parse(weekstart); t <= DateTime.Parse(weekend); t = t.AddDays(1))
{
if (dayCnt == 7)
break;
hRQtable.Add(t.DayOfWeek.ToString(), t.Date.ToString("yyyy-MM-dd"));
dayCnt = dayCnt + 1;
}
}
XWPFTable table = null;
table = doc.CreateTable();
// table = cteatetemprow(table, dtWeek, dispalyMaterial);
table.Width = 1000000;
if (dt.Rows.Count > 0)
{
//星期head 完毕
//食物与材料不对应分N次循环各餐分七次循环个列
XWPFTableRow m_Row;
XWPFTableCell cell;
CT_Tc cttc;
CT_TcPr ctPr;
CT_TblWidth wid;
CT_R ctr;
CT_RPr ctrpr;
CT_Color cor;
CT_OnOff b;
CT_HpsMeasure sz;
for (int i = 0; i < dt.Rows.Count; i++) //循环餐
{
m_Row = table.CreateRow();//创建一行
cell = m_Row.GetCell(0);// m_Row.CreateCell();
cttc = cell.GetCTTc();
ctPr = cttc.AddNewTcPr();
//wid = new CT_TblWidth();
//wid.w = "500";
//ctPr.tcW = wid;
ctr = cttc.GetPList()[0].AddNewR();
ctrpr = ctr.AddNewRPr();
ctrpr.AddNewRFonts().hint = ST_Hint.eastAsia;
cor = new CT_Color();
cor.val = "black";
ctrpr.color = cor;
b = new CT_OnOff();
b.val = true;
ctrpr.b = b;
sz = new CT_HpsMeasure();
sz.val = (ulong.Parse("25"));
ctrpr.sz = sz;
ctPr.vAlign.val = ST_VerticalJc.center;
ctr.AddNewT().Value = " " + dt.Rows[i]["餐次"].ToString() + " ";
for (int x = 0; x < dtWeek.Rows.Count; x++) //循环列
{
string weekName = "星期" + NumToChina(Convert.ToInt32(dtWeek.Rows[x]["Week"]));
cell = m_Row.CreateCell();
// 转化字符串为集合关键字符(:&)示范(荷包蛋&大米:10;荷包蛋&鸡蛋:30 )循环li
string StrMon = dt.Rows[i][weekName].ToString();
string StrRecipName = null; //菜谱名
string StrTempRecipName = null;
string[] arr = StrMon.Split(';');
List mList = new List();
if (StrMon != "")
{
string tablefd = "";
for (int j = 0; j < arr.Length; j++)
{
StrTempRecipName = arr[j].Split('&')[0];
if (StrRecipName != StrTempRecipName)
{
if (j == 0)
tablefd += arr[j].Split('&')[0];
else
tablefd += "、" + arr[j].Split('&')[0];
}
StrRecipName = arr[j].Split('&')[0];
//组合食材+量集合
mList.Add(arr[j].Split('&')[1]);
}
cell.SetText(tablefd);
}
else
{
if (i == dt.Rows.Count - 1)
cell.SetText(". .");
}
//显示材料:量
Hashtable tb = new Hashtable();
if (dispalyMaterial == 1)
{
cell = m_Row.CreateCell();
if (mList.Count > 0)
{
mList.Sort();
tb = getFoodNameValue(mList); //合并材料
int tempi = 1;
foreach (DictionaryEntry de in tb)
{
if (tb.Count != tempi)
cell.SetText(de.Key + ": " + de.Value + "g " + "、"); //追加==str.append()
else
cell.SetText(de.Key + ": " + de.Value + "g ");
tempi = tempi + 1;
}
}
else
{
cell.SetText(". .");
}
}
}
}
table.RemoveRow(0);
m_Row = table.InsertNewTableRow(0);//创建一行
cell = m_Row.CreateCell();
cttc = cell.GetCTTc();
ctPr = cttc.AddNewTcPr();
wid = new CT_TblWidth();
wid.w = "500";
ctPr.tcW = wid;
ctr = cttc.GetPList()[0].AddNewR();
ctrpr = ctr.AddNewRPr();
ctrpr.AddNewRFonts().hint = ST_Hint.eastAsia;
cor = new CT_Color();
cor.val = "black";
ctrpr.color = cor;
b = new CT_OnOff();
b.val = true;
ctrpr.b = b;
sz = new CT_HpsMeasure();
sz.val = (ulong.Parse("25"));
ctrpr.sz = sz;
ctr.AddNewT().Value = " 餐次";
for (int i = 0; i < dtWeek.Rows.Count; i++)
{
string weekName = " 星期" + NumToChina(Convert.ToInt32(dtWeek.Rows[i]["Week"])) + " ";
cell = m_Row.CreateCell();//创建一个单元格,创建单元格时就创建了一个CT_P
cttc = cell.GetCTTc(); // w = new CT_TblWidth(); w.w = "300";
ctPr = cttc.AddNewTcPr(); //ctPr.tcW = w;
ctPr.noWrap.val = true;
ctr = cttc.GetPList()[0].AddNewR();
ctrpr = ctr.AddNewRPr();
ctrpr.b = b;
ctrpr.sz = sz;
if (dispalyMaterial == 1)
ctPr.gridSpan.val = "2";//合并2列
ctPr.vAlign.val = ST_VerticalJc.both;
ctrpr.AddNewRFonts().hint = ST_Hint.eastAsia;
cttc.GetPList()[0].AddNewPPr().AddNewJc().val = ST_Jc.center;
if
(hRQtable[NumToweek(Convert.ToInt32(dtWeek.Rows[i]["Week"])).ToString()] != null)
{
weekName += "(" + hRQtable[NumToweek(Convert.ToInt32(dtWeek.Rows[i]["Week"]))].ToString() + ")";
}
ctr.AddNewT().Value = weekName;
}
}
// table.RemoveRow(1);
DataTable dt_memo = new DataTable();
CC.Model.R_RecipeWeekMain modelrwm = new CC.Model.R_RecipeWeekMain();
modelrwm = new CC.DAL.R_RecipeWeekMain().GetModel(recpweekId);
XWPFParagraph p = doc.CreateParagraph();
XWPFRun r = p.CreateRun();
r.SetBold(true);
r.SetText("备注信息:" + modelrwm.Annotation.ToString());
r.SetBold(true);
r.SetFontFamily("Courier");
p.SetAlignment(ParagraphAlignment.CENTER);
r.SetFontSize(10);
return doc;
}
#endregion
#region //公共函数
private DataTable RCC(DataTable _outDataSource)
{
//从DataTable中读取不重复的item行,用来构造新DataTable的列
DataTable distinct_date = _outDataSource.DefaultView.ToTable(true, "mealName");
DataTable new_DataTable = new DataTable();
//将名称列添加到新表中
DataColumn new_mealName_col = new DataColumn();
new_mealName_col.ColumnName = "餐次";
new_mealName_col.Caption = "";
new_DataTable.Columns.Add(new_mealName_col);
DataColumn new_mon_col = new DataColumn();
new_mon_col.ColumnName = "星期一";
new_mon_col.Caption = "";
new_DataTable.Columns.Add(new_mon_col);
DataColumn new_tue_col = new DataColumn();
new_tue_col.ColumnName = "星期二";
new_tue_col.Caption = "";
new_DataTable.Columns.Add(new_tue_col);
DataColumn new_wed_col = new DataColumn();
new_wed_col.ColumnName = "星期三";
new_wed_col.Caption = "";
new_DataTable.Columns.Add(new_wed_col);
DataColumn new_thur_col = new DataColumn();
new_thur_col.ColumnName = "星期四";
new_thur_col.Caption = "";
new_DataTable.Columns.Add(new_thur_col);
DataColumn new_fri_col = new DataColumn();
new_fri_col.ColumnName = "星期五";
new_fri_col.Caption = "";
new_DataTable.Columns.Add(new_fri_col);
DataColumn new_sat_col = new DataColumn();
new_sat_col.ColumnName = "星期六";
new_sat_col.Caption = "";
new_DataTable.Columns.Add(new_sat_col);
DataColumn new_sun_col = new DataColumn();
new_sun_col.ColumnName = "星期天";
new_sun_col.Caption = "";
new_DataTable.Columns.Add(new_sun_col);
StringBuilder str_sum = new StringBuilder();
//到此新表已经构建完毕,下面开始为新表添加数据*/
//从原DataTable中读出不重复的名称,以名称为关键字来构造新表的行//聚合各周材料字段(白菜:20g)与菜谱字段(白菜汤)
//需要再次处理拆分材料字段进行材料量的合并
DataRow[] drs;
DataRow new_dr;
foreach (DataRow dr in distinct_date.Rows)
{
new_dr = new_DataTable.NewRow();
new_dr["餐次"] = dr["mealName"].ToString();
foreach (DataRow _dr in _outDataSource.Rows)
{
// drs = _outDataSource.Select("mealName='" + dr["mealName"].ToString() + "' ");
if (new_dr["餐次"].ToString() == _dr["mealName"].ToString())
{
new_dr["星期一"] = new_dr["星期一"].ToString() == "" ? _dr["星期一"].ToString().Replace(';', ' ').Trim() : _dr["星期一"].ToString() == "" ? new_dr["星期一"].ToString() : new_dr["星期一"].ToString() + ";" + _dr["星期一"].ToString().Replace(';', ' ').Trim();
new_dr["星期二"] = new_dr["星期二"].ToString() == "" ? _dr["星期二"].ToString().Replace(';', ' ').Trim() : _dr["星期二"].ToString() == "" ? new_dr["星期二"].ToString() : new_dr["星期二"].ToString() + ";" + _dr["星期二"].ToString().Replace(';', ' ').Trim();
new_dr["星期三"] = new_dr["星期三"].ToString() == "" ? _dr["星期三"].ToString().Replace(';', ' ').Trim() : _dr["星期三"].ToString() == "" ? new_dr["星期三"].ToString() : new_dr["星期三"].ToString() + ";" + _dr["星期三"].ToString().Replace(';', ' ').Trim();
new_dr["星期四"] = new_dr["星期四"].ToString() == "" ? _dr["星期四"].ToString().Replace(';', ' ').Trim() : _dr["星期四"].ToString() == "" ? new_dr["星期四"].ToString() : new_dr["星期四"].ToString() + ";" + _dr["星期四"].ToString().Replace(';', ' ').Trim();
new_dr["星期五"] = new_dr["星期五"].ToString() == "" ? _dr["星期五"].ToString().Replace(';', ' ').Trim() : _dr["星期五"].ToString() == "" ? new_dr["星期五"].ToString() : new_dr["星期五"].ToString() + ";" + _dr["星期五"].ToString().Replace(';', ' ').Trim();
new_dr["星期六"] = new_dr["星期六"].ToString() == "" ? _dr["星期六"].ToString().Replace(';', ' ').Trim() : _dr["星期六"].ToString() == "" ? new_dr["星期六"].ToString() : new_dr["星期六"].ToString() + ";" + _dr["星期六"].ToString().Replace(';', ' ').Trim();
new_dr["星期天"] = new_dr["星期天"].ToString() == "" ? _dr["星期天"].ToString().Replace(';', ' ').Trim() : _dr["星期天"].ToString() == "" ? new_dr["星期天"].ToString() : new_dr["星期天"].ToString() + ";" + _dr["星期天"].ToString().Replace(';', ' ').Trim();
}
}
new_DataTable.Rows.Add(new_dr);
}
return new_DataTable;
}
private Hashtable getFoodNameValue(List mList)
{
Hashtable tb = new Hashtable();
string name = ""; double value = 0.0;
string tempname = ""; double tempvalue = 0.0;
for (int j = 0; j < mList.Count; j++)
{
name = mList[j].Split(':')[0];
if (name != tempname)
{
tb.Add(name, mList[j].Split(':')[1]);
tempvalue = double.Parse(mList[j].Split(':')[1].Trim());
}
else
{
tb.Remove(name);
tempvalue = tempvalue + double.Parse(mList[j].Split(':')[1].Trim());
tb.Add(name, tempvalue);
}
tempname = name;
}
return tb;
}
protected string NumToweek(int week)
{
switch (week)
{
case 1: return "Monday";
case 2: return "Tuesday";
case 3: return "Wednesday";
case 4: return "Thursday";
case 5: return "Friday";
case 6: return "Saturday";
case 7: return "Sunday";
default: return "0";
}
}
#endregion
#region //营养分析报告
public XWPFDocument tbGetReport(int RecipeWeekId, XWPFDocument mydoc)
{
ViewState["Score"] = 100;
StringBuilder str = new StringBuilder();
string strdate = "";
string eattype = "";
string schoolname = "";
//0.绑定头部信息
XWPFDocument doc = mydoc;
CC.Model.R_RecipeWeekMain model = new BLL.R_RecipeWeekMain().GetModel(RecipeWeekId);
eattype = DAL.R_RecipeChildCnt.GetRecipeMealStr(RecipeWeekId);//就餐方式
if (model != null)
{
string start = model.WeekStart.ToLongDateString();
string end = model.WeekEnd.ToLongDateString();
strdate = start + "~" + end;
schoolname = new CC.DAL.T_School().GetModel(model.SchoolId).Name;
}
XWPFParagraph grap = doc.CreateParagraph();
XWPFRun run = grap.CreateRun();
run.SetFontSize(16);
grap.SetAlignment(ParagraphAlignment.CENTER);
run.SetText("周食谱营养分析报告(每人每日在园量)");
run.SetBold(true);
run.SetFontFamily("Courier");
grap = doc.CreateParagraph();
run = grap.CreateRun();
run.SetFontSize(12);
grap.SetAlignment(ParagraphAlignment.CENTER);
run.SetFontFamily("Courier");
run.SetText(schoolname + " " + strdate);
grap = doc.CreateParagraph();
XWPFRun canshirun = grap.CreateRun();
canshirun.SetFontSize(12);
grap.SetAlignment(ParagraphAlignment.CENTER);
canshirun.SetFontFamily("Courier");
canshirun.SetText("餐式:" + eattype);
doc = GetReportAnyaly1(RecipeWeekId, doc);//.Replace("
"
doc.CreateParagraph();//换行
// run = grap.CreateRun();
doc = GetReportAnyaly2(Int32.Parse(ViewState["HidRecipwweekId"].ToString()), doc);
doc.CreateParagraph();
run = grap.CreateRun();
doc = GetReportAnyaly3(Int32.Parse(ViewState["HidRecipwweekId"].ToString()), doc);
doc.CreateParagraph();
run = grap.CreateRun();
doc = GetReportAnyaly4(Int32.Parse(ViewState["HidRecipwweekId"].ToString()), doc);
doc.CreateParagraph();
run = grap.CreateRun();
XWPFParagraph grapAdvice = doc.CreateParagraph();
XWPFRun graprun = grapAdvice.CreateRun();
graprun.SetText("5. 营养分析建议");
graprun.SetBold(true);
graprun.SetFontFamily("Courier");
grapAdvice.SetAlignment(ParagraphAlignment.LEFT);
XWPFTable table = doc.CreateTable();
XWPFTableRow m_Row = table.CreateRow();//创建一行
m_Row.GetCell(0).SetText(GetProposal());
table.RemoveRow(0);
double sumScore = HWF.HW_StrToDouble(HWF.HW_StrToDouble(ViewState["Score"].ToString()).ToString("f2"));
if (sumScore < 0)
{
sumScore = 0;
}
canshirun.SetText(" 总分"+sumScore.ToString());
return doc;
}
//推荐量计算报告
private XWPFDocument GetReportAnyaly1(int RecipeWeekId, XWPFDocument doc)
{
DataTable dtRec = DAL.R_NutritionRecommend.GetNutritionRecommend(RecipeWeekId).Tables[0];
DataTable dtWeek = DAL.R_NutritionRecommend.GetNutritionRecipeWeek(RecipeWeekId).Tables[0];
decimal Score = HWF.HW_StrToDecimal(DAL.R_RptScoreSet.GetList().Tables[0].Rows[0]["ScoreAvg"].ToString()); //分值
if (dtRec.Rows.Count == 1 && dtWeek.Rows.Count == 1)
{
XWPFParagraph grap = doc.CreateParagraph();
XWPFRun run = grap.CreateRun();
run.SetText("1.各营养素的摄入量与推荐营养素摄入量比较(人均)");
run.SetBold(true);
run.SetFontFamily("Courier");
grap.SetAlignment(ParagraphAlignment.LEFT);
XWPFTable table = doc.CreateTable();
XWPFTableRow m_Row = table.CreateRow();//创建一行
//m_Row.SetRepeatHeader(true);
m_Row.GetCell(0).SetText("营养素");
XWPFTableCell cell = m_Row.CreateCell();
cell.SetText("推荐量");
cell = m_Row.CreateCell();
cell.SetText("摄入量");
cell = m_Row.CreateCell();
cell.SetText("摄入量占推荐量比例");
cell = m_Row.CreateCell();
cell.SetText("实际百分比");
cell = m_Row.CreateCell();
cell.SetText("评价");
cell = m_Row.CreateCell();
cell.SetText("扣分");
#region //建立结果表
DataTable dtscore = new DataTable();
dtscore.Columns.Add("ItemName");
dtscore.Columns.Add("Result");
dtscore.Columns.Add("Score");
dtscore.Columns.Add("Field");
string ItemName = string.Empty;
string Field = string.Empty;
#endregion
for (int i = 0; i < 8; i++)
{
#region //获取对应字段值
switch (i)
{
case 2:
ItemName = "钙";
Field = "Calcium";
break;
case 3:
ItemName = "锌";
Field = "Zinc";
break;
case 4:
ItemName = "维生素A";
Field = "VitaminA";
break;
case 5:
ItemName = "硫胺素B1";
Field = "Thiamine";
break;
case 6:
ItemName = "尼克酸";
Field = "NickAcid";
break;
case 7:
ItemName = "抗坏血酸C";
Field = "AscorbicAcid";
break;
}
#endregion
//实际百分比
decimal pro = HWF.HW_StrToDecimal(dtWeek.Rows[0][i].ToString()) / HWF.HW_StrToDecimal(dtRec.Rows[0][i].ToString());
//摄入量占推荐量比例(区间)
DataTable dt = DAL.R_NutrientsSet.GetNutritionSet(pro, i).Tables[0];
string prointerval = "";
string result = "";
decimal LowValue = HWF.HW_StrToDecimal(dt.Rows[0]["LowValue"].ToString());//开始值
decimal ExcessValue = HWF.HW_StrToDecimal(dt.Rows[0]["ExcessValue"].ToString());//结束值
if (dt.Rows.Count > 0)
{
result = dt.Rows[0]["Result"].ToString();
prointerval = dt.Rows[0]["LowValue"].ToString() + "~" + dt.Rows[0]["ExcessValue"].ToString();
}
ViewState["Item" + i] = result;
m_Row = table.CreateRow();//创建一行
m_Row.GetCell(0).SetText(dtRec.Columns[i].ToString());
cell = m_Row.CreateCell();
cell.SetText(dtRec.Rows[0][i].ToString());
cell = m_Row.CreateCell();
cell.SetText(dtWeek.Rows[0][i].ToString());
cell = m_Row.CreateCell();
cell.SetText(prointerval);
cell = m_Row.CreateCell();
cell.SetText(pro.ToString("f2"));
cell = m_Row.CreateCell();
cell.SetText(result);
cell = m_Row.CreateCell();
if (result == "过剩")
{
double score = HWF.HW_StrToDouble((((pro - ExcessValue) / ExcessValue) * Score).ToString("f2"));
if (score == 0)
{
score = 0.01;
}
double SumScore = HWF.HW_StrToDouble(ViewState["Score"].ToString()) - score;
ViewState["Score"] = SumScore;
if(i==7)
cell.SetText(score.ToString() + " .");
else
cell.SetText(score.ToString());
#region //评价以及分值
if (score > 0.05 && i > 1)
{
DataRow dr = dtscore.NewRow();
dr[0] = ItemName;
dr[1] = result;
dr[2] = score;
dr[3] = Field;
dtscore.Rows.Add(dr);
}
#endregion
}
else if (result == "不足"||result=="严重不足")
{
double score = HWF.HW_StrToDouble((((LowValue - pro) / LowValue) * Score).ToString("f2"));
if (score == 0)
{
score = 0.01;
}
double SumScore = HWF.HW_StrToDouble(ViewState["Score"].ToString()) - score;
ViewState["Score"] = SumScore;
if (i == 7)
cell.SetText(score.ToString() + " .");
else
cell.SetText(score.ToString());
#region //评价以及分值
if (score > 0.05 && i > 1)
{
DataRow dr = dtscore.NewRow();
dr[0] = ItemName;
dr[1] = result;
dr[2] = score;
dr[3] = Field;
dtscore.Rows.Add(dr);
}
#endregion
}
else
{
if(i==7)
cell.SetText("0 .");
else
cell.SetText("0");
}
}
table.RemoveRow(0);
ViewState["dtScore"] = dtscore;
}
return doc;
}
//热量营养素来源比报告
private XWPFDocument GetReportAnyaly2(int RecipeWeekId, XWPFDocument doc)
{
DataTable dtHeat = DAL.R_NutrientsSet.GetRecipeWeekHeat(RecipeWeekId).Tables[0];
decimal Score =
HWF.HW_StrToDecimal(DAL.R_RptScoreSet.GetList().Tables[0].Rows[1]["ScoreAvg"].ToString()); //分值
if (dtHeat.Rows.Count > 0)
{
XWPFParagraph grap = doc.CreateParagraph();
XWPFRun run = grap.CreateRun();
run.SetText("2.热量的营养素来源比例");
run.SetBold(true);
run.SetFontFamily("Courier");
grap.SetAlignment(ParagraphAlignment.LEFT);
XWPFTable table = doc.CreateTable();
XWPFTableRow m_Row = table.CreateRow();//创建一行
m_Row.GetCell(0).SetText("营养素");
XWPFTableCell cell = m_Row.CreateCell();
cell.SetText("热量(千卡)");
cell = m_Row.CreateCell();
cell.SetText("合理百分比");
cell = m_Row.CreateCell();
cell.SetText("实际摄入百分比");
cell = m_Row.CreateCell();
cell.SetText("评价");
cell = m_Row.CreateCell();
cell.SetText("扣分");
for (int i = 0; i < 3; i++)
{
decimal pro = HWF.HW_StrToDecimal(dtHeat.Rows[0][i + 3].ToString());
//热量来源比列(区间)
DataTable dt = DAL.R_NutrientsSet.GetHeatPer(pro, i + 4).Tables[0];
string prointerval = "";
string result = "";
decimal StartValue = HWF.HW_StrToDecimal(dt.Rows[0]["StartValue"].ToString());//开始值
decimal EndValue = HWF.HW_StrToDecimal(dt.Rows[0]["EndValue"].ToString());//结束值
if (dt.Rows.Count > 0)
{
prointerval = dt.Rows[0]["StartValue"].ToString() + "~" + dt.Rows[0]["EndValue"].ToString();
result = dt.Rows[0]["Result"].ToString();
}
ViewState["Heat" + i] = result;
m_Row = table.CreateRow();//创建一行
m_Row.GetCell(0).SetText(dtHeat.Columns[i].ToString());
cell = m_Row.CreateCell();
cell.SetText(dtHeat.Rows[0][i].ToString());
cell = m_Row.CreateCell();
cell.SetText(prointerval);
cell = m_Row.CreateCell();
cell.SetText(pro.ToString());
cell = m_Row.CreateCell();
cell.SetText(result);
cell = m_Row.CreateCell();
if (result == "偏高")
{
double score = HWF.HW_StrToDouble((((pro - EndValue) / EndValue) * Score).ToString("f2"));
if (score == 0)
{
score = 0.01;
}
double SumScore = HWF.HW_StrToDouble(ViewState["Score"].ToString()) - score;
ViewState["Score"] = SumScore;
if (i == 2)
cell.SetText(score.ToString() + " .");
else
cell.SetText(score.ToString());
}
else if (result == "偏低")
{
double score = HWF.HW_StrToDouble((((StartValue - pro) / StartValue) * Score).ToString("f2"));
if (score == 0)
{
score = 0.01;
}
double SumScore = HWF.HW_StrToDouble(ViewState["Score"].ToString()) - score;
ViewState["Score"] = SumScore;
if (i == 2)
cell.SetText(score.ToString() + " .");
else
cell.SetText(score.ToString());
}
else
{
if (i == 2)
cell.SetText("0 .");
else
cell.SetText("0");
}
}
table.RemoveRow(0);
}
return doc;
}
//优质蛋白质比率报告
private XWPFDocument GetReportAnyaly3(int RecipeWeekId, XWPFDocument mydoc)
{
XWPFDocument doc = mydoc;
StringBuilder str = new StringBuilder();
DataTable dtper = DAL.R_NutrientsSet.GetPer(RecipeWeekId).Tables[0];
DataTable dtWeight = DAL.R_NutrientsSet.GetWeightByProtein(RecipeWeekId).Tables[0];//按分类统计进餐量decimal Score = HWF.HW_StrToDecimal(DAL.R_RptScoreSet.GetList().Tables[0].Rows[2]["ScoreAvg"].ToString()); //分值
double goodscore = 0;
double ungoodscore = 0;
if (dtper.Rows.Count > 0)
{
CT_Tc cttc = null;// cellx.GetCTTc();
CT_TcPr ctPr = null;// cttc.AddNewTcPr();
XWPFParagraph grap = doc.CreateParagraph();
XWPFRun run = grap.CreateRun();
run.SetText("3. 优质蛋白质比例");
run.SetBold(true);
run.SetFontFamily("Courier");
grap.SetAlignment(ParagraphAlignment.LEFT);
XWPFTable table = doc.CreateTable();
//创建一行