示例#1
0
        public static PrintClientConfig GetClientConfig(string path)
        {
            PrintClientConfig            printClientConfig = new PrintClientConfig();
            PrintItemControlModel        temp    = new PrintItemControlModel();
            List <PrintItemControlModel> reValue = new List <PrintItemControlModel>();

            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                //数据提取
                xmlDoc.Load(path);
                //基本信息获取
                foreach (XmlAttribute item in xmlDoc.SelectNodes("/PrintItemControls")[0].Attributes)
                {
                    CommonRule.SetPropertyValue(printClientConfig, item.Name, item.Value);
                }
                foreach (XmlNode item in xmlDoc.SelectNodes("/PrintItemControls/PrintItemControl"))
                {
                    temp = new PrintItemControlModel();
                    //打印属性
                    foreach (XmlAttribute attribute in item.Attributes)
                    {
                        CommonRule.SetPropertyValue(temp, attribute.Name, attribute.Value);
                    }
                    reValue.Add(temp);
                }
                printClientConfig.PrintItemControls = reValue;
            }
            catch
            {
                printClientConfig = null;
            }
            return(printClientConfig);
        }
示例#2
0
 /// <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;
             }
         }
     }
 }
示例#3
0
        public static List <ParameterModel> GetHelpDocument(string fileName)
        {
            List <ParameterModel> reValue = new List <ParameterModel>();
            XmlDocument           xmlDoc  = new XmlDocument();

            xmlDoc.Load(fileName);
            foreach (XmlNode item in xmlDoc.SelectNodes("/Items/Item"))
            {
                ParameterModel temp = new ParameterModel();
                foreach (XmlAttribute attribute in item.Attributes)
                {
                    CommonRule.SetPropertyValue(temp, attribute.Name, attribute.Value);
                }
                reValue.Add(temp);
            }
            return(reValue);
        }
示例#4
0
        /// <summary>
        /// 获取打印模板
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static PrintFactoryModel GetPrintTemplet(string path, out string errorInfo)
        {
            errorInfo = string.Empty;
            PrintItemModel        printItem    = null;
            ConttrolDataItemModel controlItem  = null;
            FunctionDataItemModel functionItem = null;
            PrintFactoryModel     reValue      = new PrintFactoryModel();
            List <PrintItemModel> printItems   = new List <PrintItemModel>();

            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(path);
                //基本信息获取
                XmlNodeList baseData = xmlDoc.SelectNodes("/Print");
                if (baseData.Count < 1)
                {
                    throw new Exception("无效的打印配置文件.");
                }
                foreach (XmlAttribute item in baseData[0].Attributes)
                {
                    CommonRule.SetPropertyValue(reValue, item.Name, item.Value);
                }
                //数据提取
                foreach (XmlNode item in xmlDoc.SelectNodes("/Print/PrintItem"))
                {
                    printItem = new PrintItemModel()
                    {
                    };
                    //打印属性
                    foreach (XmlAttribute attribute in item.Attributes)
                    {
                        CommonRule.SetPropertyValue(printItem, attribute.Name, attribute.Value);
                    }
                    //Control
                    XmlNodeList temp = item.SelectNodes("ConttrolDataSource");
                    if (temp != null && temp.Count > 0)
                    {
                        controlItem = new ConttrolDataItemModel();
                        foreach (XmlAttribute controlNode in temp[0].Attributes)
                        {
                            CommonRule.SetPropertyValue(controlItem, controlNode.Name, controlNode.Value);
                        }
                        printItem.ConttrolData = controlItem;
                    }
                    //Function
                    temp = item.SelectNodes("FunctionDataSource");
                    if (temp != null && temp.Count > 0)
                    {
                        functionItem = new FunctionDataItemModel();
                        foreach (XmlAttribute functionNode in temp[0].Attributes)
                        {
                            if (functionNode.Name.Equals("FunctionIndexs"))
                            {
                                if (!string.IsNullOrWhiteSpace(functionNode.Value))
                                {
                                    functionItem.FunctionIndexs        = CommonRule.ParseIndexs(functionNode.Value);
                                    functionItem.FunctionIndexsCaption = functionNode.Value;
                                }
                            }
                            else
                            {
                                CommonRule.SetPropertyValue(functionItem, functionNode.Name, functionNode.Value);
                            }
                        }
                        printItem.FunctionData = functionItem;
                    }
                    //Parameters
                    temp = item.SelectNodes("Parameters");
                    if (temp != null && temp.Count > 0)
                    {
                        //参数列表提取
                        if (temp[0].HasChildNodes)
                        {
                            ParameterModel p = null;
                            Dictionary <string, string> parameters = new Dictionary <string, string>();
                            foreach (XmlNode child in temp[0].ChildNodes)
                            {
                                p = new ParameterModel();
                                foreach (XmlAttribute childattribute in child.Attributes)
                                {
                                    CommonRule.SetPropertyValue(p, childattribute.Name, childattribute.Value);
                                }
                                parameters.Add(p.Key, p.Value);
                            }
                            printItem.Parameters = parameters;
                        }
                    }
                    printItems.Add(printItem);
                }
                reValue.PrintItems = printItems;
            }
            catch (Exception ex)
            {
                errorInfo = ex.Message;
                reValue   = null;
            }
            return(reValue);
        }
示例#5
0
 /// <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;
             }
         }
     }
 }