public static DataGridViewConsoleForm.Message CreateRepeatCellInRowMessage(DataGridViewConsoleForm.Level level, int rowIdx, int[][] repeats) { DataGridViewConsoleForm.Message message = new DataGridViewConsoleForm.Message(); message.Level = level; message.Row = rowIdx; message.Column = -1; message.Caption = GetVerifyMessage(VerifyType.RepeatCellInRow); StringBuilder textSb = new StringBuilder("重复的列"); for (int iRepeats = 0; iRepeats < repeats.Length; iRepeats++) { textSb.AppendLine(); int[] repeat = repeats[iRepeats]; for (int iRepeat = 0; iRepeat < repeat.Length; iRepeat++) { textSb.Append(ConvertUtility.NumberToLetter(repeat[iRepeat] + 1)); if (iRepeat < repeat.Length - 1) { textSb.Append(", "); } } } message.Text = textSb.ToString(); return(message); }
public static DataGridViewConsoleForm.Message CreateTabOrLineBreakMessage(DataGridViewConsoleForm.Level level, int rowIdx, int colIdx, string cellValue) { DataGridViewConsoleForm.Message message = new DataGridViewConsoleForm.Message(); message.Level = level; message.Row = rowIdx; message.Column = colIdx; message.Caption = GetVerifyMessage(VerifyType.TabOrLineBreak); message.Text = string.Format("({0})", cellValue); return(message); }
public bool SaveFile(string path) { SaveLayout(); List <DataGridViewConsoleForm.Message> messageList; DataGridViewConsoleForm.Level verifyLevel = VerifierUtility.VerifyWithVerifier(m_Layout.Verifier, m_DataGridView, out messageList); DataGridViewConsoleForm.ShowForm(messageList, m_DataGridView, "保存文件"); bool canSave = false; if (verifyLevel == DataGridViewConsoleForm.Level.Info) { canSave = true; } else if (verifyLevel == DataGridViewConsoleForm.Level.Warning) { if (MessageBox.Show("您现在有Warning,确定存储吗?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { canSave = true; } } if (canSave) { // 保存文件 CsvExport myExport = new CsvExport(",", false); try { for (int rowIdx = 0; rowIdx < m_DataTable.Rows.Count; rowIdx++) { myExport.AddRow(); DataRow dataRow = m_DataTable.Rows[rowIdx]; for (int colIdx = 0; colIdx < m_DataTable.Columns.Count; colIdx++) { string value = (string)dataRow[colIdx]; myExport[colIdx.ToString()] = value; } } myExport.ExportToFile(path); } catch (Exception ex) { DebugUtility.ShowExceptionMessageBox(string.Format("保存文件({0})失败", path), ex); return(false); } return(true); } else { MessageBox.Show(string.Format("保存文件({0})失败", path), "提示"); return(false); } }
/// <summary> /// 头尾空白字符 /// </summary> public static DataGridViewConsoleForm.Message Verify_HeadAndTailWhiteSpace(DataGridViewConsoleForm.Level level, int rowIdx, int colIdx, string cellValue) { if (cellValue.Trim() == cellValue) { return(null); } else { DataGridViewConsoleForm.Message message = CreateMessage(level, rowIdx, colIdx, VerifyType.HeadAndTailWhiteSpace); message.Text = string.Format(message.Text, cellValue); return(message); } }
private static DataGridViewConsoleForm.Message CreateMessage(DataGridViewConsoleForm.Level level, int rowIdx, int colIdx, VerifyType verifyType) { GetVerifyMessage(verifyType, out string messageCaption, out string messageText); DataGridViewConsoleForm.Message message = new DataGridViewConsoleForm.Message { Level = level, Row = rowIdx, Column = colIdx, Caption = messageCaption, Text = messageText }; return(message); }
/// <summary> /// 非法字符("\t", "\r\n"),csv文件中就不应该有这些字符 /// </summary> public static DataGridViewConsoleForm.Message Verify_TabOrCRLF(DataGridViewConsoleForm.Level level, int rowIdx, int colIdx, string cellValue) { if (cellValue.Contains('\t') || cellValue.Contains("\r\n")) { DataGridViewConsoleForm.Message message = CreateMessage(level, rowIdx, colIdx, VerifyType.TabOrCRLF); message.Text = string.Format(message.Text, cellValue); return(message); } else { return(null); } }
/// <summary> /// 本地化单元格内容中开头包含占位符"PLACEHOLDER" /// </summary> public static DataGridViewConsoleForm.Message Verify_Localization_PlaceHolder(DataGridViewConsoleForm.Level level, int rowIdx, int colIdx, string cellValue) { if (cellValue.Trim().StartsWith("PLACEHOLDER")) { DataGridViewConsoleForm.Message message = CreateMessage(level, rowIdx, colIdx, VerifyType.Localization_PlaceHolder); message.Text = string.Format(message.Text, cellValue); return(message); } else { return(null); } }
/// <summary> /// 本地化表第一行第一个单元格应为"String ID" /// </summary> public static DataGridViewConsoleForm.Message Verify_Localization_FirstCell(DataGridViewConsoleForm.Level level, int rowIdx, int colIdx, string cellValue) { if (cellValue == "String ID") { return(null); } else { DataGridViewConsoleForm.Message message = CreateMessage(level, rowIdx, colIdx, VerifyType.Localization_FirstCell); message.Text = string.Format(message.Text, cellValue); return(message); } }
/// <summary> /// 本地化Key不能包含空白字符 /// </summary> public static DataGridViewConsoleForm.Message Verify_Localization_KeyWhiteSpace(DataGridViewConsoleForm.Level level, int rowIdx, string key) { // 本地化key为空 if (key.Contains(" ") || key.Trim() != key) { DataGridViewConsoleForm.Message message = CreateMessage(level, rowIdx, 0, VerifyType.Localization_KeyWhiteSpace); message.Text = string.Format(message.Text, key); return(message); } else { return(null); } }
/// <summary> /// 本地化不能包含重复Key /// </summary> public static DataGridViewConsoleForm.Message Verify_Localization_RepeatKey(DataGridViewConsoleForm.Level level, string[] keys) { List <int> excludes = new List <int>(); // 排除"String ID" excludes.Add(0); for (int iKey = 1; iKey < keys.Length; iKey++) { string iterKey = keys[iKey]; if (string.IsNullOrWhiteSpace(iterKey)) { // 排除空Key excludes.Add(iKey); } } int[][] repeats = StringUtility.CheckRepeat(keys, excludes.ToArray()); if (repeats == null) { return(null); } else { DataGridViewConsoleForm.Message message = CreateMessage(level, -1, 0, VerifyType.Localization_RepeatKey); StringBuilder textSb = new StringBuilder(256); for (int iRepeats = 0; iRepeats < repeats.Length; iRepeats++) { int[] repeat = repeats[iRepeats]; // 重复的行号 for (int iRepeat = 0; iRepeat < repeat.Length; iRepeat++) { textSb.Append(repeat[iRepeat] + 1); if (iRepeat < repeat.Length - 1) { textSb.Append(", "); } } textSb.Append(string.Format(" Key:({0})", keys[repeat[0]])); textSb.AppendLine(); } message.Text = string.Format(message.Text, textSb.ToString()); return(message); } }
/// <summary> /// key不为空的情况下,未填写文本 /// </summary> public static DataGridViewConsoleForm.Message Verify_Localization_EmptyText(DataGridViewConsoleForm.Level level, int rowIdx, int colIdx, string key, string text) { if (string.IsNullOrEmpty(key)) { return(null); } else { if (string.IsNullOrWhiteSpace(text)) { DataGridViewConsoleForm.Message message = CreateMessage(level, rowIdx, colIdx, VerifyType.Localization_EmptyText); return(message); } else { return(null); } } }
/// <summary> /// 本地化单元格内容去掉换行符后,一段文本重复了两次则验证失败 /// 检测规则并不严格。例,以下内容是重复的: /// "ABCDABCD" /// "ABC\r\nD\rABCD" /// 但以下内容不属于重复的: /// "ABCD ABCD" /// "ABCDxABCD" /// 单元格内容的长度小于m的不再检测范围 /// m是硬编码写死的,因为这个校验规则并不常用 /// Q:为什么会有这个校验规则? /// A:因为新来的策划,不知道怎么操作的,造成了这个错误,为了筛选出有问题的本地化内容,所以添加了这个校验规则 /// </summary> public static DataGridViewConsoleForm.Message Verify_Localization_Special1(DataGridViewConsoleForm.Level level, int rowIdx, int colIdx, string key, string cellValue) { string formatedValue = cellValue.Replace("\r", "").Replace("\n", ""); if (formatedValue.Length < 10 || formatedValue.Length % 2 != 0) { return(null); } if (formatedValue.Substring(0, formatedValue.Length / 2) == formatedValue.Substring(formatedValue.Length / 2)) { DataGridViewConsoleForm.Message message = CreateMessage(level, rowIdx, colIdx, VerifyType.Localization_Special1); message.Caption = string.Format(message.Caption, key); message.Text = string.Format(message.Text, cellValue); return(message); } else { return(null); } }
public override void Verify(DataGridView dataGridView, ref List <DataGridViewConsoleForm.Message> messageList, ref bool hasError, ref bool hasWarning) { for (int rowIdx = 0; rowIdx < dataGridView.Rows.Count; rowIdx++) { DataGridViewRow dataRow = dataGridView.Rows[rowIdx]; // 魔法数字:Key不需要检测。 注释列, 中文列的重复太多不检测 int[][] repeats = VerifierUtility.VerifyRepeatCellInRow(dataRow, new int[] { 0, 1, 7, 12, 14 }); if (repeats != null) { messageList.Add(VerifierUtility.CreateRepeatCellInRowMessage(DataGridViewConsoleForm.Level.Info, rowIdx, repeats)); } for (int colIdx = 0; colIdx < dataGridView.Columns.Count; colIdx++) { string value = (string)dataRow.Cells[colIdx].Value; if (!VerifierUtility.VerifyTabOrLineBreak(value)) { hasError = true; messageList.Add(VerifierUtility.CreateTabOrLineBreakMessage(DataGridViewConsoleForm.Level.Error, rowIdx, colIdx, value)); } if (!VerifierUtility.VerifyHeadAndTailWhiteSpace(value)) { hasWarning = true; DataGridViewConsoleForm.Level level = DataGridViewConsoleForm.Level.Warning; // 本地化表第一列是Key,Key前后包含空格是Error if (colIdx == 0) { hasError = true; level = DataGridViewConsoleForm.Level.Error; } messageList.Add(VerifierUtility.CreateHeadAndTailWhiteSpaceMessage(level, rowIdx, colIdx, value)); } } } }
/// <summary> /// 本地化Key不能为空 /// 除非整行都是空 /// </summary> public static DataGridViewConsoleForm.Message Verify_Localization_EmptyKey(DataGridViewConsoleForm.Level level, int rowIdx, DataGridViewRow dataRow, string key) { // 本地化key为空 if (string.IsNullOrWhiteSpace(key)) { // 如果这一行所有单元格都为空,就说明这行是分割行 for (int colIdx = 0; colIdx < dataRow.Cells.Count; colIdx++) { string cellValue = (string)dataRow.Cells[colIdx].Value; if (!string.IsNullOrWhiteSpace(cellValue)) { DataGridViewConsoleForm.Message message = CreateMessage(level, rowIdx, 0, VerifyType.Localization_EmptyKey); message.Text = string.Format(message.Text, cellValue); return(message); } } return(null); } else { return(null); } }
/// <summary> /// 一行内,单元格值重复 /// </summary> /// <param name="exclueds">排除的单元格</param> /// <returns>见StringUtility.CheckRepeat</returns> public static DataGridViewConsoleForm.Message Verify_RepeatCellInRow(DataGridViewConsoleForm.Level level, int rowIdx, DataGridViewRow dataRow, int[] exclueds) { string[] strs = new string[dataRow.Cells.Count]; for (int iCell = 0; iCell < strs.Length; iCell++) { strs[iCell] = (string)dataRow.Cells[iCell].Value; } int[][] repeats = StringUtility.CheckRepeat(strs, exclueds); if (repeats == null) { return(null); } else { DataGridViewConsoleForm.Message message = CreateMessage(level, rowIdx, -1, VerifyType.RepeatCellInRow); StringBuilder textSb = new StringBuilder(256); for (int iRepeats = 0; iRepeats < repeats.Length; iRepeats++) { int[] repeat = repeats[iRepeats]; // 重复的列号(A,B,C……) for (int iRepeat = 0; iRepeat < repeat.Length; iRepeat++) { textSb.Append(ConvertUtility.NumberToLetter(repeat[iRepeat] + 1)); if (iRepeat < repeat.Length - 1) { textSb.Append(", "); } } textSb.Append(string.Format(" 重复的值:({0})", dataRow.Cells[repeat[0]].Value)); textSb.AppendLine(); } message.Text = string.Format(message.Text, textSb.ToString()); return(message); } }
public DataGridViewConsoleForm.Level VerifySelfAndShowConsole(string consoleTitle) { DataGridViewConsoleForm.Level verifyLevel = VerifySelf(out List <DataGridViewConsoleForm.Message> messageList); DataGridViewConsoleForm.ShowForm(messageList, m_DataGridView, consoleTitle); return(verifyLevel); }