示例#1
0
        public static String[] ListPrinters()
        {
            PrinterSettings.StringCollection printers = System.Drawing.Printing.PrinterSettings.InstalledPrinters;

            String[] result = new String[printers.Count];

            int i = 0;

            foreach (string printer in printers)
            {
                result[i++] = printer;
            }

            return(result);
        }
        /// <summary>
        /// 判断系统中是否存在打印机
        /// </summary>
        /// <returns>TRUE:存在打印机;FALSE:不存在打印机</returns>
        private bool PrinterExists()
        {
            PrinterSettings.StringCollection snames = PrinterSettings.InstalledPrinters;

            foreach (string s in snames)
            {
                if (s.ToLower().Trim() == s.ToLower().Trim())
                {
                    return(true);
                }
            }

            MessageBox.Show("没找到打印机!\n只有安装了打印机才能进行打印", "没找到打印机",
                            MessageBoxButtons.OK, MessageBoxIcon.Warning);
            return(false);
        }
示例#3
0
        public static void FillPrintersComboBox(ComboBox comboBox)
        {
            comboBox.Items.Clear();

            PrinterSettings.StringCollection installedPrinters = PrinterSettings.InstalledPrinters;
            foreach (var priner in installedPrinters)
            {
                var it = comboBox.Items.Add(priner.ToString());
                if (new PrinterSettings {
                    PrinterName = priner.ToString()
                }.IsDefaultPrinter)
                {
                    comboBox.SelectedIndex = it;
                }
            }
        }
示例#4
0
        public bool findPrinter(string keyOfPrinterName)
        {
            String printerName = ConfigurationManager.AppSettings.Get(keyOfPrinterName);

            PrinterSettings.StringCollection installedPrinters = PrinterSettings.InstalledPrinters;

            for (int i = 0; i < PrinterSettings.InstalledPrinters.Count; i++)
            {
                if (PrinterSettings.InstalledPrinters[i] == printerName)
                {
                    return(true);
                }
            }

            return(false);
        }
示例#5
0
        private bool exist(string printer)
        {
            PrinterSettings.StringCollection installedPrinters = PrinterSettings.InstalledPrinters;
            bool result;

            foreach (string text in installedPrinters)
            {
                if (text.ToLower().Trim() == printer.ToLower().Trim())
                {
                    result = true;
                    return(result);
                }
            }
            result = false;
            return(result);
        }
示例#6
0
        private void Form1_Load(object sender, EventArgs e)
        {
            RegistryKey reg = Registry.CurrentUser.CreateSubKey("Software\\AppAutoPrint\\Settings");

            try { txtFrom.Text = reg.GetValue("path_From").ToString(); }
            catch { txtFrom.Text = ""; }
            try { txtJornal.Text = reg.GetValue("path_Jornal").ToString(); }
            catch { txtJornal.Text = ""; }

            PrinterSettings.StringCollection sc = PrinterSettings.InstalledPrinters;
            for (int i = 0; i < sc.Count; i++)
            {
                comboBox1.Items.Add(sc[i]);
            }
            if (txtJornal.Text != " ")
            {
                string[] JornalList = System.IO.Directory.GetFiles(txtJornal.Text, "*.doc");
                for (int j = 0; j < JornalList.Length; j++)
                {
                    comboBox2.Items.Add(new System.IO.FileInfo(JornalList[j]).Name);
                }
            }

            RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\AppAutoPrint\\NameOfFind");

            if (key == null)
            {
                RegistryKey keynew = Registry.CurrentUser.CreateSubKey("Software\\AppAutoPrint\\NameOfFind");
                keynew.SetValue("printer_Name", @"\\stavropolct\HP4350-OPERO");
                keynew.SetValue("jornal_Name", "Журнал_работы-Ежедневный.doc");
                int index  = comboBox1.FindString(keynew.GetValue("printer_Name").ToString());
                int index2 = comboBox2.FindString(keynew.GetValue("jornal_Name").ToString());
                comboBox2.SelectedIndex = index2;
                comboBox1.SelectedIndex = index;
            }
            else
            {
                int index  = comboBox1.FindString(key.GetValue("printer_Name").ToString());
                int index2 = comboBox2.FindString(key.GetValue("jornal_Name").ToString());
                comboBox2.SelectedIndex = index2;
                comboBox1.SelectedIndex = index;
            }

            chkVisible.Checked = true;
        }
示例#7
0
        static public bool PrinterExists(PrintDocument prtdoc)
        {
            //PrintDocument prtdoc = new PrintDocument();
            string strDefaultPrinter = prtdoc.PrinterSettings.PrinterName;      //获取默认的打印机名

            PrinterSettings.StringCollection snames = PrinterSettings.InstalledPrinters;

            foreach (string s in snames)
            {
                if (s.ToLower().Trim() == s.ToLower().Trim())
                {
                    return(true);
                }
            }
            MessageBox.Show("没找到打印机!\n只有安装了打印机才能进行打印", "没找到打印机",
                            MessageBoxButtons.OK, MessageBoxIcon.Warning);
            return(false);
        }
        /// <summary>
        /// 绑定打印机
        /// </summary>
        public void InitializePrinter()
        {
            PrinterSettings.StringCollection printers = PrinterSettings.InstalledPrinters;

            foreach (string s in printers)
            {
                tsddbPrinter.DropDownItems.Add(s, null, new EventHandler(tsmiPrinter_Click));
            }

            if (!string.IsNullOrEmpty(SystemSetting.DefaultPrinterName))
            {
                tsddbPrinter.Text = "打印机:" + SystemSetting.DefaultPrinterName;
            }
            else
            {
                tsddbPrinter.Text = "打印机:" + printers[0];
            }
        }
示例#9
0
 ///<summary>recursive</summary>
 private void SetControls(Control c, PrinterSettings.StringCollection installedPrinters)
 {
     foreach (Control control in c.Controls)
     {
         SetControls(control, installedPrinters);
         if (control == checkSimple)
         {
             continue;
         }
         if (control.GetType() == typeof(ComboBox))
         {
             FillCombo((ComboBox)control, installedPrinters);
         }
         if (control.GetType() == typeof(CheckBox))
         {
             FillCheck((CheckBox)control);
         }
     }
 }
示例#10
0
 private void FormPrinterSetup_Load(object sender, System.EventArgs e)
 {
     PrinterSettings.StringCollection installedPrinters = null;
     try {
         installedPrinters = PrinterSettings.InstalledPrinters;
     }
     catch (Exception ex) {           //do not let the window open if printers cannot be accessed
         FriendlyException.Show(Lan.g(this, "Unable to access installed printers."), ex);
         DialogResult = DialogResult.Cancel;
         return;
     }
     checkSimple.Checked = PrefC.GetBool(PrefName.EasyHidePrinters);
     SetSimple();
     SetControls(this, installedPrinters);
     if (Clinics.IsMedicalPracticeOrClinic(Clinics.ClinicNum))
     {
         labelTPandPerio.Text = Lan.g(this, "Treatment Plans");
     }
 }
示例#11
0
        public void print()
        {
            PrintDocument pdoc = new PrintDocument();

            PrinterSettings.StringCollection px = PrinterSettings.InstalledPrinters;
            List <string> printerlist           = new List <string>();

            foreach (string x in px)
            {
                printerlist.Add(x);
            }
            if (printerlist.Count >= 2)
            {
                //    pdoc.PrinterSettings.PrinterName = printerlist[0];
                //System.Console.WriteLine(printerlist[0]);
            }
            pdoc.PrintPage += new PrintPageEventHandler(xx);
            pdoc.Print();
        }
示例#12
0
 public Form1()
 {
     InitializeComponent();
     try
     {
         // Показать последние введённые данные
         ShowLastData(DeSerializeNote(Way.LastData));
     }
     catch
     {
         MessageBox.Show("Не удалось загрузить последние данные");
         AllData data = new AllData();
         data.CountCert        = 1;
         rBtCountCert1.Checked = true;
         PrinterSettings.StringCollection sc = PrinterSettings.InstalledPrinters;
         data.PrintName = sc[1];
     }
     this.Text = "Мастер удостоверений вер. " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
     CheckDataFolder();
 }
示例#13
0
        // Filles PrinterSelectionComboBox with list of installed printers upon opening
        public static void SetPrinterOptions()
        {
            PrinterSettings.StringCollection printers = PrinterSettings.InstalledPrinters;
            List <string> printersList   = new List <string>();
            var           LongestPrinter = (name : "", length : 0);

            foreach (string printer in printers)
            {
                LongestPrinter = (printer.Count() > LongestPrinter.length) ? (printer, printer.Count()) : LongestPrinter;
                printersList.Add(printer);
            }

            MainReference.PrinterSelectionComboBoxReference.ComboBox.Width         = TextRenderer.MeasureText(LongestPrinter.name, MainReference.PrinterSelectionComboBoxReference.ComboBox.Font).Width + 20;
            MainReference.PrinterSelectionComboBoxReference.ComboBox.DropDownWidth = MainReference.PrinterSelectionComboBoxReference.ComboBox.Width;

            MainReference.PrinterSelectionComboBoxReference.ComboBox.Items.Clear();
            MainReference.PrinterSelectionComboBoxReference.ComboBox.Items.AddRange(printersList.ToArray <object>());

            MainReference.PrinterSelectionComboBoxReference.SelectedItem = SelectedPrinter ?? PrinterSettings.PrinterName;
        }
示例#14
0
        /// <summary>
        /// 判断系统中是否存在打印机
        /// </summary>
        /// <returns>TRUE:存在打印机;FALSE:不存在打印机</returns>
        private bool PrinterExists(PrintDocument prtdoc)
        {
            string strDefaultPrinter = prtdoc.PrinterSettings.PrinterName;      //获取默认的打印机名

            PrinterSettings.StringCollection snames = PrinterSettings.InstalledPrinters;

            foreach (string s in snames)
            {
                if (s.ToLower().Trim() == s.ToLower().Trim())
                {
                    return(true);
                }
            }
            if (bool_fbl)
            {
                resolution.setResolution(1024, 768, 60, 32);
            }
            MessageBox.Show("没找到打印机!\n只有安装了打印机才能进行打印", "没找到打印机",
                            MessageBoxButtons.OK, MessageBoxIcon.Warning);
            return(false);
        }
示例#15
0
        bool InSave = false; //Флаг сохранялись ли настройки

        public Settings(MainForm P)
        {
            InitializeComponent();
            parent = P;


            if (parent.admin.InError && parent.admin.TypeError == 1)
            {
                tabPage1.Parent = tabControl2;
                tabPage3.Parent = tabControl2;
                tabPage4.Parent = tabControl2;
            }

            string[] RS232 = System.IO.Ports.SerialPort.GetPortNames();

            for (int i = 0; i < RS232.Length; i++)
            {
                comboBox1.Items.Add(RS232[i]);
            }

            if (!parent.admin.InError)
            {
                List <Hashtable> Tracks = parent.admin.model.GetAllTracks();
                for (int i = 0; i < Tracks.Count; i++)
                {
                    comboBox2.Items.Add(Tracks[i]["name"]);
                }
            }
            PrinterSettings.StringCollection sc = PrinterSettings.InstalledPrinters;
            for (int i = 0; i < sc.Count; i++)
            {
                comboBox4.Items.Add(sc[i]);
                comboBox5.Items.Add(sc[i]);
            }

            LoadSettings();
        }
        protected override void OnMessage(MessageEventArgs e)
        {
            WsCommand command = JsonConvert.DeserializeObject <WsCommand>(e.Data);

            if (command.Command == "print")
            {
                #region print
                Logger.InfoLog("print " + command.Seq + "  data:" + command.Data);
                lock (this) {
                    if (command.Type == "image")
                    {
                        if (command.Data.StartsWith("["))
                        {
                            // 多个图片
                            List <KeyValuePair <string, string> > imageList = JsonConvert.DeserializeObject <List <KeyValuePair <string, string> > >(command.Data);
                            printImage(command.Seq, command.Printer, imageList);
                        }
                        else
                        {
                            printImage(command.Seq, command.Printer, command.Data);
                        }
                    }
                    else if (command.Type == "html")
                    {
                        if (command.Data.StartsWith("["))
                        {
                            // 多个html
                            List <KeyValuePair <string, string> > htmlList = JsonConvert.DeserializeObject <List <KeyValuePair <string, string> > >(command.Data);
                        }
                        else
                        {
                            printHtml(command.Seq, command.Data);
                        }
                    }
                    else
                    {
                        string extension = Path.GetExtension(command.Data);
                        if (Regex.IsMatch(extension, @"(jpg|jpeg|png|jfif)", RegexOptions.IgnoreCase))
                        {
                            printImage(command.Seq, command.Printer, command.Data);
                        }
                        else if (Regex.IsMatch(extension, @"(html|html)", RegexOptions.IgnoreCase))
                        {
                            printHtml(command.Seq, command.Data);
                        }
                    }
                }

                #endregion
            }
            else if (command.Command == "getPrinters")
            {
                #region getPriters 打印机列表
                PrinterSettings.StringCollection printers = PrinterSettings.InstalledPrinters;
                List <string> result = new List <string>();
                foreach (string item in printers)
                {
                    result.Add(item);
                }
                WsResponse <List <string> > chkr = new WsResponse <List <string> >();
                chkr.Seq  = command.Seq;
                chkr.Data = result;
                Send(JsonConvert.SerializeObject(chkr));
                #endregion
            }
            else if (command.Command == "checkPrinter")
            {
                #region checkPrinter 查看打印机是否正常开启
                PrinterSettings.StringCollection printers = PrinterSettings.InstalledPrinters;
                bool hasThePrinter = false;
                foreach (string item in printers)
                {
                    if (command.Data == item)
                    {
                        hasThePrinter = true;
                        break;
                    }
                }
                WsResponse <string> er = new WsResponse <string>();
                er.Seq = command.Seq;
                if (hasThePrinter)
                {
                    er.Data = "OK";
                }
                else
                {
                    er.Code = "NG";
                }
                Send(JsonConvert.SerializeObject(er));
                #endregion
            }
            else
            {
                #region error
                WsResponse <string> er = new WsResponse <string>();
                er.Seq  = command.Seq;
                er.Code = "NG";
                er.Data = "命令" + command.Command + "不支持";
                Send(JsonConvert.SerializeObject(er));
                #endregion
            }
        }
示例#17
0
 public PrintManager()
 {
     this.installed = PrinterSettings.InstalledPrinters;
     this.getDefaultPrinter();
 }
示例#18
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            dtFechaEnvasado.SelectedDate = DateTime.Today;
            txtCopiasProducto.Text       = CopiasProducto.ToString();
            txtCopiasCaja.Text           = CopiasCaja.ToString();
            txtCopiasTotal.Text          = CopiasTotal.ToString();
            txtCierre.Text = ProductosParaCierre.ToString();

            PrinterSettings.StringCollection lstImpresoras = PrinterSettings.InstalledPrinters;
            cmbImpresoraProducto.ItemsSource = lstImpresoras;
            cmbImpresoraCaja.ItemsSource     = lstImpresoras;
            cmbImpresoraTotal.ItemsSource    = lstImpresoras;

            PrinterSettings ps = new PrinterSettings();

            cmbImpresoraProducto.SelectedItem = ps.PrinterName;
            cmbImpresoraCaja.SelectedItem     = ps.PrinterName;
            cmbImpresoraTotal.SelectedItem    = ps.PrinterName;

            TrabajoActivo = TrabajoGestor.ObtenerTrabajoActivo(Configuracion.NombreEquipo);
            if (TrabajoActivo != null)
            {
                txtLote.Text = TrabajoActivo.Lote;
                dtFechaEnvasado.SelectedDate = TrabajoActivo.Fecha;
                if (!string.IsNullOrEmpty(TrabajoActivo.EtiquetaProducto))
                {
                    RutaEtiquetas = System.IO.Path.GetDirectoryName(TrabajoActivo.EtiquetaProducto);
                }
                if (!string.IsNullOrEmpty(TrabajoActivo.EtiquetaCaja))
                {
                    RutaEtiquetas = System.IO.Path.GetDirectoryName(TrabajoActivo.EtiquetaCaja);
                }
                if (!string.IsNullOrEmpty(TrabajoActivo.EtiquetaTotal))
                {
                    RutaEtiquetas = System.IO.Path.GetDirectoryName(TrabajoActivo.EtiquetaTotal);
                }
                txtEtiquetaProducto.Text = System.IO.Path.GetFileName(TrabajoActivo.EtiquetaProducto);
                txtEtiquetaCaja.Text     = System.IO.Path.GetFileName(TrabajoActivo.EtiquetaCaja);
                txtEtiquetaTotal.Text    = System.IO.Path.GetFileName(TrabajoActivo.EtiquetaTotal);
                if (lstImpresoras.Cast <string>().ToList().Contains(TrabajoActivo.ImpresoraProducto))
                {
                    cmbImpresoraProducto.SelectedItem = TrabajoActivo.ImpresoraProducto;
                }
                if (lstImpresoras.Cast <string>().ToList().Contains(TrabajoActivo.ImpresoraCaja))
                {
                    cmbImpresoraCaja.SelectedItem = TrabajoActivo.ImpresoraCaja;
                }
                if (lstImpresoras.Cast <string>().ToList().Contains(TrabajoActivo.ImpresoraTotal))
                {
                    cmbImpresoraTotal.SelectedItem = TrabajoActivo.ImpresoraTotal;
                }
                txtCopiasProducto.Text = TrabajoActivo.CopiasProducto.ToString();
                CopiasProducto         = TrabajoActivo.CopiasProducto;
                CopiasCaja             = TrabajoActivo.CopiasCaja;
                CopiasTotal            = TrabajoActivo.CopiasTotal;
                ProductosParaCierre    = TrabajoActivo.NumeroProductosCierre;
                txtCopiasCaja.Text     = TrabajoActivo.CopiasCaja.ToString();
                txtCopiasTotal.Text    = TrabajoActivo.CopiasTotal.ToString();
                txtCierre.Text         = TrabajoActivo.NumeroProductosCierre.ToString();
                // Sólo dejar cambiar las impresoras, las copias y el número de productos para el cierre de caja automático.
                txtLote.IsReadOnly                 = true;
                btnLimpiaLote.IsEnabled            = false;
                btnLimpiaProducto.IsEnabled        = false;
                btnLimpiaCaja.IsEnabled            = false;
                btnLimpiaTotal.IsEnabled           = false;
                btnTecladoLote.IsEnabled           = false;
                btnBuscaEtiquetaProducto.IsEnabled = false;
                btnBuscaEtiquetaCaja.IsEnabled     = false;
                btnBuscaEtiquetaTotal.IsEnabled    = false;
                dtFechaEnvasado.IsEnabled          = false;
            }
            else
            {
                TrabajoActivo = new Trabajo();
            }
        }
示例#19
0
        private void Init()
        {
            string Addr = txt_MESServer.Text.Trim();
            string user = txt_UserName.Text.Trim();
            string pwd  = txt_Password.Text.Trim();
            string bu   = cmb_bu.SelectedText;

            client = new MESSocketClient(Addr, user, pwd, bu);
            try
            {
                cbx_comportlist.DataSource    = GetComlist(true);
                cbx_comportlist.SelectedIndex = 0;
                if (getRegValue("ComPortName") != "")
                {
                    cbx_comportlist.SelectedItem = getRegValue("ComPortName");
                }
                else
                {
                    cbx_comportlist.SelectedItem = "COM1";
                }
                if (getRegValue("BaudRate") != "")
                {
                    txt_BaudRate.Text = getRegValue("BaudRate");
                }
                if (getRegValue("WeighterType") != "")
                {
                    cbx_WeighterType.SelectedItem = getRegValue("WeighterType");
                }
                if (getRegValue("ZebraPort") != "")
                {
                    txt_ZebraPort.Text = getRegValue("ZebraPort");
                }
                if (getRegValue("isLocalPath") != "")
                {
                    cb_isLocalPath.Checked = Convert.ToBoolean(getRegValue("isLocalPath"));
                }
                SocketService.PrinterList = new string[4];
                PrinterSettings.StringCollection collection = PrinterSettings.InstalledPrinters;
                List <string> PrinterList = new List <string>();
                foreach (string item in collection)
                {
                    cbx_Printer1.Items.Add(item);
                    cbx_Printer2.Items.Add(item);
                    cbx_Printer3.Items.Add(item);
                    cbx_Printer4.Items.Add(item);
                }
                PrintDocument doc            = new PrintDocument();
                string        defaultPrinter = doc.PrinterSettings.PrinterName;
                if (getRegValue("Printer1") != "")
                {
                    cbx_Printer1.SelectedItem = getRegValue("Printer1");
                }
                else
                {
                    cbx_Printer1.SelectedItem = defaultPrinter;
                }
                if (getRegValue("Printer2") != "")
                {
                    cbx_Printer2.SelectedItem = getRegValue("Printer2");
                }
                else
                {
                    cbx_Printer2.SelectedItem = defaultPrinter;
                }
                if (getRegValue("Printer3") != "")
                {
                    cbx_Printer3.SelectedItem = getRegValue("Printer3");
                }
                else
                {
                    cbx_Printer3.SelectedItem = defaultPrinter;
                }
                if (getRegValue("Printer4") != "")
                {
                    cbx_Printer4.SelectedItem = getRegValue("Printer4");
                }
                else
                {
                    cbx_Printer4.SelectedItem = defaultPrinter;
                }
            }
            catch (Exception ex)
            {
                log.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ex.Message);
            }
        }