public string RegisterShift(Shift shift, Instructor instructor, string shiftType, string _IDClone, DateTime dateToday) { string returnMessage = ""; string mailExceptionHolder = ""; int salary = shift.Salary; string hireDate = instructor.HireDate; DateTime ShiftDateTime = DateTime.Parse(dateToday.ToString()); bool _DateRegistered = CheckDate(_IDClone, ShiftDateTime); if (_DateRegistered == true) { using (SqlConnection con = new SqlConnection(_ConnectionString)) { try { con.Open(); SqlCommand _GetEmploymentDate = new SqlCommand("spGetStartDate", con); _GetEmploymentDate.CommandType = System.Data.CommandType.StoredProcedure; _GetEmploymentDate.Parameters.Add(new SqlParameter("@Medlemsnr", _IDClone)); SqlDataReader reader = _GetEmploymentDate.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { hireDate = reader["Ansat"].ToString(); } } reader.Close(); DateTime employmentDate = DateTime.Parse(hireDate); DateTime watchDate = ShiftDateTime; watchDate = watchDate.AddYears(-3); if (employmentDate <= watchDate) { salary = 100; } else { salary = 75; } SqlCommand spinningWatch = new SqlCommand("spRegisterWatch", con); spinningWatch.CommandType = System.Data.CommandType.StoredProcedure; spinningWatch.Parameters.Add(new SqlParameter("@Medlemsnr", _IDClone)); spinningWatch.Parameters.Add(new SqlParameter("@Type", shiftType)); spinningWatch.Parameters.Add(new SqlParameter("@Dato", dateToday)); spinningWatch.Parameters.Add(new SqlParameter("@Honorar", salary)); spinningWatch.ExecuteNonQuery(); mailExceptionHolder = GetMail(_IDClone, ShiftDateTime.ToString()); } catch (SqlException e) { returnMessage = "FEJL: " + e.Message; } catch (FormatException e1) { returnMessage = "FEJL: " + e1.Message; } catch (Exception e2) { returnMessage = "FEJL: Forkert indtastet - " + e2.Message; } returnMessage = returnMessage + mailExceptionHolder; if (returnMessage == "") { returnMessage = "Vagt registreret og mail sendt"; } } } else { returnMessage = "Der er allerede en vagt registreret for denne dato."; } return(returnMessage); }
internal string GetShiftListAll(Shift shift, Instructor instructor, string startDate, string endDate) { DateTime ShiftStartDate = DateTime.Parse(startDate.ToString()); DateTime ShiftEndDate = DateTime.Parse(endDate.ToString()); DateTime DT; string ifError = ""; string normalRows = ""; string shiftListFromDatabaseAll = ""; //Variables for subtotal calculation: string currentName = ""; string previousName = ""; int i = -1; string subtotalRows = ""; using (SqlConnection con = new SqlConnection(_ConnectionString)) { try { con.Open(); SqlCommand _ShowShiftListAll = new SqlCommand("spShowShiftsFromSpecificPeriod", con); _ShowShiftListAll.CommandType = CommandType.StoredProcedure; _ShowShiftListAll.Parameters.Add(new SqlParameter("@startDate", ShiftStartDate)); _ShowShiftListAll.Parameters.Add(new SqlParameter("@endDate", ShiftEndDate)); SqlDataReader reader = _ShowShiftListAll.ExecuteReader(); List <int> subtotal = new List <int>(); if (reader.HasRows) { while (reader.Read()) { currentName = reader["Navn"].ToString(); if (currentName != previousName) { if (i > -1) { subtotalRows = subtotalRows + previousName + ": " + subtotal[i] + "kr." + "\n"; } i++; subtotal.Add(0); } instructor.InstructorID = reader["InstructorID"].ToString(); instructor.Name = currentName; shift.Type = reader["Type"].ToString(); DT = DateTime.Parse(reader["Dato"].ToString()); shift.Date = DT.ToString("dd-MM-yyyy"); string salary = reader["Honorar"].ToString(); previousName = instructor.Name; shift.Salary = int.Parse(salary); subtotal[i] = subtotal[i] + shift.Salary; normalRows = normalRows + (instructor.InstructorID + " | " + instructor.Name + " | " + shift.Type + " | " + shift.Date + " | " + shift.Salary + "\n"); } } subtotalRows = subtotalRows + previousName + ": " + subtotal[i] + "kr." + "\n"; } catch (SqlException e) { ifError = "FEJL: " + e.Message; } catch (FormatException e1) { ifError = "FEJL: " + e1.Message; } shiftListFromDatabaseAll = normalRows + subtotalRows; if (ifError != "") { shiftListFromDatabaseAll = ifError; } return(shiftListFromDatabaseAll); } }
public void AddToRepo(Shift shift) { _ShiftList.Add(shift); }