-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form6.cs
103 lines (89 loc) · 2.93 KB
/
Form6.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
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.Threading.Tasks;
using System.Windows.Forms;
namespace AutomationOrderTakingTerminal
{
public partial class Form6 : Form
{
private SerialPort serialPort;
private string readData;
public Form6()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
serialPort = new SerialPort();
serialPort.BaudRate = 9600;
serialPort.PortName = textBox1.Text;
serialPort.Parity = Parity.None;
serialPort.DataBits = 8;
serialPort.StopBits = StopBits.One;
serialPort.DataReceived += SerialPort_DataReceived;
try
{
serialPort.Open();
textBox3.Text = "";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
}
private void button2_Click(object sender, EventArgs e)
{
ListViewItem listViewItem = new ListViewItem();
listViewItem.Text = textBox3.Text;
listViewItem.SubItems.Add(textBox4.Text);
listView1.Items.Add(listViewItem);
label5.Text = textBox3.Text;
textBox3.Clear();
textBox4.Clear();
}
private void button3_Click(object sender, EventArgs e)
{
foreach (ListViewItem item in listView1.SelectedItems)
listView1.Items.Remove(item);
label6.Text = "()";
label8.Text = "()";
}
private void button4_Click(object sender, EventArgs e)
{
double sum = 0;
double[] list = new double[listView1.Items.Count];
for (int i = 0; i < listView1.Items.Count; i++)
{
list[i] = Convert.ToDouble(listView1.Items[i].SubItems[1].Text.ToString());
sum += list[i];
}
label6.Text = Convert.ToString(sum);
}
private void button5_Click(object sender, EventArgs e)
{
double sumPrice = Convert.ToDouble(label6.Text);
double ratio = Convert.ToDouble(textBox2.Text);
double newPrice = sumPrice * (100 - ratio) / 100;
label8.Text = Convert.ToString(newPrice);
}
private void button6_Click(object sender, EventArgs e)
{
this.Close();
}
void SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
readData = serialPort.ReadLine();
this.Invoke(new EventHandler(Displaydata_Events));
}
private void Displaydata_Events(Object sender, EventArgs e)
{
textBox3.AppendText(readData);
}
}
}