Currently my app checks to see if what a managers Email address is based on the department that an employee submitting a form is in.
It then sends an email to the manager notifying them that there is a pending requestl
This is shown in the following code:
string sEmail = null; using (SqlCommand cmd = new SqlCommand(@"SELECT dm.ManagerEmployeeID FROM [PTO].[dbo].[Employees] e1 INNER JOIN [PTO].[dbo].[DepartmentManagers] dm ON dm.DepartmentID = e1.DepartmentID WHERE e1.EmployeeID = @EmployeeID", conn)) { cmd.Parameters.AddWithValue("@EmployeeID", sEmpId); int nMgrEmpID = Convert.ToInt32(cmd.ExecuteScalar()); if (nMgrEmpID > 0) { using (SqlConnection connCUDB = new SqlConnection(ConfigurationManager.ConnectionStrings["CentralUserDB"].ConnectionString)) { connCUDB.Open(); try { using (SqlCommand cmdCUDB = new SqlCommand(@"SELECT Email FROM Users WHERE AdjusterNumber = @PilotID", connCUDB)) { cmdCUDB.Parameters.AddWithValue("@PilotID", nMgrEmpID); object o = cmdCUDB.ExecuteScalar(); if (o != DBNull.Value) { sEmail = Convert.ToString(o); } } } finally { connCUDB.Close(); } } } } if (!String.IsNullOrWhiteSpace(sEmail)) { //email MailMessage msg = new MailMessage(); //msg.To.Add("XXX@gmail.com"); msg.To.Add(sEmail); msg.Subject = "PTO Request "; //msg.From = new MailAddress("XXX@gmail.com"); msg.From = new MailAddress("jXXXr@pilotcat.com"); msg.Body = "A PTO Request has been submitted for your approval"; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.EnableSsl = true; smtp.UseDefaultCredentials = true; smtp.Credentials = new System.Net.NetworkCredential("XXX7@gmail.com", "*"); smtp.Send(msg); } }
I was told that there would be certain situations that a department will have more than one manager. So I need to somehow change the way I set them email value.
Someone mentioned that I could use a SQL Data Reader and put the info into an Array.
I'm just not sure how I would go about doing that. Can someone show me what I need to change in this code in order to accomplish this.
Thanks
JS