public void ToXML()
        {
            _VM_Template.PrintIiemList.Clear();
            XmlDocument Xmls = new XmlDocument();

            Xmls.LoadXml(_SlipModel.SlipTemplate);
            XmlNode nodes = Xmls.SelectSingleNode("Print");

            if (nodes.ChildNodes[0].InnerText == "    #SeatNo#")
            {
                for (int i = 0; i < 8; i++)
                {
                    nodes.RemoveChild(nodes.ChildNodes[0]);
                }
                //_IsOldType = true;
            }
            else
            {
                //_IsOldType = false;
            }

            nodes.RemoveChild(nodes.ChildNodes[nodes.ChildNodes.Count - 1]);
            foreach (XmlNode xmln in nodes.ChildNodes)
            {
                ViewModel.ViewModelPrintItem ss = new ViewModelPrintItem();
                switch (xmln.LocalName)
                {
                case "Content":
                    ss.FontSize = Convert.ToInt32(xmln.Attributes["size"].Value);
                    ss.TextInfo = xmln.InnerText;
                    ss.IsItalic = xmln.Attributes["italic"].Value;
                    ss.IsBold   = xmln.Attributes["bold"].Value;
                    break;

                case "Pic":
                    Image  img = imageLocation(xmln.InnerText);
                    string url = string.Format(@"{0}temp\{1}", AppDomain.CurrentDomain.BaseDirectory, xmln.InnerText);
                    ss.IsImage   = true;
                    ss.ImageInfo = new System.Windows.Media.Imaging.BitmapImage(new Uri(url, UriKind.RelativeOrAbsolute));
                    break;

                default:
                    break;
                }
                //滚动logo图片
                Image  Logo    = imageLocation(_SlipModel.ImageUrl);
                string logourl = string.Format(@"{0}temp\{1}", AppDomain.CurrentDomain.BaseDirectory, _SlipModel.ImageUrl);
                _LogoImageInfo = new System.Windows.Media.Imaging.BitmapImage(new Uri(logourl, UriKind.RelativeOrAbsolute));
                //客户图片
                Image  KH    = imageLocation(_SlipModel.ImageUrl);
                string KHurl = string.Format(@"{0}temp\{1}", AppDomain.CurrentDomain.BaseDirectory, _SlipModel.ImageUrl);
                _PrintWindowImageInfo = new System.Windows.Media.Imaging.BitmapImage(new Uri(KHurl, UriKind.RelativeOrAbsolute));

                _VM_Template.PrintIiemList.Add(ss);
            }
            OnPropertyChanged("VM_Template");
        }
        /// <summary>
        /// 插入项目
        /// </summary>
        /// <param name="index"></param>
        public void InsertItem(ViewModelPrintItem item, int index)
        {
            string functionName = "InsertItem";

            try
            {
                item.TemplateNo = TemplateNo;
                PrintIiemList.Insert(index, item);
            }
            catch (AMS.Model.CustomerException ex)
            {
                ErrorMessage = string.Format("{0} 出自{1}.{2}", ex.Message, ex.ErrorSourcesClass, ex.ErrorSourcesFunction);
            }
            catch (Exception ex)
            {
                ErrorMessage = string.Format("{0} 出自{1}.{2}", ex.Message, CLASSNAME, functionName);
            }
        }
        /// <summary>
        /// 添加图片
        /// </summary>
        public ViewModelPrintItem AddImage(string imagePath)
        {
            string functionName = "AddImage";

            try
            {
                ViewModelPrintItem item = new ViewModelPrintItem();
                item.IsImage   = true;
                item.ImageInfo = new BitmapImage(new Uri(imagePath, UriKind.RelativeOrAbsolute));
                return(item);
            }
            catch (AMS.Model.CustomerException ex)
            {
                ErrorMessage = string.Format("{0} 出自{1}.{2}", ex.Message, ex.ErrorSourcesClass, ex.ErrorSourcesFunction);
                return(new ViewModelPrintItem());
            }
            catch (Exception ex)
            {
                ErrorMessage = string.Format("{0} 出自{1}.{2}", ex.Message, CLASSNAME, functionName);
                return(new ViewModelPrintItem());
            }
        }
Esempio n. 4
0
 public void ToViewModel()
 {
     TemplateItem.PrintIiemList.Clear();
     foreach (Model.PrintItem item in PrintReceiptModel.TemplateItem)
     {
         ViewModelPrintItem viewmodel = new ViewModelPrintItem();
         viewmodel.IsImage = item.IsImage;
         if (viewmodel.IsImage)
         {
             viewmodel.ImageInfo = ImageSaveLocation(item.ImagePath);
         }
         else
         {
             viewmodel.FontSize = item.FontSize;
             viewmodel.IsBold   = item.IsBold ? "Bold" : "Normal";
             viewmodel.IsItalic = item.IsItalic ? "Italic" : "Normal";
             viewmodel.IsImage  = item.IsImage;
             viewmodel.TextInfo = item.TextInfo;
         }
         TemplateItem.PrintIiemList.Add(viewmodel);
     }
 }