/// <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); }
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 BuildInsertRowSql(string wfMatrixID, WfMatrixRow row) { 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_OPERATOR_TYPE, (int)row.OperatorType); insertBuilder.AppendItem(DB_FIELD_OPERATOR, row.Operator); insertBuilder.AppendTenantCode(); result.Append(INSERT_MR_SQL_CLAUSE_PREFIX); result.Append(insertBuilder.ToSqlString(TSqlBuilder.Instance)); result.Append(TSqlBuilder.Instance.DBStatementSeperator); return(result.ToString()); }
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()); }
public WfMatrixRowUsers(WfMatrixRow wfMatrixRow) { Row = wfMatrixRow; }