-
Notifications
You must be signed in to change notification settings - Fork 0
/
ApproveAllocation.xaml.cs
131 lines (105 loc) · 4.59 KB
/
ApproveAllocation.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
using ClosedXML.Excel;
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 ApproveAllocation.xaml
/// </summary>
public partial class ApproveAllocation : Window
{
DataTable values,valuesC;
string allocationID="",allocateToID="";
string equipmentID = "", requestID = "";
int myGridSelectedIndex = 0;
private void printButton_Click(object sender, RoutedEventArgs e)
{
if(Home.printDatatableToExcel("Approved Allocations", "approved_items", valuesC))
{
myMessageBox mm = new myMessageBox("Exported to Excel Succefully", "Success", "Ok", 0);
mm.ShowDialog();
}
else
{
myMessageBox mm = new myMessageBox("Error Occured", "Error", "Ok", 1);
mm.ShowDialog();
}
}
public ApproveAllocation()
{
InitializeComponent();
try
{
values = DBManager.selectForAllocationApproval();
valuesC = values.Clone();
approved_Items.ItemsSource = valuesC.AsDataView();
approve_allocation_request.ItemsSource = values.AsDataView();
}
catch
{
}
}
private void approve_allocation_request_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
try
{
myGridSelectedIndex = approve_allocation_request.SelectedIndex;
allocationID = values.Rows[approve_allocation_request.SelectedIndex][0].ToString();
equipmentID = values.Rows[approve_allocation_request.SelectedIndex][1].ToString();
allocateToID= values.Rows[approve_allocation_request.SelectedIndex][5].ToString();
requestID = values.Rows[approve_allocation_request.SelectedIndex][6].ToString();
}
catch
{
}
}
private void approveButton_Click(object sender, RoutedEventArgs e)
{
try
{
if ((equipmentID != "") && (allocationID != "") && allocateToID != "")
{
string query = "UPDATE allocate_item SET allocation_date='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',om_approved='1' WHERE id='" + allocationID + "'";
string query2 = "UPDATE equipment_list SET current_Location='" + allocateToID + "' WHERE equipment_id='" + equipmentID + "'";
int allocatedNo = Convert.ToInt32(DBManager.selectAllocatedNumber(requestID).Rows[0][0].ToString());
string query3 = "UPDATE allocation_request SET allocated_item_no=" + (allocatedNo + 1) + " WHERE id='" + requestID + "'";
if (DBManager.UpdateDatabaseQuery(query) && DBManager.UpdateDatabaseQuery(query2) && DBManager.UpdateDatabaseQuery(query3))
{
valuesC.Rows.Add(values.Rows[myGridSelectedIndex].ItemArray);
//approved_Items.Columns.Add(approve_allocation_request.)
myMessageBox mm = new myMessageBox("Approved Successfully", "Success", "OK", 0);
mm.ShowDialog();
// MessageBox.Show("Approved Succefully", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
values = DBManager.selectForAllocationApproval();
approve_allocation_request.ItemsSource = values.AsDataView();
allocationID = "";
allocateToID = "";
equipmentID = "";
}
else
{
myMessageBox mm = new myMessageBox("Error Occured", "Error", "OK", 1);
mm.ShowDialog();
// MessageBox.Show("Error Occured", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
catch
{
}
}
}
}