protected void BtnCreateRMA_Click(object sender, EventArgs e) { StringBuilder lineBuild = new StringBuilder(); StringBuilder shippingBuild = new StringBuilder(); string lineError = ""; try { shipToName = txtShipToName.Text; shipToAddress1 = txtShipToAddress1.Text; shipToAddress2 = txtShipToAddress2.Text; shipToCity = txtShipToCity.Text; shipToCode = txtShipToCode.Text; shipToState = txtShipToState.Text; no = tcNo.Text; docNo = tcDocNo.Text; notes = txtNotes.Text; resources = cbxResources.Checked; printRMA = cbxPrintRMA.Checked; createLabel = cbxCreateLabel.Checked; //email = txtCustEmail.Text; returnTrackingNo = txtInsertTrackingNo.Text; imeiNo = tcIMEINo.Text; string validateMsg = ValidateInput(); bool validateZendesk = false; bool allValidLines = true; int rowCount = 0; int controlCount = 0; Zendesk ticket = new Zendesk(); if (validateMsg == "All Input Valid") { bool process = true; if (createLabel) { validateZendesk = ZendeskIssueReturnLabelControl.VerifyInput(ref ticket); process = validateZendesk; } if (process) { if (ZendeskIssueReturnLabelControl.NewZendeskTicket) { email = ZendeskIssueReturnLabelControl.EmailTo; } else { email = String.IsNullOrEmpty(ticket.FromEmailAddress) ? string.Empty : ticket.FromEmailAddress; } foreach (TableRow row in tblCreateReturnOrderTableDetails.Rows) { rowCount++; string itemNo = string.Empty; int qtyLine = 0; int actionQty = 0; string reasonCode = string.Empty; int reqReturnAction = -1; controlCount = 0; foreach (TableCell cell in row.Cells) { if (cell.ID.Contains("itemNo_")) { itemNo = cell.Text.ToString(); } if (cell.ID.Contains("itemQuantity_")) { int.TryParse(cell.Text.ToString(), out qtyLine); } if (cell.ID.Contains("actionQty_")) { int.TryParse(cell.Text.ToString(), out actionQty); } foreach (Control c in cell.Controls) { controlCount++; //if (c.GetType() == typeof(TextBox)) //{ // string value = ((TextBox)c).Text; // int.TryParse(value, out actionQty); //} if (c.GetType() == typeof(DropDownList)) { int index = ((DropDownList)c).SelectedIndex; if (c.ID.Contains("ddlReturnReasonCode")) { /* v7.1 - 3 October 2018 - Neil Jansen * Updated logic to filter out incorrect catagories for Return Reason Code */ List <ReturnReason> sr = (List <ReturnReason>)Session["ReturnReasons"]; List <ReturnReason> rl = new List <ReturnReason>(); foreach (ReturnReason item in sr) { if (item.Category != "Part Request" && item.Category != "Cancel Order" && item.Category != "Partial Refund" && item.Category != "Unknown" && item.Category != "Nonconformed" && item.Category != "Vendor Rejected") { rl.Add(item); } } reasonCode = (rl)[index].ReasonCode; } else if (c.ID.Contains("ddlREQReturnAction")) { reqReturnAction = index; } } } string lineValidMessage = string.Empty; if ((rowCount > 1 && controlCount == 2 && actionQty != 0)) { lineValidMessage = ValidateLine(itemNo, qtyLine, actionQty, reasonCode, reqReturnAction); if (lineValidMessage == "Valid Line Input") { lineBuild.Append(itemNo).Append(":"); lineBuild.Append(actionQty).Append(":"); lineBuild.Append(reasonCode).Append(":"); lineBuild.Append(reqReturnAction).Append(","); } else { allValidLines = false; if (lineError == "") { lineError = lineValidMessage; } } } } } if (allValidLines) { string lineValues = lineBuild.ToString(); CreatedReturnHeader crh = new CreatedReturnHeader(); SendService ss = new SendService(); if (no.ToUpper().Contains("RMA")) { update = true; } else { update = false; } shippingBuild.Append(shipToName).Append(":"); shippingBuild.Append(shipToAddress1).Append(":"); shippingBuild.Append(shipToAddress2).Append(":"); shippingBuild.Append(shipToCity).Append(":"); shippingBuild.Append(shipToCode).Append(":"); shippingBuild.Append(shipToState); string shippingDetails = shippingBuild.ToString(); crh = ss.CreateReturnOrder(no, docNo, string.Empty, notes, resources, printRMA, createLabel, email, lineValues, update, returnTrackingNo, shippingDetails, imeiNo, zendeskTicketNo); ClientScript.RegisterStartupScript(this.GetType(), "returnRMA", "alert('" + crh.RMANo + "');", true); if (createLabel) { ZendeskIssueReturnLabelControl.IssueZendeskReturnLabel(crh.RMANo, docNo, false, ticket); } // Replace legacy with Zendesk return label //worker = new Thread(() => //{ // try // { // ss.LegacyReturnLabel(crh.RMANo, email, sessionID); // } // catch (Exception workerE) // { // Log.Error(workerE.Message, workerE); // ClientScript.RegisterStartupScript(this.GetType(), "labelError", "alert('" + workerE.Message.Replace("'", "\"") + "');", true); // } //}); //worker.Start(); Session["CreatedRMA"] = crh; Session["NoUserInteraction"] = true; if (!ZendeskIssueReturnLabelControl.GenerateURL) { ClientScript.RegisterStartupScript(this.GetType(), "openCreatedRMA", "OpenCreatedRMA();", true); } } else { ClientScript.RegisterStartupScript(this.GetType(), "lineError", "alert('" + lineError + "');", true); } } } else { ClientScript.RegisterStartupScript(this.GetType(), "validateMsg", "alert('" + validateMsg + "');", true); } } catch (Exception ex) { Log.Error(ex.Message, ex); ClientScript.RegisterStartupScript(this.GetType(), "errorAlert", "alert('" + ex.Message.Replace("'", "\"") + "');", true); if (ex.Message.ToLower().Contains("session")) { ClientScript.RegisterStartupScript(this.GetType(), "closeErrorAlert", "parent.window.close();", true); } } }