/// <summary> /// PES解析方法 /// </summary> /// <param name="parameters"></param> /// <param name="commonPrintModel"></param> /// <param name="parseFuntionNameSpace"></param> /// <param name="dataFuntionNameSpace"></param> /// <param name="XDeviation"></param> /// <param name="YDeviation"></param> public static void ParsePrintTempletInforForPES(Dictionary <string, string> parameters, PrintFactoryModel commonPrintModel, string parseFuntionNameSpace, string dataFuntionNameSpace, int XDeviation, int YDeviation) { if (commonPrintModel.PrintItems != null) { foreach (PrintItemModel item in commonPrintModel.PrintItems) { item.XDeviation = XDeviation; item.YDeviation = YDeviation; if (item.DataSourceType == 1) { if (item.ConttrolData == null || string.IsNullOrWhiteSpace(item.ConttrolData.ControlName)) { throw new Exception(string.Format("请正确设置打印条目<{0}>的ConttrolDataDataSource属性值.", item.PrintCaption)); } if (!parameters.ContainsKey(item.ConttrolData.ControlName)) { throw new Exception(string.Format("未查询到{0}【{1}】键值对.", item.ConttrolData.ControlCaption, item.ConttrolData.ControlName)); } string value = parameters[item.ConttrolData.ControlName]; item.ConttrolData.ValueContainer = string.Format(item.ConttrolData.ValueContainer, value); item.PrintKeyValue = string.Format(item.PrintKeyValue, item.ConttrolData.ValueContainer); } else if (item.DataSourceType == 2) { if (item.FunctionData == null || string.IsNullOrWhiteSpace(item.FunctionData.FunctionName)) { throw new Exception(string.Format("请正确设置打印条目<{0}>的FunctionDataSource属性值.", item.PrintCaption)); } item.FunctionData.ParseFuntion = CommonRule.LoadClassInstance <IDataFunction>(dataFuntionNameSpace, item.FunctionData.FunctionName); item.FunctionData.ValueContainer = string.Format(item.FunctionData.ValueContainer, item.FunctionData.ParseFuntion.DataParseFuntion(commonPrintModel.PrintItems, item.FunctionData.FunctionIndexs)); item.PrintKeyValue = string.Format(item.PrintKeyValue, item.FunctionData.ValueContainer); } if (string.IsNullOrWhiteSpace(item.PrintFunctionName)) { throw new Exception(string.Format("请设置打印条目<{0}>的PrintFunctionName属性值.", item.PrintCaption)); } item.ParseFuntion = CommonRule.LoadClassInstance <IPrintFunction>(parseFuntionNameSpace, item.PrintFunctionName); item.DefaultParameters = DefaultPropertyValueTable.PrintFunctionDefaultParameters.FirstOrDefault(p => { return(p.Key == item.PrintFunctionName); }).Value; if (string.IsNullOrWhiteSpace(item.PrintKeyValue)) { item.PrintKeyValue = string.Empty; } } } }
/// <summary> /// 解析打印模板 /// </summary> /// <param name="commonPrintModel"></param> /// <param name="parseFuntionNameSpace"></param> public static void ParsePrintTempletInfo(FrameworkElement element, PrintFactoryModel commonPrintModel, string parseFuntionNameSpace, string dataFuntionNameSpace, int XDeviation, int YDeviation) { if (commonPrintModel.PrintItems != null) { foreach (PrintItemModel item in commonPrintModel.PrintItems) { item.XDeviation = XDeviation; item.YDeviation = YDeviation; if (item.DataSourceType == 1) { if (item.ConttrolData == null) { throw new Exception(string.Format("请正确设置打印条目<{0}>的ConttrolData值.", item.PrintCaption)); } DependencyObject dependencyObject = DependencyHelper.FindVisualChildByName(element, item.ConttrolData.ControlName); if (dependencyObject == null) { throw new Exception(string.Format("未从界面获取到<{0},{1}>控件.", item.ConttrolData.ControlCaption, item.ConttrolData.ControlName)); } if (string.IsNullOrWhiteSpace(item.ConttrolData.ControlName)) { throw new Exception(string.Format("请正确设置打印条目<{0}>的ConttrolData属性的PropertyName属性值.", item.PrintCaption)); } object value = CommonRule.GetPropertyValue(dependencyObject, item.ConttrolData.PropertyName); if (!string.IsNullOrWhiteSpace(item.ConttrolData.ChildPropertyName)) { if (value == null) { throw new Exception(string.Format("未从界面获取到<{0}>的{1}值.", item.ConttrolData.ControlCaption, item.ConttrolData.PropertyName)); } value = CommonRule.GetPropertyValue(value, item.ConttrolData.ChildPropertyName); } item.ConttrolData.ValueContainer = string.Format(item.ConttrolData.ValueContainer, value); item.PrintKeyValue = string.Format(item.PrintKeyValue, item.ConttrolData.ValueContainer); } else if (item.DataSourceType == 2) { if (item.FunctionData == null || string.IsNullOrWhiteSpace(item.FunctionData.FunctionName)) { throw new Exception(string.Format("请正确设置打印条目<{0}>的ConttrolDataSource属性值.", item.PrintCaption)); } item.FunctionData.ParseFuntion = CommonRule.LoadClassInstance <IDataFunction>(dataFuntionNameSpace, item.FunctionData.FunctionName); item.FunctionData.ValueContainer = string.Format(item.FunctionData.ValueContainer, item.FunctionData.ParseFuntion.DataParseFuntion(commonPrintModel.PrintItems, item.FunctionData.FunctionIndexs)); item.PrintKeyValue = string.Format(item.PrintKeyValue, item.FunctionData.ValueContainer); } if (string.IsNullOrWhiteSpace(item.PrintFunctionName)) { throw new Exception(string.Format("请设置打印条目<{0}>的PrintFunctionName属性值.", item.PrintCaption)); } item.ParseFuntion = CommonRule.LoadClassInstance <IPrintFunction>(parseFuntionNameSpace, item.PrintFunctionName); item.DefaultParameters = DefaultPropertyValueTable.PrintFunctionDefaultParameters.FirstOrDefault(p => { return(p.Key == item.PrintFunctionName); }).Value; if (string.IsNullOrWhiteSpace(item.PrintKeyValue)) { item.PrintKeyValue = string.Empty; } } } }