protected void BtnCreatePartialRefund_Click(object sender, EventArgs e)
        {
            StringBuilder lineBuild = new StringBuilder();
            string        lineError = "";

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

                User u = (User)Session["ActiveUser"];

                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 tblPartialRefundDetails.Rows)
                    {
                        rowCount++;
                        string  itemNo       = string.Empty;
                        int     qtyLine      = 0;
                        int     actionQty    = 0;
                        string  reasonCode   = string.Empty;
                        decimal refundOption = 0;

                        controlCount = 0;
                        int cellCount = 0;

                        foreach (TableCell cell in row.Cells)
                        {
                            cellCount++;

                            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;

                                    if (c.ID.Contains("ddlReturnReasonCode_"))
                                    {
                                        List <ReturnReason> sr = (List <ReturnReason>)Session["ReturnReasons"];
                                        List <ReturnReason> rl = new List <ReturnReason>();
                                        foreach (ReturnReason item in sr)
                                        {
                                            if (item.Category == "Partial Refund" || item.Category == "")
                                            {
                                                rl.Add(item);
                                            }
                                        }
                                        reasonCode = (rl)[index].ReasonCode;
                                    }

                                    if (c.ID.Contains("ddlRefundOption"))
                                    {
                                        List <RefundOptions> ro    = new RefundOptions().Populate();
                                        List <RefundOptions> newRo = new List <RefundOptions>();
                                        double total = 0;

                                        foreach (RefundOptions option in ro)
                                        {
                                            if (Session["OrderTotal"] != null)
                                            {
                                                total = Convert.ToDouble(Session["OrderTotal"]);
                                            }

                                            if (total <= 20)
                                            {
                                                if (option.Tier == "20Dollar")
                                                {
                                                    newRo.Add(option);
                                                }
                                            }
                                            else if (option.Tier == u.RefundTier)
                                            {
                                                newRo.Add(option);
                                            }
                                        }

                                        string value = (newRo)[index].Option.Replace("%", "");
                                        Decimal.TryParse(value, out refundOption);
                                    }
                                }
                            }

                            string lineValidMessage = string.Empty;

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

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

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

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

                        ss.PartialRefund(no, docNo, lineValues, zendeskTicketNo);
                        Session["NoUserInteraction"] = true;

                        ClientScript.RegisterStartupScript(this.GetType(), "refundedOrder", "alert('Order " + no + " has been partially refunded.');", true);
                        ClientScript.RegisterStartupScript(this.GetType(), "closeRefundOrder", "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);
                }
            }
        }