-
Notifications
You must be signed in to change notification settings - Fork 0
/
addEquipment.xaml.cs
136 lines (117 loc) · 4.97 KB
/
addEquipment.xaml.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
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace Equipment_Manager
{
/// <summary>
/// Interaction logic for addEquipment.xaml
/// </summary>
public partial class addEquipment : Window
{
DataTable operators;
DataTable machines;
DataTable siteLoc;
DataTable eqType;
DataTable eqStatus;
DataTable insuranceStat;
DataTable suppliers;
public addEquipment()
{
InitializeComponent();
try
{
machines = DBManager.selectFromMachines();
siteLoc = DBManager.selectSiteLocations();
eqType = DBManager.selectEquipmentType();
eqStatus = DBManager.selectEquipmentStatus();
insuranceStat = DBManager.selectInsuranceStatuses();
operators = DBManager.selectDriversAndOperators();
suppliers= DBManager.selectSuppliers();
machineTypeBox.ItemsSource = machines.AsDataView();
currentLocationBox.ItemsSource = siteLoc.AsDataView();
equipmentTypeBox.ItemsSource = eqType.AsDataView();
currentStatusBox.ItemsSource = eqStatus.AsDataView();
insuranceStatusBox.ItemsSource = insuranceStat.AsDataView();
operatorNameBox.ItemsSource = operators.AsDataView();
supplierBox.ItemsSource = suppliers.AsDataView();
}
catch
{
}
}
private void addEquipmentButton_Click(object sender, RoutedEventArgs e)
{
string opId;
if (operatorNameBox.SelectedValue == null)
{
opId = "";
}
else
{
opId = operatorNameBox.SelectedValue.ToString();
}
string resp = DBManager.InsertIntoEquipments("('"+ equipmentIdBox.Text +"','" + machineTypeBox.SelectedValue.ToString()+ "','" + plateNumberBox.Text + "','" + manufacturedYearBox.Text + "','" + currentLocationBox.SelectedValue.ToString() + "','" + currentStatusBox.SelectedValue.ToString() + "','" + investmentCostBox.Text+"','"+servicedEveryBox.Text+"','"+ equipmentTypeBox.SelectedValue.ToString() +"','"+insuranceStatusBox.SelectedValue.ToString()+"','"+ opId + "','" +DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") +"')");
if (resp.Contains("Success"))
{
myMessageBox mm = new myMessageBox("Equipment Added Successfully", "Success", "OK", 0);
mm.ShowDialog();
//MessageBox.Show("Success", "Equipment added Succesfully!", MessageBoxButton.OK, MessageBoxImage.Information);
this.Close();
}
else
{
myMessageBox mm = new myMessageBox(resp, "Error", "OK", 1);
mm.ShowDialog();
// MessageBox.Show("error", resp, MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private void equipmentTypeBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
try
{
string eqID = DBManager.selectIdTag(equipmentTypeBox.SelectedValue.ToString()).Rows[0][2].ToString()+"-" + DBManager.countEquipments(equipmentTypeBox.SelectedValue.ToString()).ToString("D6");
int i = 0;
while (DBManager.countDuplicateEquipments(eqID) != 0)
{
i = i + 1;
eqID = DBManager.selectIdTag(equipmentTypeBox.SelectedValue.ToString()).Rows[0][2].ToString() + "-" + (DBManager.countEquipments(equipmentTypeBox.SelectedValue.ToString())+i).ToString("D6");
}
equipmentIdBox.Text = eqID;
}
catch
{
}
}
private void machineTypeBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
try
{
string selectdMachine = machineTypeBox.SelectedValue.ToString();
DataTable machinGrp = DBManager.selectMachineGroups(selectdMachine);
if (Convert.ToInt16(machinGrp.Rows[0][0].ToString()) == 4)
{
operators = DBManager.selectOperators("5");
}
else
{
operators = DBManager.selectOperators("9");
}
operatorNameBox.ItemsSource = operators.AsDataView();
}
catch
{
}
}
}
}