コード例 #1
0
        protected void BtnCreatePartRequest_Click(object sender, EventArgs e)
        {
            StringBuilder lineBuild     = new StringBuilder();
            StringBuilder shippingBuild = new StringBuilder();
            string        lineError     = "";

            try
            {
                no = tcNo.Text;
                externalDocumentNo = tcDocNo.Text;
                notes = txtNotes.Text;
                email = txtCustEmail.Text;

                string validateMsg   = ValidateInput();
                bool   allValidLines = true;
                int    rowCount      = 0;
                int    controlCount  = 0;

                if (!String.IsNullOrWhiteSpace(txtZendeskTicketNo.Text) || !String.IsNullOrEmpty(txtZendeskTicketNo.Text))
                {
                    if (txtZendeskTicketNo.Text.Length == 7)
                    {
                        int.TryParse(txtZendeskTicketNo.Text, out zendeskTicketNo);
                    }
                    else
                    {
                        validateMsg = "Zendesk Ticket # should be 7 numeric characters.";
                    }
                }

                if (validateMsg == "All Input Valid")
                {
                    foreach (TableRow row in tblCreateReturnOrderTableDetails.Rows)
                    {
                        rowCount++;
                        string itemNo      = string.Empty;
                        string desc        = string.Empty;
                        int    qtyLine     = 0;
                        int    actionQty   = 0;
                        int    partRequest = 0;
                        string reason      = string.Empty;

                        controlCount = 0;

                        foreach (TableCell cell in row.Cells)
                        {
                            if (cell.ID.Contains("itemNo_"))
                            {
                                itemNo = cell.Text.ToString();
                            }

                            if (cell.ID.Contains("desc_"))
                            {
                                desc = cell.Text.ToString();
                            }

                            if (cell.ID.Contains("itemQuantity_"))
                            {
                                int.TryParse(cell.Text.ToString(), out qtyLine);
                            }

                            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("ddlPartRequest_"))
                                    {
                                        partRequest = ((DropDownList)c).SelectedIndex;
                                    }

                                    if (c.ID.Contains("ddlReason_"))
                                    {
                                        /* 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 == "")
                                            {
                                                rl.Add(item);
                                            }
                                        }
                                        reason = (rl)[index].ReasonCode;
                                    }
                                }
                            }

                            string lineValidMessage = string.Empty;

                            if ((rowCount > 1 && controlCount == 3 && actionQty != 0))
                            {
                                lineValidMessage = ValidateLine(itemNo, qtyLine, actionQty, partRequest, reason);

                                if (lineValidMessage == "Valid Line Input")
                                {
                                    lineBuild.Append(itemNo).Append(":");
                                    lineBuild.Append(desc).Append(":");
                                    lineBuild.Append(actionQty).Append(":");
                                    lineBuild.Append(partRequest).Append(":");
                                    lineBuild.Append(reason).Append(",");
                                }
                                else
                                {
                                    allValidLines = false;

                                    if (lineError == "")
                                    {
                                        lineError = lineValidMessage;
                                    }
                                }
                            }
                        }
                    }

                    if (allValidLines)
                    {
                        string lineValues             = lineBuild.ToString();
                        CreatedPartRequestHeader cprh = new CreatedPartRequestHeader();

                        SendService ss = new SendService();

                        cprh = ss.CreatePartialRequest(no, externalDocumentNo, lineValues, notes, "", email, zendeskTicketNo);

                        Session["CreatedPartRequest"] = cprh;
                        Session["NoUserInteraction"]  = true;

                        Session["CopyRowTable"]     = null;
                        Session["PartRequestTable"] = null;

                        ClientScript.RegisterStartupScript(this.GetType(), "returnPartRequest", "alert('" + cprh.QuoteNo + "');", true);
                        ClientScript.RegisterStartupScript(this.GetType(), "openCreatedPartRequest", "OpenCreatedPartRequest();", 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);
                }
            }
        }