private bool judgeIsNullDataSource(IClientRuleConfig clientRule, DataSet dsData) { bool result = false; if (clientRule == null) { string message = getMessage(ChartViewStatic.ERROR_NULL_CLIENTRULE); throw new MB.Util.APPException(message, APPMessageType.DisplayToUser); } if (dsData == null || dsData.Tables[0].Rows.Count == 0) { string message = getMessage(ChartViewStatic.ERROR_NULL_DATASET); throw new MB.Util.APPException(message, APPMessageType.DisplayToUser); } List <ColumnPropertyInfo> columnPropertyInfos = getColumnPropertyInfo(clientRule); if (0 != columnPropertyInfos.Count && 0 != dsData.Tables[0].Rows.Count) { result = true; } return(result); }
/// <summary> /// 为当前表单绑定的实体对象注入默认值. /// </summary> /// <param name="currentEntity">当前表单绑定的实体对象</param> /// <param name="clientRuleCfg">配置</param> protected void PopulateDefaultValue(object currentEntity, IClientRuleConfig clientRuleCfg) { var filePath = GetDefaultValueFilePath(currentEntity); // 读取需要保存默认值的列 var defaultValueColumns = clientRuleCfg.UIRuleXmlConfigInfo.GetDefaultColumns().Where(kv => kv.Value.SaveDefaultValue).Select(kv => kv.Value).ToList(); //读取编辑列的配置信息 Dictionary <string, MB.WinBase.Common.ColumnEditCfgInfo> editColumnCfg = clientRuleCfg.UIRuleXmlConfigInfo.ColumnsCfgEdit; if (defaultValueColumns.Count > 0) { if (File.Exists(filePath)) { var entity = DataContractSerializeHelper.Deserialize(currentEntity.GetType(), File.ReadAllText(filePath)); foreach (var column in defaultValueColumns) { var value = MyReflection.Instance.InvokePropertyForGet(entity, column.Name); if (value != null) { MyReflection.Instance.InvokePropertyForSet(currentEntity, column.Name, value); } } } } }
/// <summary> /// <see cref="MB.WinBase.IFace.CreateDataBinding"/> /// </summary> public void CreateDataBinding(IClientRuleConfig clientRule, DataSet dsData) { try { _DataSet = dsData; bool notNullDataSource = judgeIsNullDataSource(clientRule, dsData); if (notNullDataSource) { List <ColumnPropertyInfo> columnPropertyInfos = getColumnPropertyInfo(clientRule); _ColumnPropertyInfos = columnPropertyInfos; string identity = getIdentity(clientRule); _Identity = identity; if (null != _DefaultChartType) { bindDefaultChart(_DefaultChartType, dsData.Tables[0].Columns, _PagerSettings); } else { ChartViewHelper chartViewHelper = new ChartViewHelper(); ChartEventArgs chartEventArgs = new ChartEventArgs(); chartEventArgs.ChartType = SeriesChartType.Pie; _ChartEventArgs = chartEventArgs; List <ChartAreaInfo> chartAreaInfos = chartViewHelper.CreateChartData(dsData, columnPropertyInfos, chartEventArgs, _PagerSettings); _XValueCount = chartViewHelper.XValueCount; _PagerSettings.PageIndex = 0; _PagerSettings.PageCount = _XValueCount / _PagerSettings.PageSize + 1; showBindingNavigator(_PagerSettings); IChart chart = new PieChart(_BaseChart); chart.AreaDataList = chartAreaInfos; } setNavigationStatus(true); setPageButton(); } else { setNavigationStatus(false); } } catch (Exception ex) { MB.WinBase.ApplicationExceptionTerminate.DefaultInstance.ExceptionTerminate(ex); } }
private List <ColumnPropertyInfo> getColumnPropertyInfo(IClientRuleConfig clientRule) { List <ColumnPropertyInfo> filtedColumnPropertyInfos = new List <ColumnPropertyInfo>(); List <ColumnPropertyInfo> columnPropertyInfos = new List <ColumnPropertyInfo>(); var cols = clientRule.UIRuleXmlConfigInfo.GetDefaultColumns(); columnPropertyInfos.AddRange(cols.Values); filtedColumnPropertyInfos = filterColumnPropertyInfos(columnPropertyInfos); return(filtedColumnPropertyInfos); }
/// <summary> /// 保存默认值 /// </summary> /// <param name="bindingSource">当前编辑窗口数据绑定</param> /// <param name="clientRuleCfg">配置</param> protected void SaveDefaultValue(BindingSourceEx bindingSource, IClientRuleConfig clientRuleCfg) { if (bindingSource.Current != null) { // 保存为默认值 var defaultValueColumns = clientRuleCfg.UIRuleXmlConfigInfo.GetDefaultColumns().Where(kv => kv.Value.SaveDefaultValue).Select(kv => kv.Value).ToList(); if (defaultValueColumns.Count > 0) { try { File.WriteAllText(GetDefaultValueFilePath(bindingSource.Current), DataContractSerializeHelper.Serialize(bindingSource.Current.GetType(), bindingSource.Current)); } catch (Exception e) { MessageBox.Show("保存默认值出错." + e.Message); } } } }
private string getIdentity(IClientRuleConfig clientRule) { string identity = string.Format("{0} {1}", clientRule.GetType().FullName, clientRule.ClientLayoutAttribute.UIXmlConfigFile); return(identity); }