comExports.aspx.cs 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Collections.Specialized;
  5. using System.Data;
  6. using System.IO;
  7. using System.Reflection;
  8. using System.Text;
  9. using System.Web;
  10. using BizCom;
  11. using Newtonsoft.Json;
  12. using Newtonsoft.Json.Linq;
  13. using NPOI.SS.UserModel;
  14. using NPOI.XSSF.UserModel;
  15. using SiteCore;
  16. using SiteCore.Handler;
  17. using Utils;
  18. public partial class Reports_comExports : ReportBaseX
  19. {
  20. static int exp_page_size = 9999;
  21. protected void Page_Load(object sender, EventArgs e)
  22. {
  23. if (CurrentUser == null)
  24. {
  25. Response.Write("账户过期无法导出,请重新登录!");
  26. return;
  27. }
  28. CommonHelper.PageExpires();
  29. String type = Request["type"];
  30. try
  31. {
  32. switch (type)
  33. {
  34. case "bexcel":
  35. {
  36. string extName = Request["extname"];
  37. string exData = GetPostString("hExData");
  38. string exSdate = GetPostString("hExSdate");
  39. string exEdate = GetPostString("hExEdate");
  40. //数据来源
  41. List<Dictionary<string, object>> data = Utils.Serialization.JSON.ToDictionaryList(exData);
  42. String json = Request["columns"];
  43. List<Dictionary<string, object>> columns = Utils.Serialization.JSON.ToDictionaryList(json);
  44. ExportExcel(exSdate, exEdate, extName, columns, data);
  45. break;
  46. }
  47. case "excel2":
  48. {
  49. //string extName = Request["extname"];
  50. //string exSdate = GetPostString("hExSdate");
  51. //string exEdate = GetPostString("hExEdate");
  52. ////数据来源
  53. //List<Dictionary<string, object>> data = SearchData();
  54. //String json = Request["columns"];
  55. //List<Dictionary<string, object>> columns = Utils.Serialization.JSON.ToDictionaryList(json);
  56. //ExportNopi(exSdate, exEdate, extName,ref columns, ref data);
  57. //ExportExcel(exSdate, exEdate, extName, columns, data);
  58. break;
  59. }
  60. case "excel":
  61. {
  62. string extName = Request["extname"];
  63. string exSdate = GetPostString("hExSdate");
  64. string exEdate = GetPostString("hExEdate");
  65. //数据来源
  66. DataTable data = GetDtData();// SearchData();
  67. int c = data.Rows.Count;
  68. String json = Request["columns"];
  69. List<Dictionary<string, object>> columns = Utils.Serialization.JSON.ToDictionaryList(json);
  70. ExportNopiXLSX(exSdate, exEdate, extName, ref columns, data);
  71. if (data != null)
  72. {
  73. data.Clear();
  74. data.Dispose();
  75. }
  76. if (c > 1000) GC.Collect();
  77. //ExportExcel(exSdate, exEdate, extName, columns, data);
  78. break;
  79. }
  80. default:
  81. break;
  82. }
  83. }
  84. catch (Exception ex)
  85. {
  86. //Response.Write("无法导出" + ex.Message);
  87. //Response.End();
  88. }
  89. }
  90. private void enableQueryStringWriting()
  91. {
  92. var qs = Request.QueryString;
  93. var queryString = (NameValueCollection)Request.GetType().GetField("_queryString", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(Request);
  94. PropertyInfo readOnlyInfo = queryString.GetType().GetProperty("IsReadOnly", BindingFlags.NonPublic | BindingFlags.Instance);
  95. readOnlyInfo.SetValue(queryString, false, null);
  96. }
  97. public void setQueryString(string parms)
  98. {
  99. //Request.QueryString.Add(;
  100. enableQueryStringWriting();
  101. NameValueCollection nvc = new NameValueCollection();
  102. parms = parms.TrimStart('&');
  103. string[] pArr = parms.Split('&');
  104. string[] tArr;
  105. foreach (string p in pArr)
  106. {
  107. tArr = p.Split('=');
  108. //nvc.Add(tArr[0], tArr[1]);
  109. Request.QueryString.Set(tArr[0], tArr[1]);
  110. }
  111. }
  112. public DataTable GetDtData()
  113. {
  114. string url = GetPostString("url");
  115. url = HttpUtility.UrlDecode(url);
  116. int idx = url.IndexOf("t=");
  117. url = url.Substring(idx + 2);//.Replace("t=", "");
  118. string mname = "";
  119. if (url.IndexOf("&") != -1)
  120. {
  121. int ui = url.IndexOf("&");
  122. string parms = url.Substring(ui + 1);
  123. setQueryString(parms);
  124. mname = url.Substring(0, ui).Trim();
  125. }
  126. else mname = url.Trim();
  127. sync sentity = new sync();
  128. Type t = sentity.GetType();
  129. MethodInfo mi = t.GetMethod(mname); //根据字符串名称获得对应的方法
  130. t.GetField("ex_psize").SetValue(sentity, 100000);
  131. mi.Invoke(sentity, null);
  132. //DataTable dt=(DataTable)t.GetField("ex_dtable").GetValue(sentity);
  133. return sentity.ex_dtable;
  134. //sentity.ex_psize = 2014091;// exp_page_size;
  135. //sentity.get_erp_orderlist();
  136. //return sentity.ex_dtable;
  137. }
  138. public void ExportNopiXLSX(string exSdate, string exEdate, string extName, ref List<Dictionary<string, object>> columns, DataTable data)
  139. {
  140. excelName = (extName == "" ? "导出报表" : extName);
  141. createExcel();
  142. iSheet = xssfworkbook.GetSheetAt(0);
  143. iSheet.DefaultRowHeight = 22 * 20;
  144. //iSheet.CreateRow(0);
  145. NPOI.SS.UserModel.IRow row = iSheet.CreateRow(0);
  146. int c = 0;
  147. row.Height = 22 * 20;
  148. //row.RowStyle = GetExHeadStyle();
  149. List<string> cols = new List<string>();
  150. //设置excel头
  151. foreach (Dictionary<string, object> dic in columns)
  152. {
  153. cols.Add(dic["field"].ToString());
  154. createHeaderCell(row, c, dic["header"].ToString());
  155. //iSheet.AutoSizeColumn(c);
  156. iSheet.SetColumnWidth(c, Convert.ToInt32(dic["width"].ToString().Replace("px", "")) * 65);
  157. //row.CreateCell(c).SetCellValue(dic["header"].ToString());
  158. c++;
  159. }
  160. int r = 1;
  161. int bc = 0;
  162. int rc = data.Rows.Count;
  163. bool isHaveCtid = false;
  164. if (data.Columns.IndexOf("ctid") != -1)
  165. {
  166. isHaveCtid = true;
  167. }
  168. //insertSimpleRow(iSheet, r, rc, iSheet.GetRow(1));
  169. IRow iRow = null;
  170. string v;
  171. float maxH = 0;
  172. int clen = 0;
  173. float h = 0;
  174. try
  175. {
  176. foreach (DataRow da_dic in data.Rows)
  177. {
  178. bc = 0;
  179. iRow = iSheet.CreateRow(r);//iSheet.CreateRow(r); //
  180. maxH = 0;
  181. h = 0;
  182. foreach (string col in cols)
  183. {
  184. if (isHaveCtid)
  185. {
  186. if (col == "tid" && da_dic["ctid"].ToString().IndexOf("S_") != -1)
  187. {
  188. v = getFS(col, da_dic["ctid"]).ToString();
  189. }
  190. else
  191. v = getFS(col, da_dic[col]).ToString();
  192. }
  193. else
  194. v = getFS(col, da_dic[col]).ToString();
  195. createItemCell(iRow, bc, v);
  196. clen = Encoding.UTF8.GetBytes(v).Length;
  197. if (clen > 0)
  198. {
  199. h = 20 * (clen / 60 + 1);
  200. if (maxH < h)
  201. {
  202. maxH = h;
  203. }
  204. }
  205. //setStringCell(r, bc, );
  206. bc++;
  207. }
  208. iRow.HeightInPoints = maxH;
  209. r++;
  210. }
  211. }
  212. catch (Exception ex)
  213. {
  214. XLog.SaveLog(0, ex.Message);
  215. }
  216. DownLoadFile_Ex();
  217. }
  218. public void DownLoadFile_Ex()
  219. {
  220. try
  221. {
  222. using (NpoiMemoryStream ms = new NpoiMemoryStream())
  223. {
  224. ms.AllowClose = false;
  225. xssfworkbook.Write(ms);
  226. ms.Flush();
  227. ms.Seek(0, SeekOrigin.Begin);
  228. ms.AllowClose = true;
  229. //xssfworkbook.Write(ms);
  230. Response.Clear();
  231. Response.Buffer = true;
  232. Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1);
  233. Response.Expires = 0;
  234. Response.AddHeader("pragma", "no-cache");
  235. Response.AddHeader("cache-control", "private");
  236. Response.CacheControl = "no-cache";
  237. //Response.Charset = "GB2312";
  238. Response.Charset = "UTF-8";
  239. //Response.AppendHeader("Content-Disposition", "attachment;filename=" + excelName + ".xls");
  240. Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(excelName + ".xlsx", System.Text.Encoding.UTF8));
  241. Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
  242. //Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
  243. Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
  244. ms.WriteTo(Response.OutputStream);
  245. //Response.Flush();
  246. }
  247. }
  248. catch (Exception ex)
  249. {
  250. }
  251. finally
  252. {
  253. if (xssfworkbook != null)
  254. {
  255. xssfworkbook.Close();
  256. xssfworkbook.Dispose();
  257. xssfworkbook = null;
  258. iSheet = null;
  259. }
  260. }
  261. //Response.End();
  262. //Response.Write(ExportTable(data, columns));
  263. }
  264. public List<Dictionary<string, object>> SearchData()
  265. {
  266. //查询条件
  267. /*string key = Request["key"];
  268. //字段排序
  269. String sortField = Request["sortField"];
  270. String sortOrder = Request["sortOrder"];
  271. */
  272. string url = Request["url"];
  273. url = HttpUtility.UrlDecode(url);
  274. List<string> parms = new List<string>();
  275. foreach (string key in Request.Form)
  276. {
  277. if (key == "url") continue;
  278. if (key == "columns") continue;
  279. if (key == "pageSize") continue;
  280. parms.Add(key + "=" + Request.Form[key]);
  281. }
  282. string fstr = string.Join("&", parms.ToArray());//.ToString();
  283. fstr = HttpUtility.UrlDecode(fstr);
  284. List<Dictionary<string, object>> lists = getComReportData(getUrl(url), fstr);
  285. //Newtonsoft.Json.JsonConvert.DeserializeObject<Hashtable>()
  286. //Hashtable result =
  287. return lists;// result["data"] as ArrayList;
  288. }
  289. public List<Dictionary<string, object>> getComReportData(string url, string parms)
  290. {
  291. HttpCookie lcCookie = HttpContext.Current.Request.Cookies[webConfig.CookieName];
  292. string name = HttpUtility.UrlDecode(lcCookie.Values["User"]);
  293. string ticket = lcCookie.Values["Ticket"];
  294. if (parms == "") parms = "pageSize=" + exp_page_size;
  295. else parms += "&pageSize=" + exp_page_size;
  296. parms += "&_expt=1";
  297. //parms = HttpUtility.UrlEncode(parms);
  298. HttpHelper http = new HttpHelper();
  299. HttpItem item = new HttpItem()
  300. {
  301. URL = url,
  302. Method = "POST",
  303. ContentType = "application/x-www-form-urlencoded; charset=UTF-8",
  304. Cookie = webConfig.CookieName + "=user=" + name + "&ticket=" + ticket,
  305. Postdata = parms
  306. };
  307. item.PostEncoding = Encoding.UTF8;
  308. HttpResult hresult = http.GetHtml(item);
  309. string html = hresult.Html;
  310. JObject jobj = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(html);
  311. if (jobj["total"] != null)
  312. {
  313. List<Dictionary<string, object>> lists_sec;
  314. List<Dictionary<string, object>> lists = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(jobj["data"].ToString());
  315. int pg = (Convert.ToInt32(jobj["total"]) - 1) / exp_page_size + 1; // exp_page_size;
  316. if (pg > 1)
  317. {
  318. for (int i = 2; i <= pg; i++)
  319. {
  320. if (i == 2) parms = parms.Replace("pageIndex=0", "pageIndex=1");
  321. else parms = parms.Replace("pageIndex=" + (i - 3), "pageIndex=" + (i - 1));
  322. item = new HttpItem()
  323. {
  324. URL = url,
  325. Method = "POST",
  326. ContentType = "application/x-www-form-urlencoded; charset=UTF-8",
  327. Cookie = webConfig.CookieName + "=user=" + name + "&ticket=" + ticket,
  328. Postdata = parms
  329. };
  330. hresult = http.GetHtml(item);
  331. html = hresult.Html;
  332. jobj = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(html);
  333. html = string.Empty;
  334. if (jobj["total"] != null)
  335. {
  336. lists_sec = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(jobj["data"].ToString());
  337. lists.AddRange(lists_sec);
  338. //lists_sec.Clear();
  339. }
  340. jobj = null;
  341. }
  342. }
  343. return lists;
  344. //Hashtable htable= JsonConvert.DeserializeObject<Hashtable>(jobj["data"].ToString());
  345. }
  346. return null;
  347. }
  348. public void ExportExcel(string exSdate, string exEdate, string extName, List<Dictionary<string, object>> columns, List<Dictionary<string, object>> data)
  349. {
  350. Response.Clear();
  351. Response.Buffer = true;
  352. Response.Charset = "GB2312";
  353. //Response.Charset = "UTF-8";
  354. Response.AppendHeader("Content-Disposition", "attachment;filename=" + extName + ".xls");
  355. Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
  356. Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
  357. EnableViewState = false;
  358. string _exdata = "";
  359. try
  360. {
  361. _exdata = ExportTable(exSdate, exEdate, extName, data, columns);
  362. }
  363. catch (Exception ex)
  364. {
  365. string ex2 = ex.Message;
  366. }
  367. byte[] array = Encoding.Default.GetBytes(_exdata);
  368. int dataBufferSize = 5 * 1024 * 1024;
  369. byte[] buffer = null;
  370. long hasRead = 0;
  371. using (MemoryStream stream = new MemoryStream(array))
  372. {
  373. long contentLength = stream.Length;
  374. int currentRead = 0;
  375. while (hasRead < contentLength)
  376. {
  377. buffer = new byte[dataBufferSize];
  378. currentRead = stream.Read(buffer, 0, dataBufferSize);
  379. Response.OutputStream.Write(buffer, 0, currentRead);
  380. Response.Flush();
  381. hasRead += currentRead;
  382. }
  383. }
  384. array = null;
  385. Response.End();
  386. }
  387. #region table
  388. public static string ExportTable(string exSdate, string exEdate, string extName, List<Dictionary<string, object>> data, List<Dictionary<string, object>> columns)
  389. {
  390. ArrayList columnsBottom = getColumnsBottom(columns);
  391. ArrayList columnsTable = getColumnsTable(columns);
  392. StringBuilder sb = new StringBuilder();
  393. //data = ds.DataSetName + "\n";
  394. //dg.Cells[10].Attributes.Add("style", "vnd.ms-excel.numberformat: @;");
  395. //data += tb.TableName + "\n";
  396. sb.AppendLine("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">");
  397. sb.AppendLine("<table cellspacing=\"0\" cellpadding=\"5\" rules=\"all\" border=\"1\">");
  398. sb.AppendLine("<tr style=\"border-right:none;border-bottom:none\"><td style=\"height:30px;text-align:center;font-size:15.0pt;font-weight:700;border-right:none;border-bottom:none\" colspan=\"" + columnsBottom.Count + "\">" + extName + "</td></tr>");
  399. sb.AppendLine("<tr style=\"border-right:none;border-bottom:none\"><td style=\"height:25px;text-align:center;font-size:10.5pt;border-right:none;border-bottom:none\" colspan=\"" + columnsBottom.Count + "\">" + getTime(exSdate, exEdate) + "</td></tr>");
  400. //写出列名
  401. for (int i = 0; i < columnsTable.Count; i++)
  402. {
  403. ArrayList columnsRow = (ArrayList)columnsTable[i];
  404. sb.AppendLine("<tr style=\"font-weight: bold; white-space: nowrap;height:25px;\">");
  405. foreach (Dictionary<string, object> column in columnsRow)
  406. {
  407. if (!Convert.ToBoolean(column["visible"])) continue;
  408. if (column.ContainsKey("type"))
  409. sb.AppendLine("<td style=\"background-color:#ADD8E6\" > 序号</td>");
  410. if (column.ContainsKey("header"))
  411. sb.AppendLine("<td style=\"background-color:#ADD8E6\" " + (column.ContainsKey("colspan") ? "colspan='" + column["colspan"] + "'" : "") + " " + (column.ContainsKey("rowspan") ? "rowspan='" + column["rowspan"] + "'" : "") + ">" + column["header"] + "</td>");
  412. }
  413. sb.AppendLine("</tr>");
  414. }
  415. //写出数据
  416. int count = 0;
  417. string fv = "";
  418. foreach (Dictionary<string, object> row in data)
  419. {
  420. sb.Append("<tr>");
  421. foreach (Dictionary<string, object> column in columnsBottom)
  422. {
  423. if (!Convert.ToBoolean(column["visible"])) continue;
  424. Object value = "";
  425. if (column.ContainsKey("type"))
  426. {
  427. if (Convert.ToString(column["type"]) == "indexcolumn") value = count + 1;
  428. }
  429. else
  430. {
  431. if (column.ContainsKey("field") && row.ContainsKey(column["field"].ToString()))
  432. {
  433. //renderer
  434. value = row[column["field"].ToString()];
  435. fv = value.ToString();
  436. if (fv.Length == 19 && fv.Substring(10, 1) == "T")
  437. {
  438. value = fv.Replace("T", " ");
  439. }
  440. }
  441. else
  442. {
  443. value = "";
  444. }
  445. }
  446. if (column.ContainsKey("field"))
  447. {
  448. if (column["field"].ToString() == "OrderState")
  449. {
  450. value = getOrderStateStr(Convert.ToInt32(value));
  451. }
  452. else if (column["field"].ToString() == "cashstate")
  453. {
  454. value = getOrderCashStateStr(Convert.ToInt32(value));
  455. }
  456. }
  457. sb.AppendLine("<td style=\"height:25px;vnd.ms-excel.numberformat: @;\" >" + value + "</td>");//;vnd.ms-excel.numberformat: @;
  458. }
  459. sb.AppendLine("</tr>");
  460. count++;
  461. }
  462. sb.AppendLine("</table>");
  463. return sb.ToString();
  464. }
  465. public static ArrayList getColumnsBottom(List<Dictionary<string, object>> columns)
  466. {
  467. ArrayList columnsBottom = new ArrayList();
  468. for (int i = 0; i < columns.Count; i++)
  469. {
  470. Dictionary<string, object> column = (Dictionary<string, object>)columns[i];
  471. if (column.ContainsKey("columns"))// != null
  472. {
  473. List<object> childColumns = (List<object>)column["columns"];
  474. columnsBottom.AddRange(getColumnsBottomArray(childColumns));
  475. }
  476. else
  477. {
  478. columnsBottom.Add(column);
  479. }
  480. }
  481. return columnsBottom;
  482. }
  483. public static ArrayList getColumnsBottomArray(List<object> columns)
  484. {
  485. ArrayList columnsBottom = new ArrayList();
  486. for (int i = 0; i < columns.Count; i++)
  487. {
  488. Dictionary<string, object> column = (Dictionary<string, object>)columns[i];
  489. if (column.ContainsKey("columns"))// != null
  490. {
  491. List<object> childColumns = (List<object>)column["columns"];
  492. columnsBottom.AddRange(getColumnsBottomArray(childColumns));
  493. }
  494. else
  495. {
  496. columnsBottom.Add(column);
  497. }
  498. }
  499. return columnsBottom;
  500. }
  501. public static ArrayList getColumnsTable(List<Dictionary<string, object>> columns)
  502. {
  503. ArrayList table = new ArrayList();
  504. getColumnsRows(columns, 0, table);
  505. createTableSpan(table);
  506. return table;
  507. }
  508. public static void getColumnsRows(List<Dictionary<string, object>> columns, int level, ArrayList table)
  509. {
  510. ArrayList row = null;
  511. if (table.Count > level)
  512. {
  513. row = (ArrayList)table[level];
  514. }
  515. else
  516. {
  517. row = new ArrayList();
  518. table.Add(row);
  519. }
  520. for (int i = 0; i < columns.Count; i++)
  521. {
  522. Dictionary<string, object> column = (Dictionary<string, object>)columns[i];
  523. row.Add(column);
  524. if (column.ContainsKey("columns"))
  525. {
  526. List<object> childColumns = (List<object>)column["columns"];
  527. if (childColumns != null)
  528. {
  529. getColumnsRowsObject(childColumns, level + 1, table);
  530. }
  531. }
  532. }
  533. }
  534. public static void getColumnsRowsObject(List<object> columns, int level, ArrayList table)
  535. {
  536. ArrayList row = null;
  537. if (table.Count > level)
  538. {
  539. row = (ArrayList)table[level];
  540. }
  541. else
  542. {
  543. row = new ArrayList();
  544. table.Add(row);
  545. }
  546. for (int i = 0; i < columns.Count; i++)
  547. {
  548. Dictionary<string, object> column = (Dictionary<string, object>)columns[i];
  549. row.Add(column);
  550. if (column.ContainsKey("columns"))
  551. {
  552. List<object> childColumns = (List<object>)column["columns"];
  553. if (childColumns != null)
  554. {
  555. getColumnsRowsObject(childColumns, level + 1, table);
  556. }
  557. }
  558. }
  559. }
  560. public static void createTableSpan(ArrayList table)
  561. {
  562. for (int i = 0; i < table.Count; i++)
  563. {
  564. ArrayList row = (ArrayList)table[i]; //row
  565. for (int l = 0; l < row.Count; l++)
  566. {
  567. Dictionary<string, object> cell = (Dictionary<string, object>)row[l]; //column
  568. int colSpan = getColSpan(cell);
  569. cell["colspan"] = colSpan;
  570. if (colSpan > 1)
  571. {
  572. cell["rowspan"] = 1;
  573. }
  574. else
  575. {
  576. cell["rowspan"] = table.Count - i;
  577. }
  578. }
  579. }
  580. }
  581. public static int getColSpan(Dictionary<string, object> column)
  582. {
  583. int colSpan = 0;
  584. if (column.ContainsKey("columns"))
  585. {
  586. List<object> childColumns = (List<object>)column["columns"];
  587. if (childColumns != null)
  588. {
  589. for (int i = 0; i < childColumns.Count; i++)
  590. {
  591. Dictionary<string, object> child = (Dictionary<string, object>)childColumns[i];
  592. colSpan += getColSpan(child);
  593. }
  594. }
  595. }
  596. else
  597. {
  598. colSpan = 1;
  599. }
  600. return colSpan;
  601. }
  602. #endregion
  603. #region npoi
  604. public void createHeaderCell(IRow row, int cIdx, object v)
  605. {
  606. ICell cell = row.CreateCell(cIdx);
  607. cell.CellStyle = GetExHeadStyle();
  608. cell.SetCellValue(v.ToString());
  609. }
  610. ICellStyle ex_headStyle = null;
  611. private ICellStyle GetExHeadStyle()
  612. {
  613. if (ex_headStyle == null)
  614. {
  615. ex_headStyle = xssfworkbook.CreateCellStyle();
  616. IFont font = xssfworkbook.CreateFont();
  617. font.FontName = "微软雅黑";
  618. font.FontHeightInPoints = 11;
  619. font.Boldweight = 700;
  620. ex_headStyle.SetFont(font);
  621. ex_headStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  622. ex_headStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  623. ex_headStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  624. ex_headStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  625. ex_headStyle.Alignment = HorizontalAlignment.Center;
  626. ex_headStyle.VerticalAlignment = VerticalAlignment.Center;
  627. ex_headStyle.FillForegroundColor = IndexedColors.Aqua.Index;
  628. }
  629. return ex_headStyle;
  630. }
  631. public void createItemCell(IRow row, int cIdx, object v)
  632. {
  633. ICell cell = row.CreateCell(cIdx);
  634. cell.CellStyle = GetExItemStyle();
  635. cell.SetCellValue(v.ToString());
  636. }
  637. ICellStyle ex_itemStyle = null;
  638. private ICellStyle GetExItemStyle()
  639. {
  640. if (ex_itemStyle == null)
  641. {
  642. ex_itemStyle = xssfworkbook.CreateCellStyle();
  643. ex_itemStyle.Alignment = HorizontalAlignment.Center;
  644. ex_itemStyle.WrapText = true;
  645. ex_itemStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  646. ex_itemStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  647. ex_itemStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  648. ex_itemStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  649. ex_itemStyle.VerticalAlignment = VerticalAlignment.Center;
  650. ex_itemStyle.Alignment = HorizontalAlignment.Center;
  651. IFont font = xssfworkbook.CreateFont();
  652. font.FontName = "微软雅黑";
  653. font.FontHeightInPoints = 10;
  654. ex_itemStyle.SetFont(font);
  655. //ex_itemStyle.FillForegroundColor = IndexedColors.AQUA.Index;
  656. //ex_itemStyle.FillPattern = FillPatternType.SOLID_FOREGROUND;
  657. }
  658. return ex_itemStyle;
  659. }
  660. #endregion
  661. #region private
  662. private string getFS(string col, object v)
  663. {
  664. if (v.ToString() == "") return "";
  665. switch (col.ToLower())
  666. {
  667. case "orderstate":
  668. {
  669. return getOrderStateStr(Convert.ToInt32(v));
  670. }
  671. case "cashstate":
  672. {
  673. return getOrderCashStateStr(Convert.ToInt32(v));
  674. }
  675. case "status":
  676. {
  677. return getTbStatusByState(Convert.ToString(v));
  678. }
  679. case "aftersalestate":
  680. {
  681. return getAfterSaleByState(Convert.ToInt32(v));
  682. }
  683. case "isrefund":
  684. {
  685. return getRefundByState(Convert.ToInt32(v));
  686. }
  687. case "audit_type":
  688. {
  689. return getAuditTypeByState(Convert.ToInt32(v));
  690. }
  691. case "aftersalesupplierstate":
  692. {
  693. return getSupplierVerifyState(Convert.ToInt32(v));
  694. }
  695. case "isbad":
  696. {
  697. return Convert.ToInt32(v) == 0 ? "无" : "差评单";
  698. }
  699. case "iscomplain":
  700. {
  701. int complain = Convert.ToInt32(v);
  702. if (complain == 0)
  703. {
  704. return "无";
  705. }
  706. if (complain == 1)
  707. {
  708. return "投诉成立";
  709. }
  710. if (complain == 2)
  711. {
  712. return "投诉不成立";
  713. }
  714. return "无";
  715. }
  716. }
  717. return v.ToString();
  718. }
  719. private string getUrl(string url)
  720. {
  721. url = HttpUtility.UrlDecode(url);
  722. string host = Request.Url.Host;
  723. string port = Request.Url.Port.ToString();
  724. int idx = url.IndexOf("handler/", StringComparison.OrdinalIgnoreCase);
  725. if (idx != -1)
  726. {
  727. url = "http://" + host + ":" + port + "/" + url.Substring(idx);
  728. }
  729. else
  730. {
  731. url = "http://" + host + ":" + port + "/" + url;
  732. }
  733. return url;
  734. }
  735. private static string getTime(string s, string e)
  736. {
  737. if (s != "" && e != "") return "时间:" + s + " 至 " + e;
  738. else if (s != "") return "时间:" + s;
  739. else if (e != "") return "时间:" + e;
  740. return "";
  741. }
  742. private static string getTbStatusByState(string st)
  743. {
  744. string stateStr = "";
  745. if (st == "NOT_SHIPPED")
  746. {
  747. stateStr = "待发货";
  748. }
  749. else if (st == "PART_SHIPPED")
  750. {
  751. stateStr = "部分发货";
  752. }
  753. else if (st == "SHIPPED")
  754. {
  755. stateStr = "已发货";
  756. }
  757. else if (st == "COMPLETE")
  758. {
  759. stateStr = "已完成";
  760. }
  761. else if (st == "CLOSE")
  762. {
  763. stateStr = "已关闭";
  764. }
  765. else if (st == "REFUNDED")
  766. {
  767. stateStr = "退款成功";
  768. }
  769. else if (st == "PART_REFUNDED")
  770. {
  771. stateStr = "部分退款";
  772. }
  773. else if (st == "WAIT_BUYER_RETURN_GOODS")
  774. {
  775. stateStr = "等待买家退货";
  776. }
  777. else if (st == "REJECT_REFUNDED")
  778. {
  779. stateStr = "拒绝退货";
  780. }
  781. else if (st == "WAIT_SELLER_CONFIRM_GOODS")
  782. {
  783. stateStr = "等待卖家确认收货";
  784. }
  785. else if (st == "SELLER_REFUSE_BUYER")
  786. {
  787. stateStr = "卖家拒绝退款";
  788. }
  789. else if (st == "SUCCESS")
  790. {
  791. stateStr = "退款成功";
  792. }
  793. else if (st == "CLOSED")
  794. {
  795. stateStr = "退款关闭";
  796. }
  797. else if (st == "FAILED")
  798. {
  799. stateStr = "退款失败";
  800. }
  801. return stateStr;
  802. }
  803. private static string getOrderStateStr(int orderState)
  804. {
  805. var stateStr = "";
  806. if (orderState == 0)
  807. {
  808. stateStr = "待领单";
  809. }
  810. else if (orderState == 1)
  811. {
  812. stateStr = "待发布";
  813. }
  814. else if (orderState == 2)
  815. {
  816. stateStr = "待抢单";
  817. }
  818. else if (orderState == 3)
  819. {
  820. stateStr = "待设计";
  821. }
  822. else if (orderState == 4)
  823. {
  824. stateStr = "设计中";
  825. }
  826. else if (orderState == 5)
  827. {
  828. stateStr = "设计完成";
  829. }
  830. else if (orderState == 6)
  831. {
  832. stateStr = "下单完成";
  833. }
  834. else if (orderState == 7)
  835. {
  836. stateStr = "已发货";
  837. }
  838. else if (orderState == 8)
  839. {
  840. stateStr = "已完成";
  841. }
  842. else if (orderState == 9)
  843. {
  844. stateStr = "已关闭";
  845. }
  846. return stateStr;
  847. }
  848. private static string getOrderCashStateStr(int orderState)
  849. {
  850. var stateStr = "";
  851. if (orderState == 0)
  852. {
  853. stateStr = "待审核";
  854. }
  855. else if (orderState == 1)
  856. {
  857. stateStr = "已审核";
  858. }
  859. else if (orderState == 2)
  860. {
  861. stateStr = "已退回";
  862. }
  863. return stateStr;
  864. }
  865. public static string getAfterSaleByState(int orderState)
  866. {
  867. var stateStr = "";
  868. if (orderState == 1)
  869. {
  870. stateStr = "待处理";
  871. }
  872. else if (orderState == 2)
  873. {
  874. stateStr = "售后主管审核";
  875. }
  876. else if (orderState == 3)
  877. {
  878. stateStr = "责任主管审核";
  879. }
  880. else if (orderState == 4)
  881. {
  882. stateStr = "已完成";
  883. }
  884. return stateStr;
  885. }
  886. public static string getRefundByState(int orderState)
  887. {
  888. var stateStr = "";
  889. if (orderState == 1)
  890. {
  891. stateStr = "申请退款中";
  892. }
  893. else if (orderState == 2)
  894. {
  895. stateStr = "退款完成";
  896. }
  897. else if (orderState == 3)
  898. {
  899. stateStr = "部分退款";
  900. }
  901. else if (orderState == 4)
  902. {
  903. stateStr = "等待买家退货";
  904. }
  905. else if (orderState == 5)
  906. {
  907. stateStr = "买家拒绝退货";
  908. }
  909. else if (orderState == 6)
  910. {
  911. stateStr = "等待卖家确认收货";
  912. }
  913. return stateStr;
  914. }
  915. public static string getAuditTypeByState(int state)
  916. {
  917. var stateStr = "";
  918. if (state == 0)
  919. {
  920. stateStr = "审核中";
  921. }
  922. else if (state == 1)
  923. {
  924. stateStr = "审核通过";
  925. }
  926. else if (state == 2)
  927. {
  928. stateStr = "已退回";
  929. }
  930. return stateStr;
  931. }
  932. public static string getSupplierVerifyState(int state)
  933. {
  934. var stateStr = "";
  935. if (state == 0)
  936. {
  937. stateStr = "待审核";
  938. }
  939. else if (state == 1)
  940. {
  941. stateStr = "认可";
  942. }
  943. else if (state == 2)
  944. {
  945. stateStr = "不认可";
  946. }
  947. return stateStr;
  948. }
  949. #endregion
  950. }