Form1.cs
6.68 KB
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using MoyaAdminLib;
using MoyaSignup.Properties;
using ThermoPrinterLibrary;
namespace MoyaSignup
{
public partial class Form1 : Form
{
[DllImport("user32.dll")]
public static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vlc);
[DllImport("user32.dll")]
public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
private const int ShutdownHotkey = 1;
private ThermoPrinter _thermoPrinter;
public bool AllowShutdown { get; set; }
//public delegate void ThermoPrinterEvent(ThermoPrinter.Models model);
//public event ThermoPrinterEvent SetPrinter;
public Form1()
{
RestClient.ApiApplicationKey = Settings.Default.ApiApplicationKey;
RestClient.ApiPass = Settings.Default.ApiPass;
RestClient.ApiUser = Settings.Default.ApiUser;
RestClient.ApiURL = Settings.Default.ApiURL;
InitializeComponent();
RegisterHotKey(Handle, ShutdownHotkey, 3, (int) Keys.S);
}
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x0312 && m.WParam.ToInt32() == ShutdownHotkey)
{
AllowShutdown = true;
Application.Exit();
}
base.WndProc(ref m);
}
enum Language
{
Finnish = 0,
English = 1
}
// Language currentLanguage = Language.English;
/*
void changed()
{
if (!pictureTaken )
{
this.lblMessage.Text = "Ota kuva ensin painamalla 'Käytä tätä kuvaa' nappia";
this.lblMessage.ForeColor = Color.Red;
this.btnSave.Enabled = false;
return;
}
this.lblMessage.ForeColor = Color.Green;
this.lblMessage.Text = "OK, varmista tietojen oikeellisuus ja tallenna";
this.btnSave.Enabled = true;
}*/
public void SetPrinter(ThermoPrinter.Models model)
{
_thermoPrinter = new ThermoPrinter(model);
try
{
_thermoPrinter.Start(Settings.Default.printerPort);
_thermoPrinter.SetBarcodeWidth(ThermoPrinter.BarcodeWidths.Small);
_thermoPrinter.SetCharacterAlignment(ThermoPrinter.CharacterAlignments.Center);
_thermoPrinter.SetPositionHRI(ThermoPrinter.HRIPrintingPositions.Below);
}
catch
{
_thermoPrinter = null;
}
}
private void Form1_Load(object sender, EventArgs e)
{
/*if (AutoUpdateLib.AutoUpdateCore.CheckForUpdates(null))
{
Application.ExitThread(); //program is required to close by autoupdate (probably updated)
return;
}*/
if (Debugger.IsAttached)
WindowState = FormWindowState.Normal;
var form = new ApiSettings();
form.ShowDialog();
if (Settings.Default.printerPort != null && Settings.Default.ThermoPrinter > 0)
{
var model = (ThermoPrinter.Models) Settings.Default.ThermoPrinter;
SetPrinter(model);
}
userLoginControl1.SetPrinter += SetPrinter;
}
/*
private void btnSave_Click(object sender, EventArgs e)
{
if (!checkSaveSafety())
{
this.btnSave.Enabled = false;
return;
}
this.Cursor = Cursors.WaitCursor;
this.btnSave.Enabled = false;
this.Enabled = false;
this.btnSave.Refresh();
//savePicture(pid);
MessageBox.Show("Tallennus onnistui.\r\nMene infotiskille, ja kerro heille tämä numero, niin he opastavat sinut eteenpäin.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Enabled = true;
this.Cursor = Cursors.Default;
}*/
/*
private void txtName_TextChanged(object sender, EventArgs e)
{
changed();
}*/
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (!AllowShutdown)
{
e.Cancel = true;
}
else
{
_thermoPrinter?.Stop();
}
}
private void Form1_Deactivate(object sender, EventArgs e)
{
if (!AllowShutdown)
{
Activate();
}
else
{
UnregisterHotKey(Handle, ShutdownHotkey);
}
}
private void Form1_KeyUp(object sender, KeyEventArgs e)
{
/* if (e.Alt && e.Control && e.KeyCode == Keys.S)
{
AllowShutdown = true;
Application.Exit();
return;
}
if (e.Alt && e.KeyCode == Keys.F5)
{
//userDetailsEditor1.SetPrinter(ThermoPrinterLibrary.ThermoPrinter.Models.IDP3210);
//MessageBox.Show("Printteri: IDP3210");
}*/
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Alt && e.Control && e.KeyCode == Keys.S)
{
AllowShutdown = true;
Close();
}
}
private void Form1_MouseClick(object sender, MouseEventArgs e)
{
/*
if (e.Button == MouseButtons.Right)
{
allowShutdown = true;
Application.Exit();
return;
}*/
}
private void button1_Click(object sender, EventArgs e)
{
AllowShutdown = true;
Application.Exit();
}
private void userLoginControl1_LoginOk(object sender, EventArgs e)
{
userLoginControl1.Visible = false;
userDetailsEditor1.LoadUser(userLoginControl1.CurrentUser);
userDetailsEditor1.ThermoPrinter = _thermoPrinter;
userLoginControl1.Clear();
userDetailsEditor1.Visible = true;
//userLoginControl1.CurrentUser;
}
private void userDetailsEditor1_Load(object sender, EventArgs e)
{
}
private void userDetailsEditor1_CloseView(object sender, EventArgs e)
{
userDetailsEditor1.Visible = false;
userLoginControl1.Visible = true;
}
}
}