-
Notifications
You must be signed in to change notification settings - Fork 0
/
PrinterSettings.cs
108 lines (88 loc) · 3.52 KB
/
PrinterSettings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using StockCounter.Properties;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace StockCounter
{
public partial class PrinterSettings : Form
{
public PrinterSettings()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
System.Drawing.Printing.PrinterSettings.StringCollection printers = System.Drawing.Printing.PrinterSettings.InstalledPrinters;
List<string> src = new List<string>(printers.Count);
src.Add(Settings.Default.PrinterNull);
foreach (string p in printers)
src.Add(p);
comboBoxPrinterName.DataSource = src;
int selected = -1;
if (!string.IsNullOrEmpty(Settings.Default.PrinterName))
{
for(int i = 0;i < src.Count; i++)
{
if (src[i].Equals(Settings.Default.PrinterName))
{
selected = i;
break;
}
}
}
if(selected < 0 && src.Count > 0){
selected = 0;
Settings.Default.PrinterName = src[0];
Settings.Default.Save();
}
if(selected >= 0 && comboBoxPrinterName.Items.Count > 0)
{
comboBoxPrinterName.SelectedIndex = selected;
}
List<string> formats = new List<string>();
formats.Add("Code39");
formats.Add("Code128");
comboBoxBarcodeFormat.DataSource = formats;
if (string.IsNullOrEmpty(Settings.Default.Barcode))
comboBoxBarcodeFormat.SelectedIndex = 0;
else
comboBoxBarcodeFormat.SelectedItem = Settings.Default.Barcode;
numericUpDownWidth.Value = Settings.Default.PageWidth;
numericUpDownHeight.Value = Settings.Default.PageHeight;
string[] names = SerialPort.GetPortNames();
if (names != null && names.Length > 0)
{
comboBoxScannerSerialPort.Items.AddRange(names);
if (!string.IsNullOrEmpty(Settings.Default.ScannerPort))
{
comboBoxScannerSerialPort.SelectedItem = Settings.Default.ScannerPort;
}
}
else
comboBoxScannerSerialPort.DataSource = null;
}
private void buttonOK_Click(object sender, EventArgs e)
{
if(comboBoxPrinterName.SelectedIndex < 0)
{
MessageBox.Show("Nenhuma impressora selecionada...", "Impressora", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
Settings.Default.PrinterName = comboBoxPrinterName.SelectedValue.ToString();
Settings.Default.Barcode = comboBoxBarcodeFormat.SelectedValue.ToString();
Settings.Default.PageWidth = (int)numericUpDownWidth.Value;
Settings.Default.PageHeight = (int)numericUpDownHeight.Value;
Settings.Default.ScannerPort = comboBoxScannerSerialPort.SelectedItem == null ? String.Empty : comboBoxScannerSerialPort.SelectedItem.ToString();
Settings.Default.Save();
this.DialogResult = DialogResult.OK;
Close();
}
}
}