public CellCommentManager CheckUpdateResult() { CellCommentManager comments = new CellCommentManager(); foreach (ImportCondition eachCond in _check_conditions) { if (eachCond == _primary_condition) { continue; } Dictionary <string, Record> records = new Dictionary <string, Record>(); foreach (Record each in _key_sets.AllRecord) { if (eachCond.EmptySkipValidate) //檢查是否要略過驗證空白資料。 { if (eachCond.IsEmptyKey(each)) //如果是空白資料的話就 Skip。 { continue; } } string key = eachCond.GetKeyByInternalName(each); //Console.WriteLine(each["CourseID"] + " " + key); if (!records.ContainsKey(key)) { records.Add(key, each); } else { int rowIndex = each.SourceRowIndex; if (rowIndex < 0) { rowIndex = records[key].SourceRowIndex; if (rowIndex < 0) { continue; } } foreach (ImportField eachField in eachCond.Fields) { int columnIndex = _sheet.GetFieldIndex(eachField.FieldName); string msg = string.Format("更新資料後會造成欄位「{0}」與資料庫中資料重複。", eachCond.GetCombineFieldName()); comments.WriteError(rowIndex, columnIndex, msg); } } } } return(comments); }
private void SummaryValidateInfo(CellCommentManager cmmManager) { corrects = new List <CellComment>(); errors = new List <CellComment>(); warnings = new List <CellComment>(); foreach (CellComment each in cmmManager) { if (each.BestComment is CorrectComment) { corrects.Add(each); } if (each.BestComment is ErrorComment) { errors.Add(each); } if (each.BestComment is WarningComment) { warnings.Add(each); } } lblCorrectCount.Text = corrects.Count.ToString(); lblErrorCount.Text = errors.Count.ToString(); lblWarningCount.Text = warnings.Count.ToString(); if (corrects.Count > 0 || errors.Count > 0) { ProgressMessage("發現錯誤資料…"); wpValidation.NextButtonEnabled = eWizardButtonState.False; } else { ProgressMessage("未發現錯誤資料…"); wpValidation.NextButtonEnabled = eWizardButtonState.True; } }
private void btnValidate_Click(object sender, EventArgs e) { try { lblCorrectCount.Text = "0"; lblErrorCount.Text = "0"; lblWarningCount.Text = "0"; //int t1 = Environment.TickCount; ProgressMessage("載入資料檢查規則…"); ValidateHelper validator = new ValidateHelper(Context, null); SheetHelper sheet = new SheetHelper(Context.SourceFile); TipStyles styles = new TipStyles(sheet); //Console.WriteLine("載入驗證規則時間:{0}", Environment.TickCount - t1); validator.ProgressChanged += new ProgressChangedEventHandler(Validator_ProgressChanged); pgValidProgress.Value = 0; //t1 = Environment.TickCount; ProgressMessage("驗證資料中…"); lnkCancelValid.Visible = true; _cancel_validate = false; cellManager = validator.Validate(sheet); lnkCancelValid.Visible = false; //Console.WriteLine("驗證時間:{0}", Environment.TickCount - t1); validator.ProgressChanged -= new ProgressChangedEventHandler(Validator_ProgressChanged); if (_cancel_validate) { wpValidation.NextButtonEnabled = eWizardButtonState.False; ProgressMessage("資料驗證已由使用者取消…"); return; } else { wpValidation.NextButtonEnabled = eWizardButtonState.True; } //t1 = Environment.TickCount; SummaryValidateInfo(cellManager); //Console.WriteLine("Summary 時間:{0}", Environment.TickCount - t1); //t1 = Environment.TickCount; sheet.ClearComments(); sheet.SetAllStyle(styles.Default); foreach (CellComment each in cellManager) { CommentItem item = each.BestComment; int row, column; row = each.RowIndex; column = each.ColumnIndex; if (item is CorrectComment) { sheet.SetComment(row, column, item.Comment); sheet.SetStyle(row, column, styles.Correct); sheet.SetValue(row, column, (item as CorrectComment).NewValue); } if (item is ErrorComment) { sheet.SetComment(row, column, item.Comment); sheet.SetStyle(row, column, styles.Error); } if (item is WarningComment) { sheet.SetComment(row, column, item.Comment); sheet.SetStyle(row, column, styles.Warning); } } //Console.WriteLine("Output Errors 時間:{0}", Environment.TickCount - t1); sheet.SetFieldsStyle(Context.SelectedFields, styles.Header); sheet.Save(Context.SourceFile); } catch (Exception ex) { FISCA.Presentation.Controls.MsgBox.Show(ex.Message); wpValidation.NextButtonEnabled = eWizardButtonState.False; } }