protected void btnAllocate_Click(object sender, EventArgs e)
    {
        int intCount = 0;

        intCallStatus = 10;
        string assignflag = "";

        intAppointment  = int.Parse(ddlAppointment.SelectedValue);
        lblMessage.Text = "";
        string strAllRefNo = "";

        if (ddlProductDiv.SelectedIndex > 0)
        {
            intProductDivision = int.Parse(ddlProductDiv.SelectedValue);
        }
        intState = int.Parse(ddlState.SelectedValue);
        intCity  = int.Parse(ddlCity.SelectedValue);
        if (ddlSC.SelectedValue != "0")
        {
            foreach (GridViewRow gvRow in gvFresh.Rows)
            {
                // chkChild
                if (((CheckBox)gvRow.FindControl("chkBxSelect")).Checked == true)
                {
                    intCount = intCount + 1;
                    objSuspenseAccount.BaseLineId = int.Parse(((HiddenField)gvRow.FindControl("hdnBaselineID")).Value.ToString());

                    string strRefNo = ((HiddenField)gvRow.FindControl("hdnComplaint_RefNo")).Value.ToString();
                    objSuspenseAccount.SC_SNo = int.Parse(ddlSC.SelectedValue.ToString());
                    objSuspenseAccount.EmpID  = Membership.GetUser().UserName.ToString();

                    assignflag = objSuspenseAccount.CheckASCPermission(strRefNo);

                    if (assignflag == "y")
                    {
                        objSuspenseAccount.UpdateCallStatus();

                        //Code Done By Pravesh To send SMS on Wrong Allocatde Complaints.
                        #region SMS Store to SMS_TRANS
                        try
                        {
                            //If customer no is valid then send message End
                            //If SC no is valid then send message start
                            objSuspenseAccount.Complaint_RefNo     = ((HiddenField)gvRow.FindControl("hdnComplaint_RefNo")).Value.ToString();
                            objCallRegistration.Complaint_RefNoOUT = objSuspenseAccount.Complaint_RefNo;
                            DataSet dsStatus = objSuspenseAccount.GetStatusFromActivityLog();
                            string  strValidNumberCus = "", lngCustomerId = "", strASCMessage = "";
                            string  strValidNumberAsc = "", smsMobNumb = "", strUniqueNo = "";
                            string  strAltNo = "", strCustomerMessage = "", strCity = "";
                            string  strState = "", strTemAdd = "", strTotalSMS = "";
                            bool    blnFlagSMSCus = false, blnFlagSMSASC = false;
                            DataSet dsCustMobNo = objSuspenseAccount.GetCustMobNo();
                            if (dsCustMobNo.Tables[0].Rows.Count != 0)
                            {
                                strUniqueNo   = dsCustMobNo.Tables[0].Rows[0]["UniqueContact_No"].ToString();
                                strAltNo      = dsCustMobNo.Tables[0].Rows[0]["AltTelNumber"].ToString();
                                lngCustomerId = dsCustMobNo.Tables[0].Rows[0]["CustomerID"].ToString();
                            }
                            if (CommonClass.ValidateMobileNumber(strUniqueNo, ref strValidNumberCus))
                            {
                                smsMobNumb    = strValidNumberCus;
                                blnFlagSMSCus = true;
                            }
                            else if (CommonClass.ValidateMobileNumber(strAltNo, ref strValidNumberCus))
                            {
                                smsMobNumb    = strValidNumberCus;
                                blnFlagSMSCus = true;
                            }
                            int statusID = 0;
                            foreach (DataRow drw in dsStatus.Tables[0].Rows)
                            {
                                if (int.Parse(drw["StatusId"].ToString()) == 24)
                                {
                                    statusID = 24;
                                }
                            }

                            ServiceContractorMaster objSC = new ServiceContractorMaster();
                            objSC.BindServiceContractorOnSNo(objSuspenseAccount.SC_SNo, "SELECT_INDIVIDUAL_SC_BASED_ON_SCSNO");
                            //If customer no is valid then send message start
                            if (statusID == 24)
                            {
                                if (blnFlagSMSCus)
                                {
                                    //Message for customer
                                    strCustomerMessage = "Please Ignore The Previous SMS, Your Complaint No:" + objCallRegistration.Complaint_RefNoOUT + " will now be attended by " + objSC.SCName + "-" + objSC.PhoneNo;
                                    CommonClass.SendSMS(smsMobNumb, objCallRegistration.Complaint_RefNoOUT, lngCustomerId, DateTime.Now.Date.ToString("yyyyMMdd"), "CGL", strCustomerMessage, strCustomerMessage, "CUS");
                                }
                            }
                            else
                            {
                                if (blnFlagSMSCus)
                                {
                                    //Message for customer
                                    strCustomerMessage = "Your Complaint No:" + objCallRegistration.Complaint_RefNoOUT + " will be attended by " + objSC.SCName + "-" + objSC.PhoneNo;
                                    CommonClass.SendSMS(smsMobNumb, objCallRegistration.Complaint_RefNoOUT, lngCustomerId, DateTime.Now.Date.ToString("yyyyMMdd"), "CGL", strCustomerMessage, strCustomerMessage, "CUS");
                                }
                            }
                            #region SMS For ASC
                            if (objSC.MobileNo != "")
                            {
                                if (CommonClass.ValidateMobileNumber(objSC.MobileNo, ref strValidNumberAsc))
                                {
                                    blnFlagSMSASC = true;
                                }

                                if (blnFlagSMSASC)
                                {
                                    //Message for ASC
                                    strASCMessage = objCallRegistration.Complaint_RefNoOUT + "-" + ((HiddenField)gvRow.FindControl("hdnUNIT_DESC")).Value.ToString() + "-";
                                    if (bool.Parse(((HiddenField)gvRow.FindControl("hdnAppointmentReq")).Value.ToString()))
                                    {
                                        strASCMessage += "Y-";
                                    }
                                    else
                                    {
                                        strASCMessage += "N-";
                                    }
                                    strASCMessage += ((HiddenField)gvRow.FindControl("hdnLastName")).Value.ToString() + "-" + strUniqueNo;
                                    strCity        = ((HiddenField)gvRow.FindControl("hdnCity_Desc")).Value.ToString();
                                    strState       = ((HiddenField)gvRow.FindControl("hdnState_Desc")).Value.ToString();
                                    strTemAdd      = ((HiddenField)gvRow.FindControl("hdnAddress")).Value.ToString();
                                    strTotalSMS    = strASCMessage + strTemAdd + " " + strCity + " " + strState;
                                    string strASCCityState = "";
                                    int    intLen          = 0;
                                    strASCCityState = strASCMessage + " " + strCity + " " + strState;
                                    intLen          = strASCCityState.Length;
                                    intLen          = 159 - intLen;
                                    if (strTemAdd.Length > intLen)
                                    {
                                        strTemAdd = strTemAdd.Substring(0, intLen);
                                    }
                                    strASCMessage += strTemAdd + " " + strCity + " " + strState;

                                    CommonClass.SendSMS(strValidNumberAsc, objCallRegistration.Complaint_RefNoOUT, objSC.SCCode, DateTime.Now.Date.ToString("yyyyMMdd"), "CGL", strASCMessage, strTotalSMS, "ASC");
                                }
                            }
                            #endregion SMS For ASC

                            //If SC no is valid then send message end
                        }
                        catch (Exception ex)
                        {
                            //Writing Error message to File using CommonClass WriteErrorErrFile method taking arguments as URL of page
                            // trace, error message
                            CommonClass.WriteErrorErrFile(Request.RawUrl.ToString(), ex.StackTrace.ToString() + "-->" + ex.Message.ToString());
                        }
                        #endregion SMS Store to SMS_TRANS
                        lblMessage.Visible = true;
                        strAllRefNo        = strAllRefNo + strRefNo + ",";
                    }

                    else
                    {
                        lblMessage1.Text = "Can't Allocate Complaint to " + ddlSC.SelectedItem.Text + ".As this Product division is not attach with him.";
                    }
                }
            }

            if (assignflag == "y")
            {
                if (ViewState["strUserTypr"] != null)
                {
                    strUserTypr = ViewState["strUserTypr"].ToString();
                    objSuspenseAccount.UserName = Membership.GetUser().UserName.ToString();
                    if (strUserTypr == "CG" || strUserTypr == "CGCE")
                    {
                        intCountRecord = objSuspenseAccount.BindGVSuspensAccount(gvFresh, intProductDivision, intSCNo, intCallStatus, intState, intCity, intAppointment, intCountRecord);
                    }
                    else
                    {
                        intCountRecord = objSuspenseAccount.BindGVSuspensAccountForAllRegion(gvFresh, intProductDivision, intSCNo, intCallStatus, intState, intCity, intAppointment, intCountRecord);
                    }
                    if (gvFresh.Rows.Count == 0)
                    {
                        gvFresh.Visible = false;
                    }

                    if (intCount == 0)
                    {
                        lblMessage.Text = CommonClass.getErrorWarrning(enuErrorWarrning.RecordUpdated, enuMessageType.UserMessage, true, "Please  select any  complaint RefNo");
                    }
                    else
                    {
                        strAllRefNo     = strAllRefNo.TrimEnd(',');
                        lblMessage.Text = CommonClass.getErrorWarrning(enuErrorWarrning.RecordUpdated, enuMessageType.UserMessage, true, "Complaint RefNo " + strAllRefNo + " is allocated to " + ddlSC.SelectedItem.Text);
                        ddlSC.Items.Clear();
                        ddlSC.Items.Insert(0, new ListItem("Select", "0"));
                    }
                }
                else
                {
                    lblMessage.Text = CommonClass.getErrorWarrning(enuErrorWarrning.RecordUpdated, enuMessageType.UserMessage, true, "Please click on ‘find button’ to allocate Service Contractor");
                }
                if (gvFresh.Rows.Count > 0)
                {
                    int intRecord = gvFresh.Rows.Count;
                    lblMessage.Visible = true;
                    tbSearch.Visible   = true;
                    tdRowCount.Visible = true;
                    lblRowCount.Text   = intCountRecord.ToString();
                }
                else
                {
                    tdRowCount.Visible = false;
                    tbSearch.Visible   = false;
                }
            }
        }
    }
 protected void Page_Unload(object sender, EventArgs e)
 {
     objCommonClass             = null;
     objServiceContractorMaster = null;
     objsql = null;
 }