private static byte[] GetStringBytes(WDBSheet sheet, out Dictionary <string, int> strOffsetDic) { strOffsetDic = new Dictionary <string, int>(); strOffsetDic.Add("", 0); MemoryStream stream = new MemoryStream(); ByteWriter.WriteString(stream, ""); for (int i = 0; i < sheet.LineCount; ++i) { WDBLine line = sheet.GetLineAtIndex(i); for (int j = 0; j < sheet.FieldCount; ++j) { WDBField field = sheet.GetFieldAtIndex(j); if (field.FieldType == WDBFieldType.String || field.FieldType == WDBFieldType.Address || field.FieldType == WDBFieldType.Lua) { WDBCell cell = line.GetCellByCol(field.Col); string cellValue = cell.GetValue(field); string content = cellValue ?? ""; if (field.FieldType == WDBFieldType.Lua) { content = GetLuaFuncContent(content); } if (strOffsetDic.ContainsKey(content)) { continue; } strOffsetDic.Add(content, (int)stream.Length); ByteWriter.WriteString(stream, content); } } } return(stream.ToArray()); }
protected override bool DoVerify() { if (sheet.Name != CurrentSheetName) { CurrentSheetName = null; } if (CurrentSheetName == null) { CurrentSheetName = sheet.Name; contentRepeatedDic.Clear(); } Dictionary <string, int> repeatedDic = null; if (!contentRepeatedDic.TryGetValue(field.Name, out repeatedDic)) { repeatedDic = new Dictionary <string, int>(); contentRepeatedDic[field.Name] = repeatedDic; for (int i = 0; i < sheet.LineCount; ++i) { WDBLine tLine = sheet.GetLineAtIndex(i); WDBCell tCell = tLine.GetCellByCol(field.Col); string tValue = tCell.GetValue(field) ?? string.Empty; if (repeatedDic.ContainsKey(tValue)) { repeatedDic[tValue]++; } else { repeatedDic[tValue] = 1; } } } string cellValue = cell.GetValue(field) ?? string.Empty; if (repeatedDic != null && repeatedDic.TryGetValue(cellValue, out var count) && count > 1) { errors.Add(GetErrorMsg(WDBVerifyConst.VALIDATION_CELL_UNIQUE_REPEAT_ERR, cellValue)); return(false); } return(true); }
private static byte[] GetLineBytes(WDBSheet sheet, Dictionary <string, int> strOffsetDic) { MemoryStream stream = new MemoryStream(); for (int i = 0; i < sheet.LineCount; ++i) { WDBLine line = sheet.GetLineAtIndex(i); for (int j = 0; j < sheet.FieldCount; ++j) { WDBField field = sheet.GetFieldAtIndex(j); WDBCell cell = line.GetCellByCol(field.Col); string cellValue = cell.GetValue(field); if (field.FieldType == WDBFieldType.String || field.FieldType == WDBFieldType.Address || field.FieldType == WDBFieldType.Lua) { string content = cellValue ?? ""; if (field.FieldType == WDBFieldType.Lua) { content = GetLuaFuncContent(content); } if (!strOffsetDic.TryGetValue(content, out var offset)) { throw new Exception(); } ByteWriter.WriteInt(stream, offset); } else if (field.FieldType == WDBFieldType.Bool) { if (string.IsNullOrEmpty(cellValue) || !bool.TryParse(cellValue, out var result)) { ByteWriter.WriteBool(stream, false); } else { ByteWriter.WriteBool(stream, result); } } else if (field.FieldType == WDBFieldType.Int || field.FieldType == WDBFieldType.Text) { if (string.IsNullOrEmpty(cellValue) || !int.TryParse(cellValue, out var result)) { ByteWriter.WriteInt(stream, 0); } else { ByteWriter.WriteInt(stream, result); } } else if (field.FieldType == WDBFieldType.Id || field.FieldType == WDBFieldType.Ref) { if (string.IsNullOrEmpty(cellValue) || !int.TryParse(cellValue, out var result)) { ByteWriter.WriteInt(stream, -1); } else { ByteWriter.WriteInt(stream, result); } } else if (field.FieldType == WDBFieldType.Long) { if (string.IsNullOrEmpty(cellValue) || !long.TryParse(cellValue, out var result)) { ByteWriter.WriteLong(stream, 0); } else { ByteWriter.WriteLong(stream, result); } } else if (field.FieldType == WDBFieldType.Float) { if (string.IsNullOrEmpty(cellValue) || !float.TryParse(cellValue, out var result)) { ByteWriter.WriteFloat(stream, 0); } else { ByteWriter.WriteFloat(stream, result); } } else { throw new Exception(); } } } return(stream.ToArray()); }