/// <summary> /// 确定分组列,汇总列,汇总条件的设置 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSure_Click(object sender, EventArgs e) { try { List <DynamicGroupUIColumns> dyUIColumns = new List <DynamicGroupUIColumns>(); DynamicGroupSetting setting = _DynamicGroupUIHelper.GetDynamicGroupSetting(ref dyUIColumns); if (setting == null || setting.DataAreaFields == null || setting.DataAreaFields.Count <= 0) { MB.WinBase.MessageBoxEx.Show("请设置聚组条件"); } else { _DynamicGroupGridHost.DynamicGroupSettingForQuery = setting; _DynamicGroupUIHelper.SaveDynamicGroupSettings(dyUIColumns); MB.WinBase.MessageBoxEx.Show("动态聚组的条件保存成功"); this.DialogResult = DialogResult.OK; } } catch (Exception ex) { MB.Util.TraceEx.Write(string.Format("动态聚组设定汇总列出错:{0}", ex.ToString())); MB.WinBase.ApplicationExceptionTerminate.DefaultInstance.ExceptionTerminate(ex); } }
/// <summary> /// 保存配置信息 /// </summary> public static void SaveDynamicGroupSettings(MB.XWinLib.PivotGrid.PivotGridEx pivotGrid, IClientRuleQueryBase clientRuleObject, DynamicGroupSetting setting) { try { //保存列配置信息 if (!Directory.Exists(DYNAMIC_GROUP_DIR)) { Directory.CreateDirectory(DYNAMIC_GROUP_DIR); } if (setting != null) { //string sectionName = clientRuleObject.GetType().FullName + "~" + pivotGrid.Name; string sectionName = getDynamicSettingSectionName(clientRuleObject); string fullFileName = string.Format(DYNAMIC_GROUP_SETTING_FULLNAME, sectionName); if (File.Exists(fullFileName)) { File.Delete(fullFileName); } var serializer = new MB.Util.Serializer.DataContractFileSerializer <DynamicGroupSetting>(fullFileName); serializer.Write(setting); string pivotFullName = string.Format(DYNAMIC_GROUP_PIVOT_GRID_LAYOUT, sectionName); if (File.Exists(pivotFullName)) { File.Delete(pivotFullName); } pivotGrid.SaveLayoutToXml(pivotFullName); } } catch (Exception ex) { throw MB.Util.APPExceptionHandlerHelper.PromoteException(ex, "保存动态聚组设定失败"); } }
/// <summary> /// 根据Grid得到动态聚组的最终结果,用来传递到服务端 /// </summary> /// <param name="dyUIColumns">用来保存Grid的当前状态</param> /// <returns>动态聚组设定,用来传递到服务端的</returns> public MB.Util.Model.DynamicGroupSetting GetDynamicGroupSetting(ref List <DynamicGroupUIColumns> dyUIColumns) { //用到的全局变量 DynamicGroupCfgInfo dyConfigInfo = _DynamicCfgInfo; GridControlEx grid = _GirdControl; DynamicGroupSetting setting = new DynamicGroupSetting(); //设置实体 setting.EntityInfos.MainEntity = dyConfigInfo.MainEntityInfo; setting.EntityInfos.DetailEntity = dyConfigInfo.DetailEntityInfo; //设置关系 if (_DynamicCfgInfo.RelationInfo != null) { setting.RelationInfos = _DynamicCfgInfo.RelationInfo.Values.ToList <DynamicGroupRelationInfo>(); } BindingList <DynamicGroupUIColumns> uiColList = grid.DataSource as BindingList <DynamicGroupUIColumns>; foreach (DynamicGroupUIColumns column in uiColList) { dyUIColumns.Add(column); if (!column.SELECTED) { continue; } string entityName = column.ENTITY_NAME; string colName = column.COLUMN_NAME; if (string.IsNullOrEmpty(column.AGG_TYPE)) { //对分组列做处理 if (setting.GroupFields.ContainsKey(entityName)) { setting.GroupFields[entityName].Add(colName); } else { var list = new List <string>(); list.Add(colName); setting.GroupFields.Add(entityName, list); } } else { //对聚组列做处理 DataAreaField dataField = new DataAreaField(); dataField.Name = colName; dataField.Description = column.COLUMN_DESCRIPTION; dataField.SummaryItemType = (MB.Util.Model.SummaryItemType)Enum.Parse(typeof(MB.Util.Model.SummaryItemType), column.AGG_TYPE.ToString(), true); if (string.Compare(dyConfigInfo.MainEntityInfo.Name, entityName) == 0) { dataField.DataType = dyConfigInfo.MainEntityColInfo[colName].DataType; dataField.EntityName = entityName; dataField.EntityDescription = dyConfigInfo.MainEntityInfo.Description; if (!string.IsNullOrEmpty(column.AGG_CONDITION_OPERATOR) && !string.IsNullOrEmpty(column.AGG_VALUE)) { dataField.ConditionOperator = (DynamicGroupConditionOperator)Enum.Parse(typeof(DynamicGroupConditionOperator), column.AGG_CONDITION_OPERATOR); dataField.ConditionValue = column.AGG_VALUE; } } else { if (dyConfigInfo.DetailEntityInfo != null) { dataField.DataType = dyConfigInfo.DetailEntityColInfo[colName].DataType; dataField.EntityName = entityName; dataField.EntityDescription = dyConfigInfo.DetailEntityInfo.Description; if (!string.IsNullOrEmpty(column.AGG_CONDITION_OPERATOR) && !string.IsNullOrEmpty(column.AGG_VALUE)) { dataField.ConditionOperator = (DynamicGroupConditionOperator)Enum.Parse(typeof(DynamicGroupConditionOperator), column.AGG_CONDITION_OPERATOR); dataField.ConditionValue = column.AGG_VALUE; } } } if (setting.DataAreaFields.ContainsKey(entityName)) { setting.DataAreaFields[entityName].Add(dataField); } else { var list = new List <DataAreaField>(); list.Add(dataField); setting.DataAreaFields.Add(entityName, list); } } } return(setting); }