forked from pistol88/dvizh-seller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettingsForm.cs
186 lines (152 loc) · 6.76 KB
/
SettingsForm.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DvizhSeller
{
public partial class SettingsForm : Form
{
CashierForm cashierForm;
services.Database db = new services.Database();
int loadedFiscalType;
repositories.Cashbox cashboxes;
services.DataMapper dataMapper;
public SettingsForm(CashierForm setCashierForm)
{
cashierForm = setCashierForm;
cashboxes = new repositories.Cashbox(db);
dataMapper = new services.DataMapper(db);
dataMapper.FillCashboxes(cashboxes);
InitializeComponent();
}
private void renderFiscalSettings()
{
if(fiscal.Checked)
fiscalSettings.Enabled = true;
else
fiscalSettings.Enabled = false;
if (fiscalDriverTypeBox.SelectedIndex == 0)
{
fiscalComPortBox.Enabled = true;
atolSettingsButton.Enabled = false;
}
if (fiscalDriverTypeBox.SelectedIndex == 1)
{
fiscalComPortBox.Enabled = false;
atolSettingsButton.Enabled = true;
}
}
private void SettingsForm_Load(object sender, EventArgs e)
{
protocolBox.Text = Properties.Settings.Default.protocol;
hostBox.Text = Properties.Settings.Default.host;
dbFileBox.Text = Properties.Settings.Default.dbFile;
clientBox.Text = Properties.Settings.Default.client;
currencyBox.Text = Properties.Settings.Default.currency;
tokenBox.Text = Properties.Settings.Default.token;
online.Checked = Properties.Settings.Default.online;
fiscal.Checked = Properties.Settings.Default.fiscal;
testMode.Checked = Properties.Settings.Default.testMode;
barcodescaner.Checked = Properties.Settings.Default.barcodescaner;
checkNoteBox.Text = Properties.Settings.Default.checkNote;
roundingTypeBox.SelectedIndex = Properties.Settings.Default.roundingType;
roundingBox.Text = Properties.Settings.Default.rounding.ToString();
fiscalComPortBox.Text = Properties.Settings.Default.fiscalComPort.ToString();
autoOpenTabletBox.Checked = Properties.Settings.Default.autoOpenTablet;
autoStartWebServerBox.Checked = Properties.Settings.Default.autoStartWebServer;
taxBox.Text = Properties.Settings.Default.taxType.ToString();
Item vikiItem = new Item("VikiPrint (Пирит)", 1);
fiscalDriverTypeBox.Items.Add(vikiItem);
Item atolItem = new Item("АТОЛ", 2);
fiscalDriverTypeBox.Items.Add(atolItem);
foreach (entities.Cashbox cashbox in cashboxes.GetList())
{
Item item = new Item(cashbox.GetName(), cashbox.GetId());
cashboxId.Items.Add(item);
if(cashbox.GetId() == Properties.Settings.Default.cashboxId)
{
cashboxId.SelectedItem = item;
}
}
if (Properties.Settings.Default.fiscalDriverType == 0)
fiscalDriverTypeBox.SelectedItem = vikiItem;
else
fiscalDriverTypeBox.SelectedItem = atolItem;
loadedFiscalType = fiscalDriverTypeBox.SelectedIndex;
renderFiscalSettings();
}
private void settingsSave_Click(object sender, EventArgs e)
{
Properties.Settings.Default.protocol = protocolBox.Text;
Properties.Settings.Default.host = hostBox.Text;
Properties.Settings.Default.client = clientBox.Text;
Properties.Settings.Default.currency = currencyBox.Text;
Properties.Settings.Default.token = tokenBox.Text;
Properties.Settings.Default.online = online.Checked;
Properties.Settings.Default.fiscal = fiscal.Checked;
Properties.Settings.Default.testMode = testMode.Checked;
Properties.Settings.Default.barcodescaner = barcodescaner.Checked;
Properties.Settings.Default.checkNote = checkNoteBox.Text;
Properties.Settings.Default.roundingType = roundingTypeBox.SelectedIndex;
Properties.Settings.Default.rounding = Convert.ToInt16(roundingBox.Text);
Properties.Settings.Default.dbFile = dbFileBox.Text;
Properties.Settings.Default.fiscalComPort = fiscalComPortBox.Text;
Properties.Settings.Default.fiscalDriverType = fiscalDriverTypeBox.SelectedIndex;
Properties.Settings.Default.autoOpenTablet = autoOpenTabletBox.Checked;
Properties.Settings.Default.autoStartWebServer = autoStartWebServerBox.Checked;
Properties.Settings.Default.taxType = Convert.ToInt16(taxBox.Text);
object selectedItem = cashboxId.SelectedItem;
Properties.Settings.Default.cashboxId = Convert.ToInt32(selectedItem.GetHashCode());
if (fiscal.Checked)
cashierForm.ActivateFiscal();
else
cashierForm.DeactivateFiscal();
Properties.Settings.Default.Save();
if (Properties.Settings.Default.fiscalDriverType != loadedFiscalType)
MessageBox.Show("Перезапустите программу, чтобы сменить драйвер.");
savingInfo.Text = "Сохранено.";
}
private class Item
{
public string Name;
public int Value;
public Item(string name, int value)
{
Name = name; Value = value;
}
public override string ToString()
{
return Name;
}
public override int GetHashCode()
{
return Value;
}
}
private void fiscal_CheckedChanged(object sender, EventArgs e)
{
renderFiscalSettings();
}
private void fiscalDriverTypeBox_SelectedValueChanged(object sender, EventArgs e)
{
renderFiscalSettings();
}
private void atolSettingsButton_Click(object sender, EventArgs e)
{
try
{
FprnM1C.IFprnM45 cmd = new FprnM1C.FprnM45();
cmd.ShowProperties();
}
catch (Exception)
{
MessageBox.Show("Драйвер не установлен или поврежден. Скачайте и установите драйвера оборудования с сайта dvizh.net!");
}
}
}
}