//get dictionary of days and the hours that users worked in this day on any project public static Dictionary <string, double> GetHoursWorkedOnProjectByDays(int idProject, int month) { //select days and for every day the sum of hours that the users worked on specipic project on specipic month string query = $"SELECT DAY(d.startDatePresence),sum(SELECT DATEDIFF(hour,startDatePresence,endDatePresence) FROM truth_time_ct.daily_presence d WHERE idProject={idProject} and month(startDatePresence)={month} group by(DAY(startDatePresence))) "; Func <MySqlDataReader, Dictionary <string, double> > func = (reader) => { Dictionary <string, double> DailySupply = new Dictionary <string, double>(); while (reader.Read()) { DailySupply.Add( (string)reader[0], (double)reader[1]); } return(DailySupply); }; return(DBUse.RunReaderDictionary(query, func)); }
//why not * up.idUserProject,up.hoursProjectUser,up.idUser,up.idProject //return dictionary of userProject and the hours that the user worked to this userProject; public static Dictionary <UserProject, double> GetDictionaryOfHoursThatUserWorkedOnProjectInPrecent(int idUser) { //for user select all data of userProjects of him with the time that he worked for that project; string query = $"SELECT *,sum(SELECT DATEDIFF(hour, startDatePresence, endDatePresence) FROM truth_time_ct.daily_presence WHERE idProject=up.idProject and idUser={idUser}) from truth_time_ct.users_projects up WHERE up.idUser={idUser} Group By up.idUserProject,up.hoursProjectUser,up.idUser,up.idProject"; Func <MySqlDataReader, Dictionary <UserProject, double> > func = (reader) => { Dictionary <UserProject, double> myDictionary = new Dictionary <UserProject, double>(); while (reader.Read()) { myDictionary.Add(new UserProject { IdUserProject = (int)reader[0], HoursProjectUser = (int)reader[1], IdUser = (int)reader[2], IdProject = (int)reader[3] }, (int)reader[4]); } return(myDictionary); }; return(DBUse.RunReaderDictionary(query, func)); }