comExports.aspx.cs 33 KB

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