public static PMSAgency Read(SqlDataReader reader)
    {
        PMSAgency retval = new PMSAgency();

        for (int i = 0; i < reader.FieldCount; i++)
        {
            switch (reader.GetName(i))
            {
                case "GroupSegment":
                    retval.Segment = Helper.ToString(reader[i]);
                    break;
                case "AType":
                    retval.ActionType = Helper.ToString(reader[i]);
                    break;
                case "Agency":
                    retval.AgencyName = Helper.ToString(reader[i]);
                    break;
                case "Market":
                    retval.Market = Helper.ToString(reader[i]);
                    break;
                case "RepGroup":
                    retval.RepGroup = Helper.ToString(reader[i]);
                    break;
               case "SiteID":
                    retval.SiteID = Helper.ToInt32(reader[i]);
                    break;
            }
        }
        return retval;
    }
    public static void UpdatePMSAgency(PMSAgency value)
    {
        //@AType varchar(4),@SiteID int,@Agency varchar(50), @Mkt varchar(20),@RepG varchar(30),@Seg varchar(40)
        SqlParameter[] param = new SqlParameter[] {
            new SqlParameter("@AType", value.ActionType),
            new SqlParameter("@SiteID", value.SiteID),
            new SqlParameter("@Agency", value.AgencyName.Trim()),
            new SqlParameter("@Mkt", value.Market),
            new SqlParameter("@RepG", value.RepGroup),
            new SqlParameter("@Seg", value.Segment)
        };
        //throw new Exception(value.ActionType + "-" + value.SiteID + "-" + value.AgencyName + "-" + value.Market + "-" + value.RepGroup + "-" + value.Segment);

        SqlHelper.ExecuteNonQuery(Helper.ConnectionString, CommandType.StoredProcedure, "usp_ManageEdit_Agency", param);
    }
    public static PMSAgencyList GetPMSAgency(PMSAgency item)
    {
        PMSAgencyList retval = new PMSAgencyList();

        SqlParameter[] param = new SqlParameter[]{
            new SqlParameter("@SiteID", item.SiteID),
            new SqlParameter("@Agency", item.AgencyName)
        };
        //throw new Exception(item.SiteID.ToString() + item.AgencyName);
        using (SqlDataReader reader = SqlHelper.ExecuteReader(Helper.ConnectionString, CommandType.StoredProcedure, "usp_ManageAgency", param))
        {
            while (reader.Read())
            {
                retval.Add(Read(reader));
            }
        }
        return retval;
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        PMSAgency item = new PMSAgency();
        //Action Type
        item.ActionType = lblAType.Text;
        item.SiteID = Convert.ToInt32(lblSiteID.Text);
        item.AgencyName = lblAgency.Text;
        item.Market = Helper.ToString(ddlMarket.SelectedValue);
        item.RepGroup = txtRepG.Text;
        item.Segment = Helper.ToString(ddlSegment.Text);

        //@AType varchar(4),@SiteID int,@Agency varchar(50), @Mkt varchar(20),@RepG varchar(30),@Seg varchar(40)
        //throw new Exception(item.PremID + "-" + item.PersonnelID + "-" + item.GiftCharge + "-" + item.Budget);

         PMSAgencyDB.UpdatePMSAgency(item);

        //update the grid

        GridView1.DataBind();
        lblCount.Text = GridView1.Rows.Count.ToString() + " records on this page. ";
        lblMessages.Text = "Information Updated Successfully: <b><font color='blue'>" + lblAType.Text + "</font></b>";
        ClearItems();
        PnlDetail.Visible = false;
    }