示例#1
0
        private async void btnSync_Click(object sender, EventArgs e)
        {
            this.btnSync.Enabled = false;

            try
            {
                DateTime from     = this.dtpFrom.Value;
                DateTime to       = this.dtpTo.Value;
                string   userName = this.txtUser.Text;
                string   password = this.txtPassword.Text;

                string MEOOption = this.cmbMEOOptions.SelectedValue as string;
                string status    = this.cmbSubTaskStatusOptions.SelectedValue as string;

                if (String.IsNullOrEmpty(userName) || userName.Trim().Length == 0 || String.IsNullOrEmpty(password) || password.Trim().Length == 0)
                {
                    MessageBox.Show("User Name and Password cannot be empty.");
                    this.btnSync.Enabled = true;
                    return;
                }

                List <string> subTaskStatusList = new List <string>();
                if (String.IsNullOrEmpty(status) && status.Trim().Length > 0 && status == "Empty")
                {
                    subTaskStatusList.Add(status);
                }

                List <string> meoOptions = new List <string>();
                if (!String.IsNullOrEmpty(MEOOption) && MEOOption.Trim().Length > 0 && MEOOption != "Empty")
                {
                    meoOptions.Add(MEOOption);
                }

                var issues = await JiraProxy.GetUpdatedIssueListByTimeslot(userName, password, from, to, subTaskStatusList, meoOptions);

                /*
                 * issue.fields.assignee.name = "*****@*****.**"
                 * issue.fields.assignee.emailAddress = "*****@*****.**"
                 * issue.fields.assignee.displayName = "Gordon Chen"
                 * issue.fields.issueType.name = "Sub-task"
                 * issue.fields.issueType.subtask = true
                 * issue.fields.parent.key = "ENGSUPP-14215"
                 * issue.fields.parent.fields.summary = "Unable to delete logs in Batch Engine"
                 * issue.fields.parent.fields.status.name = "In Progress"
                 * */

                string defaultMEO = this.cmbDefautMEO.SelectedValue as string;
                if (defaultMEO == "Empty")
                {
                    defaultMEO = "";
                }

                List <SubTask> SubTaskList = new List <SubTask>();
                foreach (var issue in issues)
                {
                    SubTask subTask = new SubTask();
                    subTask.SubTaskKey            = issue.key;
                    subTask.SubTaskSummary        = issue.fields.summary;
                    subTask.SubTaskStatus         = issue.fields.status.name;
                    subTask.SubTaskAssignee       = issue.fields.assignee.displayName;
                    subTask.MEO                   = issue.fields.customfield_14101 != null ? issue.fields.customfield_14101.value : defaultMEO;
                    subTask.TimeSpent             = "" + Math.Round((double)issue.fields.timespent / 3600, 2) + "h";
                    subTask.AssociatedJirakey     = issue.fields.parent.key;
                    subTask.AssociatedJiraSummary = issue.fields.parent.fields.summary;

                    SubTaskList.Add(subTask);
                }

                DataTable table = new DataTable("M.E.O Report");
                table.Columns.Add("No", typeof(int));
                table.Columns.Add("SubTaskKey", typeof(string));
                table.Columns.Add("SubTaskSummary", typeof(string));
                table.Columns.Add("SubTaskStatus", typeof(string));
                table.Columns.Add("SubTaskAssignee", typeof(string));
                table.Columns.Add("MEO", typeof(string));
                table.Columns.Add("TimeSpent", typeof(string));
                table.Columns.Add("AssociatedJirakey", typeof(string));
                table.Columns.Add("AssociatedJiraSummary", typeof(string));

                int index = 1;
                foreach (var subTask in SubTaskList)
                {
                    DataRow row = table.NewRow();
                    row["No"]                    = index;
                    row["SubTaskKey"]            = subTask.SubTaskKey;
                    row["SubTaskSummary"]        = subTask.SubTaskSummary;
                    row["SubTaskStatus"]         = subTask.SubTaskStatus;
                    row["SubTaskAssignee"]       = subTask.SubTaskAssignee;
                    row["MEO"]                   = subTask.MEO;
                    row["TimeSpent"]             = subTask.TimeSpent;
                    row["AssociatedJirakey"]     = subTask.AssociatedJirakey;
                    row["AssociatedJiraSummary"] = subTask.AssociatedJiraSummary;

                    table.Rows.Add(row);
                    index++;
                }

                this.dgvSubTaskTable.AutoGenerateColumns = false;
                this.dgvSubTaskTable.DataSource          = table;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            this.btnSync.Enabled = true;
        }
        private async void btnListWorkLogList_Click(object sender, EventArgs e)
        {
            this.btnListWorkLogList.Enabled = false;

            DateTime from = this.dtpFrom.Value;
            DateTime to   = this.dtpTo.Value;

            from = DateTime.Today.AddDays(-1);
            to   = DateTime.Today.AddDays(1);

            var GetUpdatedIssueListByAssignee = JiraProxy.GetUpdatedIssueListByTimeslot(from, to);
            var issueList = await GetUpdatedIssueListByAssignee;

            if (issueList == null || issueList.Count == 0)
            {
                return;
            }

            Dictionary <string, JiraTask> workLogsStore = new Dictionary <string, JiraTask>();

            foreach (var issue in issueList)
            {
                if (issue == null)
                {
                    continue;
                }

                string taskKey        = issue.fields.parent.key;
                string taskSummary    = issue.fields.parent.fields.summary;
                string taskType       = issue.fields.parent.fields.issuetype.name;
                string subTaskkey     = issue.key;
                string subTaskSummary = issue.fields.summary;

                var workLogs = await JiraProxy.GetWorklogs(issue);

                if (workLogs != null && workLogs.Count > 0)
                {
                    foreach (var worklog in workLogs)
                    {
                        if (worklog.created.Year == DateTime.Today.Year &&
                            worklog.created.Month == DateTime.Today.Month &&
                            worklog.created.Day == DateTime.Today.Day)
                        {
                            if (!workLogsStore.ContainsKey(taskKey))
                            {
                                JiraTask jiraTask = new JiraTask();
                                jiraTask.Key      = taskKey;
                                jiraTask.summary  = taskSummary;
                                jiraTask.Type     = taskType;
                                jiraTask.subTasks = new Dictionary <string, SubTask>();
                                workLogsStore.Add(taskKey, jiraTask);
                            }

                            JiraTask jiraTask1 = workLogsStore[taskKey];
                            if (!jiraTask1.subTasks.ContainsKey(subTaskkey))
                            {
                                SubTask subTask = new SubTask();
                                subTask.Key     = subTaskkey;
                                subTask.summary = subTaskSummary;
                                jiraTask1.subTasks.Add(subTaskkey, subTask);
                            }

                            SubTask subTask1 = jiraTask1.subTasks[subTaskkey];
                            if (subTask1.worklogs == null)
                            {
                                subTask1.worklogs = new List <Worklog>();
                            }

                            Worklog workLog = new Worklog();
                            workLog.displayName = worklog.author.displayName;
                            workLog.timeSpent   = worklog.timeSpent;
                            workLog.comment     = worklog.comment.Replace("\r\n", ";");
                            subTask1.worklogs.Add(workLog);

                            jiraTask1.subTasks[subTaskkey] = subTask1;
                            workLogsStore[taskKey]         = jiraTask1;
                        }
                    }
                }
            }

            /*
             * string dailyWorkLogSummaryReport = "";
             * int index1 = 1;
             * foreach (string taskKey in workLogsStore.Keys)
             * {
             *  JiraTask jiraTask = workLogsStore[taskKey];
             *
             *  dailyWorkLogSummaryReport += index1 + " " + jiraTask.Type + " - " + taskKey + " " + jiraTask.summary + "<br/>";
             *
             *  int index2 = 1;
             *  foreach (string subTaskkey in jiraTask.subTasks.Keys)
             *  {
             *      SubTask subTask = jiraTask.subTasks[subTaskkey];
             *
             *      dailyWorkLogSummaryReport += index1 + "." + index2 + " Sub Task: " + subTaskkey + " " + subTask.summary + "<br/>";
             *
             *      int index3 = 1;
             *      foreach (var workLog in subTask.worklogs)
             *      {
             *          dailyWorkLogSummaryReport += index1 + "." + index2 + "." + index3 + " " + workLog.displayName + "[" + workLog.timeSpent + "]" + workLog.comment + "<br/>";
             *
             *          index3++;
             *      }
             *
             *      index2++;
             *  }
             *
             *  dailyWorkLogSummaryReport += "<br/><br/>";
             *  index1++;
             * }
             */

            string dailyWorkLogSummaryReport = "";
            Dictionary <string, List <IndividualWorkLog> > IndividualWorkLogs = new Dictionary <string, List <IndividualWorkLog> >();

            foreach (string taskKey in workLogsStore.Keys)
            {
                JiraTask jiraTask = workLogsStore[taskKey];
                foreach (string subTaskkey in jiraTask.subTasks.Keys)
                {
                    SubTask subTask = jiraTask.subTasks[subTaskkey];
                    foreach (var workLog in subTask.worklogs)
                    {
                        IndividualWorkLog individualWorkLog = new IndividualWorkLog();
                        individualWorkLog.jiraKey        = taskKey;
                        individualWorkLog.summary        = jiraTask.summary;
                        individualWorkLog.subTaskSummary = subTask.summary;
                        individualWorkLog.timeSpent      = workLog.timeSpent;
                        individualWorkLog.comment        = workLog.comment;

                        if (!IndividualWorkLogs.ContainsKey(workLog.displayName))
                        {
                            IndividualWorkLogs.Add(workLog.displayName, new List <IndividualWorkLog>());
                        }
                        List <IndividualWorkLog> workLogs = IndividualWorkLogs[workLog.displayName];
                        workLogs.Add(individualWorkLog);
                        IndividualWorkLogs[workLog.displayName] = workLogs;
                    }
                }
            }

            dailyWorkLogSummaryReport = @"<table cellspacing='1' cellpadding='1' border='0' bgcolor='111111' style='border-collapse:collapse;border-spacing:0;border-left:1px solid #888;border-top:1px solid #888;background:#efefef;'>
                                            <tr>
                                                <td align='center' style='border-right:1px solid #888;border-bottom:1px solid #888;padding:1px 10px;'>No</td>
                                                <td align='center' style='border-right:1px solid #888;border-bottom:1px solid #888;padding:1px 10px;'>Name</td>
                                                <td align='center' style='border-right:1px solid #888;border-bottom:1px solid #888;padding:1px 10px;'>Work Logs</td>                                               
                                            </tr>";

            int i = 1;

            foreach (string name in IndividualWorkLogs.Keys)
            {
                dailyWorkLogSummaryReport += "  <tr>";
                dailyWorkLogSummaryReport += "      <td align='center' style='border-right:1px solid #888;border-bottom:1px solid #888;padding:1px 10px;'>" + i + "</td>";
                dailyWorkLogSummaryReport += "      <td align='center' style='border-right:1px solid #888;border-bottom:1px solid #888;padding:1px 10px;'>" + name + "</td>";
                dailyWorkLogSummaryReport += "      <td align='left' style='border-right:1px solid #888;border-bottom:1px solid #888;padding:1px 10px;'>";

                int j = 1;
                List <IndividualWorkLog> workLogs = IndividualWorkLogs[name];
                foreach (var worklog in workLogs)
                {
                    dailyWorkLogSummaryReport += "" + j + ") " + worklog.jiraKey + " - " + worklog.summary + "<br/>";
                    dailyWorkLogSummaryReport += "[" + worklog.subTaskSummary + "] " + worklog.timeSpent + " - " + worklog.comment + "<br/>";
                    j++;
                }
                dailyWorkLogSummaryReport += "      </td>";
                dailyWorkLogSummaryReport += "  </tr>";

                i++;
            }

            dailyWorkLogSummaryReport += "</table>";

            string content          = @"Hi, All guys<br/><br/>Below is the work log summary report.<br/><br/>" + dailyWorkLogSummaryReport + "Thanks<br/>Accela Support Team";
            string fromEmailAddress = "*****@*****.**";
            string toEmailAddress   = "[email protected];[email protected]";
            string ccEmailAddress   = "*****@*****.**";
            string subject          = "Daily Work Log Summary - " + DateTime.Now.Month + "/" + DateTime.Now.Day + "/" + DateTime.Now.Year;

            try
            {
                EmailUtil.SendEmail(fromEmailAddress, toEmailAddress, ccEmailAddress, subject, content);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Failed to send email");
            }

            System.Console.WriteLine(dailyWorkLogSummaryReport);

            this.btnListWorkLogList.Enabled = true;
        }