public static bool CheckConstraints(object value, RuleColumn rc, ref string message) { if (value == null && !rc.IsNullable) { message = "“" + rc.Label + "”不能为空值!"; return(false); } if (rc != null && rc.HasConstraints) { string constraints = rc.Constraints.Trim(); message = rc.ErrorMessage.Trim(); if (constraints.ToUpper().StartsWith("REGEXP:")) { return(ExecRegexp(constraints.Substring(7, constraints.Length - 7), (string)value, ref message)); } else if (constraints.ToUpper().StartsWith("NEGREGEXP:")) { return(ExecNegRegexp(constraints.Substring(10, constraints.Length - 10), (string)value, ref message)); } else if (constraints.ToUpper().StartsWith("JAVASCRIPT:")) { string script = constraints.Substring(11, constraints.Length - 11); if (script != null && !script.Equals("")) { return(ExecScript("JavaScript", script, (string)value, ref message)); } } else if (constraints.ToUpper().IndexOf("</CHECK>") > 0) { string[] checks = StrUtil.GetSplitList(constraints, "</CHECK>"); if (checks != null && checks.Length > 0) { string scripttype, script; int index; foreach (string check in checks) { scripttype = ""; script = ""; index = check.ToUpper().IndexOf("<CHECK TYPE=\""); if (index >= 0) { script = check.Substring(index + 13, check.Length - index - 13); index = script.ToUpper().IndexOf("\">"); if (index >= 0) { scripttype = script.Substring(0, index).Trim().ToUpper(); script = script.Substring(index + 2, script.Length - index - 2); } } if (script != null && !script.Equals("")) { if (scripttype.Equals("REGEXP")) { if (!ExecRegexp(script, (string)value, ref message)) { return(false); } } else if (scripttype.Equals("NEGREGEXP")) { if (!ExecNegRegexp(script, (string)value, ref message)) { return(false); } } else if (scripttype != null && !scripttype.Equals("")) { if (!ExecScript(scripttype, script, (string)value, ref message)) { return(false); } } } } } } else { return(ExecRegexp(constraints, (string)value, ref message)); } } return(true); }
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"); } }
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(); } }
public static string Encode(string data) { return(data != null?Convert.ToBase64String(StrUtil.ToByteArray(data)) : ""); }