-
Notifications
You must be signed in to change notification settings - Fork 0
/
StaffSelect.cs
163 lines (131 loc) · 5.3 KB
/
StaffSelect.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
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
/// Grenci CPA 411 Project
/// Authors: Justin Bloss, Will Hoffman, Victor Stahlman, & Cameron Weaver
/// Project goal: make a program for Dr. Anthony Grenci to use at his CPA firm to keep track of billing, and automate the calculation process.
/// Page: This page is for selecting who is working on stuff. basically it is a quick way to search what jobs a staff is doing.
/// one can add and edit staff with the buttons on the form that link to StaffAddEdit
/// hitting select will bring up a list of active jobs they are working on.
///
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace GrenciCPA
{
public partial class StaffSelect : Form
{
private string connectionString;
private SqlCommand command;
private SqlConnection connection;
private int staffID = 0;
private List<AStaff> StaffObjList;
public StaffSelect()
{
InitializeComponent();
}
private void CreateStaffList()
{
StaffObjList.Clear();
string GetStaffSQL = "SELECT STAFF_ID, STAFF_FIRST_NAME, STAFF_LAST_NAME, STAFF_RATE_PER_HR, STAFF_ACTIVE FROM STAFF_TABLE";
//Pulled from App.config
connectionString = Properties.Settings.Default.GrenciDBConnectionString;
try
{
connection = new SqlConnection(connectionString);
command = new SqlCommand(GetStaffSQL, connection);
//Open the connection
connection.Open();
//Create a SQL Data Reader object
SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
//Keep reading as long as I have data from the database to read
while (reader.Read())
{
AStaff tempStaff = new AStaff();
if (reader["STAFF_ID"] != DBNull.Value)
{
tempStaff.StaffID = (reader["STAFF_ID"] as int?) ?? 0;
}
if (reader["STAFF_FIRST_NAME"] != DBNull.Value)
{
tempStaff.StaffFirstName = reader["STAFF_FIRST_NAME"] as string;
}
if (reader["STAFF_LAST_NAME"] != DBNull.Value)
{
tempStaff.StaffLastName = reader["STAFF_LAST_NAME"] as string;
}
if (reader["STAFF_RATE_PER_HR"] != DBNull.Value)
{
tempStaff.StaffRate = (reader["STAFF_RATE_PER_HR"] as decimal?) ?? 0.00m;
}
if (reader["STAFF_ACTIVE"] != DBNull.Value)
{
tempStaff.Active = reader.GetBoolean(reader.GetOrdinal("STAFF_ACTIVE"));
}
//Add the temporary plot stuff from list.
StaffObjList.Add(tempStaff);
tempStaff = null;
}
connection.Close();
}
catch (Exception ex)
{
MessageBox.Show("Could not retrieve clients from Database.! \n Error reads: " + ex.Message);
}
}
private void FillStaffDropdown()
{
foreach (AStaff aStaff in StaffObjList)
{
cboStaff.Items.Add(aStaff.StaffFirstName + " " + aStaff.StaffLastName);
}
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnSelect_Click(object sender, EventArgs e)
{
foreach (AStaff aStaff in StaffObjList)
{
if (cboStaff.Text == aStaff.StaffFirstName + " " + aStaff.StaffLastName)
staffID = aStaff.StaffID;
}
if (staffID != 0)
{
Jobs form = new Jobs(staffID, " ");//way to quickly make an overload on the jobs
form.ShowDialog();
StaffSelect_Load(null, null);
}
}
private void btnEdit_Click(object sender, EventArgs e)
{
foreach (AStaff aStaff in StaffObjList)
{
if (cboStaff.Text == aStaff.StaffFirstName + " " + aStaff.StaffLastName)
staffID = aStaff.StaffID;
}
if (staffID != 0)
{
StaffAddEdit form = new StaffAddEdit(staffID);
form.ShowDialog();
StaffSelect_Load(null, null);
}
}
private void btnAdd_Click(object sender, EventArgs e)
{
StaffAddEdit form = new StaffAddEdit();
form.ShowDialog();
}
private void StaffSelect_Load(object sender, EventArgs e)
{
StaffObjList = new List<AStaff>();
CreateStaffList();
FillStaffDropdown();
}
}
}