Exemple #1
0
        protected void BtnCancelOrder_Click(object sender, EventArgs e)
        {
            StringBuilder lineBuild = new StringBuilder();
            string        lineError = "";

            try
            {
                no    = tcNo.Text;
                docNo = tcDocNo.Text;

                string validateMsg   = string.Empty;
                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 == string.Empty)
                {
                    foreach (TableRow row in tblCancelOrderTableDetails.Rows)
                    {
                        rowCount++;
                        string itemNo     = string.Empty;
                        int    qtyLine    = 0;
                        int    actionQty  = 0;
                        string reasonCode = string.Empty;

                        controlCount = 0;

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

                            if (cell.ID.Contains("itemQuanity_"))
                            {
                                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;

                                    List <ReturnReason> sr = (List <ReturnReason>)Session["ReturnReasons"];
                                    List <ReturnReason> rl = new List <ReturnReason>();
                                    foreach (ReturnReason item in sr)
                                    {
                                        if (item.Category == "Cancel Order" || item.Category == "")
                                        {
                                            rl.Add(item);
                                        }
                                    }
                                    reasonCode = (rl)[index].ReasonCode;
                                }
                            }

                            string lineValidMessage = string.Empty;

                            if ((rowCount > 1 && controlCount == 2 && actionQty != 0))
                            {
                                lineValidMessage = ValidateLine(itemNo, qtyLine, actionQty, reasonCode);

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

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

                    if (allValidLines)
                    {
                        string      lineValues = lineBuild.ToString();
                        SendService ss         = new SendService();

                        ss.CancelOrder(no, docNo, lineValues, zendeskTicketNo);
                        Session["NoUserInteraction"] = true;
                        Session["SearchValue"]       = "ORDER CANCELLED";

                        ClientScript.RegisterStartupScript(this.GetType(), "cancelledOrder", "alert('Order " + no + " has been successfully cancelled.');", true);
                        ClientScript.RegisterStartupScript(this.GetType(), "closeCancelOrder", "CloseAfterCancel();", 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(), "exceptionAlert", "alert('" + ex.Message.Replace("'", "\"") + "');", true);

                if (ex.Message.ToLower().Contains("session"))
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "closeErrorAlert", "parent.window.close();", true);
                }
            }
        }