-
Notifications
You must be signed in to change notification settings - Fork 0
/
FormRepointAppoint.cs
115 lines (95 loc) · 3.49 KB
/
FormRepointAppoint.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
using DispatcherService.Classes;
using EPV.Data;
using EPV.Database;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace DispatcherService
{
public partial class FormRepointAppoint : Form
{
private EPVDatabase database;
public Appoint Appoint { get; private set; }
private string currentComment;
private Point fromPoint;
public SecurityUser User
{
get { return (SecurityUser)((FormStart)Application.OpenForms["FormStart"]).User; }
}
private FormRepointAppoint()
{
InitializeComponent();
}
public FormRepointAppoint(EPVDatabase _database, Appoint appoint, Point _fromPoint)
: this()
{
database = _database;
Appoint = appoint;
fromPoint = _fromPoint;
Text = Appoint.TrackInfo;
}
private void FormRepointAppoint_Load(object sender, EventArgs e)
{
Permit permit = Appoint.GetPermit(database);
if (permit == null)
{
MessageBox.Show(DispatcherService.Resources.Error.PermitNotFound);
Close();
}
currentComment = permit.GetComment(database);
tboxComment.Text = currentComment;
Points points = new DispatcherService.Points(database, Appoint.Unit);
cboxPoint.DataSource = points;
}
private void buttonOk_Click(object sender, EventArgs e)
{
if (CheckPoint(cboxPoint.SelectedItem)
&& CheckComment(tboxComment.Text))
{
UpdatePermitComment(tboxComment.Text);
Appoint.SetToPoint(database, Appoint.Unit, (Point)cboxPoint.SelectedItem, DateTime.Now, User);
DialogResult = DialogResult.OK;
}
}
private bool CheckComment(string text)
{
if (text.Length > 0
|| MessageBox.Show("При пустом комментарии машину может не пройти через пункт пропуска. Оставить незаполненным?",
"Внимание", MessageBoxButtons.YesNo) == DialogResult.Yes)
return true;
return false;
}
private bool CheckPoint(object selectedItem)
{
if (selectedItem == null || !(selectedItem is Point))
{
MessageBox.Show("Не указано новое место погрузки/разгрузки");
return false;
}
return true;
}
private void UpdatePermitComment(string text)
{
Permit permit = Appoint.GetPermit(database);
permit.UpdateComment(database, text);
}
private void cboxPoint_SelectedIndexChanged(object sender, EventArgs e)
{
if (cboxPoint.SelectedItem != null)
{
Point point = cboxPoint.SelectedItem as Point;
if (point != null)
{
tboxComment.Text = currentComment + Environment.NewLine;
tboxComment.Text += "ДОЗАГРУЗ: переезд с пункта " + fromPoint.Name;
tboxComment.Text += " в пункт " + point.Name;
}
}
}
}
}