protected void Button1_Click(object sender, EventArgs e)
    {
      //  new RobotTableAdapters.InsuranceCompanyTableAdapter().Insert();
        try
        {
            ValidateIssurance();
            RobotTableAdapters.CollateralType_CarEquipTableAdapter robot = new RobotTableAdapters.CollateralType_CarEquipTableAdapter();
            RobotTableAdapters.InsuranceTableAdapter robotInsuranceTable = new RobotTableAdapters.InsuranceTableAdapter();

            //initialize values
            int collateralId = Convert.ToInt32(Request.QueryString["collateralId"]);
            int CollateralTypeId = Convert.ToInt32(Request.QueryString["CollateralTypeId"]);

            double varValueAsAtDate = 0;

            varValueAsAtDate = Convert.ToDouble(ValueAsAtDate.Text);


            //insert values into CollateralType_CarEquipTableAdapter and retrieve max id as collateralDetailsId
            int collateralDetailsId = Convert.ToInt32(robot.proc_insert_car(TypeOfCarEquip.Text, Make.Text, YearOfManufacture.SelectedItem.Text, varValueAsAtDate, ChassisNo.Text,
                -1, collateralId, Smart.GetEmployeeID(), "NULL"));

            hiddenDetailsId.Text = collateralDetailsId.ToString();
            //see if he filled the insurance form, then run the block of code that will do the insrt into insurance table
            if (insuranceStatusId.SelectedValue == "1")
            {
                int varPeriodOfInsuranceCover = 0; double varAmountInsured = 0;
                varPeriodOfInsuranceCover = Convert.ToInt32(PeriodOfInsuranceCover.Text);
                varAmountInsured = Convert.ToDouble(AmountInsured.Text);

                robotInsuranceTable.Insert(Convert.ToInt32(insuranceStatusId.SelectedValue), Convert.ToInt32(InsuranceCover_id.SelectedValue), collateralDetailsId, CollateralTypeId,
                    InsuranceCompany.Text, Convert.ToDateTime(DateOfInsurance.Value), varPeriodOfInsuranceCover, varAmountInsured, keyClause.Text, Smart.GetEmployeeID(), Convert.ToInt32(InsuranceCompany.SelectedValue));
            }
            else
            {
                robotInsuranceTable.Insert(Convert.ToInt32(insuranceStatusId.SelectedValue), -1, collateralDetailsId, CollateralTypeId,
                    "", null, -1, 0, null, Smart.GetEmployeeID(), -1);
            }

            //enable and move focus to next tab, disable current tab
            ASPxPageControl1.TabPages[1].Enabled = true;


            ASPxPageControl1.ActiveTabIndex = 1;
        }
        catch (Exception ex)
        {
            _errorMessageCar.Text = ex.Message;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
      //  new RobotTableAdapters.InsuranceCompanyTableAdapter().Insert();        
        try
        {
            ValidateIssurance();
            RobotTableAdapters.CollateralType_CarEquipTableAdapter robot = new RobotTableAdapters.CollateralType_CarEquipTableAdapter();
            RobotTableAdapters.InsuranceTableAdapter robotInsuranceTable = new RobotTableAdapters.InsuranceTableAdapter();

            //initialize values
            int collateralId = Convert.ToInt32(Request.QueryString["collateralId"]);
            int CollateralTypeId = Convert.ToInt32(Request.QueryString["CollateralTypeId"]);
            String collateraldetails_id = Request.QueryString["collateraldetails_id"];
            int collateraldetailsid = Convert.ToInt32(Request.QueryString["collateraldetails_id"]);

            double varValueAsAtDate = 0;
            varValueAsAtDate = Convert.ToDouble(ValueAsAtDate.Text);

            //insert values into CollateralType_CarEquipTableAdapter and retrieve max id as collateralDetailsId
            robot.Update(TypeOfCarEquip.Text, Make.Text, YearOfManufacture.SelectedItem.Text, varValueAsAtDate, ChassisNo.Text,
               -1, collateralId, Smart.GetEmployeeID(), "NULL", collateraldetailsid);

            hiddenDetailsId.Text = collateraldetailsid.ToString();
            //see if he filled the insurance form, then run the block of code that will do the insrt into insurance table

            int insureID = Convert.ToInt32(InsuranceID.Value);
            int varPeriodOfInsuranceCover = 0; double varAmountInsured = 0;
            /*Response.Write("Date =" + DateOfInsurance.Value);
            Response.Write("PeriodOfInsuranceCover =" + PeriodInsured.Text);
            Response.Write("insuranceStatusId =" + insuranceStatusId.SelectedValue);
            Response.Write("InsuranceCover_id =" + InsuranceCover_id.SelectedValue);
            Response.Write("InsuranceCompany =" + InsuranceCompany.Text);
            Response.Write("AmountInsured =" + AmountInsured.Text);
            Response.End();*/
            // string x = PeriodInsured.Text;

            //varPeriodOfInsuranceCover = Convert.ToInt32(PeriodInsured.Text);
            //varAmountInsured = Convert.ToDouble(AmountInsured.Text);
            if (insuranceStatusId.SelectedValue == "2")
            {
                robotInsuranceTable.Update(Convert.ToInt32(insuranceStatusId.SelectedValue), -1, collateraldetailsid, CollateralTypeId,
                   null, null, null, null, null, Smart.GetEmployeeID(), -1, insureID);
            }
            else
            {
                // varAmountInsured = Convert.ToDouble(AmountInsured.Text);
                robotInsuranceTable.Update(Convert.ToInt32(insuranceStatusId.SelectedValue), Convert.ToInt32(InsuranceCover_id.SelectedValue), collateraldetailsid, CollateralTypeId,
                  InsuranceCompany.Text, Convert.ToDateTime(DateOfInsurance.Value), Convert.ToInt32(PeriodInsured.Text), Convert.ToDouble(AmountInsured.Text), keyClause.Text, Smart.GetEmployeeID(), Convert.ToInt32(InsuranceCompany.SelectedValue), insureID);
            }


            //enable and move focus to next tab, disable current tab
            ASPxPageControl1.TabPages[1].Enabled = true;


            ASPxPageControl1.ActiveTabIndex = 1;
            CheckBoxList1_Load();
        }
        catch (Exception ex)
        {
            _errorMessageCar.Text = ex.Message;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        String collateraldetails_id = Request.QueryString["collateraldetails_id"];

        if (!IsPostBack)
        {
          //  insuranceStatusId.SelectedIndex = 1;
            ASPxPageControl1.TabPages[0].Enabled = true;
            ASPxPageControl1.TabPages[1].Enabled = false;
            ASPxPageControl1.TabPages[2].Enabled = false;
            ASPxPageControl1.TabPages[3].Enabled = false;

            int years = DateTime.Now.Year;

            for (int i = 0; i < 30; i++)
            { 
                years--;
                YearOfManufacture.Items.Add(new ListItem(years.ToString(), years.ToString()));
            }

            ASPxPageControl1.ActiveTabIndex = 2;
            int collateraldetailsid = Convert.ToInt32(Request.QueryString["collateraldetails_id"]);

            //this code is for population of fields when update mode is set
            RobotTableAdapters.CollateralType_CarEquipTableAdapter Engine = new RobotTableAdapters.CollateralType_CarEquipTableAdapter();


            DataTable returnedData = Engine.getCarEquipById(Convert.ToInt32(collateraldetails_id));

            //TEXTBOXES
            TypeOfCarEquip.Text = returnedData.Rows[0]["TypeOfCarEquip"].ToString();
            ChassisNo.Text = returnedData.Rows[0]["ChassisNo"].ToString();
            Make.Text = returnedData.Rows[0]["Make"].ToString();
            ValueAsAtDate.Text = returnedData.Rows[0]["ValueAsAtDate"].ToString();
            if(returnedData.Rows[0]["documenttype_id"].ToString() !="-1")
                documenttype_id.SelectedValue = returnedData.Rows[0]["documenttype_id"].ToString();
            //DROPDOWN

            YearOfManufacture.SelectedValue = returnedData.Rows[0]["YearOfManufacture"].ToString();
        //this code takes care of the population of insurance controls

        try
        {
            RobotTableAdapters.InsuranceTableAdapter InsuranceEngine = new RobotTableAdapters.InsuranceTableAdapter();


            DataTable InsuranceData = InsuranceEngine.proc_getInsuranceById(Convert.ToInt32(collateraldetails_id), 4);

            //TEXTBOXES

              insuranceStatusId.SelectedValue = InsuranceData.Rows[0]["InsuranceStatus_id"].ToString();
              InsuranceID.Value = InsuranceData.Rows[0]["Insurance_id"].ToString();
              if (InsuranceData.Rows[0]["InsuranceStatus_id"].ToString() == "1" || InsuranceData.Rows[0]["InsuranceStatus_id"].ToString() == "3")
            {
			    PeriodInsured.Text = InsuranceData.Rows[0]["PeriodOfInsuranceCover"].ToString();
                keyClause.Text = InsuranceData.Rows[0]["KeyClause"].ToString();
                AmountInsured.Text = InsuranceData.Rows[0]["AmountInsured"].ToString();

                DateTime dt;
                dt = Convert.ToDateTime(InsuranceData.Rows[0]["DateOfInsurance"].ToString());
                DateOfInsurance.Value = ((DateTime)dt).ToString("MM/dd/yyyy");

                //DROPDOWNS

                InsuranceCompany.SelectedValue = InsuranceData.Rows[0]["InsuranceCompany"].ToString();
                InsuranceCover_id.SelectedValue = InsuranceData.Rows[0]["InsuranceCover_id"].ToString();
            }

        }
        catch (Exception)
        {


        }
        }
        CheckBoxList1_Load();
    }