示例#1
0
        private void btnPrintBarcode_Click(object sender, System.EventArgs e)
        {
            //myDymoAddin = new DymoAddIn();
            //myLabel = new DymoLabels();
            IPrinter printer = Framework.GetPrinters()[cboPrinterName.Text];

            if (printer is ILabelWriterPrinter)
            {
                ////_label.SetObjectText("BARCODE_TEST", "54321");
                //ILabelWriterPrintParams printParams = null;
                //ILabelWriterPrinter labelWriterPrinter = printer as ILabelWriterPrinter;
                //_label.Print(printer, printParams);
            }
            else
            {
                _label.Print(printer); // print with default params
            }
            myDymoAddin = new DymoAddIn();
            myLabel     = new DymoLabels();
            if (myDymoAddin.Open(@"C:\Users\Aaron\Documents\DYMO Label\Labels\SmallNameBadgeTest.label"))
            {
                myLabel.SetField("lblPrice", _test);
                myDymoAddin.StartPrintJob();
                myDymoAddin.Print(1, false);
                myDymoAddin.EndPrintJob();
            }
        }
 public int? GetCurrentPaperTray()
 {
     try
     {
         var dymoAddin = new DymoAddIn();
         return dymoAddin.GetCurrentPaperTray();
     }
     catch (COMException)
     {
         return null;
     }
     catch (Exception ex)
     {
         _log.ErrorFormat("Errore inaspettato nel controllo del PaperTray - {0} - azienda:{1}", ex, Utility.GetMethodDescription(), Login.Instance.CurrentLogin().Azienda);
         return null;
     }
 }
 public bool IsTwinTurboPrinter(string printerName)
 {
     try
     {
         var dymoAddin = new DymoAddIn();
         return dymoAddin.IsTwinTurboPrinter(printerName);
     }
     catch (COMException)
     {
         return false;
     }
     catch (Exception ex)
     {
         _log.ErrorFormat("Errore inaspettato nel controllo di TwinTurbo - {0} - azienda:{1}", ex, Utility.GetMethodDescription(), Login.Instance.CurrentLogin().Azienda);
         return false;
     }
 }
 public bool IsPrinterInstalled()
 {
     try
     {
         var dymoAddin = new DymoAddIn();
         return true;
     }
     catch (InvalidCastException)
     {
         return false;
     }
     catch (COMException)
     {
         return false;
     }
     catch (Exception ex)
     {
         _log.ErrorFormat("Errore inaspettato nel controllo di installazione del software Dymo - {0} - azienda:{1}", ex, Utility.GetMethodDescription(), Login.Instance.CurrentLogin().Azienda);
         return false;
     }
 }
示例#5
0
        //private void txtBoughtPrice_TextChanged(object sender, TextChangedEventArgs e)
        //{
        //    int errorCounter = 0;
        //    errorCounter = Regex.Matches(txtBoughtPrice.Text, @"[a-zA-Z]").Count;
        //    if (errorCounter > 0)
        //    {
        //        MessageBox.Show("Bought Price cannot contain characters. Please try again");
        //        txtBoughtPrice.Text = txtBoughtPrice.Text.Substring(0, txtBoughtPrice.Text.Length - 1);
        //    }
        //}

        //private void txtContactNum_TextChanged(object sender, TextChangedEventArgs e)
        //{
        //    int errorCounter = 0;
        //    errorCounter = Regex.Matches(txtContactNum.Text, @"[a-zA-Z]").Count;
        //    if (errorCounter > 0)
        //    {
        //        MessageBox.Show("Contact Number cannot contain characters. Please try again");
        //        txtContactNum.Text = txtContactNum.Text.Substring(0, txtContactNum.Text.Length - 1);
        //    }
        //}
        #endregion

        #region Barcode Button
        private void btnBarcode_Click(object sender, RoutedEventArgs e)
        {
            //Switcher.Switch(new BarcodeWindow());



            myDymoAddin = new DymoAddIn();
            myLabel     = new DymoLabels();

            try
            {
                if (myDymoAddin.Open(@"C:\Labels\SaleSmall.label"))
                {
                    if ((txtBrand.Text.ToString().Equals(null) || txtBrand.Text.ToString().Equals("")) ||
                        //(txtModel.Text.ToString().Equals(null) || txtModel.Text.ToString().Equals("")) ||
                        (txtSaleDate.Text.ToString().Equals(null) || txtSaleDate.Text.ToString().Equals("")) ||
                        (txtNetwork.Text.ToString().Equals(null) || txtNetwork.Text.ToString().Equals("")) ||
                        (txtDisplayPrice.Text.ToString().Equals(null) || txtDisplayPrice.Text.ToString().Equals("")))
                    {
                        MessageBox.Show("Sale Date, Brand, Model, Network or DisplayPrice is empty");
                    }
                    else
                    {
                        if (!listOfIDs.Contains(txtSaleDate.Text))
                        {
                            btnSaveSaleForm_Click(this, new RoutedEventArgs());
                        }
                        else
                        {
                            MessageBox.Show("Barcode has printed and Item already has been saved");
                        }

                        string combine = txtBrand.Text;// +" " + txtModel.Text;
                        string combineAddDetailsNetwork = txtAdditionalNotice.Text + "  " + txtNetwork.Text;

                        //open the connection
                        if (myConn.State != System.Data.ConnectionState.Open)
                        {
                            myConn.Open();
                        }

                        //define the command reference
                        MySqlCommand mySQLcommand = new MySqlCommand();

                        //define the connection used by the command object
                        mySQLcommand.Connection = myConn;

                        ////define the command text
                        mySQLcommand.CommandText = "SELECT * FROM cmc_repairs_stock WHERE date_sold=@date_sold";

                        DateTime mydate = DateTime.Now;

                        //add values provided by user

                        if (txtSaleDate.Text.Equals(null) || txtSaleDate.Text.Equals(""))
                        {
                            MessageBox.Show("This cannot be null");
                        }
                        else
                        {
                            mySQLcommand.Parameters.AddWithValue("@date_sold", txtSaleDate.Text);
                        }

                        //mySQLcommand.ExecuteNonQuery();
                        MySqlDataReader mySQLDataReader;
                        mySQLDataReader = mySQLcommand.ExecuteReader();

                        while (mySQLDataReader.Read())
                        {
                            id = mySQLDataReader.GetString("id");
                        }

                        //close the connection
                        myConn.Close();

                        myLabel.SetField("lblBrand", combine.ToString());
                        myLabel.SetField("lblSaleDate", txtSaleDate.Text);
                        myLabel.SetField("lbl_ID", id.ToString());
                        myLabel.SetField("lblNetwork", combineAddDetailsNetwork.ToString());
                        myLabel.SetField("lblPrice", "£" + txtDisplayPrice.Text);
                        myDymoAddin.StartPrintJob();
                        myDymoAddin.Print(1, false);
                        myDymoAddin.EndPrintJob();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("There is an error with the label, please check all fields and try again.");
            }
        }
示例#6
0
 private void print(Enrollment enrollment)
 {
     var oldtitle = window.Title;
       window.Title = oldtitle + " (printing...)";
       var printjob = new DymoAddIn();
       var label = new DymoLabels();
       if (printjob.Open(@"Person.LWL"))
       {
     label.SetField("Name", enrollment.FullName);
     label.SetField("School", enrollment.School);
     printjob.StartPrintJob();
     printjob.Print(1, false);
     printjob.EndPrintJob();
     window.Title = oldtitle;
       }
 }
 public IList<string> GetPrinters()
 {
     try
     {
         var dymoAddin = new DymoAddIn();
         var prtNames = dymoAddin.GetDymoPrinters();
         if (prtNames != null)
         {
             var printers = prtNames.Split('|');
             return printers.ToList();
         }
         _log.WarnFormat("Fallita la richiesta dell'elenco delle stampanti Dymo - {0} - fileName:{1}", Utility.GetMethodDescription(), dymoAddin.FileName);
         return new List<string>();
     }
     catch (COMException ex)
     {
         _log.WarnFormat("Richiesto elenco stampante Dymo per sistema su cui il software Dymo non è installato - {0} - azienda:{1}", ex, Utility.GetMethodDescription(), Login.Instance.CurrentLogin().Azienda);
         return new List<string>();
     }
     catch (Exception ex)
     {
         _log.ErrorFormat("Errore inaspettato nella lettura delle etichettatrici Dymo disponibili - {0} - azienda:{1}", ex, Utility.GetMethodDescription(), Login.Instance.CurrentLogin().Azienda);
         throw;
     }
 }
        public void Print(IList<string> indirizzi, string labelType, string printer, int? tray)
        {
            try
            {
                if (IsPrinterInstalled())
                {
                    var dymoAddin = new DymoAddIn();
                    var label = new DymoLabels();

                    byte[] labelLayout = null;

                    if (string.IsNullOrEmpty(labelType))
                        labelType = GetTipoEtichetta();

                    switch (labelType)
                    {
                        case "Address":
                            labelLayout = StampaEtichetteDymoResources.Indirizzo_28x89;
                            break;
                        case "ReturnAddressInt":
                            labelLayout = StampaEtichetteDymoResources.Indirizzo_mittente_25x54;
                            break;
                        case "LargeAddress":
                            labelLayout = StampaEtichetteDymoResources.Indirizzo_grande_36x89;
                            break;
                        case "ArchiviazioneOttica":
                            labelLayout = StampaEtichetteDymoResources.ArchiviazioneOttica_25x54;
                            break;
                    }

                    if (labelLayout != null)
                    {
                        var doc = new DocumentInfo { Body = labelLayout, FileName = "sfera.label" };
                        var tempFolder = _manageDocumentService.GetTempFolder(doc, null);
                        if (!string.IsNullOrEmpty(tempFolder))
                        {
                            doc.FileName = tempFolder;
                            var fileName = _manageDocumentService.Save(doc);
                            if (dymoAddin.Open(fileName))
                            {
                                dymoAddin.SelectPrinter(printer);
                                dymoAddin.StartPrintJob();

                                foreach (var indirizzo in indirizzi)
                                {
                                    label.SetField("TESTO", indirizzo);
                                    if(tray == null)
                                        dymoAddin.Print(1, false);
                                    else
                                        dymoAddin.Print2(1, false, tray.Value);
                                }
                                dymoAddin.EndPrintJob();
                            }
                        }
                    }
                    else
                    {
                        _log.WarnFormat("Tipo di etichetta Dymo non riconosciuta - {0} - layout:{1} - printer:{2}", Utility.GetMethodDescription(), labelType, printer);
                    }
                }
            }
            catch (COMException ex)
            {
                _log.ErrorFormat("Richiesto elenco stampante Dymo per sistema su cui il software Dymo non è installato - {0} - azienda:{1}", ex, Utility.GetMethodDescription(), Login.Instance.CurrentLogin().Azienda);
            }
            catch (Exception ex)
            {
                _log.ErrorFormat("Errore inaspettato nella stampa delle etichette Dymo - {0} - azienda:{1}", ex, Utility.GetMethodDescription(), Login.Instance.CurrentLogin().Azienda);
                throw;
            }
        }
 public string GetCurrentPrinter()
 {            
     try
     {
         var dymoAddin = new DymoAddIn();
         return dymoAddin.GetCurrentPrinterName();
     }
     catch (COMException ex)
     {
         _log.WarnFormat("Richiesto elenco stampante Dymo per sistema su cui il software Dymo non è installato - {0} - azienda:{1}", ex, Utility.GetMethodDescription(), Login.Instance.CurrentLogin().Azienda);
         return string.Empty;
     }
     catch (Exception ex)
     {
         _log.ErrorFormat("Errore inaspettato nella lettura delle etichettatrice Dymo corrente - {0} - azienda:{1}", ex, Utility.GetMethodDescription(), Login.Instance.CurrentLogin().Azienda);
         throw;
     }
 }
        void print_label(bool currentFails)
        {
            DymoAddIn myDymoAddin = new DymoAddIn();
            IDymoAddIn5 d3 = (IDymoAddIn5)myDymoAddin;

            dymo_label_templates f = new dymo_label_templates();

            DateTime today = DateTime.Today;
            String lbl;

            String filepath = @"C:\\TorchTester2\\Curr.label";
            int side = 0;
            if (currentFails) {
                side = 1;
                lbl = f.FAIL;
                lbl = lbl.Replace("{{DATE}}", today.ToShortDateString());
                string partno = uniq.ToString() + " - " + (lotPartNumber - 1).ToString() + "/" + TESTS_IN_LOT.ToString();
                lbl = lbl.Replace("{{PART_NUMBER}}", partno);  // Read from db.
                for (int i = 1; i <= 8; i++) {
                    String r;
                    //2 and none.
                    if (testResults.ContainsKey(i)) {
                        if (i <= 4) {
                            r = String.Format("{0:0.##}", testResults[i]);
                        } else {
                            r = ((int)Math.Floor(testResults[i])).ToString();
                        }
                    } else {
                        r = "   *";
                    }

                    if (i <= 4) {
                        lbl = lbl.Replace("{{l" + i + "}}", r);
                    } else {
                        lbl = lbl.Replace("{{f" + (i-4).ToString() + "}}", r);
                    }
                 }
            } else {
                lbl = f.PASS;
                lbl = lbl.Replace("{{DATE}}", today.ToShortDateString());
                //MAKE UNIQUE HERE
                string partno = uniq.ToString() + " - " + (lotPartNumber - 1).ToString() + "/" + TESTS_IN_LOT.ToString();
                lbl = lbl.Replace("{{PART_NUMBER}}", partno);  // Read from db.
            }

            System.IO.File.WriteAllText(filepath, lbl);

            string printerName = "DYMO LabelWriter 450 Twin Turbo";
            DYMO.Label.Framework.ILabelWriterPrinter printer =
                DYMO.Label.Framework.Framework.GetPrinters()[printerName] as DYMO.Label.Framework.ILabelWriterPrinter;
            //var j = DYMO.Label.Framework.Label.Open(@"C:\Users\Public\Curr.label");
            //j.Print("DYMO LabelWriter 450 Twin Turbo");

            if (d3.Open(filepath)) {
                d3.StartPrintJob();
                d3.SelectPrinter(printerName);
                d3.Print2(1, true, side);
                d3.EndPrintJob();
            }
            //clean up the file so there arent a billion files spewed around.
            //System.IO.File.Delete(filepath);
        }