private static void FillTableData(DataTable table, string body, int offset, int length) { string colFlag = "<F", curColFlag, curRow, curCol, curBody = body; DataRowCollection datarows = table.Rows; DataRow row = null; DataColumnCollection columns = table.Columns; DataColumn column; int sdpDataType = 0; int index, subindex; string[] rows = StrUtil.GetParamList(curBody, "<R>"); table.Clear(); if (offset < 0) { offset = 0; } if (length < 0) { length = rows.Length - offset; } int limit = offset + length >= rows.Length ? rows.Length : offset + length; for (int i = 0; i < length; i++) { if (offset + i >= limit) { break; } curRow = rows[offset + i]; if (curRow.Equals("")) { continue; } curRow = StrUtil.ReplaceStr(curRow, SignConstant.RowReplace, SignConstant.RowSign); row = table.NewRow(); for (int j = 0; j < columns.Count; j++) { curColFlag = colFlag + Convert.ToString(j) + ">"; index = curRow.IndexOf(curColFlag); if (index > 0) { curCol = curRow.Substring(0, index); subindex = curRow.Length - index - curColFlag.Length; curRow = curRow.Substring(index + curColFlag.Length, subindex); if (!curCol.Equals("")) { curCol = StrUtil.ReplaceStr(curCol, SignConstant.FieldReplace, SignConstant.FieldSign); column = columns[j]; sdpDataType = TableUtil.IntProperty(column, "SDPDataType"); if (sdpDataType == 0) { sdpDataType = DataTypes.ToDataType(column.DataType); } switch (sdpDataType) { case DataTypes.dtBLOB: row[j] = BCUtil.Decode(curCol); break; case DataTypes.dtCLOB: row[j] = StrUtil.FromByteArray(BCUtil.Decode(curCol)); break; case DataTypes.dtXMLType: row[j] = StrUtil.FromByteArray(BCUtil.Decode(curCol)); break; case DataTypes.dtBoolean: row[j] = curCol.Equals("1") ? true : false; break; //case DataTypes.dtDateTime: // row[j] = Convert.ToDateTime(curCol); // break; //case DataTypes.dtDate: // row[j] = Convert.ToDateTime(curCol); // break; //case DataTypes.dtTime: // row[j] = Convert.ToDateTime(curCol); // break; default: row[j] = curCol; break; } } } } datarows.Add(row); } if (length > 0) { table.AcceptChanges(); } }
private static void FillTableMetaData(DataTable table, string head) { string colFlag = "<F", curColFlag, curRow, curCol, curHead = head; DataColumn column = null; int index, subindex; string[] rows = StrUtil.GetParamList(head, "<R>"); bool hasPK = false; table.Columns.Clear(); int count = rows.Length; for (int i = 0; i < count; i++) { curRow = rows[i]; if (curRow.Equals("")) { continue; } column = null; for (int j = 0; j < 5; j++) { curColFlag = colFlag + Convert.ToString(j) + ">"; index = curRow.IndexOf(curColFlag); if (index > 0) { curCol = curRow.Substring(0, index); subindex = curRow.Length - index - curColFlag.Length; curRow = curRow.Substring(index + curColFlag.Length, subindex); if (!curCol.Equals("")) { switch (j) { case 0: column = new DataColumn(curCol); break; case 1: column.Caption = curCol; break; case 2: TableUtil.SetProperty(column, "SDPDataType", curCol); column.DataType = DataTypes.ToType(Convert.ToInt32(curCol)); break; case 3: if (column.DataType.ToString().Equals("System.String")) { column.MaxLength = Convert.ToInt32(curCol); } break; case 4: TableUtil.SetProperty(column, "PK", curCol); hasPK = true; break; } } } } if (column != null) { table.Columns.Add(column); } } if (hasPK) { TableUtil.SetProperty(table, "HasPK", hasPK ? "1" : "0"); } }