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
| using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.Office.Interop.Excel;
using System.Xml;
namespace Konsultant
{
public partial class MainForm : Form
{
private Microsoft.Office.Interop.Excel.Application ObjExcel;
private Microsoft.Office.Interop.Excel.Workbook ObjWorkBook;
private Microsoft.Office.Interop.Excel.Worksheet ObjWorkSheet;
private string time;
private string put;
private string puth_old = null;
private bool timeColorRed = false;
public MainForm(string[] args)
{
InitializeComponent();
timer_smen.Stop();
this.WindowState = FormWindowState.Maximized;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
ProgStart();
}
//Таймер
void Timer_smenTick(object sender, EventArgs e)
{
if(l_timer.Text == "0")
{
timer_smen.Stop();
l_timer.ForeColor = SystemColors.ControlText;
timeColorRed = false;
Update_dan();
}
else
l_timer.Text = Convert.ToString(Convert.ToInt32(l_timer.Text) - 1);
if((timeColorRed == false) && (Convert.ToInt32(l_timer.Text) < (Convert.ToInt32(time) / 3)))
{
l_timer.ForeColor = Color.Red;
timeColorRed = true;
}
}
//Считывание из Excel вручную
private void открытьToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog openDialog = new OpenFileDialog();
openDialog.Filter = "Файл Excel|*.XLSX;*.XLS";
openDialog.ShowDialog();
if (openDialog.FileName != "")
LoadExcel(openDialog.FileName);
else
MessageBox.Show("Ошибка при считывании Excel файла", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
//Считывание из Excel
private void LoadExcel(string putExcel)
{
try
{
ObjExcel = new Microsoft.Office.Interop.Excel.Application();
//Книга.
ObjWorkBook = ObjExcel.Workbooks.Open(putExcel);
//Таблица.
ObjWorkSheet = ObjExcel.ActiveSheet as Microsoft.Office.Interop.Excel.Worksheet;
Microsoft.Office.Interop.Excel.Range rg = null;
//Иникатор
loading frm = new loading();
frm.Show(this);
this.Enabled = false;
Int32 row = 3;
dataGridViewMain.Rows.Clear();
List<String> arr = new List<string>();
while (ObjWorkSheet.get_Range("a" + row, "a" + row).Value != null)
{
// Читаем данные из ячейки
rg = ObjWorkSheet.get_Range("a" + row, "g" + row);
foreach (Microsoft.Office.Interop.Excel.Range item in rg)
{
try
{
arr.Add(item.Value.ToString().Trim());
}
catch { arr.Add(""); }
}
if (arr[0] != "Профессия")
{
dataGridViewMain.Rows.Add(arr[0], arr[1], arr[4], arr[5], arr[6]);
(frm.Controls["Kol"] as System.Windows.Forms.Label).Text = Convert.ToString(row - 1);
}
row++;
arr.Clear();
}
this.Enabled = true;
frm.Close();
//MessageBox.Show("Файл успешно считан!", "Считывания Excel файла", MessageBoxButtons.OK, MessageBoxIcon.Information);
Update_dan();
}
catch (Exception ex)
{
MessageBox.Show("Ошибка: " + ex.Message, "Ошибка при считывании Excel файла", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
//ObjWorkBook.Close();
//(false, "", null)
// Закрытие приложения Excel.
ObjExcel.Quit();
ObjWorkBook = null;
ObjWorkSheet = null;
ObjExcel = null;
GC.Collect();
}
}
//Обновление информации
private void Update_dan()
{
Random rnd = new Random();
int index =rnd.Next(0, dataGridViewMain.RowCount);
L_prof.Text=dataGridViewMain.Rows[index].Cells[0].Value.ToString();
L_org.Text=dataGridViewMain.Rows[index].Cells[1].Value.ToString();
L_zp.Text=dataGridViewMain.Rows[index].Cells[2].Value.ToString();
L_adr.Text=dataGridViewMain.Rows[index].Cells[3].Value.ToString();
L_rab_mes.Text=dataGridViewMain.Rows[index].Cells[4].Value.ToString();
l_timer.Text = time;
timer_smen.Start();
}
//Включение выключение рамки
private void убратьРамкуToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.FormBorderStyle == System.Windows.Forms.FormBorderStyle.None)
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
else
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
}
//Выход
private void выходToolStripMenuItem_Click(object sender, EventArgs e)
{
Close();
}
//При запуске
private void ProgStart()
{
if (System.IO.File.Exists((System.Windows.Forms.Application.StartupPath + "\\config.xml")) == false)
{
Options frm_opt = new Options();
frm_opt.ShowDialog();
LoadXML();
}
else //Считывание XML
{
LoadXML();
}
}
//Загрузка из XML
private void LoadXML()
{
XmlTextReader XmlReader = new XmlTextReader((System.Windows.Forms.Application.StartupPath + "\\config.xml"));
while (XmlReader.Read())
{
if (XmlReader.NodeType == XmlNodeType.Element)
{
if (XmlReader.Name.Equals("Constant"))
{
time = Convert.ToString(XmlReader.GetAttribute("Time"));
put = Convert.ToString(XmlReader.GetAttribute("Put"));
}
}
}
XmlReader.Close();
if (puth_old != put)
{
puth_old = put;
LoadExcel(put);
}
else
Update_dan();
}
//Окно настроек
private void настройкиToolStripMenuItem_Click_1(object sender, EventArgs e)
{
Options frm = new Options();
frm.ShowDialog();
LoadXML();
}
//Изменение размера формы
private void MainForm_SizeChanged(object sender, EventArgs e)
{
int temp = this.Size.Height / 30;
tabControl1.Font = new System.Drawing.Font(tabControl1.Font.Name, temp);
L_prof.Font = tabControl1.Font;
L_org.Font = tabControl1.Font;
L_adr.Font = tabControl1.Font;
l_timer.Font = tabControl1.Font;
adr_org.Font = tabControl1.Font;
org_g.Font = tabControl1.Font;
}
}
} |