private void ServiceTimer_Tick(object sender, System.Timers.ElapsedEventArgs e) { timer.Stop(); DateTime now = DateTime.Now; if (now.ToShortTimeString().Substring(0, 1) == ConfigurationValues.HourToRun && now.ToShortTimeString().IndexOf(ConfigurationValues.AmPmToRun) > 0) { DeleteEmployeeData(); List<EBSEmployee> employeeDataList = new List<EBSEmployee>(); EBSEmployee employeeData = new EBSEmployee(); try { string sql = "SELECT Employee_ID,Name_First, Name_Last,Status,Phone_Mobile,Bussiness_Unit,Location,Email_personal,flag_mobile_tel,Flag_txt_msg,Flag_email,Flag_Home_tel,Phone_home,CareProviderID,Username,UserID from EBS_Employees"; using (OdbcConnection conn = new OdbcConnection("DSN=Test;Uid=walden;Pwd=walden")) { conn.Open(); using (OdbcCommand comm = new OdbcCommand(sql, conn)) { OdbcDataReader dr = comm.ExecuteReader(); while (dr.Read()) { try { employeeData = new EBSEmployee(); try { employeeData.Employee_ID = dr.GetString(0); } catch { } try { employeeData.Name_First = dr.GetString(1) + " " + dr.GetString(2); } catch { } try { employeeData.Status = dr.GetString(3); } catch { } try { employeeData.Phone_Mobile = dr.GetString(4); } catch { } try { employeeData.Bussiness_Unit = dr.GetString(5); } catch { } try { employeeData.Location = dr.GetString(6); } catch { } try { employeeData.Email_personal = dr.GetString(7); } catch { } try { employeeData.flag_mobile_tel = dr.GetString(8); } catch { } try { employeeData.Flag_txt_msg = dr.GetString(9); } catch { } try { employeeData.Flag_email = dr.GetString(10); } catch { } try { employeeData.Flag_Home_tel = dr.GetString(11); } catch { } try { employeeData.Phone_Home = dr.GetString(12); } catch { } try { employeeData.CareProviderID = dr.GetString(13); } catch { } try { employeeData.Username = dr.GetString(14); } catch { } try { employeeData.UserID = dr.GetString(15); } catch { } } catch (Exception er) { Logging.LogErrors(ConfigurationValues.ErrorLogPath, er.ToString()); } InsertEmployeeData(employeeData); employeeDataList.Add(employeeData); } } } } catch (Exception er) { Logging.LogErrors(ConfigurationValues.ErrorLogPath, er.ToString()); } Console.WriteLine(DateTime.Now.ToShortTimeString()); Thread.Sleep(3600000); } timer.Start(); }
private static void InsertEmployeeData(EBSEmployee employeeData) { using (IDbConnection db = new SqlConnection("Server=HMDN-FAX\\WALDENLTD;User ID=sa;password=0Griswold;Database=walden;Persist Security Info=True")) { try { const string query = "INSERT INTO [EmployeeData]" + " (" + " [Employee_ID]" + " ,[Name_First]" + " ,[Name_Last]" + " ,[Phone_Mobile]" + " ,[Phone_Home]" + " ,[Bussiness_Unit]" + " ,[Status]" + " ,[Location]" + " ,[Department]" + " ,[Email_personal]" + " ,[flag_mobile_tel]" + " ,[Flag_txt_msg]" + " ,[Flag_email]" + " ,[Flag_Home_tel]" + " ,[CareProviderID]" + " ,[Username]" + " ,[UserID]" + " )" + " VALUES" + " (" + " @Employee_ID,@Name_First,@Name_Last,@Phone_Mobile,@Phone_Home,@Bussiness_Unit,@Status" + " ,@Location,@Department,@Email_personal,@flag_mobile_tel,@Flag_txt_msg,@Flag_email" + " ,@Flag_Home_tel,@CareProviderID,@Username,@UserID" + " )"; int rowsAffectd = db.Execute(query, employeeData); // return true; } catch (Exception er) { string s1 = er.ToString(); // return false; //Log.LogMessage(er.ToString()); } } }