コード例 #1
0
ファイル: LabelPrinter.cs プロジェクト: Molmed/ChiasmaDeposit
        public void Print(BarCodeLabel[] barCodeLabels,
                          Int32 fontHeight,
                          Int32 fontWidth,
                          Int32 offsetX,
                          Int32 offsetY,
                          BarCodeTextPositions textPosition)
        {
            String       labelScriptFile;
            ZPLGenerator ZPLGen;

            try
            {
                ZPLGen          = new ZPLGenerator();
                labelScriptFile = Environment.GetEnvironmentVariable("TEMP") + "\\Chi_ZPL.ZPL";

                // Check that all bar codes are valid.
                foreach (BarCodeLabel barCodeLabel in barCodeLabels)
                {
                    if (!ZPLGen.ValidateBarCode128c(barCodeLabel.BarCode))
                    {
                        MessageBox.Show("The bar code " + barCodeLabel.BarCode + " is not a valid Code128c bar code.", Config.GetDialogTitleStandard());
                        return;
                    }
                }

                // Write the ZPL script to the temporary location on the local disc.
                ZPLGen.GenerateCode128c(labelScriptFile, barCodeLabels, fontHeight, fontWidth, offsetX, offsetY, textPosition);

                // Print file.
                Print(labelScriptFile);

                // Delete script file.
                File.Delete(labelScriptFile);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error when attempting to print bar codes: " + ex.Message, Config.GetDialogTitleStandard(), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }