private static void FillMatrixRowsToWorksheet(WorkbookNode workbook, WfMatrix matrix, bool roleAsPerson) { NamedLocationCollection locations = workbook.Names.ToLocations(); locations.SortByColumn(); WorksheetNode worksheet = workbook.Worksheets[GetWorksheet(locations)]; int startRowIndex = GetStartRow(locations); int currentRowIndex = -1; foreach (WfMatrixRow matrixRow in matrix.Rows) { RowNode row = new RowNode(); if (currentRowIndex == -1) { currentRowIndex = startRowIndex + 1; row.Index = currentRowIndex; } foreach (CellLocation location in locations) { CellNode cell = new CellNode(); WfMatrixCell mCell = matrixRow.Cells.Find(c => c.Definition.DimensionKey == location.Name); if (mCell != null) { cell.Data.Value = GetCellValue(roleAsPerson, mCell, matrixRow); } row.Cells.Add(cell); } worksheet.Table.Rows.Add(row); } }
/// <summary> /// 创建单元格的值 /// </summary> /// <param name="roleAsPerson"></param> /// <param name="cell"></param> /// <param name="row"></param> /// <returns></returns> private static string GetCellValue(bool roleAsPerson, WfMatrixCell cell, WfMatrixRow row) { if (roleAsPerson == false) { return(cell.StringValue); } if (cell.Definition.DimensionKey == "OperatorType") { return(WfMatrixOperatorType.Person.ToString()); } if (cell.Definition.DimensionKey == "Operator") { var typeCell = row.Cells.Find(p => p.Definition.DimensionKey == "OperatorType"); if (typeCell.StringValue == WfMatrixOperatorType.Role.ToString()) { var users = GetUsersInRole(cell.StringValue); StringBuilder namesBuilder = new StringBuilder(); foreach (var user in users) { namesBuilder.AppendFormat("{0},", user.LogOnName); } if (namesBuilder.Length > 0) { namesBuilder.Remove(namesBuilder.Length - 1, 1); } return(namesBuilder.ToString()); } } return(cell.StringValue); }
/// <summary> /// 将某个操作人,换成某几个操作人 /// </summary> /// <param name="originalOperator"></param> /// <param name="replaceOperators"></param> /// <returns>替换了几次。最多是一次替换。没有替换则返回0</returns> public int ReplaceOperator(string originalOperator, params string[] replaceOperators) { int result = 0; if (this.Operator.IsNotEmpty() && originalOperator.IsNotEmpty()) { string[] originalUsers = this.Operator.Split(SOARolePropertyRow.OperatorSplitters, StringSplitOptions.RemoveEmptyEntries); //先整理一下需要被替换的人 List <string> replaceUsers = new List <string>(); if (replaceOperators != null) { foreach (string user in replaceOperators) { if (originalUsers.Exists(s => string.Compare(s, user, true) == 0) == false) { replaceUsers.Add(user); } } } List <string> targetUsers = new List <string>(); bool added = false; foreach (string user in originalUsers) { if (string.Compare(user, originalOperator, true) == 0) { result = 1; if (added == false) { targetUsers.AddRange(replaceUsers); added = true; } } else { targetUsers.Add(user); } } this.Operator = string.Join(",", targetUsers.ToArray()); WfMatrixCell cell = this.Cells.FindByDefinitionKey("Operator"); if (cell != null) { cell.StringValue = this.Operator; } } return(result); }
private static WfMatrixRow GenerateMatrixRow(WfMatrix matrix, RowNode rowNode, NamedLocationCollection locations, int index) { WfMatrixRow mRow = new WfMatrixRow(matrix); mRow.RowNumber = index; int emptyCellCount = 0; foreach (WfMatrixDimensionDefinition dd in matrix.Definition.Dimensions) { CellLocation location = locations[dd.DimensionKey]; CellNode cell = rowNode.GetCellByIndex(location.Column); WfMatrixCell mCell = new WfMatrixCell(dd); mCell.StringValue = cell.Data.InnerText.Trim(); mRow.Cells.Add(mCell); switch (dd.DimensionKey) { case "Operator": mRow.Operator = cell.Data.InnerText; break; case "OperatorType": WfMatrixOperatorType opType = WfMatrixOperatorType.Person; Enum.TryParse(cell.Data.InnerText, out opType); mRow.OperatorType = opType; break; default: if (mCell.StringValue.IsNullOrEmpty()) { emptyCellCount++; } break; } } if (emptyCellCount >= matrix.Definition.Dimensions.Count - 2) { //如果每一列都为空(不算Operator和OperatorType),那么认为整行都为空 mRow = null; } else { matrix.Rows.Add(mRow); } return(mRow); }
private static void ImportExcel2007(Stream importStream, WfMatrix matrix, Action notifier, string processDescKey) { DataTable dt = DocumentHelper.GetRangeValuesAsTable(importStream, "Matrix", "A3"); int rowIndex = 0; foreach (DataRow row in dt.Rows) { WfMatrixRow matrixRow = new WfMatrixRow(matrix) { RowNumber = rowIndex }; foreach (var dimension in matrix.Definition.Dimensions) { WfMatrixCell matrixCell = new WfMatrixCell(dimension); matrixCell.StringValue = row[dimension.DimensionKey].ToString(); switch (dimension.DimensionKey) { case "Operator": matrixRow.Operator = row[dimension.DimensionKey].ToString(); break; case "OperatorType": WfMatrixOperatorType opType = WfMatrixOperatorType.Person; Enum.TryParse(row[dimension.DimensionKey].ToString(), out opType); matrixRow.OperatorType = opType; break; default: break; } matrixRow.Cells.Add(matrixCell); } if (notifier != null) { notifier(); } rowIndex++; matrix.Rows.Add(matrixRow); } WfMatrixAdapter.Instance.DeleteByProcessKey(matrix.ProcessKey); WfMatrixAdapter.Instance.Update(matrix); }
private static string BuildInsertCellSql(string wfMatrixID, WfMatrixRow row, WfMatrixCell cell) { StringBuilder result = new StringBuilder(); InsertSqlClauseBuilder insertBuilder = new InsertSqlClauseBuilder(); insertBuilder.AppendItem(DB_FIELD_MATRIX_ID, wfMatrixID); insertBuilder.AppendItem(DB_FIELD_MATRIX_ROW_ID, row.RowNumber); insertBuilder.AppendItem(DB_FIELD_DIMENSION_KEY, cell.Definition.DimensionKey); insertBuilder.AppendItem(DB_FIELD_STRING_VALUE, cell.StringValue); insertBuilder.AppendTenantCode(); result.Append(INSERT_MC_SQL_CLAUSE_PREFIX); result.Append(insertBuilder.ToSqlString(TSqlBuilder.Instance)); result.Append(TSqlBuilder.Instance.DBStatementSeperator); return(result.ToString()); }