public void FromValueString(StringKeyList varList, String value) { Type c = ConstUtil.GetStringValueType(varList, value); StringValueInfo info = new StringValueInfo(); info.ValueType = c; info.ValueContext = ConstUtil.GetStringValueContext(varList, value); }
public static void FillArgumentHolder(StringKeyList varList, string[] values, ArgumentHolder a) { StringValueInfo info = new StringValueInfo(); for (int i = 0; i < values.Length; i++) { info.FromValueString(varList, values[i]); a.SetArgument(info.ValueType, info.ValueContext); } }
public Row GenerateRow(int rr, int mc, bool header, StringKeyList stringTable) { Row row = new Row() { RowIndex = (uint)rr }; for (int i = 0; i < mc; i++) { row.AppendChild(GetCell(null, i, rr, header ? (uint)7 : (uint)6, stringTable)); } return(row); }
public static ArgumentHolder CreateArgumentHolder(StringKeyList varList, string[] values) { ArgumentHolder a = new ArgumentHolder(); FillArgumentHolder(varList, values, a); return a; }
public static string[] GetPropertyNameTokens1(StringKeyList varList, string propertyName) { string actualName = propertyName; string key = null; string[] strValues = null; int keyStart = propertyName.IndexOf('['); // ���������// if (keyStart != -1 && propertyName.EndsWith("]")) { // �����������ƣ�����ͨ�������getter��setter����// actualName = propertyName.Substring(0, keyStart); // ȡ������ֵ// key = propertyName.Substring(keyStart + 1, propertyName.Length - 1); // ȡ�ò���ֵ// strValues = ConstUtil.SplitStringValues(key); } string canonicalName = actualName; if (key != null) canonicalName = canonicalName + "[" + key + "]"; int resLength = 2; if (strValues != null) resLength += strValues.Length; string[] strRes = new string[resLength]; strRes[0] = canonicalName; strRes[1] = actualName; if (strValues != null) { for (int i = 0; i < strValues.Length; i++) { strRes[i + 2] = ConstUtil.GetStringValueContext(varList, strValues[i]); } } return strRes; }
/** * ȡ���ַ�����ʾ�IJ����б����ֵ�����ݡ� * * @param values * @return */ public static string[] GetStringValueContexts(StringKeyList varList, string values) { string[] strings = SplitStringValues(values); return GetStringValueContexts(varList, strings); }
public static Object DoStaticMethod(Type classType, String methodName, StringKeyList varList) { return DoStaticMethod(classType, methodName, "", varList); }
public static Object DoObjectMethod(Object obj, String methodName, StringKeyList varList) { return DoObjectMethod(obj, methodName, "", varList); }
public static Object GetStringValueObject(StringKeyList varList, string value) { Type t = null; Object obj; string customValue = value.Trim(); // �ж��Ƿ�Ϊ��������ֵ// if (IsString(customValue)) { return GetContextAsString(customValue); } else if (IsChar(customValue)) { return GetContextAsChar(customValue); } else if (IsByte(customValue)) { return Byte.Parse(customValue); } else if (IsShort(customValue)) { return short.Parse(customValue); } else if (IsInt(customValue)) { return Int32.Parse(customValue); } else if (IsLong(customValue)) { return long.Parse(customValue); } else if (IsFloat(customValue)) { return Single.Parse(customValue); } else if (IsDouble(customValue)) { return Double.Parse(customValue); } else if (IsBoolean(customValue)) { return Boolean.Parse(customValue); } // ���Ǽ����͵�ֵ������Ϊ�Ƕ��������б�������// if (varList != null) { obj = varList.GetValue(customValue); if (obj != null) { t = obj.GetType(); } } return t; }
/** * ȡ���ַ�����ʾ�IJ����б����ֵ�����ݡ� * * @param values * @return */ public static string[] GetStringValueContexts(StringKeyList varList, string[] values) { string[] contexts = new string[values.Length]; for (int i = 0; i < values.Length; i++) { contexts[i] = GetStringValueContext(varList, values[i]); } return contexts; }
public void WriteMapItem(LayoutColumn map, int listIndex, object listItem, int sc, int sr, ref int mr, StringKeyList stringTable, List <Row> prows = null) { int tws = map.GetWithdSpan(); Row row = null; var rows = prows; if (prows == null) { rows = new List <Row>(); mr++; row = GenerateRow(mr, mc, listItem == null, stringTable); WriteCell(row.GetFirstChild <Cell>(), listItem == null ? (object)"#" : (object)(listIndex + 1), stringTable); rows.Add(row); sc = 1; } var nr = mr; foreach (var item in map) { if (item.Visible) { map.GetVisibleIndex(item, out int c, out int r); c += sc; r += sr; if (item.Count > 0) { WriteMapItem(item, listIndex, listItem, c, r, ref mr, stringTable, rows); } else { int rr = nr + r; if (rows.Count <= r) { mr++; row = GenerateRow(rr, mc, listItem == null, stringTable); rows.Add(row); } else { row = rows[r]; } object celldata = ((LayoutColumn)item).Text; if (listIndex == -2) { celldata = list.GetCollectedValue((LayoutColumn)item, group); } if (listItem != null) { object val = list.ReadValue(listItem, (ILayoutCell)item); celldata = list.FormatValue(listItem, val, (ILayoutCell)item); if (val is decimal && ((ILayoutCell)item).Format != "p") { celldata = val; } if (prows == null && c == 1 && listItem is Node) { var s = GroupHelper.Level((Node)listItem) * 4; celldata = celldata.ToString().PadLeft(celldata.ToString().Length + s, '-'); } } var cellc = (Cell)row.ChildElements.GetItem(c); WriteCell(cellc, celldata, stringTable); if (celldata is decimal) { cellc.StyleIndex = 3; } int ws = map.GetRowWidthSpan(item.Row); int hs = map.GetRowHeightSpan(item.Row, true); if (tws > ws && hs > 1) { mcells.Add(new MergeCell() { Reference = new CellRange(c, rr, c + tws - ws, rr + hs - 1).ToString() }); } else if (tws > ws) { mcells.Add(new MergeCell() { Reference = new CellRange(c, rr, c + tws - ws, rr).ToString() }); } else if (hs > 1) { mcells.Add(new MergeCell() { Reference = new CellRange(c, rr, c, rr + hs - 1).ToString() }); } } } } if (prows == null) { if (rows.Count > 1) { mcells.Add(new MergeCell() { Reference = new CellRange(0, nr, 0, nr + rows.Count - 1).ToString() }); } if (listItem is Node) { foreach (var item in rows) { item.OutlineLevel = (byte)(GroupHelper.Level((IGroup)listItem)); if (((IGroup)listItem).IsCompaund) { item.Collapsed = !((IGroup)listItem).Expand; } if (item.OutlineLevel > 0) { item.Hidden = !((IGroup)listItem).IsExpanded; } } } WriteRows(writer, rows); if (listItem is Node && map != null) { var i = 0; foreach (var item in ((Node)listItem).Nodes) { WriteMapItem(map, i++, item, 0, 0, ref mr, stringTable); } } } }
public virtual void Export(string fileName, LayoutList list) { this.list = list; using (SpreadsheetDocument xl = SpreadsheetDocument.Create(fileName, SpreadsheetDocumentType.Workbook)) { // Add a WorkbookPart to the document. WorkbookPart workbookpart = xl.AddWorkbookPart(); workbookpart.Workbook = new Workbook(); //add styles WorkbookStylesPart wbsp = workbookpart.AddNewPart <WorkbookStylesPart>(); wbsp.Stylesheet = CreateStylesheet(); wbsp.Stylesheet.Save(); // Add a WorksheetPart to the WorkbookPart. var worksheetPart = workbookpart.AddNewPart <WorksheetPart>(); // Add a SharedStringTablePart to the WorkbookPart. var stringPart = workbookpart.AddNewPart <SharedStringTablePart>(); var stringTable = new StringKeyList(); // Add Sheets to the Workbook. var sheets = xl.WorkbookPart.Workbook.AppendChild(new Sheets()); // Append a new worksheet and associate it with the workbook. var sheet = new Sheet() { Id = xl.WorkbookPart.GetIdOfPart(worksheetPart), SheetId = 1, Name = "DataSheet" }; sheets.Append(sheet); workbookpart.Workbook.Save(); mcells = new List <MergeCell>(); writer = OpenXmlWriter.Create(worksheetPart); writer.WriteStartElement(new Worksheet()); writer.WriteStartElement(new SheetProperties()); writer.WriteElement(new OutlineProperties() { SummaryBelow = false, SummaryRight = false }); writer.WriteEndElement(); mc = 0; writer.WriteStartElement(new Columns()); WriteMapColumns(list.ListInfo.Columns, 0, 0); writer.WriteEndElement(); writer.WriteStartElement(new SheetData()); int ind = 1; var row = new Row() { RowIndex = (uint)ind, Height = 25 }; row.AppendChild(GetCell(list.Description, 0, ind, (uint)13, stringTable)); WriteRows(writer, new List <Row>(new Row[] { row })); mcells.Add(new MergeCell() { Reference = new CellRange(0, 1, mc - 1, 1).ToString() }); WriteMapItem(list.ListInfo.Columns, -1, null, 0, 0, ref ind, stringTable); if (list.Selection.Count > 1) { var items = list.Selection.GetItems <object>(); for (var i = 0; i < items.Count; i++) { var item = items[i]; WriteMapItem(list.ListInfo.Columns, i, item, 0, 0, ref ind, stringTable); } } else if (list.NodeInfo != null) { var items = list.NodeInfo.Nodes.GetTopLevel().ToList(); for (var i = 0; i < items.Count; i++) { var item = items[i] as Node; WriteMapItem(list.ListInfo.Columns, i, item, 0, 0, ref ind, stringTable); } } else if (list.ListInfo.GroupVisible) { foreach (LayoutGroup g in list.Groups) { this.group = g; if (list.ListInfo.GroupHeader) { ind++; var header = new Row() { RowIndex = (uint)ind, CustomHeight = true, Height = 20 }; header.AppendChild(GetCell(g.TextValue, 0, ind, 8, stringTable)); mcells.Add(new MergeCell() { Reference = new CellRange(0, ind, mc - 1, ind).ToString() }); WriteRow(writer, header); } for (int i = g.IndexStart; i <= g.IndexEnd; i++) { WriteMapItem(list.ListInfo.Columns, i, list.ListSource[i], 0, 0, ref ind, stringTable); } if (list.ListInfo.CollectingRow) { WriteMapItem(list.ListInfo.Columns, -2, null, 0, 0, ref ind, stringTable); } //ind++; } } else { for (int i = 0; i < list.ListSource.Count; i++) { WriteMapItem(list.ListInfo.Columns, i, list.ListSource[i], 0, 0, ref ind, stringTable); } if (list.ListInfo.CollectingRow) { WriteMapItem(list.ListInfo.Columns, -2, null, 0, 0, ref ind, stringTable); } } writer.WriteEndElement(); if (mcells.Count > 0) { writer.WriteStartElement(new MergeCells()); foreach (var cell in mcells) { writer.WriteElement(cell); } writer.WriteEndElement(); } writer.WriteEndElement(); writer.Close(); } }
public void ExpMapLayout(SheetData sheetData, LayoutColumn map, int scol, int srow, out int mcol, out int mrow, LayoutList list, object listItem, StringKeyList stringTable) { int tws = map.GetWithdSpan(); //int ths = tool.LayoutMapTool.GetHeightSpan(map); mrow = srow; mcol = scol; Row temp = null; for (int i = 0; i < map.Count; i++) { var item = map[i]; if (!item.Visible) { continue; } map.GetVisibleIndex(item, out int c, out int r); c += scol; r += srow; if (item.Count > 0) { ExpMapLayout(sheetData, item, c, r, out c, out r, list, listItem, stringTable); } else { object celldata = ((LayoutColumn)item).Text; if (list != null) { object val = list.ReadValue(listItem, (ILayoutCell)item); celldata = list.FormatValue(listItem, val, (ILayoutCell)item); if (val is decimal && decimal.TryParse(celldata.ToString(), out decimal dval)) { celldata = val; } } Cell cell = GetCell(celldata, c, r, celldata is decimal ? 3U : 6U, stringTable); if (list == null) { cell.StyleIndex = 7; GetColumn(sheetData, c + 1, item.Width); } if (temp == null || temp.RowIndex != r) { temp = GetRow(sheetData, r, mrow >= r); } temp.Append(cell); int ws = map.GetRowWidthSpan(item.Row); if (tws > ws) { MergeCell mcell = new MergeCell() { Reference = new CellRange(c, r, c + tws - ws, r).ToString() }; GetMergeCells(sheetData.Parent).Append(mcell); } int hs = map.GetRowHeightSpan(item.Row, true); if (hs > 1) { MergeCell mcell = new MergeCell() { Reference = new CellRange(c, r, c, r + hs - 1).ToString() }; GetMergeCells(sheetData.Parent).Append(mcell); } } if (r > mrow) { mrow = r; } if (c > mcol) { mcol = c; } } }
public override void Export(string filename, LayoutList list) { using (SpreadsheetDocument xl = SpreadsheetDocument.Create(filename, SpreadsheetDocumentType.Workbook)) { // Add a WorkbookPart to the document. WorkbookPart workbookpart = xl.AddWorkbookPart(); workbookpart.Workbook = new Workbook(); //add styles WorkbookStylesPart wbsp = workbookpart.AddNewPart <WorkbookStylesPart>(); wbsp.Stylesheet = CreateStylesheet(); wbsp.Stylesheet.Save(); // Add a SharedStringTablePart to the WorkbookPart. var stringPart = workbookpart.AddNewPart <SharedStringTablePart>(); var stringTable = new StringKeyList(); // Add a WorksheetPart to the WorkbookPart. WorksheetPart worksheetPart = workbookpart.AddNewPart <WorksheetPart>(); SheetData sd = new SheetData(); Worksheet worksheet = new Worksheet(sd); worksheetPart.Worksheet = worksheet; // Add Sheets to the Workbook. Sheets sheets = xl.WorkbookPart.Workbook.AppendChild <Sheets>(new Sheets()); // Append a new worksheet and associate it with the workbook. Sheet sheet = new Sheet() { Id = xl.WorkbookPart.GetIdOfPart(worksheetPart), SheetId = 1, Name = "DataSheet" }; sheets.Append(sheet); workbookpart.Workbook.Save(); //List<ILayoutItem> cols = LayoutMapTool.GetVisibleItems(list.ListInfo.Columns); //columns ExpMapLayout(sd, list.ListInfo.Columns, 0, 1, out int mc, out int ind, null, null, stringTable); //data if (list.ListInfo.GroupVisible) { foreach (LayoutGroup g in list.Groups) { ind++; Cell cell = GetCell(g.TextValue, 0, (int)ind, 8, stringTable); GetRow(sd, ind, false).Append(cell); MergeCells mcells = GetMergeCells(worksheet); MergeCell mcell = new MergeCell() { Reference = new StringValue(cell.CellReference + ":" + Helper.IntToChar(mc) + (ind).ToString()) }; mcells.Append(mcell); for (int i = g.IndexStart; i <= g.IndexEnd; i++) { ind++; ExpMapLayout(sd, list.ListInfo.Columns, 0, ind, out mc, out ind, list, list.ListSource[i], stringTable); } } } else { foreach (object o in list.ListSource) { ind++; ExpMapLayout(sd, list.ListInfo.Columns, 0, ind, out mc, out ind, list, o, stringTable); } } worksheet.Save(); OpenXmlValidator validator = new OpenXmlValidator(); var errors = validator.Validate(xl); StringBuilder sb = new StringBuilder(); foreach (var error in errors) { sb.AppendLine(error.Description); sb.AppendLine(error.Path.XPath.ToString()); sb.AppendLine(); } if (sb.Length > 0) { //System.Windows.Forms.MessageDialog.ShowMessage(sb.ToString()); } xl.Close(); } }
public override long Parse(byte[] data, uint offset, uint ends) { string[] sMethod = null; string[] sLines = null; uint headerSize = 0; for (uint i = offset; i < ends - 3; i++) { if (data[i] == '\r' && data[i + 1] == '\n' && data[i + 2] == '\r' && data[i + 3] == '\n') { sLines = Encoding.ASCII.GetString(data, (int)offset, (int)(i - offset)).Split(new string[] { "\r\n" }, StringSplitOptions.None); headerSize = i + 4; break; } } if (headerSize == 0) { return(-1); } Cookies = new StringKeyList(); PostForms = new KeyList <string, object>(); Query = new StringKeyList(); Headers = new StringKeyList(); sMethod = sLines[0].Split(' '); Method = getMethod(sMethod[0].Trim()); if (sMethod.Length == 3) { sMethod[1] = WebUtility.UrlDecode(sMethod[1]); if (sMethod[1].Length >= 7) { if (sMethod[1].Substring(0, 7) == "http://") { sMethod[1] = sMethod[1].Substring(sMethod[1].IndexOf("/", 7)); } } URL = sMethod[1].Trim(); if (URL.IndexOf("?", 0) != -1) { Filename = URL.Split(new char[] { '?' }, 2)[0]; } else { Filename = URL; } if (Filename.IndexOf("%", 0) != -1) { Filename = WebUtility.UrlDecode(Filename); } Version = sMethod[2].Trim(); } // Read all headers for (int i = 1; i < sLines.Length; i++) { if (sLines[i] == String.Empty) { // Invalid header return(0); } if (sLines[i].IndexOf(':') == -1) { // Invalid header return(0); } string[] header = sLines[i].Split(new char[] { ':' }, 2); header[0] = header[0].ToLower(); Headers[header[0]] = header[1].Trim(); if (header[0] == "cookie") { string[] cookies = header[1].Split(';'); foreach (string cookie in cookies) { if (cookie.IndexOf('=') != -1) { string[] splitCookie = cookie.Split('='); splitCookie[0] = splitCookie[0].Trim(); splitCookie[1] = splitCookie[1].Trim(); if (!(Cookies.ContainsKey(splitCookie[0].Trim()))) { Cookies.Add(splitCookie[0], splitCookie[1]); } } else { if (!(Cookies.ContainsKey(cookie.Trim()))) { Cookies.Add(cookie.Trim(), String.Empty); } } } } } // Query String if (URL.IndexOf("?", 0) != -1) { string[] SQ = URL.Split(new char[] { '?' }, 2)[1].Split('&'); foreach (string S in SQ) { if (S.IndexOf("=", 0) != -1) { string[] qp = S.Split(new char[] { '=' }, 2); if (!Query.ContainsKey(WebUtility.UrlDecode(qp[0]))) { Query.Add(WebUtility.UrlDecode(qp[0]), WebUtility.UrlDecode(qp[1])); } } else { if (!(Query.ContainsKey(WebUtility.UrlDecode(S)))) { Query.Add(WebUtility.UrlDecode(S), null); } } } } // Post Content-Length if (Method == HTTPMethod.POST) { try { uint postSize = uint.Parse((string)Headers["content-length"]); // check limit if (postSize > data.Length - headerSize) { return(postSize - (data.Length - headerSize)); } if (Headers["content-type"].StartsWith("application/x-www-form-urlencoded") || Headers["content-type"] == "" || Headers["content-type"] == null) { string[] PostVars = null; PostVars = Encoding.UTF8.GetString(data, (int)headerSize, (int)postSize).Split('&'); for (int J = 0; J < PostVars.Length; J++) { if (PostVars[J].IndexOf("=") != -1) { string key = WebUtility.HtmlDecode( WebUtility.UrlDecode(PostVars[J].Split(new char[] { '=' }, 2)[0])); if (PostForms.Contains(key)) { PostForms[key] = WebUtility.HtmlDecode( WebUtility.UrlDecode(PostVars[J].Split(new char[] { '=' }, 2)[1])); } else { PostForms.Add(key, WebUtility.HtmlDecode( WebUtility.UrlDecode(PostVars[J].Split(new char[] { '=' }, 2)[1]))); } } else if (PostForms.Contains("unknown")) { PostForms["unknown"] = PostForms["unknown"] + "&" + WebUtility.HtmlDecode(WebUtility.UrlDecode(PostVars[J])); } else { PostForms.Add("unknown", WebUtility.HtmlDecode(WebUtility.UrlDecode(PostVars[J]))); } } } else if (Headers["content-type"].StartsWith("multipart/form-data")) { int st = 1; int ed = 0; string strBoundry = "--" + Headers["content-type"].Substring( Headers["content-type"].IndexOf("boundary=", 0) + 9); string[] sc = Encoding.UTF8.GetString(data, (int)headerSize, (int)postSize).Split( new string[] { strBoundry }, StringSplitOptions.None); for (int j = 1; j < sc.Length - 1; j++) { string[] ps = sc[j].Split(new string[] { "\r\n\r\n" }, 2, StringSplitOptions.None); ps[1] = ps[1].Substring(0, ps[1].Length - 2); // remove the empty line st = ps[0].IndexOf("name=", 0) + 6; ed = ps[0].IndexOf("\"", st); PostForms.Add(ps[0].Substring(st, ed - st), ps[1]); } } else { //PostForms.Add(Headers["content-type"], Encoding.Default.GetString( )); Message = DC.Clip(data, headerSize, postSize); } return(headerSize + postSize); } catch { return(0); } } return(headerSize); }
/** * ȡ���ַ�����ʾ�����ݵ����͡� * * @param value * @return */ public static Type GetStringValueType(StringKeyList varList, string value) { Type t = null; Object obj; string customValue = value.Trim(); // �ж��Ƿ�Ϊ��������ֵ// if (IsString(customValue)) { t = typeof(string); } else if (IsChar(customValue)) { t = typeof(Char); } else if (IsByte(customValue)) { t = typeof(Byte); } else if (IsShort(customValue)) { t = typeof(Int16); } else if (IsInt(customValue)) { t = typeof(Int32); } else if (IsLong(customValue)) { t = typeof(Int64); } else if (IsFloat(customValue)) { t = typeof(Single); } else if (IsDouble(customValue)) { t = typeof(Double); } else if (IsBoolean(customValue)) { t = typeof(Boolean); } // ���Ǽ����͵�ֵ������Ϊ�Ƕ��������б�������// if (varList != null) { obj = varList.GetValue(customValue); if (obj != null) { t = obj.GetType(); } } return t; }
/** * ִ�з���. * * @param obj * ����. * @param methodName * �������� * @param parameterValues * ����ֵ,��","�ֿ�. * @return * @ */ public static Object DoObjectMethod(Object obj, String methodName, String parameterValues, StringKeyList varList) { return DoMethod(obj.GetType(), obj, methodName, parameterValues, varList); }
public static Type[] GetStringValueTypees(StringKeyList varList, string values) { string[] a = SplitStringValues(values); Type[] b = new Type[a.Length]; for (int i = 0; i < a.Length; i++) { b[i] = GetStringValueType(varList, a[i]); } return b; }
public static Object DoStaticMethod(Type classType, String methodName, String parameterValues, StringKeyList varList) { return DoMethod(classType, null, methodName, parameterValues, varList); }
/** * ȡ���ַ�����ʾ����ֵ�����ݡ� * * @param value * @return */ public static string GetStringValueContext(StringKeyList varList, string value) { Type t = GetStringValueType(varList, value); return GetStringValueContext(value, t); }
/** * ִ�з���,��������Ϊ��̬�Ļ����. * * @param classType * @param obj * @param methodName * @param parameterValues * @return * @throws IllegalArgumentException * @throws IllegalAccessException * @throws InvocationTarGetException */ private static Object DoMethod(Type classType, Object obj, String methodName, String parameterValues, StringKeyList varList) { // ȡ�����ݵ��������// Type[] pts = ConstUtil.GetStringValueTypees(varList, parameterValues); // ģ��ȡ�÷������������Ϳ�����������͵ļ�������// MethodInfo m = GetMethod(classType, methodName, pts, true); // ִ�з���// return m.Invoke(obj, GetObjectValues(parameterValues, GetParameterTypes(m.GetParameters()))); }
public StringValueInfo(StringKeyList varList, String value) { FromValueString(varList, value); }