public static string Get相关人(IRepository rep, 普通票 票, 普通箱 箱, 合同费用项 htfyx) { object entity; if (箱 != null) { entity = 箱; } else { entity = 票; } string ret = null; if (htfyx is 委托人合同费用项) { return(票.委托人编号); } else if (htfyx is 付款合同费用项) { string mrxgr = (htfyx as 付款合同费用项).默认相关人; object r = EntityScript.CalculateExpression(mrxgr, entity); ret = string.IsNullOrEmpty(mrxgr) || r == null ? null : r.ToString().Replace("\"", ""); if (string.IsNullOrEmpty(ret)) { ret = null; } } else if (htfyx is 受托人合同费用项) { object cyr = EntityScript.GetPropertyValue(票, "承运人编号"); if (cyr != null) { return(cyr.ToString()); } else { return(null); } } else { throw new ArgumentException("Invalid htfyx Type!"); } return(ret); }
/// <summary> /// /// </summary> /// <param name="entity"></param> public string Calculate(object entity) { StringBuilder sb = new StringBuilder(); foreach (GridColumnWarningInfo info in m_warningInfos) { if (!Authority.AuthorizeByRule(info.Visible)) { continue; } object ret = EntityScript.CalculateExpression(info.Expression, entity); if (ret != null && (bool)ret) { sb.Append(info.Text); sb.Append(","); } } return(sb.ToString()); }
public static string Get相关人(IRepository rep, 车辆产值 产值, 任务 任务, 合同费用项 htfyx) { 车队合同费用项 cdhtfyx = htfyx as 车队合同费用项; switch (cdhtfyx.费用归属) { case 费用归属.委托人: return(任务.委托人编号); case 费用归属.车主: return(产值.承运人编号); case 费用归属.驾驶员: return(产值.驾驶员编号); case 费用归属.对外: { object entity; if (任务 != null) { entity = 任务; } else { entity = 产值; } string ret = null; object r = EntityScript.CalculateExpression(cdhtfyx.默认相关人, entity); ret = string.IsNullOrEmpty(cdhtfyx.默认相关人) || r == null ? null : r.ToString().Replace("\"", ""); if (string.IsNullOrEmpty(ret)) { ret = null; } return(ret); } default: throw new ArgumentException("Invalid 费用归属!"); } }
/// <summary> /// GetVariableFunctionResult /// </summary> /// <param name="rowList"></param> /// <param name="functionName"></param> /// <param name="fieldName"></param> /// <param name="format"></param> /// <param name="level"></param> /// <param name="expression"></param> /// <returns></returns> public static string GetVariableFunctionResult(Xceed.Grid.Collections.ReadOnlyDataRowList rowList, string functionName, string fieldName, string format, int level, string expression) { // VariableText中不能带%(默认是作为VariableText的分隔符) if (!string.IsNullOrEmpty(expression)) { expression = expression.Replace('#', '%'); } switch (functionName.ToUpper()) { case "COUNT": int cnt = 0; foreach (Xceed.Grid.DataRow row in rowList) { if (string.IsNullOrEmpty(expression)) { cnt++; } else { object s = EntityScript.CalculateExpression(expression, row.Tag); int? r = Feng.Utils.ConvertHelper.ToInt(s); if (r.HasValue) { cnt += r.Value; } } } return(cnt.ToString()); case "SUM": decimal sum = 0; foreach (Xceed.Grid.DataRow row in rowList) { if (string.IsNullOrEmpty(expression)) { sum += Convert.ToDecimal(row.Cells[fieldName].Value); } else { object s = EntityScript.CalculateExpression(expression, row.Tag); decimal?r = Feng.Utils.ConvertHelper.ToDecimal(s); if (r.HasValue) { sum += r.Value; } } } return(string.IsNullOrEmpty(format) ? sum.ToString("N2") : sum.ToString(format)); case "ALLTRUE": { bool all = true; foreach (Xceed.Grid.DataRow row in rowList) { if (string.IsNullOrEmpty(expression)) { } else { object s = EntityScript.CalculateExpression(expression, row.Tag); bool? r = Feng.Utils.ConvertHelper.ToBoolean(s); if (!r.HasValue || !r.Value) { all = false; break; } } } return(all ? "全" : "否"); } } return(string.Empty); }
internal static void SetGridRowCellColors(this IBoundGrid grid, Xceed.Grid.DataRow row) { GridRowInfo rowInfo = ADInfoBll.Instance.GetGridRowInfo(grid.GridName); object entity = row.Tag; if (!string.IsNullOrEmpty(rowInfo.BackColor)) { string s = (string)EntityScript.CalculateExpression(rowInfo.BackColor, entity); if (!string.IsNullOrEmpty(s)) { row.BackColor = System.Drawing.Color.FromName(s); } else { row.ResetBackColor(); } } if (!string.IsNullOrEmpty(rowInfo.ForeColor)) { string s = (string)EntityScript.CalculateExpression(rowInfo.ForeColor, entity); if (!string.IsNullOrEmpty(s)) { row.ForeColor = System.Drawing.Color.FromName(s); } else { row.ResetForeColor(); } } foreach (GridCellInfo cellInfo in ADInfoBll.Instance.GetGridCellInfos(grid.GridName)) { Xceed.Grid.Cell cell = row.Cells[cellInfo.GridColumName]; if (cell == null) { continue; } if (!string.IsNullOrEmpty(cellInfo.BackColor)) { string s = (string)EntityScript.CalculateExpression(cellInfo.BackColor, entity); if (!string.IsNullOrEmpty(s)) { cell.BackColor = System.Drawing.Color.FromName(s); } else { cell.ResetBackColor(); } } if (!string.IsNullOrEmpty(rowInfo.ForeColor)) { string s = (string)EntityScript.CalculateExpression(cellInfo.ForeColor, entity); if (!string.IsNullOrEmpty(s)) { cell.ForeColor = System.Drawing.Color.FromName(s); } else { cell.ResetForeColor(); } } } }
/// <summary> /// /// </summary> /// <param name="entity"></param> /// <param name="gridName"></param> /// <returns></returns> public Dictionary <string, object> Process(object entity, string gridName) { Dictionary <string, object> r = new Dictionary <string, object>(); // grid if (!Authority.AuthorizeByRule(ADInfoBll.Instance.GetGridInfo(gridName).Visible)) { return(r); } // row if (!Permission.AuthorizeByRule(ADInfoBll.Instance.GetGridRowInfo(gridName).Visible, entity)) { return(r); } // column foreach (GridColumnInfo info in ADInfoBll.Instance.GetGridColumnInfos(gridName)) { object v = null; if ((m_useColumnVisible && !Authority.AuthorizeByRule(info.ColumnVisible)) || (!m_useColumnVisible && !Authority.AuthorizeByRule(info.DataControlVisible))) { continue; } else { if (info.GridColumnType != GridColumnType.Normal && info.GridColumnType != GridColumnType.ExpressionColumn) { continue; } if (string.IsNullOrEmpty(info.PropertyName)) { v = null; } else if (info.GridColumnType == GridColumnType.Normal) { v = EntityScript.GetPropertyValue(entity, info.Navigator, info.PropertyName); } else if (info.GridColumnType == GridColumnType.ExpressionColumn) { if (info.PropertyName.Contains("%")) { v = EntityScript.CalculateExpression(info.PropertyName, entity); } else { v = ProcessInfoHelper.TryExecutePython(info.PropertyName, new Dictionary <string, object>() { { "entity", entity } }); } } else { continue; } } if (v == System.DBNull.Value) { v = null; } if (v == null) { r[info.GridColumnName] = null; continue; } string vs = null; if (GridColumnInfoHelper.CreateType(info).IsEnum) { vs = v.ToString(); } switch (info.CellViewerManager) { case "Combo": case "MultiCombo": vs = GetViewerText(v, info); break; case "Object": vs = EntityHelper.ReplaceEntity(info.CellViewerManagerParam, v, null); break; case "Numeric": case "Integer": case "Long": case "Currency": vs = Convert.ToDouble(v).ToString(GetFormatString(info)); break; case "Date": case "DateTime": vs = Convert.ToDateTime(v).ToString(GetFormatString(info)); break; default: vs = v.ToString(); break; } r[info.GridColumnName] = vs; //// cell //foreach (GridCellInfo info in GridSettingInfoCollection.Instance[gridName].GridCellInfos) //{ //} } return(r); }
/// <summary> /// 根据Entity的值设置row's cell值 /// </summary> /// <param name="grid"></param> /// <param name="entity"></param> /// <param name="row"></param> public static void SetDataRowsIListData(this IBoundGrid grid, object entity, Xceed.Grid.DataRow row) { // 如果同一个实体类,只是里面内容变了,重新设置不会设置成功 row.Tag = null; if (entity == null) { return; } row.Tag = entity; foreach (GridColumnInfo info in ADInfoBll.Instance.GetGridColumnInfos(grid.GridName)) { try { switch (info.GridColumnType) { case GridColumnType.Normal: if (row.Cells[info.GridColumnName] != null && !string.IsNullOrEmpty(info.PropertyName)) { row.Cells[info.GridColumnName].Value = EntityScript.GetPropertyValue(entity, info.Navigator, info.PropertyName); } break; case GridColumnType.WarningColumn: row.Cells[info.GridColumnName].Value = (row.Cells[info.GridColumnName].ParentColumn as WarningColumn).Calculate(entity); break; case GridColumnType.StatColumn: { if (row.DetailGrids.Count == 0) { return; //throw new ArgumentException("stateColumn should has detailgrids."); } row.Cells[info.GridColumnName].Value = Feng.Utils.ConvertHelper.ChangeType( MySummaryRow.GetSummaryResult(row.DetailGrids[0].GetSortedDataRows(true), info.PropertyName), row.Cells[info.GridColumnName].ParentColumn.DataType); } break; case GridColumnType.ExpressionColumn: { //var info2 = info; //var row2 = row; //Feng.Async.AsyncHelper.Start(() => //{ // if (info2.PropertyName.Contains("%")) // { // return EntityScript.CalculateExpression(info2.PropertyName, entity); // } // else // { // return Feng.Utils.ProcessInfoHelper.TryExecutePython(info2.PropertyName, // new Dictionary<string, object>() { { "entity", entity }, { "row", row2 } }); // } //}, (result) => //{ // row2.Cells[info2.GridColumnName].Value = result; //}); if (info.PropertyName.Contains("%")) { row.Cells[info.GridColumnName].Value = EntityScript.CalculateExpression(info.PropertyName, entity); } else { row.Cells[info.GridColumnName].Value = ProcessInfoHelper.TryExecutePython(info.PropertyName, new Dictionary <string, object>() { { "entity", entity }, { "row", row } }); } } break; case GridColumnType.ImageColumn: { var i = Feng.Windows.ImageResource.Get(info.PropertyName); row.Cells[info.GridColumnName].Value = i == null ? null : i.Reference; } break; case GridColumnType.CheckColumn: { row.Cells[info.GridColumnName].Value = false; } break; case GridColumnType.NoColumn: case GridColumnType.SplitColumn: break; case GridColumnType.UnboundColumn: { try { row.Cells[info.GridColumnName].Value = Feng.Utils.ConvertHelper.ChangeType(info.PropertyName, Feng.Utils.ReflectionHelper.GetTypeFromName(info.TypeName)); } catch (Exception) { } } break; case GridColumnType.IndexColumn: { row.Cells[info.GridColumnName].Value = row.Index + 1; } break; default: throw new NotSupportedException("invalid GridColumnType of " + info.GridColumnType); } } catch (Exception ex) { ExceptionProcess.ProcessWithResume(new ArgumentException(info.PropertyName + " info is invalid!", ex)); } } }