public void GetIssue_ProjectFromRedmine(bool redmineProject, bool selectedProject, bool bothProject, string textProject) { redmineData.listIssue.Clear(); redmineData.listOpenIssue.Clear(); redmineData.listProject.Clear(); redmineData.listMonthHours.Clear(); List <string> listProject = getListProject(textProject); try { NameValueCollection parametr = new NameValueCollection { { "project_id", "*" } }; foreach (Project project in redmineManager.GetObjects <Project>(parametr)) { //MessageBox.Show(project.Status.ToString()); //redmineData.listProject.Add(project); if (isAddProject(redmineProject, selectedProject, bothProject, listProject, project)) { redmineData.listProject.Add(project); } } parametr = new NameValueCollection { { "status_id", "open" } }; foreach (Issue issue in redmineManager.GetObjects <Issue>(parametr)) { Project project = redmineData.listProject.Find(x => x.Id == issue.Project.Id); if (project != null) { if ((issue.StartDate != null) & (issue.DueDate != null) & (issue.AssignedTo != null)) { redmineData.listOpenIssue.Add(issue); } } } parametr = new NameValueCollection { { "status_id", "*" } }; foreach (Issue issue in redmineManager.GetObjects <Issue>(parametr)) { Project project = redmineData.listProject.Find(x => x.Id == issue.Project.Id); if (issue.Id == 936) { Issue issue_jornals = redmineManager.GetObject <Issue>(issue.Id.ToString(), new NameValueCollection { { "include", "journals" } }); this.EmailSaveIssue = issue_jornals; } if (issue.Id == 937) { Issue issue_jornals = redmineManager.GetObject <Issue>(issue.Id.ToString(), new NameValueCollection { { "include", "journals" } }); foreach (var journal in issue_jornals.Journals) { string note = journal.Notes; if (!note.Equals("")) { MonthHours monthHours = new MonthHours(note); redmineData.listMonthHours.Add(monthHours); } } } if (project != null) { if ((issue.StartDate != null) & (issue.DueDate != null) & (issue.AssignedTo != null)) { redmineData.listIssue.Add(issue); //if (!issue.Status.Name.Contains("Закрыта") & !issue.Status.Name.Contains("Решена") & // !issue.Status.Name.Contains("Отклонена")) //{ // foreach (IssueRelation issueRelation in redmineManager.GetObjects<IssueRelation>(new NameValueCollection { { "issue_id", issue.Id.ToString() } })) // { // if (issueRelation != null) // issue.Relations.Add(issueRelation); // } //} } } //else // listIssue.Add(issue); } } catch (Exception ex) { MessageBox.Show("Error - " + ex.Message); MessageBox.Show(redmineData.listIssue[(redmineData.listIssue.Count - 1)].Id.ToString()); } LoadHours.GetYearsFromListIssue(listYear, redmineData.listIssue); }
public void GetUserFromRedmine(Dictionary <string, string> bossName) //params string[] noNameForReport) { NameValueCollection parametr; countTotalRecord = 0; curReadRecord = 0; ClearLists(); progressBar.InvokeIfNeeded(delegate { progressBar.DisplayStyle = ProgressBarDisplayText.CustomText; }); progressBar.InvokeIfNeeded(delegate { progressBar.CustomText = "Загрузка записей, подождите пожалуйста."; }); progressBar.InvokeIfNeeded(delegate { progressBar.Minimum = 0; }); //SetInitProgBar(progressBar, 0, 5, 1); try { //parametr = new NameValueCollection { { "user_id", "*" } }; //countTotalRecord += redmineManager.GetObjects<User>(parametr).Count; //progressBar.InvokeIfNeeded(delegate { progressBar.PerformStep(); }); //progressBar.InvokeIfNeeded(delegate { progressBar.CustomText = "Список № " + progressBar.Value + "/5"; }); //parametr = new NameValueCollection { { "group_id", "*" } }; //countTotalRecord += redmineManager.GetObjects<Group>(parametr).Count; //progressBar.InvokeIfNeeded(delegate { progressBar.PerformStep(); }); //progressBar.InvokeIfNeeded(delegate { progressBar.CustomText = "Список № " + progressBar.Value + "/5"; }); //parametr = new NameValueCollection { { "status_id", "*" } }; //countTotalRecord += redmineManager.GetObjects<Issue>(parametr).Count; //progressBar.InvokeIfNeeded(delegate { progressBar.PerformStep(); }); //progressBar.InvokeIfNeeded(delegate { progressBar.CustomText = "Список № " + progressBar.Value + "/5"; }); //parametr = new NameValueCollection { { "project_id", "*" } }; //countTotalRecord += redmineManager.GetObjects<Project>(parametr).Count; //progressBar.InvokeIfNeeded(delegate { progressBar.PerformStep(); }); //progressBar.InvokeIfNeeded(delegate { progressBar.CustomText = "Список № " + progressBar.Value + "/5"; }); //parametr = new NameValueCollection { { "user_id", "*" } }; //countTotalRecord += redmineManager.GetObjects<TimeEntry>(parametr).Count; //progressBar.InvokeIfNeeded(delegate { progressBar.PerformStep(); }); //progressBar.InvokeIfNeeded(delegate { progressBar.CustomText = "Список № " + progressBar.Value + "/5"; }); //progressBar.InvokeIfNeeded(delegate { progressBar.Value = 0; }); //progressBar.InvokeIfNeeded(delegate { progressBar.Maximum = countTotalRecord; }); //progressBar.InvokeIfNeeded(delegate { progressBar.Step = 1; }); parametr = new NameValueCollection { { "user_id", "*" } }; List <User> listUserRedm = redmineManager.GetObjects <User>(parametr); countTotalRecord = listUserRedm.Count; SetInitProgBar(progressBar, 0, countTotalRecord, 1); foreach (var user in listUserRedm) { if (user.IsCustomFieldEqual("Учет трудозатратах/месяц")) { listUser.Add(user); //userRedmine.listIssue = this.listIssue; UserRedmine userRedmine = new UserRedmine(this.monthValueHours); userRedmine.bossName = bossName; userRedmine.Value = user; userRedmine.listProject = this.listProject; curReadRecord++; progressBar.InvokeIfNeeded(delegate { progressBar.PerformStep(); }); progressBar.InvokeIfNeeded(delegate { progressBar.CustomText = "Запись № " + progressBar.Value + "/ " + countTotalRecord; }); listUserRedmine.Add(userRedmine); Debug.WriteLine(curReadRecord); } //parametr = new NameValueCollection { { "user_id", user.Id.ToString() } }; //int count = redmineManager.GetObjects<TimeEntry>(parametr).Count; //if (count > 0) //{ // UserRedmine userRedmine = new UserRedmine(); // userRedmine.Value = user; // listUserRedmine.Add(userRedmine); // Console.WriteLine("Name = {0}, Count time entry = {1}", user.LastName, count); //} } parametr = new NameValueCollection { { "group_id", "*" } }; List <Group> listGroupRedm = redmineManager.GetObjects <Group>(parametr); countTotalRecord = listGroupRedm.Count; SetInitProgBar(progressBar, 0, countTotalRecord, 1); foreach (Group group in listGroupRedm) { curReadRecord++; progressBar.InvokeIfNeeded(delegate { progressBar.PerformStep(); }); progressBar.InvokeIfNeeded(delegate { progressBar.CustomText = "Запись № " + progressBar.Value + "/ " + countTotalRecord; }); UserGroup userGroup = new UserGroup(group.Name, group.Id); listUserRedm = redmineManager.GetObjects <User>(new NameValueCollection { { "group_id", group.Id.ToString() } }); foreach (User user in listUserRedm) { UserRedmine userRedmine = listUserRedmine.Find(x => x.Value.Id == user.Id); if (userRedmine != null) { userRedmine.listUserGroup.Add(userGroup); } } } //parametr = new NameValueCollection { { "status_id", "*" } };//{ "status_id", "*" } //Issue issueIdRedm = redmineManager.GetObject<Issue>("1435", parametr); Issue issue_jornals = redmineManager.GetObject <Issue>("1435", new NameValueCollection { { "include", "journals" } }); if (issue_jornals != null) { foreach (var journal in issue_jornals.Journals) { string note = journal.Notes; if (!note.Equals("")) { MonthHours monthHours = new MonthHours(note); listMonthHours.Add(monthHours); } } } parametr = new NameValueCollection { { "created_on", ">=" + GetFirstDateCurYear() } }; //{ "status_id", "*" } List <Issue> listIssueRedm = redmineManager.GetObjects <Issue>(parametr); countTotalRecord = listIssueRedm.Count; SetInitProgBar(progressBar, 0, countTotalRecord, 1); foreach (Issue issue in listIssueRedm) { listIssue.Add(issue); curReadRecord++; progressBar.InvokeIfNeeded(delegate { progressBar.PerformStep(); }); progressBar.InvokeIfNeeded(delegate { progressBar.CustomText = "Запись № " + progressBar.Value + "/ " + countTotalRecord; }); Debug.WriteLine(curReadRecord); Debug.WriteLine(issue.CreatedOn.Value); //if (issue.Id == 1435) //{ // Issue issue_jornals = redmineManager.GetObject<Issue>(issue.Id.ToString(), // new NameValueCollection { { "include", "journals" } }); // foreach (var journal in issue_jornals.Journals) // { // string note = journal.Notes; // if (!note.Equals("")) // { // MonthHours monthHours = new MonthHours(note); // listMonthHours.Add(monthHours); // } // } //} } parametr = new NameValueCollection { { "project_id", "*" } }; List <Project> listProjectRedm = redmineManager.GetObjects <Project>(parametr); countTotalRecord = listProjectRedm.Count; SetInitProgBar(progressBar, 0, countTotalRecord, 1); foreach (Project project in listProjectRedm) { listProject.Add(project); curReadRecord++; progressBar.InvokeIfNeeded(delegate { progressBar.PerformStep(); }); progressBar.InvokeIfNeeded(delegate { progressBar.CustomText = "Запись № " + progressBar.Value + "/ " + countTotalRecord; }); } parametr = new NameValueCollection { { "spent_on", ">=" + GetFirstDateCurYear() } }; //{ "user_id", "*" } List <TimeEntry> listTimeEntryRedm = redmineManager.GetObjects <TimeEntry>(parametr); //List<TimeEntry> listTimeEntryUnique = new List<TimeEntry>(); TimeEntry timeUniqe; for (int i = 0; i < listTimeEntryRedm.Count; i++) { TimeEntry timeI = listTimeEntryRedm[i]; timeUniqe = timeI; int j = i + 1; while (j < listTimeEntryRedm.Count) { TimeEntry timeJ = listTimeEntryRedm[j]; if ((timeI.User.Id == timeJ.User.Id) & (timeI.Project.Id == timeJ.Project.Id) & (timeI.Activity.Id == timeJ.Activity.Id) & (timeI.Id != timeJ.Id) & (timeI.SpentOn.Value.Date.Month == timeJ.SpentOn.Value.Date.Month)) { // TODO добавить поиск даты старта и даты финиша суммарной задчи timeI DateTime startDateTimeI = timeI.GetDateValue("Дата старта", TypeDates.Start); DateTime finishDateTimeI = timeI.GetDateValue("Дата завершения", TypeDates.Finish); DateTime startDateTimeJ = timeJ.GetDateValue("Дата старта", TypeDates.Start); DateTime finishDateTimeJ = timeJ.GetDateValue("Дата завершения", TypeDates.Finish); if (startDateTimeI.CompareTo(startDateTimeJ) > 0) { timeI.SetDateValue("Дата старта", startDateTimeJ); } if (finishDateTimeI.CompareTo(finishDateTimeJ) < 0) { timeI.SetDateValue("Дата завершения", finishDateTimeJ); } timeI.Hours += timeJ.Hours; listTimeEntryRedm.Remove(timeJ); } else { j++; } } } countTotalRecord = listTimeEntryRedm.Count; SetInitProgBar(progressBar, 0, countTotalRecord, 1); var qTimeEntryAll = from time in listTimeEntryRedm from userRedmine in listUserRedmine from project in listProject where time.User.Id == userRedmine.Value.Id where ((time.Project.Id == project.Id) & project.IsPublic) select new { listIssue = userRedmine.listIssue, listProject = userRedmine.listProject, userRedmine = userRedmine, listUser = listUser, Value = time }; foreach (var time in qTimeEntryAll) { UserTimeEntry userTimeEntry = new UserTimeEntry(time.listIssue, time.listProject, time.userRedmine, time.listUser); userTimeEntry.Value = time.Value; time.userRedmine.listUserTimeEntry.Add(userTimeEntry); } //foreach (var time in listTimeEntryRedm) //{ // UserRedmine userRedmine = listUserRedmine.Find(x => x.Value.Id == time.User.Id); // Project project = listProject.Find(x => x.Id == time.Project.Id); // curReadRecord++; // progressBar.InvokeIfNeeded(delegate { progressBar.PerformStep(); }); // progressBar.InvokeIfNeeded(delegate {progressBar.CustomText = "Запись № " + progressBar.Value + // "/ " + countTotalRecord; // }); // if (userRedmine != null) // { // if (project != null) // { // if (project.IsPublic) // { // UserTimeEntry userTimeEntry = new UserTimeEntry(userRedmine.listIssue, userRedmine.listProject, // userRedmine, listUser); // userTimeEntry.Value = time; // userRedmine.listUserTimeEntry.Add(userTimeEntry); // } // } // } //} } catch (Exception ex) { MessageBox.Show("Error - " + ex.Message); } listUserRedmine.Sort(); }