/// <summary> /// 命令行加载 /// </summary> /// <param name="fileName"></param> public void LoadInterfaceByCommonFileName(string fileName) { try { xmlPath = fileName; string errorInfo = string.Empty; PrintFactoryModel p = XmlHelper.GetPrintTemplet(fileName, out errorInfo); if (errorInfo != string.Empty) { System.Windows.MessageBox.Show(string.Format("获取配置文件失败:{0}", errorInfo)); xmlPath = string.Empty; return; } if (p.PrintItems == null) { System.Windows.MessageBox.Show(string.Format("未获取到有效打印条目.")); xmlPath = string.Empty; return; } CreateInterfaceByXML(p); } catch (Exception ex) { xmlPath = string.Empty; canvasSpace.Children.Clear(); System.Windows.MessageBox.Show(string.Format("打开异常:{0}", ex.Message)); } }
/// <summary> /// 获取界面打印信息 /// </summary> /// <returns></returns> public PrintFactoryModel GetPrintFactoryInfo() { string picturResource = string.Empty; //打印模板 PrintFactoryModel p = new PrintFactoryModel(); //打印条目 PrintItemModel printItemModel = null; //参数集合 Dictionary <string, string> parameters = null; //打印条目集合 List <PrintItemModel> printItems = new List <PrintItemModel>(); //工作台Width p.Width = Math.Floor(PrintLable.Width); //工作台heighht p.Height = Math.Floor(PrintLable.Height); //获取打印条目 foreach (UIElement item in canvasSpace.Children) { if (item is ContentControlBase) { ContentControlBase c = item as ContentControlBase; printItemModel = new PrintItemModel() { PrintCaption = c.PrintCaption, PrintFunctionName = c.PrintFunctionName, PrintKeyValue = c.PrintKeyValue, DataSourceType = c.DataSourceType, Index = c.Index, IsValid = c.IsValid, ConttrolData = c.ConttrolData, FunctionData = c.FunctionData, Width = c.Width.IsNaN() ? c.ActualWidth : c.Width, Height = c.Height.IsNaN() ? c.ActualHeight : c.Height }; if (c.Propertys != null && c.Propertys.Count > 0) { parameters = new Dictionary <string, string>(); foreach (PropertyModel pro in c.Propertys) { parameters.Add(pro.Name, (string)Convert.ChangeType(pro.Value, typeof(string))); } } printItemModel.Parameters = parameters; printItems.Add(printItemModel); if (item is PictureControl) { string fileName = System.IO.Path.GetFileName(c.PrintKeyValue); if (!picturResource.Contains(fileName)) { picturResource += string.Format("{0};", System.IO.Path.GetFileName(c.PrintKeyValue)); } } } } p.PicturResource = picturResource; p.PrintItems = printItems; return(p); }
public static void CommonStartPrint(FrameworkElement element, PrintFactoryModel commonPrintModel, string printFuntionNameSpace, string dataFuntionNameSpace, string printName, int printCount, int XDeviation, int YDeviation) { DeleteFilesByPath("TempImageConvertDirectory"); ParsePrintTempletInfo(element, commonPrintModel, printFuntionNameSpace, dataFuntionNameSpace, XDeviation, YDeviation); if (commonPrintHelper == null) { commonPrintHelper = new CommonPrintHelper(); } commonPrintHelper.StartPrint(commonPrintModel, printName, printCount); }
/// <summary> /// 配置文件换界面 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnOpen_Click(object sender, RoutedEventArgs e) { try { if (canvasSpace.Children.Count > 0 || xmlPath != string.Empty) { if (System.Windows.MessageBox.Show(string.Format("是否保存当前打印信息?"), "警告", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { if (string.IsNullOrWhiteSpace(xmlPath)) { My.SaveFileDialog saveFileDialog = new My.SaveFileDialog(); saveFileDialog.Filter = "All(*.xml)|*.xml"; if (saveFileDialog.ShowDialog() == My.DialogResult.OK) { xmlPath = saveFileDialog.FileName; } else { return; } } SaveInterfaceToXML(xmlPath); } } My.OpenFileDialog myDialog = new My.OpenFileDialog(); myDialog.Filter = "All(*.xml)|*.xml"; myDialog.CheckFileExists = true; myDialog.Multiselect = false; if (myDialog.ShowDialog() == My.DialogResult.OK) { xmlPath = myDialog.FileName; string errorInfo = string.Empty; PrintFactoryModel p = XmlHelper.GetPrintTemplet(xmlPath, out errorInfo); if (errorInfo != string.Empty) { System.Windows.MessageBox.Show(string.Format("获取配置文件失败:{0}", errorInfo)); xmlPath = string.Empty; return; } if (p.PrintItems == null) { System.Windows.MessageBox.Show(string.Format("未获取到有效打印条目.")); xmlPath = string.Empty; return; } CreateInterfaceByXML(p); } } catch (Exception ex) { canvasSpace.Children.Clear(); System.Windows.MessageBox.Show(string.Format("打开异常:{0}", ex.Message)); } }
private void btnLoadPrintConfig_Click(object sender, RoutedEventArgs e) { try { string errorInfo = string.Empty; if (string.IsNullOrWhiteSpace(configModel.DialogValue)) { MessageBox.Show("请选择配置模板."); return; } printTemplet = XmlHelper.GetPrintTemplet(configModel.DialogValue, out errorInfo); if (!string.IsNullOrWhiteSpace(errorInfo)) { MessageBox.Show(errorInfo); return; } //PES测试 //Dictionary<string,string> Values=new Dictionary<string,string>(); //Values.Add("Hello","41545454"); //Values.Add("World","World"); //PrintHelper.StartPrintForPES(Values, printTemplet.Clone(),"PrintStudioPrintFunction", "PrintStudioDataFunction", cbPrintName.SelectedValue.ToString(), int.Parse(txtQCNumber.Text), int.Parse(txtPrintX.Text), int.Parse(txtPrintY.Text)); //printTemplet.Clone()不行,因为主程序下无PrintFactoryModel的dll。因为Deserialize时,会在主程序下查找对应Model。 PrintFactoryModel p = printTemplet; p.PrintItems.ForEach(item => { item.PrintFunctionName = string.Format("{0}{1}", item.PrintFunctionName, (PrintClientType)(cbPrintType.SelectedItem)); }); if ((PrintClientType)(cbPrintType.SelectedItem) == PrintClientType.CommonPrinter) { PrintHelper.CommonStartPrint(this, p, "PrintStudioPrintFunction", "PrintStudioDataFunction", cbPrintName.SelectedValue.ToString(), int.Parse(txtQCNumber.Text), int.Parse(txtPrintX.Text), int.Parse(txtPrintY.Text)); } else if ((PrintClientType)(cbPrintType.SelectedItem) == PrintClientType.ZebraPrinter) { PrintHelper.ZebraStartPrint(this, p, "PrintStudioPrintFunction", "PrintStudioDataFunction", cbPrintName.SelectedValue.ToString(), int.Parse(txtQCNumber.Text), int.Parse(txtPrintX.Text), int.Parse(txtPrintY.Text)); } else if ((PrintClientType)(cbPrintType.SelectedItem) == PrintClientType.ZebraPrinter600) { PrintHelper.ZebraStartPrint(this, p, "PrintStudioPrintFunction", "PrintStudioDataFunction", cbPrintName.SelectedValue.ToString(), int.Parse(txtQCNumber.Text), int.Parse(txtPrintX.Text), int.Parse(txtPrintY.Text)); } else { PrintHelper.StartPrint(this, p, "PrintStudioPrintFunction", "PrintStudioDataFunction", cbPrintName.SelectedValue.ToString(), int.Parse(txtQCNumber.Text), int.Parse(txtPrintX.Text), int.Parse(txtPrintY.Text)); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// 开始打印 /// </summary> /// <param name="PrintItems"></param> /// <param name="printName"></param> /// <param name="printCount"></param> public void StartPrint(PrintFactoryModel printFactoryModel, string printName, int printCount) { if (printFactoryModel == null || printFactoryModel.PrintItems == null || printFactoryModel.PrintItems.Count < 1) { throw new Exception("打印条目集合不能为空."); } if (string.IsNullOrWhiteSpace(printName)) { throw new Exception("打印机名不能为空."); } if (printCount < 1) { throw new Exception("打印数量必须大于0."); } this.PrintFactory = printFactoryModel; this.PrintName = printName; this.PrintCount = printCount; this.Print(PrintName); }
/// <summary> /// 保存至XML /// </summary> private void SaveInterfaceToXML(string path) { try { PrintFactoryModel p = GetPrintFactoryInfo(); string reValue = XmlHelper.SavePrintTemplet(p, path); if (reValue != string.Empty) { System.Windows.MessageBox.Show(string.Format("保存失败:{0}", reValue)); } else { System.Windows.MessageBox.Show(string.Format("保存成功")); } } catch (Exception ex) { throw new Exception(string.Format("保存打印信息异常,{0}", ex.Message)); } }
/// <summary> /// 保存到配置文件 如果不希望出现写死的节点,如xmlDoc.CreateElement("Print"). /// 可创建一个基类,仅保存需要保存到配置文件的属性.可继承该基类,增加不需要保存到配置文件的属性. /// 保存时,仅保存基类的属性即可.当然遇到复杂类型属性,可能还是需要特殊处理哦. /// 可根据pi.PropertyType判断是否为基本类型,如果是基本类型就可以进行保存,如果是复杂类型就需要根据不同的Type /// 进行特殊处理 /// </summary> /// <param name="p"></param> /// <returns></returns> public static string SavePrintTemplet(PrintFactoryModel p, string path) { string reValue = string.Empty; XmlDocument xmlDoc = new XmlDocument(); XmlDeclaration Declaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null); XmlAttribute attribute = null; XmlNode configurationNode = xmlDoc.CreateElement("Print"); attribute = xmlDoc.CreateAttribute("Width"); attribute.Value = p.Width.ToString(); configurationNode.Attributes.Append(attribute); attribute = xmlDoc.CreateAttribute("Height"); attribute.Value = p.Height.ToString(); configurationNode.Attributes.Append(attribute); attribute = xmlDoc.CreateAttribute("PicturResource"); attribute.Value = p.PicturResource.ToString(); configurationNode.Attributes.Append(attribute); foreach (PrintItemModel item in p.PrintItems) { XmlNode printItem = xmlDoc.CreateElement("PrintItem"); attribute = xmlDoc.CreateAttribute("PrintCaption"); attribute.Value = item.PrintCaption; printItem.Attributes.Append(attribute); attribute = xmlDoc.CreateAttribute("PrintFunctionName"); attribute.Value = item.PrintFunctionName; printItem.Attributes.Append(attribute); attribute = xmlDoc.CreateAttribute("PrintKeyValue"); attribute.Value = item.PrintKeyValue; printItem.Attributes.Append(attribute); attribute = xmlDoc.CreateAttribute("DataSourceType"); attribute.Value = item.DataSourceType.ToString(); printItem.Attributes.Append(attribute); attribute = xmlDoc.CreateAttribute("Index"); attribute.Value = item.Index.ToString(); printItem.Attributes.Append(attribute); attribute = xmlDoc.CreateAttribute("IsValid"); attribute.Value = item.IsValid.ToString(); printItem.Attributes.Append(attribute); attribute = xmlDoc.CreateAttribute("Width"); attribute.Value = item.Width.ToString(); printItem.Attributes.Append(attribute); attribute = xmlDoc.CreateAttribute("Height"); attribute.Value = item.Height.ToString(); printItem.Attributes.Append(attribute); XmlNode conttrolDataSource = xmlDoc.CreateElement("ConttrolDataSource"); if (item.ConttrolData == null) { item.ConttrolData = new ConttrolDataItemModel(); } attribute = xmlDoc.CreateAttribute("ValueContainer"); attribute.Value = item.ConttrolData.ValueContainer; conttrolDataSource.Attributes.Append(attribute); attribute = xmlDoc.CreateAttribute("ControlName"); attribute.Value = item.ConttrolData.ControlName; conttrolDataSource.Attributes.Append(attribute); attribute = xmlDoc.CreateAttribute("ControlCaption"); attribute.Value = item.ConttrolData.ControlCaption; conttrolDataSource.Attributes.Append(attribute); attribute = xmlDoc.CreateAttribute("PropertyName"); attribute.Value = item.ConttrolData.PropertyName; conttrolDataSource.Attributes.Append(attribute); attribute = xmlDoc.CreateAttribute("ChildPropertyName"); attribute.Value = item.ConttrolData.ChildPropertyName; conttrolDataSource.Attributes.Append(attribute); XmlNode functionDataSource = xmlDoc.CreateElement("FunctionDataSource"); if (item.FunctionData == null) { item.FunctionData = new FunctionDataItemModel(); } attribute = xmlDoc.CreateAttribute("ValueContainer"); attribute.Value = item.FunctionData.ValueContainer; functionDataSource.Attributes.Append(attribute); attribute = xmlDoc.CreateAttribute("FunctionName"); attribute.Value = item.FunctionData.FunctionName; functionDataSource.Attributes.Append(attribute); attribute = xmlDoc.CreateAttribute("FunctionIndexs"); attribute.Value = item.FunctionData.FunctionIndexsCaption; functionDataSource.Attributes.Append(attribute); attribute = xmlDoc.CreateAttribute("RandomLength"); attribute.Value = item.FunctionData.RandomLength.ToString(); functionDataSource.Attributes.Append(attribute); attribute = xmlDoc.CreateAttribute("RandomType"); attribute.Value = item.FunctionData.RandomType.ToString(); functionDataSource.Attributes.Append(attribute); attribute = xmlDoc.CreateAttribute("IsHeadMontage"); attribute.Value = item.FunctionData.IsHeadMontage.ToString(); functionDataSource.Attributes.Append(attribute); attribute = xmlDoc.CreateAttribute("MontageLength"); attribute.Value = item.FunctionData.MontageLength.ToString(); functionDataSource.Attributes.Append(attribute); XmlNode parameters = xmlDoc.CreateElement("Parameters"); if (item.Parameters != null) { foreach (KeyValuePair <string, string> ky in item.Parameters) { XmlNode Parameter = xmlDoc.CreateElement("Parameter"); attribute = xmlDoc.CreateAttribute("Key"); attribute.Value = ky.Key; Parameter.Attributes.Append(attribute); attribute = xmlDoc.CreateAttribute("Value"); attribute.Value = ky.Value; Parameter.Attributes.Append(attribute); parameters.AppendChild(Parameter); } } printItem.AppendChild(conttrolDataSource); printItem.AppendChild(functionDataSource); printItem.AppendChild(parameters); configurationNode.AppendChild(printItem); } xmlDoc.AppendChild(configurationNode); xmlDoc.InsertBefore(Declaration, xmlDoc.DocumentElement); xmlDoc.Save(path); return(reValue); }
/// <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); }
/// <summary> /// XML创建界面 /// </summary> /// <param name="p"></param> private void CreateInterfaceByXML(PrintFactoryModel p) { //清空界面 canvasSpace.Children.Clear(); ZoomableCanvasScale = 4; PrintLable.Width = p.Width; PrintLable.Height = p.Height; UpdateScale(ScaleList[ZoomableCanvasScale], PrintLable.Width, PrintLable.Height); tbScale.Text = string.Format("{0}*", ScaleList[ZoomableCanvasScale]); foreach (PrintItemModel item in p.PrintItems) { switch (item.PrintFunctionName) { case "PrintBarcode": { BarCodeControl b = new BarCodeControl(); UpdatePrintControlData(item, b); PropertyModel o = GetPropertyItemByName(b.Propertys, "pDirec"); RotateTransform r = (RotateTransform)b.RenderTransform; if (r != null) { r.CenterX = b.Width / 2; r.CenterY = b.Height / 2; r.Angle = (int)Convert.ChangeType(o.Value, typeof(int)) * 90; } canvasSpace.Children.Add(b); break; } case "PrintTextWorld": { TextWorldControl b = new TextWorldControl(); UpdatePrintControlData(item, b); PropertyModel o = GetPropertyItemByName(b.Propertys, "fSpin"); RotateTransform r = (RotateTransform)b.RenderTransform; if (r != null) { int flag = (int)Convert.ChangeType(o.Value, typeof(int)); if (flag < 5) { r.CenterX = 0; r.CenterY = b.Height / 2; r.Angle = (flag - 1) * 90; } else { r.CenterX = b.Width / 2; r.CenterY = b.Height / 2; r.Angle = (flag - 5) * 90; } } canvasSpace.Children.Add(b); break; } case "PrintPCX": { PictureControl b = new PictureControl(); UpdatePrintControlData(item, b, false); canvasSpace.Children.Add(b); break; } case "PrintRectangle": { RectangleControl b = new RectangleControl(); UpdatePrintControlData(item, b); PropertyModel thickness = GetPropertyItemByName(b.Propertys, "thickness"); if (thickness != null) { Rectangle d = b.Content as Rectangle; if (d != null) { d.StrokeThickness = (double)Convert.ChangeType(thickness.Value, typeof(double)); } } canvasSpace.Children.Add(b); break; } case "PrintLineOr": { LineOrControl b = new LineOrControl(); UpdatePrintControlData(item, b); canvasSpace.Children.Add(b); break; } case "PrintBar2DQR": { Bar2DQRControl b = new Bar2DQRControl(); UpdatePrintControlData(item, b); b.MaxWidth = b.Width = b.MaxHeight = b.Height = item.Width; PropertyModel temp = b.Propertys.FirstOrDefault(x => { return(x.Name == "r"); }); if (temp != null) { b.CurrentEnlarge = (int)Convert.ChangeType(temp.Value, typeof(int)); } PropertyModel o = GetPropertyItemByName(b.Propertys, "o"); RotateTransform r = (RotateTransform)b.RenderTransform; if (r != null) { r.CenterX = b.Width / 2; r.CenterY = b.Height / 2; r.Angle = (int)Convert.ChangeType(o.Value, typeof(int)) * 90; } canvasSpace.Children.Add(b); break; } } } }
/// <summary> /// 通用打印For PES /// </summary> /// <param name="parameters"></param> /// <param name="commonPrintModel"></param> /// <param name="printFuntionNameSpace"></param> /// <param name="dataFuntionNameSpace"></param> /// <param name="printName"></param> /// <param name="printCount"></param> /// <param name="XDeviation"></param> /// <param name="YDeviation"></param> public static void CommonStartPrintForPES(Dictionary <string, string> parameters, PrintFactoryModel commonPrintModel, string printFuntionNameSpace, string dataFuntionNameSpace, string printName, int printCount, int XDeviation, int YDeviation) { DeleteFilesByPath("TempImageConvertDirectory"); ParsePrintTempletInforForPES(parameters, commonPrintModel, printFuntionNameSpace, dataFuntionNameSpace, XDeviation, YDeviation); if (commonPrintHelper == null) { commonPrintHelper = new CommonPrintHelper(); } commonPrintHelper.StartPrint(commonPrintModel, printName, printCount); }
/// <summary> /// 斑马打印 /// </summary> /// <param name="element"></param> /// <param name="commonPrintModel"></param> /// <param name="printFuntionNameSpace"></param> /// <param name="dataFuntionNameSpace"></param> /// <param name="printName"></param> /// <param name="printCount"></param> /// <param name="XDeviation"></param> /// <param name="YDeviation"></param> public static void ZebraStartPrint(FrameworkElement element, PrintFactoryModel commonPrintModel, string printFuntionNameSpace, string dataFuntionNameSpace, string printName, int printCount, int XDeviation, int YDeviation) { DeleteFilesByPath("TempImageConvertDirectory"); ParsePrintTempletInfo(element, commonPrintModel, printFuntionNameSpace, dataFuntionNameSpace, XDeviation, YDeviation); ZebraStartPrint(commonPrintModel.PrintItems, printName, printCount); }
/// <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; } } } }
/// <summary> /// 斑马打印 /// </summary> /// <param name="parameters"></param> /// <param name="commonPrintModel"></param> /// <param name="printFuntionNameSpace"></param> /// <param name="dataFuntionNameSpace"></param> /// <param name="printName"></param> /// <param name="printCount"></param> /// <param name="XDeviation"></param> /// <param name="YDeviation"></param> public static void ZebraStartPrintForPES(Dictionary <string, string> parameters, PrintFactoryModel commonPrintModel, string printFuntionNameSpace, string dataFuntionNameSpace, string printName, int printCount, int XDeviation, int YDeviation) { DeleteFilesByPath("TempImageConvertDirectory"); ParsePrintTempletInforForPES(parameters, commonPrintModel, printFuntionNameSpace, dataFuntionNameSpace, XDeviation, YDeviation); ZebraStartPrint(commonPrintModel.PrintItems, printName, printCount); }
/// <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; } } } }