Пример #1
0
        public static void QuitePrint(string layoutPath, string printername, string dataPath)
        {
            string tempdir = Helper.UnitHelper.GetTemplateFolderName();

            Helper.UnitHelper.UnArchiveFiles(layoutPath, tempdir);
            var doc = new System.Xml.XmlDocument();

            doc.Load(System.IO.Path.Combine(tempdir, "layout.xml"));
            var canvas = new wCanvas(doc);
            var pt     = new Helper.PrintHelper(printername, Helper.PrintHelper.DisplayToMm(canvas.Width), Helper.PrintHelper.DisplayToMm(canvas.Height));

            pt.Canvas = canvas;
            pt.Data   = Helper.ExcelHelper.ExcelToTemplateData(dataPath, "Sheet1");

            var CFG = Helper.CommandHelper.Configs;

            if (CFG.ContainsKey("print-offset"))
            {
                var printoffset = CFG["print-offset"].Split("x".ToCharArray());
                pt.OffsetMm = new PointF(float.Parse(printoffset[0]), float.Parse(printoffset[1]));
            }
//			pt.OffsetMm=new PointF(-27,-3);
//			pt.PrinterSettings.PrintToFile=true;
//			pt.PrinterSettings.PrintFileName=@"C:\Users\0115289\Desktop\N7RNAN1LOG00003_0115289.pdf";

            pt.Print();
            pt.Dispose();
            doc = null;
            System.IO.Directory.Delete(tempdir, true);
        }
Пример #2
0
        public void ConvertFile()
        {
//			return;
            var dds = System.IO.Directory.GetDirectories(@"C:\Users\0115289\Documents\SharpDevelop Projects\SpoonSystem\TemplatePrint\bin\Debug\templates");

            foreach (var ds in dds)
            {
                foreach (var f in System.IO.Directory.GetFiles(ds, "*.xml"))
                {
//					System.Diagnostics.Debug.WriteLine(f);
                    if (System.IO.Path.GetExtension(f) != ".xml")
                    {
                        continue;
                    }
                    var olddoc = new System.Xml.XmlDocument();

                    olddoc.Load(f);

                    var     doc    = Helper.XmlHelper.NewDocment();
                    wCanvas canvas = new wCanvas();
                    canvas.Author = "Elder Yao";

                    var size = olddoc.SelectSingleNode("/layout/size");
                    canvas.Size = new System.Drawing.Size(int.Parse(size.Attributes["width"].Value), int.Parse(size.Attributes["height"].Value));

                    var background = olddoc.SelectSingleNode("/layout/background");
                    canvas.BackgroundPath = @"C:\Users\0115289\Documents\SharpDevelop Projects\SpoonSystem\TemplatePrint\bin\Debug\" + background.Attributes["path"].Value;
                    var ss = float.Parse(background.Attributes["scale"].Value);
                    canvas.BackgroundRect = new Rectangle(0, 0, (int)(canvas.BackgroundImage.Width * ss), (int)(canvas.BackgroundImage.Height * ss));

                    foreach (System.Xml.XmlNode item in olddoc.SelectSingleNode("/layout/items").ChildNodes)
                    {
                        var lbl = new Controls.wLabel();
                        lbl.ShowBorder = false;
                        lbl.Name       = item.Attributes["name"].Value;
                        lbl.Text       = item.Attributes["value"].Value;
                        lbl.Rectangle  = new System.Drawing.Rectangle(
                            int.Parse(item.Attributes["left"].Value),
                            int.Parse(item.Attributes["top"].Value),
                            int.Parse(item.Attributes["width"].Value),
                            int.Parse(item.Attributes["height"].Value)
                            );
                        var fc = new System.Drawing.FontConverter();
                        lbl.Font = fc.ConvertFromString(item.Attributes["font"].Value) as System.Drawing.Font;

//						lbl.ShowBorder = true;
                        canvas.Controls.Add(lbl);
                    }

                    doc.AppendChild(canvas.ToXml(doc));
//					doc.Save(f + "x");

                    Helper.UnitHelper.ArchiveFiles(doc, f.Replace(".xml", ".bg"));
                }
            }
            System.Diagnostics.Debug.WriteLine("OK");
        }
Пример #3
0
        /// <summary>
        /// 使用JSON数据文件打印
        /// </summary>
        /// <param name="layoutPath"></param>
        /// <param name="printername"></param>
        /// <param name="jsonFile"></param>
        public static void QuitePrintJson(string layoutPath, string printername, string jsonFile)
        {
            string tempdir = Helper.UnitHelper.GetTemplateFolderName();

            Helper.UnitHelper.UnArchiveFiles(layoutPath, tempdir);
            var doc = new System.Xml.XmlDocument();

            doc.Load(System.IO.Path.Combine(tempdir, "layout.xml"));
            var canvas = new wCanvas(doc);
            var pt     = new Helper.PrintHelper(printername, Helper.PrintHelper.DisplayToMm((int)(canvas.SizeF.Width * 100)) / 100.0F, Helper.PrintHelper.DisplayToMm((int)(canvas.SizeF.Height * 100)) / 100.0F);

            pt.Canvas = canvas;

            //以下代码用于支持Demon生成Json
            var bs         = System.IO.File.ReadAllBytes(jsonFile);
            var jsonString = System.Text.Encoding.GetEncoding("gb2312").GetString(bs);

            pt.JsonData = Newtonsoft.Json.Linq.JObject.Parse(jsonString)["data"] as Newtonsoft.Json.Linq.JArray;

            ////默认方式
            //var jo = Newtonsoft.Json.Linq.JObject.Parse(System.IO.File.ReadAllText(jsonFile));
            //pt.JsonData = jo["data"] as Newtonsoft.Json.Linq.JArray;

            var CFG = Helper.CommandHelper.Configs;

            if (CFG.ContainsKey("print-offset"))
            {
                var printoffset = CFG["print-offset"].Split("x".ToCharArray());
                pt.OffsetMm = new PointF(float.Parse(printoffset[0]), float.Parse(printoffset[1]));
            }

            if (CFG.ContainsKey("pdf"))
            {
                pt.PrintToPDF    = bool.Parse(CFG["pdf"]);
                pt.PrintFileName = CFG["outfile"];
                pt.PrinterSettings.PrintToFile = true;
                pt.PrintPDF();
            }
            else
            {
                pt.Print();
            }
            //			pt.OffsetMm=new PointF(-27,-3);
            //			pt.PrinterSettings.PrintToFile=true;
            //			pt.PrinterSettings.PrintFileName=@"C:\Users\0115289\Desktop\N7RNAN1LOG00003_0115289.pdf";

            pt.Dispose();
            doc = null;
            System.IO.Directory.Delete(tempdir, true);
        }
Пример #4
0
        public void Convert()
        {
            var olddoc = new System.Xml.XmlDocument();

            olddoc.Load(@"C:\Users\0115289\Documents\SharpDevelop Projects\SpoonSystem\TemplatePrint\bin\Debug\templates\1. 顺丰\sf.xml");

            var     doc    = Helper.XmlHelper.NewDocment();
            wCanvas canvas = new wCanvas();

            canvas.Author = "Elder Yao";

            var size = olddoc.SelectSingleNode("/layout/size");

            canvas.Size = new System.Drawing.Size(int.Parse(size.Attributes["width"].Value), int.Parse(size.Attributes["height"].Value));

            var background = olddoc.SelectSingleNode("/layout/background");

            canvas.BackgroundPath  = background.Attributes["path"].Value;
            canvas.BackgroundScale = float.Parse(background.Attributes["scale"].Value);

            foreach (System.Xml.XmlNode item in olddoc.SelectSingleNode("/layout/items").ChildNodes)
            {
                var lbl = new Controls.wLabel();
                lbl.Name      = item.Attributes["name"].Value;
                lbl.Text      = item.Attributes["value"].Value;
                lbl.Rectangle = new System.Drawing.Rectangle(
                    int.Parse(item.Attributes["left"].Value),
                    int.Parse(item.Attributes["top"].Value),
                    int.Parse(item.Attributes["width"].Value),
                    int.Parse(item.Attributes["height"].Value)
                    );
                var fc = new System.Drawing.FontConverter();
                lbl.Font = fc.ConvertFromString(item.Attributes["font"].Value) as System.Drawing.Font;

                lbl.ShowBorder = false;
                canvas.Controls.Add(lbl);
            }

            doc.AppendChild(canvas.ToXml(doc));
            doc.Save(@"C:\Users\0115289\Documents\SharpDevelop Projects\SpoonSystem\TemplatePrint\bin\Debug\templates\1. 顺丰\sf.xmlx");
        }
Пример #5
0
 public wCanvasEditer(wCanvas control)
 {
     InitializeComponent();
     Control = control;
 }