-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm_main.cs
141 lines (114 loc) · 4.31 KB
/
Form_main.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
using System;
using System.Drawing;
using System.Windows.Forms;
using VolandoBoy_printer.Properties;
using Timer = System.Windows.Forms.Timer;
namespace VolandoBoy_printer
{
public partial class Form_main : Form
{
public Form_main()
{
InitializeComponent();
}
public VolandoBoy volandoBoy;
public Printer printer;
public void ShowError(string error, int duration = 3)
{
label_error.Text = error;
label_error.Visible = true;
var t = new Timer();
t.Interval = duration * 1000;
t.Tick += (s, e) =>
{
label_error.Visible = false;
t.Stop();
};
t.Start();
}
public void ActualizeStatus(string text)
{
ActualizeStatus(text, Color.White);
}
public void ActualizeStatus(string text, Color color)
{
label_status.Text = "Status: " + text;
label_status.ForeColor = color;
}
public void Log(string text, string color = "white")
{
if (label_log.Text == "log line") label_log.Text = null;
label_log.Text = text + "\n" + label_log.Text;
}
public void Log(VolandoBoy.Command command)
{
Log("[" + command.time_init + "] " + command.tag + " | " + command.restaurantPrice() + "€");
}
public bool DuplicateTickets()
{
return check_duplicate.Checked;
}
// private -----------------------------
private void OnLogin()
{
label_rest_name.Text = volandoBoy.restaurant.name;
panel_login.Visible = false;
panel_pooling.Visible = true;
if(printer != null && volandoBoy.loggedIn) volandoBoy.StartPooling();
}
private void Form_main_Load(object sender, EventArgs e)
{
volandoBoy = new VolandoBoy();
foreach (string printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters) select_printer.Items.Add(printer);
select_printer.SelectedItem = Settings.Default.printerName;
check_duplicate.Checked = Settings.Default.duplicate_tickets;
label_log.Text = null;
if (volandoBoy.Login(Settings.Default.email, Settings.Default.password)) OnLogin();
else panel_login.Visible = true;
}
// buttons --------------------------------------------------
private void button_login_Click(object sender, EventArgs e)
{
if (volandoBoy.Login(input_email.Text, input_password.Text)) OnLogin();
else
{
ShowError("Correo electrónico o contraseña incorrectos");
input_email.Text = null;
input_password.Text = null;
input_email.Focus();
}
}
private void button_logout_Click(object sender, EventArgs e)
{
volandoBoy.Logout();
panel_pooling.Visible = false;
panel_login.Visible = true;
}
private void button_test_printer_Click(object sender, EventArgs e)
{
if(printer == null) ShowError("No printer selected", 5);
else printer.PrintTest();
}
private void check_duplicate_CheckedChanged(object sender, EventArgs e)
{
Settings.Default.duplicate_tickets = check_duplicate.Checked;
Settings.Default.Save();
}
private void select_printer_SelectedIndexChanged(object sender, EventArgs e)
{
Settings.Default.printerName = select_printer.SelectedItem.ToString();
Settings.Default.Save();
if(Settings.Default.printerName.Length > 0)
{
printer = new Printer(Settings.Default.printerName);
if (volandoBoy.loggedIn) volandoBoy.StartPooling();
}
else{
volandoBoy.StopPooling();
printer = null;
ShowError("No printer selected", 5);
ActualizeStatus("Stopped, no printer", Color.Red);
}
}
}
}