Beispiel #1
0
 public void PrintParseFuntion(PrintItemModel printItem, object other = null)
 {
     try
     {
         int r = PrintRuleBase.GetPrintParameterByName <int>(printItem, "r", this.GetType().Name) * 2;
         r = r > 9 ? 9 : r;
         PrintRuleBase.PTK_DrawBar2D_QR
         (
             (PrintRuleBase.GetPrintParameterByName <int>(printItem, "pX", this.GetType().Name) + printItem.XDeviation) * 2,
             (PrintRuleBase.GetPrintParameterByName <int>(printItem, "pY", this.GetType().Name) + printItem.YDeviation) * 2,
             (PrintRuleBase.GetPrintParameterByName <int>(printItem, "w", this.GetType().Name)),
             (PrintRuleBase.GetPrintParameterByName <int>(printItem, "v", this.GetType().Name)),
             PrintRuleBase.GetPrintParameterByName <int>(printItem, "o", this.GetType().Name),
             r,
             PrintRuleBase.GetPrintParameterByName <int>(printItem, "m", this.GetType().Name),
             PrintRuleBase.GetPrintParameterByName <int>(printItem, "g", this.GetType().Name),
             PrintRuleBase.GetPrintParameterByName <int>(printItem, "s", this.GetType().Name),
             printItem.PrintKeyValue
         );
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("打印{0}异常:{1}", this.GetType().Name, ex.Message));
     }
 }
Beispiel #2
0
 public void PrintParseFuntion(PrintItemModel printItem, object other = null)
 {
     try
     {
         Graphics g = (Graphics)other;
         //这里无法精细化绘制一维码,是抛弃该打印方式的的主要原因.
         //如果说有更好的、高还原的一维码生成解决方案便可采纳.
         //但依然存在着如进纸的精准性控制、效果细微差别、条码长度不可控等问题.
         //CODE_128不支持中文字符,这里的值如果是中文,将会抛出异常.
         Bitmap img = BarCodeHelper.CreateBarCode(printItem.PrintKeyValue, BarcodeFormat.CODE_128, new EncodingOptions()
         {
             Height = (PrintRuleBase.GetPrintParameterByName <int>(printItem, "pHeight", this.GetType().Name)) / 3, PureBarcode = true, Margin = 0
         });
         g.DrawImageUnscaled
         (
             img,
             (int)(PrintRuleBase.GetPrintParameterByName <int>(printItem, "pX", this.GetType().Name) + printItem.XDeviation) / 3,
             (int)(PrintRuleBase.GetPrintParameterByName <int>(printItem, "pY", this.GetType().Name) + printItem.YDeviation) / 3
         );
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("打印{0}异常:{1}", this.GetType().Name, ex.Message));
     }
 }
Beispiel #3
0
 public void PrintParseFuntion(PrintItemModel printItem, object other = null)
 {
     try
     {
         Graphics g = (Graphics)other;
         if (!File.Exists(printItem.PrintKeyValue))
         {
             throw new Exception(string.Format("未发现图片资源{0}.", printItem.PrintKeyValue));
         }
         Bitmap img = ImageHelper.LoadImageFormFreeImage(PrintRuleBase.GetPrintParameterByName <string>(printItem, "PrintKeyValue", this.GetType().Name));
         //如果是绘制原始图DrawImageUnscaled,不同图片即使Width、Height同,Graphics呈现效果也可能不一样.这与图片数据结构及Graphics呈现有关.
         //这里使用绝对长、宽.是界面呈现大小的1/3.
         //这里的PrintFactory.Width就是目前300点打印机的dot数
         //1dot=25.4/300 mm
         //1print=25.4/100 mm
         //先将dot转mm 再将mm转print
         g.DrawImage
         (
             img,
             (PrintRuleBase.GetPrintParameterByName <int>(printItem, "pX", this.GetType().Name) + printItem.XDeviation) / 3,
             (PrintRuleBase.GetPrintParameterByName <int>(printItem, "pY", this.GetType().Name) + printItem.YDeviation) / 3,
             (float)printItem.Width / 3,
             (float)printItem.Height / 3
         );
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("打印{0}异常:{1}", this.GetType().Name, ex.Message));
     }
 }
Beispiel #4
0
        public string DataParseFuntion(List <PrintItemModel> templetModels, List <int> indexs)
        {
            try
            {
                if (indexs == null || indexs.Count < 1)
                {
                    throw new Exception(string.Format("请正确设置数据条目中使用FunctionName=\"{0}\"的ProviderIndexs值.", this.GetType().Name));
                }
                string reValue = string.Empty;
                int    index   = indexs[0];

                PrintItemModel temp = templetModels.FirstOrDefault(p =>
                {
                    return(p.Index == index);
                });
                if (temp == null)
                {
                    throw new Exception(string.Format("未查询到Index={0}的打印条目", index));
                }

                return(reValue = RandomStringHelper.GetRandomString(temp.FunctionData.RandomType, temp.FunctionData.RandomLength));
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("执行{0}异常:{1}", this.GetType().Name, ex.Message));
            }
        }
 public void PrintParseFuntion(PrintItemModel printItem, object other = null)
 {
     try
     {
         if (!File.Exists(printItem.PrintKeyValue))
         {
             throw new Exception(string.Format("未发现图片资源{0}.", printItem.PrintKeyValue));
         }
         string format = Path.GetExtension(printItem.PrintKeyValue);
         if (!format.ToUpper().Equals(".PCX"))
         {
             string desPath0 = string.Format("{0}\\{1}\\{2}{3}", AppDomain.CurrentDomain.BaseDirectory, "TempImageConvertDirectory", Guid.NewGuid(), ".pcx");
             ImageHelper.ChangeFormat(printItem.PrintKeyValue, desPath0, 144);
             printItem.PrintKeyValue = desPath0;
         }
         string desPath = string.Format("{0}\\{1}\\{2}{3}", AppDomain.CurrentDomain.BaseDirectory, "TempImageConvertDirectory", Guid.NewGuid(), ".pcx");
         ImageHelper.Resize(printItem.PrintKeyValue, desPath, (double)2 / 3);
         printItem.PrintKeyValue = desPath;
         PrintRuleBase.PTK_PrintPCX
         (
             (PrintRuleBase.GetPrintParameterByName <int>(printItem, "pX", this.GetType().Name) + printItem.XDeviation) * 2 / 3,
             (PrintRuleBase.GetPrintParameterByName <int>(printItem, "pY", this.GetType().Name) + printItem.YDeviation) * 2 / 3,
             printItem.PrintKeyValue
         );
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("打印{0}异常:{1}", this.GetType().Name, ex.Message));
     }
 }
Beispiel #6
0
        private void UpdatePrintControlData(PrintItemModel p, ContentControlBase c)
        {
            List <PropertyModel> Propertys = new List <PropertyModel>();

            if (p.Parameters != null)
            {
                foreach (KeyValuePair <string, string> item in p.Parameters)
                {
                    PropertyModel temp = c.Propertys.FirstOrDefault(x => { return(x.Name == item.Key); });
                    if (temp != null)
                    {
                        temp.Value = item.Value;
                    }
                    if (temp.Name == "pX")
                    {
                        Canvas.SetLeft(c, (double)Convert.ChangeType(temp.Value, typeof(double)));
                    }
                    else if (temp.Name == "pY")
                    {
                        Canvas.SetTop(c, (double)Convert.ChangeType(temp.Value, typeof(double)));
                    }
                }
            }
            c.FunctionData   = p.FunctionData;
            c.ConttrolData   = p.ConttrolData;
            c.PrintKeyValue  = p.PrintKeyValue;
            c.DataSourceType = p.DataSourceType;
            c.Index          = p.Index;
            c.IsValid        = p.IsValid;
            c.Width          = p.Width;
            c.Height         = p.Height;
            AddPrinControlEventHandle(c);
        }
Beispiel #7
0
 public void PrintParseFuntion(PrintItemModel printItem, object other = null)
 {
     try
     {
         string flag = Guid.NewGuid().ToString();
         flag = flag.Substring(flag.LastIndexOf("-") + 1);
         PrintRuleBase.PTK_DrawTextTrueTypeW
         (
             PrintRuleBase.GetPrintParameterByName <int>(printItem, "pX", this.GetType().Name) + printItem.XDeviation,
             PrintRuleBase.GetPrintParameterByName <int>(printItem, "pY", this.GetType().Name) + printItem.YDeviation,
             PrintRuleBase.GetPrintParameterByName <int>(printItem, "pHeight", this.GetType().Name),
             PrintRuleBase.GetPrintParameterByName <int>(printItem, "fWidth", this.GetType().Name),
             PrintRuleBase.GetPrintParameterByName <string>(printItem, "fType", this.GetType().Name),
             PrintRuleBase.GetPrintParameterByName <int>(printItem, "fSpin", this.GetType().Name),
             PrintRuleBase.GetPrintParameterByName <int>(printItem, "fWeight", this.GetType().Name),
             PrintRuleBase.GetPrintParameterByName <int>(printItem, "fItalic", this.GetType().Name),
             PrintRuleBase.GetPrintParameterByName <int>(printItem, "fUnline", this.GetType().Name),
             PrintRuleBase.GetPrintParameterByName <int>(printItem, "fStrikeOut", this.GetType().Name),
             flag,
             printItem.PrintKeyValue
         );
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("打印{0}异常:{1}", this.GetType().Name, ex.Message));
     }
 }
Beispiel #8
0
        public void PrintParseFuntion(PrintItemModel printItem, object other = null)
        {
            try
            {
                if (!File.Exists(printItem.PrintKeyValue))
                {
                    throw new Exception(string.Format("未发现图片资源{0}.", printItem.PrintKeyValue));
                }

                //PrintRuleBase.PTK_BinGraphicsDel("*");
                //PrintRuleBase.PTK_PcxGraphicsDownload(Path.GetFileName(printItem.PrintKeyValue), printItem.PrintKeyValue);
                //PrintRuleBase.PTK_DrawPcxGraphics(
                //                                    PrintRuleBase.GetPrintParameterByName<int>(printItem, "pX", this.GetType().Name) + printItem.XDeviation,
                //                                    PrintRuleBase.GetPrintParameterByName<int>(printItem, "pY", this.GetType().Name) + printItem.YDeviation,
                //                                    Path.GetFileName(printItem.PrintKeyValue));
                PrintRuleBase.PTK_PrintPCX
                (
                    PrintRuleBase.GetPrintParameterByName <int>(printItem, "pX", this.GetType().Name) + printItem.XDeviation,
                    PrintRuleBase.GetPrintParameterByName <int>(printItem, "pY", this.GetType().Name) + printItem.YDeviation,
                    printItem.PrintKeyValue
                );
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("打印{0}异常:{1}", this.GetType().Name, ex.Message));
            }
        }
 public void PrintParseFuntion(PrintItemModel printItem, object other = null)
 {
     try
     {
         Graphics g = (Graphics)other;
         //1像素的大小是不确定的.图像大小400*500,表示长400个像素单位,宽500个像素单位.不同分辨率的设备像素单位大小不一样,因此图像显示得有大有小.
         //创建出的图像最小都是 21*21个像素点
         //300点打印机和Graphics像素单位长度之比为1:3(1像素单位长度固定).
         //Bitmap的Width为像素点个数,因此在绘制二维码时,用printItem.Width / 3弥补素单位长度之比造成的图像放大.
         //即printItem.Width为300点打印机像素点个数,printItem.Width / 3为转化后对应在的Graphics中像素点个数.
         Bitmap img = BarCodeHelper.CreateBarCode(printItem.PrintKeyValue, BarcodeFormat.QR_CODE, new EncodingOptions()
         {
             Width = (int)printItem.Width / 3, Height = (int)printItem.Height / 3, PureBarcode = true, Margin = 0
         });
         g.DrawImageUnscaled
         (
             img,
             (PrintRuleBase.GetPrintParameterByName <int>(printItem, "pX", this.GetType().Name) + printItem.XDeviation) / 3,
             (PrintRuleBase.GetPrintParameterByName <int>(printItem, "pY", this.GetType().Name) + printItem.YDeviation) / 3
         );
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("打印{0}异常:{1}", this.GetType().Name, ex.Message));
     }
 }
Beispiel #10
0
 /// <summary>
 /// 合并字符串
 /// </summary>
 /// <param name="templetModels"></param>
 /// <param name="indexs"></param>
 /// <returns></returns>
 public string DataParseFuntion(List <PrintItemModel> templetModels, List <int> indexs)
 {
     try
     {
         if (indexs == null || indexs.Count < 1)
         {
             throw new Exception(string.Format("请正确设置使用FunctionName=\"{0}\"条目的FunctionIndexs值.", this.GetType().Name));
         }
         string value   = string.Empty;
         string reValue = string.Empty;
         foreach (int item in indexs)
         {
             PrintItemModel temp = templetModels.Where(p => { return(p.Index == item); }).ElementAt(0);
             if (temp.DataSourceType != 0)
             {
                 if (temp.PrintKeyValue.Contains("{0}"))
                 {
                     throw new Exception(string.Format("请先放置{0}标签,再放置合并后的标签.", temp.Index));
                 }
             }
             reValue += temp.PrintKeyValue;
         }
         return(reValue);
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("执行{0}异常:{1}", this.GetType().Name, ex.Message));
     }
 }
Beispiel #11
0
        /// <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 void PrintParseFuntion(PrintItemModel printItem, object other = null)
 {
     try
     {
         string d    = "M";
         int    type = PrintRuleBase.GetPrintParameterByName <int>(printItem, "type", this.GetType().Name);
         int    flag = PrintRuleBase.GetPrintParameterByName <int>(printItem, "g", this.GetType().Name);
         if (flag == 0)
         {
             d = "L";
         }
         else if (flag == 1)
         {
             d = "M";
         }
         else if (flag == 2)
         {
             d = "Q";
         }
         else if (flag == 3)
         {
             d = "H";
         }
         if (type == 0)
         {
             ZebraPrinterHelper.PrintQRCode
             (
                 PrintRuleBase.GetPrintParameterByName <int>(printItem, "pX", this.GetType().Name) + printItem.XDeviation,
                 PrintRuleBase.GetPrintParameterByName <int>(printItem, "pY", this.GetType().Name) + printItem.YDeviation,
                 PrintRuleBase.GetPrintParameterByName <int>(printItem, "r", this.GetType().Name),
                 d,
                 printItem.PrintKeyValue
             );
         }
         else
         {
             ZebraPrinterHelper.PrintDataMatrix
             (
                 PrintRuleBase.GetPrintParameterByName <int>(printItem, "pX", this.GetType().Name) + printItem.XDeviation,
                 PrintRuleBase.GetPrintParameterByName <int>(printItem, "pY", this.GetType().Name) + printItem.YDeviation,
                 PrintRuleBase.GetPrintParameterByName <int>(printItem, "r", this.GetType().Name),
                 PrintRuleBase.GetPrintParameterByName <int>(printItem, "s", this.GetType().Name),
                 printItem.PrintKeyValue
             );
         }
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("打印{0}异常:{1}", this.GetType().Name, ex.Message));
     }
 }
        public List <PrintItemModel> getallprintItem(int VendorId)
        {
            var lst  = new List <PrintItemModel>();
            var data = (from p in entities.Temp_VendorBilling where p.VendorId == VendorId select p).ToList();

            foreach (var item in data)
            {
                PrintItemModel model = new PrintItemModel();
                model.BasicPrice = item.VendorPrice.Price;
                // model.Amount = item.VendorPrice.tblMenuOutlet.tblBasePriceItem.FullPrice;
                model.FullQty  = item.Qty.ToString();
                model.ItemName = item.tblItem.Name;
                lst.Add(model);
            }
            return(lst);
        }
        public ActionResult PrintAgainBill(int BillId = 0)
        {
            var            data  = db.tblBillMasters.Find(BillId);
            PrintBillModel model = new PrintBillModel();

            model.CustomerAddress        = data.Address;
            model.BillId                 = data.BillId;
            model.CustomerName           = data.CustomerName;
            model.Address                = data.tblOutlet.Address;
            model.ContactA               = data.tblOutlet.ContactA;
            model.CustomerContactNo      = data.ContactNo;
            model.discount               = data.Discount.Value;
            model.DiscountAmount         = data.DiscountAmount;
            model.NetAmount              = data.NetAmountWithoutDiscount.Value;
            model.NetAmountAfterDiscount = data.NetAmount;
            model.PackingCharge          = data.PackingCharges.Value;
            model.ServicesCharge         = data.ServicChargesAmount;
            model.ServiceTax             = data.ServiceTax.Value;
            model.ServiceTaxNo           = data.tblOutlet.ServiceTaxNo;
            model.TableNo                = data.TableNo.ToString();
            model.TinNo       = data.tblOutlet.TinNo;
            model.TotalAmount = data.TotalAmount;
            model.BillDate    = data.BillDate;
            List <PrintItemModel> lst     = new List <PrintItemModel>();
            List <PrintVatModel>  VatList = new List <PrintVatModel>();

            foreach (var item in data.tblBillDetails)
            {
                PrintItemModel pm = new PrintItemModel();
                pm.ItemName   = item.tblItem.Name;
                pm.Amount     = item.Amount;
                pm.FullQty    = item.FullQty.ToString();
                pm.BasicPrice = item.tblItem.tblBasePriceItems.Where(a => a.ItemId == item.ItemId).Select(a => a.FullPrice).FirstOrDefault();
                lst.Add(pm);
            }
            model.getAllItem = lst;
            foreach (var item in data.tblBillDetails.GroupBy(a => a.Vat))
            {
                PrintVatModel pm = new PrintVatModel();
                pm.Vat        = Convert.ToDecimal(item.Key);
                pm.amtCharges = item.Sum(a => a.VatAmount.Value);
                VatList.Add(pm);
            }
            model.getAllVat = VatList;
            return(PartialView(model));
        }
Beispiel #15
0
 public void PrintParseFuntion(PrintItemModel printItem, object other = null)
 {
     try
     {
         PrintRuleBase.PTK_DrawLineOr
         (
             PrintRuleBase.GetPrintParameterByName <int>(printItem, "pX", this.GetType().Name) + printItem.XDeviation,
             PrintRuleBase.GetPrintParameterByName <int>(printItem, "pY", this.GetType().Name) + printItem.YDeviation,
             PrintRuleBase.GetPrintParameterByName <int>(printItem, "pWidth", this.GetType().Name),
             PrintRuleBase.GetPrintParameterByName <int>(printItem, "pHeight", this.GetType().Name)
         );
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("打印{0}异常:{1}", this.GetType().Name, ex.Message));
     }
 }
Beispiel #16
0
 /// <summary>
 /// 剪裁 拼接
 /// </summary>
 /// <param name="templetModels"></param>
 /// <param name="indexs"></param>
 /// <returns></returns>
 public string DataParseFuntion(List <PrintItemModel> templetModels, List <int> indexs)
 {
     try
     {
         if (indexs == null || indexs.Count < 1)
         {
             throw new Exception(string.Format("请正确设置使用FunctionName=\"{0}\"条目的FunctionIndexs值.", this.GetType().Name));
         }
         string reValue = string.Empty;
         foreach (int item in indexs)
         {
             string         value = string.Empty;
             PrintItemModel temp  = templetModels.Where(p => { return(p.Index == item); }).ElementAt(0);
             if (temp.FunctionData.MontageLength > 0)
             {
                 if (string.IsNullOrWhiteSpace(temp.PrintKeyValue))
                 {
                     throw new Exception(string.Format("{0}(ID={1})的Value为空,不能被剪裁.", temp.PrintCaption, temp.Index));
                 }
                 if (temp.PrintKeyValue.Length < temp.FunctionData.MontageLength)
                 {
                     throw new Exception(string.Format("{0}(ID={1})的Value长度小于被剪裁长度,不能被剪裁.", temp.PrintCaption, temp.Index));
                 }
                 if (temp.FunctionData.IsHeadMontage)
                 {
                     value = temp.PrintKeyValue.Substring(0, temp.FunctionData.MontageLength);
                 }
                 else
                 {
                     value = temp.PrintKeyValue.Substring(temp.PrintKeyValue.Length - temp.FunctionData.MontageLength);
                 }
                 reValue += value;
             }
             else if (temp.FunctionData.MontageLength < 0)
             {
                 reValue += temp.PrintKeyValue;
             }
         }
         return(reValue);
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("执行{0}异常:{1}", this.GetType().Name, ex.Message));
     }
 }
 public void PrintParseFuntion(PrintItemModel printItem, object other = null)
 {
     try
     {
         ZebraPrinterHelper.PrintRectangle
         (
             (PrintRuleBase.GetPrintParameterByName <int>(printItem, "pX", this.GetType().Name) + printItem.XDeviation) * 2,
             (PrintRuleBase.GetPrintParameterByName <int>(printItem, "pY", this.GetType().Name) + printItem.YDeviation) * 2,
             (PrintRuleBase.GetPrintParameterByName <int>(printItem, "pEX", this.GetType().Name) - PrintRuleBase.GetPrintParameterByName <int>(printItem, "pX", this.GetType().Name)) * 2,
             (PrintRuleBase.GetPrintParameterByName <int>(printItem, "pEY", this.GetType().Name) - PrintRuleBase.GetPrintParameterByName <int>(printItem, "pY", this.GetType().Name)) * 2,
             PrintRuleBase.GetPrintParameterByName <int>(printItem, "thickness", this.GetType().Name)
         );
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("打印{0}异常:{1}", this.GetType().Name, ex.Message));
     }
 }
 public void PrintParseFuntion(PrintItemModel printItem, object other = null)
 {
     try
     {
         PrintRuleBase.PTK_DrawBar2D_MaxiCode
         (
             PrintRuleBase.GetPrintParameterByName <int>(printItem, "pX", this.GetType().Name) + printItem.XDeviation,
             PrintRuleBase.GetPrintParameterByName <int>(printItem, "pY", this.GetType().Name) + printItem.YDeviation,
             PrintRuleBase.GetPrintParameterByName <int>(printItem, "m", this.GetType().Name),
             PrintRuleBase.GetPrintParameterByName <int>(printItem, "u", this.GetType().Name),
             printItem.PrintKeyValue
         );
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("打印{0}异常:{1}", this.GetType().Name, ex.Message));
     }
 }
 public void PrintParseFuntion(PrintItemModel printItem, object other = null)
 {
     try
     {
         string code = PrintRuleBase.GetPrintParameterByName <string>(printItem, "pCode", this.GetType().Name);
         if (code == "1E")
         {
             ZebraPrinterHelper.PrintCode93
             (
                 (PrintRuleBase.GetPrintParameterByName <int>(printItem, "pX", this.GetType().Name) + printItem.XDeviation) * 2,
                 (PrintRuleBase.GetPrintParameterByName <int>(printItem, "pY", this.GetType().Name) + printItem.YDeviation) * 2,
                 (PrintRuleBase.GetPrintParameterByName <int>(printItem, "narrowWidth", this.GetType().Name)) * 2,
                 (PrintRuleBase.GetPrintParameterByName <int>(printItem, "pHeight", this.GetType().Name)) * 2,
                 printItem.PrintKeyValue
             );
         }
         else if (code == "1")
         {
             ZebraPrinterHelper.PrintCode128C
             (
                 (PrintRuleBase.GetPrintParameterByName <int>(printItem, "pX", this.GetType().Name) + printItem.XDeviation) * 2,
                 (PrintRuleBase.GetPrintParameterByName <int>(printItem, "pY", this.GetType().Name) + printItem.YDeviation) * 2,
                 (PrintRuleBase.GetPrintParameterByName <int>(printItem, "narrowWidth", this.GetType().Name)) * 2,
                 (PrintRuleBase.GetPrintParameterByName <int>(printItem, "pHeight", this.GetType().Name)) * 2,
                 printItem.PrintKeyValue
             );
         }
         else
         {
             ZebraPrinterHelper.PrintCode128
             (
                 PrintRuleBase.GetPrintParameterByName <int>(printItem, "pX", this.GetType().Name) + printItem.XDeviation,
                 PrintRuleBase.GetPrintParameterByName <int>(printItem, "pY", this.GetType().Name) + printItem.YDeviation,
                 PrintRuleBase.GetPrintParameterByName <int>(printItem, "narrowWidth", this.GetType().Name),
                 PrintRuleBase.GetPrintParameterByName <int>(printItem, "pHeight", this.GetType().Name),
                 printItem.PrintKeyValue
             );
         }
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("打印{0}异常:{1}", this.GetType().Name, ex.Message));
     }
 }
Beispiel #20
0
 public void PrintParseFuntion(PrintItemModel printItem, object other = null)
 {
     try
     {
         Graphics g = (Graphics)other;
         Pen      p = new Pen(Color.Black, (PrintRuleBase.GetPrintParameterByName <int>(printItem, "pHeight", this.GetType().Name)) / 3);
         g.DrawLine(
             p,
             (PrintRuleBase.GetPrintParameterByName <int>(printItem, "pX", this.GetType().Name) + printItem.XDeviation) / 3,
             (PrintRuleBase.GetPrintParameterByName <int>(printItem, "pY", this.GetType().Name) + printItem.YDeviation + PrintRuleBase.GetPrintParameterByName <int>(printItem, "pHeight", this.GetType().Name) / 2) / 3,
             (PrintRuleBase.GetPrintParameterByName <int>(printItem, "pX", this.GetType().Name) + printItem.YDeviation + PrintRuleBase.GetPrintParameterByName <int>(printItem, "pWidth", this.GetType().Name)) / 3,
             (PrintRuleBase.GetPrintParameterByName <int>(printItem, "pY", this.GetType().Name) + printItem.YDeviation + PrintRuleBase.GetPrintParameterByName <int>(printItem, "pHeight", this.GetType().Name) / 2) / 3
             );
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("打印{0}异常:{1}", this.GetType().Name, ex.Message));
     }
 }
 public void PrintParseFuntion(PrintItemModel printItem, object other = null)
 {
     try
     {
         Graphics g = (Graphics)other;
         Pen      p = new Pen(Color.Black, (PrintRuleBase.GetPrintParameterByName <int>(printItem, "thickness", this.GetType().Name)) / 3);
         g.DrawRectangle(p, new Rectangle()
         {
             X      = (PrintRuleBase.GetPrintParameterByName <int>(printItem, "pX", this.GetType().Name) + printItem.XDeviation) / 3,
             Y      = (PrintRuleBase.GetPrintParameterByName <int>(printItem, "pY", this.GetType().Name) + printItem.YDeviation) / 3,
             Width  = (int)printItem.Width / 3,
             Height = (int)printItem.Height / 3,
         });
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("打印{0}异常:{1}", this.GetType().Name, ex.Message));
     }
 }
        public void PrintParseFuntion(PrintItemModel printItem, object other = null)
        {
            try
            {
                if (!File.Exists(printItem.PrintKeyValue))
                {
                    throw new Exception(string.Format("未发现图片资源{0}.", printItem.PrintKeyValue));
                }

                ZebraPrinterHelper.PrintImage
                (
                    printItem.PrintKeyValue,
                    (PrintRuleBase.GetPrintParameterByName <int>(printItem, "pX", this.GetType().Name) + printItem.XDeviation) * 2,
                    (PrintRuleBase.GetPrintParameterByName <int>(printItem, "pY", this.GetType().Name) + printItem.YDeviation) * 2
                );
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("打印{0}异常:{1}", this.GetType().Name, ex.Message));
            }
        }
Beispiel #23
0
 public void PrintParseFuntion(PrintItemModel printItem, object other = null)
 {
     try
     {
         Graphics g = (Graphics)other;
         g.DrawString
         (
             printItem.PrintKeyValue,
             new Font(PrintRuleBase.GetPrintParameterByName <string>(printItem, "fType", this.GetType().Name), WordHeightToFontSize(PrintRuleBase.GetPrintParameterByName <double>(printItem, "pHeight", this.GetType().Name))),
             new SolidBrush(Color.Black),
             //细微修正-2 保证打印效果与界面呈现一致
             (int)((PrintRuleBase.GetPrintParameterByName <int>(printItem, "pX", this.GetType().Name) + printItem.XDeviation) / 3 - 2),
             (int)((PrintRuleBase.GetPrintParameterByName <int>(printItem, "pY", this.GetType().Name) + printItem.YDeviation) / 3 - 2),
             new StringFormat()
         );
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("打印{0}异常:{1}", this.GetType().Name, ex.Message));
     }
 }
Beispiel #24
0
 public void PrintParseFuntion(PrintItemModel printItem, object other = null)
 {
     try
     {
         PrintRuleBase.PTK_DrawBarcode
         (
             PrintRuleBase.GetPrintParameterByName <int>(printItem, "pX", this.GetType().Name) + printItem.XDeviation,
             PrintRuleBase.GetPrintParameterByName <int>(printItem, "pY", this.GetType().Name) + printItem.YDeviation,
             PrintRuleBase.GetPrintParameterByName <int>(printItem, "pDirec", this.GetType().Name),
             PrintRuleBase.GetPrintParameterByName <string>(printItem, "pCode", this.GetType().Name),
             PrintRuleBase.GetPrintParameterByName <int>(printItem, "narrowWidth", this.GetType().Name),
             PrintRuleBase.GetPrintParameterByName <int>(printItem, "pHorizontal", this.GetType().Name),
             PrintRuleBase.GetPrintParameterByName <int>(printItem, "pHeight", this.GetType().Name),
             PrintRuleBase.GetPrintParameterByName <int>(printItem, "pText", this.GetType().Name),
             printItem.PrintKeyValue
         );
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("打印{0}异常:{1}", this.GetType().Name, ex.Message));
     }
 }
Beispiel #25
0
 /// <summary>
 /// 获取指定参数名称
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="p"></param>
 /// <param name="name"></param>
 /// <param name="functionName"></param>
 /// <returns></returns>
 public static T GetPrintParameterByName <T>(PrintItemModel p, string name, string functionName)
 {
     try
     {
         if (p.Parameters == null)
         {
             throw new Exception(string.Format("参数列表为空."));
         }
         if (!p.Parameters.ContainsKey(name))
         {
             throw new Exception("未查询到有效值.");
         }
         string temp = p.Parameters.FirstOrDefault(s =>
         {
             return(s.Key.ToUpper().Trim() == name.ToUpper().Trim());
         }).Value;
         return((T)Convert.ChangeType(temp, typeof(T)));
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("获取<{0}>的打印参数<{1}>值异常:{2}", functionName, name, ex.Message));
     }
 }
 public void PrintParseFuntion(PrintItemModel printItem, object other = null)
 {
     try
     {
         Regex  cn   = new Regex("[\u4e00-\u9fa5]+");//正则表达式 表示汉字范围
         string type = PrintRuleBase.GetPrintParameterByName <string>(printItem, "fType", this.GetType().Name);
         if (type == "Arial")
         {
             type = "Y";
         }
         else if (type == "ZEBRA0")
         {
             type = "0";
         }
         else
         {
             type = "Z";
         }
         if (cn.IsMatch(printItem.PrintKeyValue))
         {
             type = "Z";
         }
         ZebraPrinterHelper.PrintString
         (
             type,
             (PrintRuleBase.GetPrintParameterByName <int>(printItem, "pHeight", this.GetType().Name)) * 2,
             (PrintRuleBase.GetPrintParameterByName <int>(printItem, "fWidth", this.GetType().Name)) * 2,
             (PrintRuleBase.GetPrintParameterByName <int>(printItem, "pX", this.GetType().Name) + printItem.XDeviation) * 2,
             (PrintRuleBase.GetPrintParameterByName <int>(printItem, "pY", this.GetType().Name) + printItem.YDeviation) * 2,
             printItem.PrintKeyValue
         );
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("打印{0}异常:{1}", this.GetType().Name, ex.Message));
     }
 }
Beispiel #27
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);
        }
        public PrintBillModel GetBill(string Path, GetBillingModel m)
        {
            PrintBillModel        model   = new PrintBillModel();
            List <PrintItemModel> lst     = new List <PrintItemModel>();
            List <PrintVatModel>  VatList = new List <PrintVatModel>();
            int       oulte      = getOutletId();
            var       outletData = (from p in entities.tblOutlets where p.OutletId == oulte select p).SingleOrDefault();
            XDocument xd         = XDocument.Load(Path);
            var       result     = from item in xd.Descendants("Items")
                                   where item.Element("UserId").Value == oulte.ToString() && item.Element("TableNo").Value == m.TableNo.ToString()
                                   select item;
            var VatDetail = (from p in xd.Descendants("Items")
                             where p.Element("UserId").Value == oulte.ToString() &&
                             p.Element("TableNo").Value == m.TableNo.ToString()
                             group p by p.Element("VatAmt").Value into g
                             select new
            {
                Vat = g.Key,
                amtCharges = g.Sum(a => Convert.ToDecimal(a.Element("VatAmountCharges").Value))                 // xd.Descendants("Items").Sum(a => Convert.ToDecimal(a.Element("VatAmountCharges").Value))
            }).ToList();

            model.BillId                 = m.BillId;
            model.TinNo                  = outletData.TinNo;
            model.ServiceTaxNo           = outletData.ServiceTaxNo;
            model.Address                = outletData.Address;
            model.ContactA               = outletData.ContactA;
            model.CustomerAddress        = m.CustomerAddress;
            model.TableNo                = m.TableNo.ToString();
            model.DiscountAmount         = Math.Truncate(m.DiscountAmount * 100) / 100;
            model.TotalAmount            = Math.Truncate(m.TotalAmount * 100) / 100;;
            model.ServicesCharge         = Math.Truncate(m.ServicesCharge * 100) / 100;;
            model.ServiceTax             = Math.Truncate(m.ServiceTax * 100) / 100;;
            model.NetAmount              = Math.Truncate(m.NetAmountWithoutDiscount * 100) / 100;;
            model.CustomerName           = m.CustomerName;
            model.PackingCharge          = m.PackingCharges;
            model.NetAmountAfterDiscount = Math.Truncate(m.NetAmount * 100) / 100;
            model.CustomerContactNo      = m.ContactNo;
            // model.BillType=
            foreach (var item in result)
            {
                PrintItemModel pm     = new PrintItemModel();
                int            Itemid = Convert.ToInt32(item.Element("ItemId").Value);
                if (Itemid == 0)
                {
                    pm.ItemName = item.Element("ItemName").Value;
                }
                else
                {
                    var Name = entities.tblItems.Where(o => o.ItemId == Itemid).Select(x => x.Name).SingleOrDefault();
                    pm.ItemName = Name;
                }
                var     amount = item.Element("Amount").Value;
                decimal amt    = Convert.ToDecimal(amount);
                pm.Amount     = Math.Round(amt, 2);
                pm.FullQty    = item.Element("FullQty").Value;
                pm.HalfQty    = item.Element("HalfQty").Value;
                pm.BasicPrice = Math.Round(Convert.ToDecimal(item.Element("Fullprice").Value), 2);
                lst.Add(pm);
            }
            model.getAllItem = lst;

            foreach (var item in VatDetail)
            {
                PrintVatModel pm          = new PrintVatModel();
                decimal       discountvat = 0;
                if (m.Discount > 0)
                {
                    decimal discount = (m.Discount / 100) * item.amtCharges;
                    discountvat = item.amtCharges - discount;
                }
                else
                {
                    discountvat = item.amtCharges;
                }
                pm.amtCharges = discountvat;
                pm.Vat        = Convert.ToDecimal(item.Vat);
                VatList.Add(pm);
            }
            model.getAllVat = VatList;
            return(model);
        }
        public PrintBillModel GetBill(string Path, GetBillingModel m)
        {
            PrintBillModel        model   = new PrintBillModel();
            List <PrintItemModel> lst     = new List <PrintItemModel>();
            List <PrintVatModel>  VatList = new List <PrintVatModel>();
            int       oulte      = xml.getOutletId();
            var       outletData = (from p in _entities.tblOutlets where p.OutletId == oulte select p).SingleOrDefault();
            XDocument xd         = XDocument.Load(Path);
            var       result     = from item in xd.Descendants("Items")
                                   where item.Element("UserId").Value == oulte.ToString()
                                   select item;
            var VatDetail = (from p in xd.Descendants("Items")
                             where p.Element("UserId").Value == oulte.ToString()
                             group p by p.Element("Vat").Value into g
                             select new
            {
                Vat = g.Key,
                amtCharges = g.Sum(a => Convert.ToDecimal(a.Element("VatAmt").Value))                 // xd.Descendants("Items").Sum(a => Convert.ToDecimal(a.Element("VatAmountCharges").Value))
            }).ToList();

            model.TinNo          = outletData.TinNo;
            model.ServiceTaxNo   = outletData.ServiceTaxNo;
            model.Address        = outletData.Address;
            model.ContactA       = outletData.ContactA;
            model.CustomerName   = string.Empty;
            model.TableNo        = m.TableNo.ToString();
            model.DiscountAmount = m.DiscountAmount;
            model.TotalAmount    = m.TotalAmount;
            model.ServicesCharge = m.ServicesCharge;
            model.NetAmount      = m.NetAmount;
            model.CustomerName   = m.CustomerName;
            foreach (var item in result)
            {
                PrintItemModel pm     = new PrintItemModel();
                int            Itemid = Convert.ToInt32(item.Element("ItemId").Value);
                if (Itemid == 0)
                {
                    pm.ItemName = item.Element("ItemName").Value;
                }
                else
                {
                    var Name = _entities.tblItems.Where(o => o.ItemId == Itemid).Select(x => x.Name).SingleOrDefault();
                    pm.ItemName = Name;
                }
                var     amount = item.Element("TotalAmount").Value;
                decimal amt    = Convert.ToDecimal(amount);
                pm.Amount  = amt;
                pm.FullQty = item.Element("FullQty").Value;
                pm.HalfQty = item.Element("HalfQty").Value;
                lst.Add(pm);
            }
            model.getAllItem = lst;

            foreach (var item in VatDetail)
            {
                PrintVatModel pm = new PrintVatModel();
                pm.amtCharges = item.amtCharges;
                pm.Vat        = Convert.ToDecimal(item.Vat);
                VatList.Add(pm);
            }
            model.getAllVat = VatList;
            return(model);
        }