Example #1
0
        private void btnMerge_Click(object sender, EventArgs e)
        {
            this.btnSync.Enabled  = false;
            this.btnMerge.Enabled = false;

            DataTable dataTable = this.dgdMergeFileList.DataSource as DataTable;

            DataView dataTableView = dataTable.DefaultView;

            dataTableView.Sort = "CaseNumber ASC, UploadDate ASC";
            dataTable          = dataTableView.ToTable();

            if (dataTable != null)
            {
                int    rowCount            = dataTable.Rows.Count;
                bool   IsMerged            = false;
                string caseId              = "";
                string caseNumber          = "";
                string caseAttachmentId    = "";
                string caseFileName        = "";
                string caseAttchmentId     = "";
                string caseAttachmentType  = "";
                string uploadedBy          = "";
                string uploadDate          = "";
                string jiraId              = "";
                string jiraKey             = "";
                string currentCaseNumber   = "";
                string commentMoveFileList = string.Empty;

                IssueRef issueRef = new IssueRef();
                for (int i = 0; i < rowCount; i++)
                {
                    DataRow row = dataTable.Rows[i];
                    IsMerged           = bool.Parse(row["IsMerged"].ToString());
                    caseId             = row["CaseId"] as string;
                    caseNumber         = row["CaseNumber"] as string;
                    caseAttachmentId   = row["CaseAttchmentId"] as string;
                    caseFileName       = row["CaseFileName"] as string;
                    caseAttchmentId    = row["CaseAttchmentId"] as string;
                    caseAttachmentType = row["CaseAttachmentType"] as string;
                    uploadDate         = row["UploadDate"] as string;
                    uploadedBy         = row["UploadedBy"] as string;
                    jiraId             = row["JiraId"] as string;
                    jiraKey            = row["JiraKey"] as string;

                    if (!String.IsNullOrEmpty(commentMoveFileList) && currentCaseNumber != caseNumber)
                    {
                        // Upload jira comment
                        commentMoveFileList = "Copy some attachments from salesforce \n------------------------------------------------------------------------\n" + commentMoveFileList;
                        JiraProxy.CreateComment(issueRef, commentMoveFileList);
                        commentMoveFileList = string.Empty;
                    }

                    issueRef.id  = jiraId;
                    issueRef.key = jiraKey;

                    if (IsMerged)
                    {
                        byte[] fileStream = SalesforceProxy.GetCaseAttachmentById(caseAttachmentId);
                        JiraProxy.UploadAttachment(issueRef, caseFileName, fileStream);

                        commentMoveFileList += "The file : <<" + caseFileName + ">> uploaded by <<" + uploadedBy + ">> on " + uploadDate + "\n";
                    }

                    currentCaseNumber = caseNumber;
                }

                if (!String.IsNullOrEmpty(commentMoveFileList))
                {
                    // Upload jira comment
                    commentMoveFileList = "Copy some attachments from salesforce \n------------------------------------------------------------------------\n" + commentMoveFileList;
                    JiraProxy.CreateComment(issueRef, commentMoveFileList);
                    commentMoveFileList = string.Empty;
                }
            }

            this.btnSync.Enabled  = true;
            this.btnMerge.Enabled = false;
        }