| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using System.Data;
- using System.IO;
- using System.Reflection;
- using System.Text;
- using System.Web;
- using BizCom;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using NPOI.SS.UserModel;
- using NPOI.XSSF.UserModel;
- using SiteCore;
- using SiteCore.Handler;
- using Utils;
- public partial class Reports_comExports : ReportBaseX
- {
- static int exp_page_size = 9999;
- protected void Page_Load(object sender, EventArgs e)
- {
- if (CurrentUser == null)
- {
- Response.Write("账户过期无法导出,请重新登录!");
- return;
- }
- CommonHelper.PageExpires();
- String type = Request["type"];
- try
- {
- switch (type)
- {
- case "bexcel":
- {
- string extName = Request["extname"];
- string exData = GetPostString("hExData");
- string exSdate = GetPostString("hExSdate");
- string exEdate = GetPostString("hExEdate");
- //数据来源
- List<Dictionary<string, object>> data = Utils.Serialization.JSON.ToDictionaryList(exData);
- String json = Request["columns"];
- List<Dictionary<string, object>> columns = Utils.Serialization.JSON.ToDictionaryList(json);
- ExportExcel(exSdate, exEdate, extName, columns, data);
- break;
- }
- case "excel2":
- {
- //string extName = Request["extname"];
- //string exSdate = GetPostString("hExSdate");
- //string exEdate = GetPostString("hExEdate");
- ////数据来源
- //List<Dictionary<string, object>> data = SearchData();
- //String json = Request["columns"];
- //List<Dictionary<string, object>> columns = Utils.Serialization.JSON.ToDictionaryList(json);
- //ExportNopi(exSdate, exEdate, extName,ref columns, ref data);
- //ExportExcel(exSdate, exEdate, extName, columns, data);
- break;
- }
- case "excel":
- {
- string extName = Request["extname"];
- string exSdate = GetPostString("hExSdate");
- string exEdate = GetPostString("hExEdate");
- //数据来源
- DataTable data = GetDtData();// SearchData();
- int c = data.Rows.Count;
- String json = Request["columns"];
- List<Dictionary<string, object>> columns = Utils.Serialization.JSON.ToDictionaryList(json);
- ExportNopiXLSX(exSdate, exEdate, extName, ref columns, data);
- if (data != null)
- {
- data.Clear();
- data.Dispose();
- }
- if (c > 1000) GC.Collect();
- //ExportExcel(exSdate, exEdate, extName, columns, data);
- break;
- }
- default:
- break;
- }
- }
- catch (Exception ex)
- {
- //Response.Write("无法导出" + ex.Message);
- //Response.End();
- }
- }
- private void enableQueryStringWriting()
- {
- var qs = Request.QueryString;
- var queryString = (NameValueCollection)Request.GetType().GetField("_queryString", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(Request);
- PropertyInfo readOnlyInfo = queryString.GetType().GetProperty("IsReadOnly", BindingFlags.NonPublic | BindingFlags.Instance);
- readOnlyInfo.SetValue(queryString, false, null);
- }
- public void setQueryString(string parms)
- {
- //Request.QueryString.Add(;
- enableQueryStringWriting();
- NameValueCollection nvc = new NameValueCollection();
- parms = parms.TrimStart('&');
- string[] pArr = parms.Split('&');
- string[] tArr;
- foreach (string p in pArr)
- {
- tArr = p.Split('=');
- //nvc.Add(tArr[0], tArr[1]);
- Request.QueryString.Set(tArr[0], tArr[1]);
- }
- }
- public DataTable GetDtData()
- {
- string url = GetPostString("url");
- url = HttpUtility.UrlDecode(url);
- int idx = url.IndexOf("t=");
- url = url.Substring(idx + 2);//.Replace("t=", "");
- string mname = "";
- if (url.IndexOf("&") != -1)
- {
- int ui = url.IndexOf("&");
- string parms = url.Substring(ui + 1);
- setQueryString(parms);
- mname = url.Substring(0, ui).Trim();
- }
- else mname = url.Trim();
- sync sentity = new sync();
- Type t = sentity.GetType();
- MethodInfo mi = t.GetMethod(mname); //根据字符串名称获得对应的方法
- t.GetField("ex_psize").SetValue(sentity, 100000);
- mi.Invoke(sentity, null);
- //DataTable dt=(DataTable)t.GetField("ex_dtable").GetValue(sentity);
- return sentity.ex_dtable;
- //sentity.ex_psize = 2014091;// exp_page_size;
- //sentity.get_erp_orderlist();
- //return sentity.ex_dtable;
- }
- public void ExportNopiXLSX(string exSdate, string exEdate, string extName, ref List<Dictionary<string, object>> columns, DataTable data)
- {
- excelName = (extName == "" ? "导出报表" : extName);
- createExcel();
- iSheet = xssfworkbook.GetSheetAt(0);
- iSheet.DefaultRowHeight = 22 * 20;
- //iSheet.CreateRow(0);
- NPOI.SS.UserModel.IRow row = iSheet.CreateRow(0);
- int c = 0;
- row.Height = 22 * 20;
- //row.RowStyle = GetExHeadStyle();
- List<string> cols = new List<string>();
- //设置excel头
- foreach (Dictionary<string, object> dic in columns)
- {
- cols.Add(dic["field"].ToString());
- createHeaderCell(row, c, dic["header"].ToString());
- //iSheet.AutoSizeColumn(c);
- iSheet.SetColumnWidth(c, Convert.ToInt32(dic["width"].ToString().Replace("px", "")) * 65);
- //row.CreateCell(c).SetCellValue(dic["header"].ToString());
- c++;
- }
- int r = 1;
- int bc = 0;
- int rc = data.Rows.Count;
- bool isHaveCtid = false;
- if (data.Columns.IndexOf("ctid") != -1)
- {
- isHaveCtid = true;
- }
- //insertSimpleRow(iSheet, r, rc, iSheet.GetRow(1));
- IRow iRow = null;
- string v;
- float maxH = 0;
- int clen = 0;
- float h = 0;
- try
- {
- foreach (DataRow da_dic in data.Rows)
- {
- bc = 0;
- iRow = iSheet.CreateRow(r);//iSheet.CreateRow(r); //
- maxH = 0;
- h = 0;
- foreach (string col in cols)
- {
- if (isHaveCtid)
- {
- if (col == "tid" && da_dic["ctid"].ToString().IndexOf("S_") != -1)
- {
- v = getFS(col, da_dic["ctid"]).ToString();
- }
- else
- v = getFS(col, da_dic[col]).ToString();
- }
- else
- v = getFS(col, da_dic[col]).ToString();
- createItemCell(iRow, bc, v);
- clen = Encoding.UTF8.GetBytes(v).Length;
- if (clen > 0)
- {
- h = 20 * (clen / 60 + 1);
- if (maxH < h)
- {
- maxH = h;
- }
- }
- //setStringCell(r, bc, );
- bc++;
- }
- iRow.HeightInPoints = maxH;
- r++;
- }
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, ex.Message);
- }
- DownLoadFile_Ex();
- }
- public void DownLoadFile_Ex()
- {
- try
- {
- using (NpoiMemoryStream ms = new NpoiMemoryStream())
- {
- ms.AllowClose = false;
- xssfworkbook.Write(ms);
- ms.Flush();
- ms.Seek(0, SeekOrigin.Begin);
- ms.AllowClose = true;
- //xssfworkbook.Write(ms);
- Response.Clear();
- Response.Buffer = true;
- Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1);
- Response.Expires = 0;
- Response.AddHeader("pragma", "no-cache");
- Response.AddHeader("cache-control", "private");
- Response.CacheControl = "no-cache";
- //Response.Charset = "GB2312";
- Response.Charset = "UTF-8";
- //Response.AppendHeader("Content-Disposition", "attachment;filename=" + excelName + ".xls");
- Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(excelName + ".xlsx", System.Text.Encoding.UTF8));
- Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
- //Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
- Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
- ms.WriteTo(Response.OutputStream);
- //Response.Flush();
- }
- }
- catch (Exception ex)
- {
- }
- finally
- {
- if (xssfworkbook != null)
- {
- xssfworkbook.Close();
- xssfworkbook.Dispose();
- xssfworkbook = null;
- iSheet = null;
- }
- }
- //Response.End();
- //Response.Write(ExportTable(data, columns));
- }
- public List<Dictionary<string, object>> SearchData()
- {
- //查询条件
- /*string key = Request["key"];
- //字段排序
- String sortField = Request["sortField"];
- String sortOrder = Request["sortOrder"];
- */
- string url = Request["url"];
- url = HttpUtility.UrlDecode(url);
- List<string> parms = new List<string>();
- foreach (string key in Request.Form)
- {
- if (key == "url") continue;
- if (key == "columns") continue;
- if (key == "pageSize") continue;
- parms.Add(key + "=" + Request.Form[key]);
- }
- string fstr = string.Join("&", parms.ToArray());//.ToString();
- fstr = HttpUtility.UrlDecode(fstr);
- List<Dictionary<string, object>> lists = getComReportData(getUrl(url), fstr);
- //Newtonsoft.Json.JsonConvert.DeserializeObject<Hashtable>()
- //Hashtable result =
- return lists;// result["data"] as ArrayList;
- }
- public List<Dictionary<string, object>> getComReportData(string url, string parms)
- {
- HttpCookie lcCookie = HttpContext.Current.Request.Cookies[webConfig.CookieName];
- string name = HttpUtility.UrlDecode(lcCookie.Values["User"]);
- string ticket = lcCookie.Values["Ticket"];
- if (parms == "") parms = "pageSize=" + exp_page_size;
- else parms += "&pageSize=" + exp_page_size;
- parms += "&_expt=1";
- //parms = HttpUtility.UrlEncode(parms);
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- URL = url,
- Method = "POST",
- ContentType = "application/x-www-form-urlencoded; charset=UTF-8",
- Cookie = webConfig.CookieName + "=user=" + name + "&ticket=" + ticket,
- Postdata = parms
- };
- item.PostEncoding = Encoding.UTF8;
- HttpResult hresult = http.GetHtml(item);
- string html = hresult.Html;
- JObject jobj = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(html);
- if (jobj["total"] != null)
- {
- List<Dictionary<string, object>> lists_sec;
- List<Dictionary<string, object>> lists = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(jobj["data"].ToString());
- int pg = (Convert.ToInt32(jobj["total"]) - 1) / exp_page_size + 1; // exp_page_size;
- if (pg > 1)
- {
- for (int i = 2; i <= pg; i++)
- {
- if (i == 2) parms = parms.Replace("pageIndex=0", "pageIndex=1");
- else parms = parms.Replace("pageIndex=" + (i - 3), "pageIndex=" + (i - 1));
- item = new HttpItem()
- {
- URL = url,
- Method = "POST",
- ContentType = "application/x-www-form-urlencoded; charset=UTF-8",
- Cookie = webConfig.CookieName + "=user=" + name + "&ticket=" + ticket,
- Postdata = parms
- };
- hresult = http.GetHtml(item);
- html = hresult.Html;
- jobj = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(html);
- html = string.Empty;
- if (jobj["total"] != null)
- {
- lists_sec = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(jobj["data"].ToString());
- lists.AddRange(lists_sec);
- //lists_sec.Clear();
- }
- jobj = null;
- }
- }
- return lists;
- //Hashtable htable= JsonConvert.DeserializeObject<Hashtable>(jobj["data"].ToString());
- }
- return null;
- }
- public void ExportExcel(string exSdate, string exEdate, string extName, List<Dictionary<string, object>> columns, List<Dictionary<string, object>> data)
- {
- Response.Clear();
- Response.Buffer = true;
- Response.Charset = "GB2312";
- //Response.Charset = "UTF-8";
- Response.AppendHeader("Content-Disposition", "attachment;filename=" + extName + ".xls");
- Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
- Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
- EnableViewState = false;
- string _exdata = "";
- try
- {
- _exdata = ExportTable(exSdate, exEdate, extName, data, columns);
- }
- catch (Exception ex)
- {
- string ex2 = ex.Message;
- }
- byte[] array = Encoding.Default.GetBytes(_exdata);
- int dataBufferSize = 5 * 1024 * 1024;
- byte[] buffer = null;
- long hasRead = 0;
- using (MemoryStream stream = new MemoryStream(array))
- {
- long contentLength = stream.Length;
- int currentRead = 0;
- while (hasRead < contentLength)
- {
- buffer = new byte[dataBufferSize];
- currentRead = stream.Read(buffer, 0, dataBufferSize);
- Response.OutputStream.Write(buffer, 0, currentRead);
- Response.Flush();
- hasRead += currentRead;
- }
- }
- array = null;
- Response.End();
- }
- #region table
- public static string ExportTable(string exSdate, string exEdate, string extName, List<Dictionary<string, object>> data, List<Dictionary<string, object>> columns)
- {
- ArrayList columnsBottom = getColumnsBottom(columns);
- ArrayList columnsTable = getColumnsTable(columns);
- StringBuilder sb = new StringBuilder();
- //data = ds.DataSetName + "\n";
- //dg.Cells[10].Attributes.Add("style", "vnd.ms-excel.numberformat: @;");
- //data += tb.TableName + "\n";
- sb.AppendLine("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">");
- sb.AppendLine("<table cellspacing=\"0\" cellpadding=\"5\" rules=\"all\" border=\"1\">");
- 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>");
- 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>");
- //写出列名
- for (int i = 0; i < columnsTable.Count; i++)
- {
- ArrayList columnsRow = (ArrayList)columnsTable[i];
- sb.AppendLine("<tr style=\"font-weight: bold; white-space: nowrap;height:25px;\">");
- foreach (Dictionary<string, object> column in columnsRow)
- {
- if (!Convert.ToBoolean(column["visible"])) continue;
- if (column.ContainsKey("type"))
- sb.AppendLine("<td style=\"background-color:#ADD8E6\" > 序号</td>");
- if (column.ContainsKey("header"))
- sb.AppendLine("<td style=\"background-color:#ADD8E6\" " + (column.ContainsKey("colspan") ? "colspan='" + column["colspan"] + "'" : "") + " " + (column.ContainsKey("rowspan") ? "rowspan='" + column["rowspan"] + "'" : "") + ">" + column["header"] + "</td>");
- }
- sb.AppendLine("</tr>");
- }
- //写出数据
- int count = 0;
- string fv = "";
- foreach (Dictionary<string, object> row in data)
- {
- sb.Append("<tr>");
- foreach (Dictionary<string, object> column in columnsBottom)
- {
- if (!Convert.ToBoolean(column["visible"])) continue;
- Object value = "";
- if (column.ContainsKey("type"))
- {
- if (Convert.ToString(column["type"]) == "indexcolumn") value = count + 1;
- }
- else
- {
- if (column.ContainsKey("field") && row.ContainsKey(column["field"].ToString()))
- {
- //renderer
- value = row[column["field"].ToString()];
- fv = value.ToString();
- if (fv.Length == 19 && fv.Substring(10, 1) == "T")
- {
- value = fv.Replace("T", " ");
- }
- }
- else
- {
- value = "";
- }
- }
- if (column.ContainsKey("field"))
- {
- if (column["field"].ToString() == "OrderState")
- {
- value = getOrderStateStr(Convert.ToInt32(value));
- }
- else if (column["field"].ToString() == "cashstate")
- {
- value = getOrderCashStateStr(Convert.ToInt32(value));
- }
- }
- sb.AppendLine("<td style=\"height:25px;vnd.ms-excel.numberformat: @;\" >" + value + "</td>");//;vnd.ms-excel.numberformat: @;
- }
- sb.AppendLine("</tr>");
- count++;
- }
- sb.AppendLine("</table>");
- return sb.ToString();
- }
- public static ArrayList getColumnsBottom(List<Dictionary<string, object>> columns)
- {
- ArrayList columnsBottom = new ArrayList();
- for (int i = 0; i < columns.Count; i++)
- {
- Dictionary<string, object> column = (Dictionary<string, object>)columns[i];
- if (column.ContainsKey("columns"))// != null
- {
- List<object> childColumns = (List<object>)column["columns"];
- columnsBottom.AddRange(getColumnsBottomArray(childColumns));
- }
- else
- {
- columnsBottom.Add(column);
- }
- }
- return columnsBottom;
- }
- public static ArrayList getColumnsBottomArray(List<object> columns)
- {
- ArrayList columnsBottom = new ArrayList();
- for (int i = 0; i < columns.Count; i++)
- {
- Dictionary<string, object> column = (Dictionary<string, object>)columns[i];
- if (column.ContainsKey("columns"))// != null
- {
- List<object> childColumns = (List<object>)column["columns"];
- columnsBottom.AddRange(getColumnsBottomArray(childColumns));
- }
- else
- {
- columnsBottom.Add(column);
- }
- }
- return columnsBottom;
- }
- public static ArrayList getColumnsTable(List<Dictionary<string, object>> columns)
- {
- ArrayList table = new ArrayList();
- getColumnsRows(columns, 0, table);
- createTableSpan(table);
- return table;
- }
- public static void getColumnsRows(List<Dictionary<string, object>> columns, int level, ArrayList table)
- {
- ArrayList row = null;
- if (table.Count > level)
- {
- row = (ArrayList)table[level];
- }
- else
- {
- row = new ArrayList();
- table.Add(row);
- }
- for (int i = 0; i < columns.Count; i++)
- {
- Dictionary<string, object> column = (Dictionary<string, object>)columns[i];
- row.Add(column);
- if (column.ContainsKey("columns"))
- {
- List<object> childColumns = (List<object>)column["columns"];
- if (childColumns != null)
- {
- getColumnsRowsObject(childColumns, level + 1, table);
- }
- }
- }
- }
- public static void getColumnsRowsObject(List<object> columns, int level, ArrayList table)
- {
- ArrayList row = null;
- if (table.Count > level)
- {
- row = (ArrayList)table[level];
- }
- else
- {
- row = new ArrayList();
- table.Add(row);
- }
- for (int i = 0; i < columns.Count; i++)
- {
- Dictionary<string, object> column = (Dictionary<string, object>)columns[i];
- row.Add(column);
- if (column.ContainsKey("columns"))
- {
- List<object> childColumns = (List<object>)column["columns"];
- if (childColumns != null)
- {
- getColumnsRowsObject(childColumns, level + 1, table);
- }
- }
- }
- }
- public static void createTableSpan(ArrayList table)
- {
- for (int i = 0; i < table.Count; i++)
- {
- ArrayList row = (ArrayList)table[i]; //row
- for (int l = 0; l < row.Count; l++)
- {
- Dictionary<string, object> cell = (Dictionary<string, object>)row[l]; //column
- int colSpan = getColSpan(cell);
- cell["colspan"] = colSpan;
- if (colSpan > 1)
- {
- cell["rowspan"] = 1;
- }
- else
- {
- cell["rowspan"] = table.Count - i;
- }
- }
- }
- }
- public static int getColSpan(Dictionary<string, object> column)
- {
- int colSpan = 0;
- if (column.ContainsKey("columns"))
- {
- List<object> childColumns = (List<object>)column["columns"];
- if (childColumns != null)
- {
- for (int i = 0; i < childColumns.Count; i++)
- {
- Dictionary<string, object> child = (Dictionary<string, object>)childColumns[i];
- colSpan += getColSpan(child);
- }
- }
- }
- else
- {
- colSpan = 1;
- }
- return colSpan;
- }
- #endregion
- #region npoi
- public void createHeaderCell(IRow row, int cIdx, object v)
- {
- ICell cell = row.CreateCell(cIdx);
- cell.CellStyle = GetExHeadStyle();
- cell.SetCellValue(v.ToString());
- }
- ICellStyle ex_headStyle = null;
- private ICellStyle GetExHeadStyle()
- {
- if (ex_headStyle == null)
- {
- ex_headStyle = xssfworkbook.CreateCellStyle();
- IFont font = xssfworkbook.CreateFont();
- font.FontName = "微软雅黑";
- font.FontHeightInPoints = 11;
- font.Boldweight = 700;
- ex_headStyle.SetFont(font);
- ex_headStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
- ex_headStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
- ex_headStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
- ex_headStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
- ex_headStyle.Alignment = HorizontalAlignment.Center;
- ex_headStyle.VerticalAlignment = VerticalAlignment.Center;
- ex_headStyle.FillForegroundColor = IndexedColors.Aqua.Index;
- }
- return ex_headStyle;
- }
- public void createItemCell(IRow row, int cIdx, object v)
- {
- ICell cell = row.CreateCell(cIdx);
- cell.CellStyle = GetExItemStyle();
- cell.SetCellValue(v.ToString());
- }
- ICellStyle ex_itemStyle = null;
- private ICellStyle GetExItemStyle()
- {
- if (ex_itemStyle == null)
- {
- ex_itemStyle = xssfworkbook.CreateCellStyle();
- ex_itemStyle.Alignment = HorizontalAlignment.Center;
- ex_itemStyle.WrapText = true;
- ex_itemStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
- ex_itemStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
- ex_itemStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
- ex_itemStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
- ex_itemStyle.VerticalAlignment = VerticalAlignment.Center;
- ex_itemStyle.Alignment = HorizontalAlignment.Center;
- IFont font = xssfworkbook.CreateFont();
- font.FontName = "微软雅黑";
- font.FontHeightInPoints = 10;
- ex_itemStyle.SetFont(font);
- //ex_itemStyle.FillForegroundColor = IndexedColors.AQUA.Index;
- //ex_itemStyle.FillPattern = FillPatternType.SOLID_FOREGROUND;
- }
- return ex_itemStyle;
- }
- #endregion
- #region private
- private string getFS(string col, object v)
- {
- if (v.ToString() == "") return "";
- switch (col.ToLower())
- {
- case "orderstate":
- {
- return getOrderStateStr(Convert.ToInt32(v));
- }
- case "cashstate":
- {
- return getOrderCashStateStr(Convert.ToInt32(v));
- }
- case "status":
- {
- return getTbStatusByState(Convert.ToString(v));
- }
- case "aftersalestate":
- {
- return getAfterSaleByState(Convert.ToInt32(v));
- }
- case "isrefund":
- {
- return getRefundByState(Convert.ToInt32(v));
- }
- case "audit_type":
- {
- return getAuditTypeByState(Convert.ToInt32(v));
- }
- case "aftersalesupplierstate":
- {
- return getSupplierVerifyState(Convert.ToInt32(v));
- }
- case "isbad":
- {
- return Convert.ToInt32(v) == 0 ? "无" : "差评单";
- }
- case "iscomplain":
- {
- int complain = Convert.ToInt32(v);
- if (complain == 0)
- {
- return "无";
- }
- if (complain == 1)
- {
- return "投诉成立";
- }
- if (complain == 2)
- {
- return "投诉不成立";
- }
- return "无";
- }
- }
- return v.ToString();
- }
- private string getUrl(string url)
- {
- url = HttpUtility.UrlDecode(url);
- string host = Request.Url.Host;
- string port = Request.Url.Port.ToString();
- int idx = url.IndexOf("handler/", StringComparison.OrdinalIgnoreCase);
- if (idx != -1)
- {
- url = "http://" + host + ":" + port + "/" + url.Substring(idx);
- }
- else
- {
- url = "http://" + host + ":" + port + "/" + url;
- }
- return url;
- }
- private static string getTime(string s, string e)
- {
- if (s != "" && e != "") return "时间:" + s + " 至 " + e;
- else if (s != "") return "时间:" + s;
- else if (e != "") return "时间:" + e;
- return "";
- }
- private static string getTbStatusByState(string st)
- {
- string stateStr = "";
- if (st == "NOT_SHIPPED")
- {
- stateStr = "待发货";
- }
- else if (st == "PART_SHIPPED")
- {
- stateStr = "部分发货";
- }
- else if (st == "SHIPPED")
- {
- stateStr = "已发货";
- }
- else if (st == "COMPLETE")
- {
- stateStr = "已完成";
- }
- else if (st == "CLOSE")
- {
- stateStr = "已关闭";
- }
- else if (st == "REFUNDED")
- {
- stateStr = "退款成功";
- }
- else if (st == "PART_REFUNDED")
- {
- stateStr = "部分退款";
- }
- else if (st == "WAIT_BUYER_RETURN_GOODS")
- {
- stateStr = "等待买家退货";
- }
- else if (st == "REJECT_REFUNDED")
- {
- stateStr = "拒绝退货";
- }
- else if (st == "WAIT_SELLER_CONFIRM_GOODS")
- {
- stateStr = "等待卖家确认收货";
- }
- else if (st == "SELLER_REFUSE_BUYER")
- {
- stateStr = "卖家拒绝退款";
- }
- else if (st == "SUCCESS")
- {
- stateStr = "退款成功";
- }
- else if (st == "CLOSED")
- {
- stateStr = "退款关闭";
- }
- else if (st == "FAILED")
- {
- stateStr = "退款失败";
- }
- return stateStr;
- }
- private static string getOrderStateStr(int orderState)
- {
- var stateStr = "";
- if (orderState == 0)
- {
- stateStr = "待领单";
- }
- else if (orderState == 1)
- {
- stateStr = "待发布";
- }
- else if (orderState == 2)
- {
- stateStr = "待抢单";
- }
- else if (orderState == 3)
- {
- stateStr = "待设计";
- }
- else if (orderState == 4)
- {
- stateStr = "设计中";
- }
- else if (orderState == 5)
- {
- stateStr = "设计完成";
- }
- else if (orderState == 6)
- {
- stateStr = "下单完成";
- }
- else if (orderState == 7)
- {
- stateStr = "已发货";
- }
- else if (orderState == 8)
- {
- stateStr = "已完成";
- }
- else if (orderState == 9)
- {
- stateStr = "已关闭";
- }
- return stateStr;
- }
- private static string getOrderCashStateStr(int orderState)
- {
- var stateStr = "";
- if (orderState == 0)
- {
- stateStr = "待审核";
- }
- else if (orderState == 1)
- {
- stateStr = "已审核";
- }
- else if (orderState == 2)
- {
- stateStr = "已退回";
- }
- return stateStr;
- }
- public static string getAfterSaleByState(int orderState)
- {
- var stateStr = "";
- if (orderState == 1)
- {
- stateStr = "待处理";
- }
- else if (orderState == 2)
- {
- stateStr = "售后主管审核";
- }
- else if (orderState == 3)
- {
- stateStr = "责任主管审核";
- }
- else if (orderState == 4)
- {
- stateStr = "已完成";
- }
- return stateStr;
- }
- public static string getRefundByState(int orderState)
- {
- var stateStr = "";
- if (orderState == 1)
- {
- stateStr = "申请退款中";
- }
- else if (orderState == 2)
- {
- stateStr = "退款完成";
- }
- else if (orderState == 3)
- {
- stateStr = "部分退款";
- }
- else if (orderState == 4)
- {
- stateStr = "等待买家退货";
- }
- else if (orderState == 5)
- {
- stateStr = "买家拒绝退货";
- }
- else if (orderState == 6)
- {
- stateStr = "等待卖家确认收货";
- }
- return stateStr;
- }
- public static string getAuditTypeByState(int state)
- {
- var stateStr = "";
- if (state == 0)
- {
- stateStr = "审核中";
- }
- else if (state == 1)
- {
- stateStr = "审核通过";
- }
- else if (state == 2)
- {
- stateStr = "已退回";
- }
- return stateStr;
- }
- public static string getSupplierVerifyState(int state)
- {
- var stateStr = "";
- if (state == 0)
- {
- stateStr = "待审核";
- }
- else if (state == 1)
- {
- stateStr = "认可";
- }
- else if (state == 2)
- {
- stateStr = "不认可";
- }
- return stateStr;
- }
- #endregion
- }
|