protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            ValidateForceSaleValue();
            try
            {                
                ValidateIssurance();
                RobotTableAdapters.CollateralType_PropertyTableAdapter robot = new RobotTableAdapters.CollateralType_PropertyTableAdapter();
                RobotTableAdapters.InsuranceTableAdapter robotInsuranceTable = new RobotTableAdapters.InsuranceTableAdapter();

                //initialize values
                int collateralId = Convert.ToInt32(Request.QueryString["collateralId"]);
                int CollateralTypeId = Convert.ToInt32(Request.QueryString["CollateralTypeId"]);
                double varForceSaleValue = 0; double varOpenMarketValue = 0;
                varForceSaleValue = Convert.ToDouble(ForceSaleValue.Text);
                varOpenMarketValue = Convert.ToDouble(OpenMarketValue.Text);

                //insert values into CollateralType_Property and retrieve max id as collateralDetailsId
                int collateralDetailsId = Convert.ToInt32(robot.Proc_insert_property(OwnershipLink.Text, Location.Text, Convert.ToInt32(state_id.SelectedValue), Name_ColDocument.Text, RefNo_ColDocument.Text, AddressWithLandMark.Text,
                   Convert.ToInt32(PropertyType_id.SelectedValue), varForceSaleValue, varOpenMarketValue, "NULL", Convert.ToDateTime(DateOfValuation.Value), Convert.ToInt32(PropertyDevelopmentStatus.SelectedValue),
                    OccupancyStatus_id.SelectedValue, collateralId, -1, Convert.ToInt32(NameOfValuer.SelectedValue), -1, property_desc.Text, "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, -1, Convert.ToInt32(InsuranceCompany.SelectedValue));
                }

                else
                {
                    robotInsuranceTable.Insert(Convert.ToInt32(insuranceStatusId.SelectedValue), null, collateralDetailsId, CollateralTypeId,
                        null, DateTime.Now, null, null, null, Smart.GetEmployeeID(), null);
                }

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

                //documenttype_id.SelectedIndex = 2;
                ASPxPageControl1.ActiveTabIndex = 1;
            }
            catch (Exception ex)
            {
                _errorMessageProperty.Text = ex.Message;
            }
        }
        catch (Exception _ex)
        {
           _errorMessageProperty_1.Text = _ex.Message;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
       try
        {
            ValidateIssurance();
            // new RobotTableAdapters.InsuranceCompanyTableAdapter().Insert();

            RobotTableAdapters.CollateralType_SalaryContractTableAdapter robot = new RobotTableAdapters.CollateralType_SalaryContractTableAdapter();
            RobotTableAdapters.InsuranceTableAdapter robotInsuranceTable = new RobotTableAdapters.InsuranceTableAdapter();
            //initialize values
            int collateralId = Convert.ToInt32(Request.QueryString["collateralId"]);
            int CollateralTypeId = Convert.ToInt32(Request.QueryString["CollateralTypeId"]);


            double varValueOfContract = 0; double varAPG = 0;

            varValueOfContract = Convert.ToDouble(ValueOfContract.Text);
            varAPG = Convert.ToDouble(APG.Text);

            //insert values into CollateralType_Cash  and retrieve max id as collateralDetailsId
            int collateralDetailsId = Convert.ToInt32(robot.proc_insert_contract(NameOfInsuringBody.Text, OriginalContractor.Text, Convert.ToDateTime(ContractAwardDate.Value),
                                        PurposeOfContract.Text, RefNo.Text, varValueOfContract, varAPG, TenureOfContract.Text, Convert.ToDateTime(MaturityDate.Value),
                                        collateralId, Smart.GetEmployeeID(), thirdparty.Text, "NULL",2));

            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 (FinInsuranceStatus_id.SelectedValue == "1" || FinInsuranceStatus_id.SelectedValue == "3")
            {
                int varPeriodOfInsuranceCover = 0; double varAmountInsured = 0;
                varPeriodOfInsuranceCover = Convert.ToInt32(FinPeriodofInsuranceCover.Text);
                varAmountInsured = Convert.ToDouble(FinAmountInsured.Text);

                robotInsuranceTable.Insert(Convert.ToInt32(FinInsuranceStatus_id.SelectedValue), Convert.ToInt32(InsuranceCover.SelectedValue), collateralDetailsId, CollateralTypeId,
                    FinInsuranceCompany.Text, Convert.ToDateTime(FinDateOfInsurance.Value), varPeriodOfInsuranceCover, varAmountInsured, FinKeyClause.Text, Smart.GetEmployeeID(), Convert.ToInt32(FinInsuranceCompany.SelectedValue));

            }
            else
            {
                robotInsuranceTable.Insert(Convert.ToInt32(FinInsuranceStatus_id.SelectedValue), null, collateralDetailsId, CollateralTypeId,
                    null, null, null, null, null, Smart.GetEmployeeID(), null);
            }



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

            ASPxPageControl1.ActiveTabIndex = 1;
        }
        catch (Exception ex)
        {
          _errorMessageSalary.Text = ex.Message;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
      //  new RobotTableAdapters.InsuranceCompanyTableAdapter().Insert();
        try
        {
            ValidateIssurance();
            RobotTableAdapters.CollateralType_StockHypoTableAdapter robot = new RobotTableAdapters.CollateralType_StockHypoTableAdapter();
            RobotTableAdapters.InsuranceTableAdapter robotInsuranceTable = new RobotTableAdapters.InsuranceTableAdapter();
            //initialize values
            int collateralId = Convert.ToInt32(Request.QueryString["collateralId"]);
            int CollateralTypeId = Convert.ToInt32(Request.QueryString["CollateralTypeId"]);


            int varTypeOfStock = 0; int varInsuranceCover_id = 0;
            double varValueOfStock = 0; int varFrequencyOfValuation = 0;
            varTypeOfStock = Convert.ToInt32(TypeOfStock_id.SelectedValue);
            varValueOfStock = Convert.ToDouble(ValueOfStock_total.Text);
            varFrequencyOfValuation = Convert.ToInt32(FrequencyOfValuation.SelectedValue);
            varInsuranceCover_id = Convert.ToInt32(InsuranceCover_id.SelectedValue);

            //insert values into CollateralType_Cash  and retrieve max id as collateralDetailsId
            int collateralDetailsId = Convert.ToInt32(robot.proc_insert_stockHypo(varTypeOfStock, ListOfStock.Text, InvoiceNo.Text,
                                        -1, varValueOfStock, NameOfStockValuer.Text, DateTime.Now, MethodOfValuation.Text, varFrequencyOfValuation,
                                        varInsuranceCover_id, collateralId, Smart.GetEmployeeID(), varFrequencyOfValuation, "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(StockPeriodOfInsuranceCover.Text);
                varAmountInsured = Convert.ToDouble(StockAmountInsured.Text);

                robotInsuranceTable.Insert(Convert.ToInt32(insuranceStatusId.SelectedValue), Convert.ToInt32(InsuranceCover_id.SelectedValue), collateralDetailsId, CollateralTypeId,
                    InsuranceCompany.Text, DateTime.Now, varPeriodOfInsuranceCover, varAmountInsured, StockKeyClause.Text, Smart.GetEmployeeID(), Convert.ToInt32(InsuranceCompany.SelectedValue));
            }
            else
            {
                robotInsuranceTable.Insert(Convert.ToInt32(insuranceStatusId.SelectedValue), null, collateralDetailsId, CollateralTypeId,
                    null, DateTime.Now, null, null, null, Smart.GetEmployeeID(), null);
            }


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


            ASPxPageControl1.ActiveTabIndex = 1;
        }
        catch (Exception ex)
        {
            _errorMessageStock.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"]);

            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 Page_Load(object sender, EventArgs e)
    {
        String collateraldetails_id = Request.QueryString["collateraldetails_id"];
        int insureID = 0;
        if (!IsPostBack)
        {
         //   insuranceStatusId.SelectedIndex = 1;
            ASPxPageControl1.TabPages[0].Enabled = true;
            ASPxPageControl1.TabPages[1].Enabled = true;
            ASPxPageControl1.TabPages[2].Enabled = false;
            ASPxPageControl1.TabPages[3].Enabled = false;

            ASPxPageControl1.ActiveTabIndex = 0;
            int collateraldetailsid = Convert.ToInt32(Request.QueryString["collateraldetails_id"]);
           
            //this code is for population of fields when update mode is set
            RobotTableAdapters.CollateralType_PropertyTableAdapter propertyEngine = new RobotTableAdapters.CollateralType_PropertyTableAdapter();


            DataTable propertyData = propertyEngine.getPropertyById(Convert.ToInt32(collateraldetails_id));

			
            OwnershipLink.Text = propertyData.Rows[0]["OwnershipLink"].ToString();
            Name_ColDocument.Text = propertyData.Rows[0]["Name_ColDocument"].ToString();
            RefNo_ColDocument.Text = propertyData.Rows[0]["RefNo_ColDocument"].ToString();
            OpenMarketValue.Text = propertyData.Rows[0]["OpenMarketValue"].ToString();
           
            DateTime dt ;
            dt= Convert.ToDateTime(propertyData.Rows[0]["DateOfValuation"].ToString());
            DateOfValuation.Value = ((DateTime)dt).ToString("MM/dd/yyyy");

            AddressWithLandMark.Text = propertyData.Rows[0]["AddressWithLandMark"].ToString();
            ForceSaleValue.Text = propertyData.Rows[0]["ForceSaleValue"].ToString();
            property_desc.Text = propertyData.Rows[0]["property_desc"].ToString();
            Location.Text = propertyData.Rows[0]["Location"].ToString();
            
            //DROPDOWN
            if (propertyData.Rows[0]["documenttype_id"].ToString() != "-1")
                documenttype_id.SelectedValue = propertyData.Rows[0]["documenttype_id"].ToString();
            
            OccupancyStatus_id.SelectedIndex = Convert.ToInt32(propertyData.Rows[0]["OccupancyStatus_id"].ToString());

            PropertyDevelopmentStatus.SelectedValue = propertyData.Rows[0]["PropertyDevelopmentStatus_id"].ToString();

            NameOfValuer.SelectedValue = propertyData.Rows[0]["valuer_id"].ToString();
            state_id.SelectedValue  = propertyData.Rows[0]["state_id"].ToString();

            PropertyType_id.SelectedValue = propertyData.Rows[0]["PropertyType_id"].ToString();
            
            //  OwnershipLink.Text = propertyData.Rows[0]["OwnershipLink"].ToString();
            
        try
        {
            RobotTableAdapters.InsuranceTableAdapter InsuranceEngine = new RobotTableAdapters.InsuranceTableAdapter();

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

            //TEXTBOXES

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

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

                //DROPDOWNS

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


        }

        }
        CheckBoxList1_Load();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            ValidateForceSaleValue();
            try
            {
                ValidateIssurance();
                RobotTableAdapters.CollateralType_PropertyTableAdapter robot = new RobotTableAdapters.CollateralType_PropertyTableAdapter();
                RobotTableAdapters.InsuranceTableAdapter robotInsuranceTable = new RobotTableAdapters.InsuranceTableAdapter();
                String collateraldetails_id = Request.QueryString["collateraldetails_id"];
                int collateraldetailsid = Convert.ToInt32(Request.QueryString["collateraldetails_id"]);

                //initialize values
                int collateralId = Convert.ToInt32(Request.QueryString["collateralId"]);
                int CollateralTypeId = Convert.ToInt32(Request.QueryString["CollateralTypeId"]);
                double varForceSaleValue = 0; double varOpenMarketValue = 0;
                varForceSaleValue = Convert.ToDouble(ForceSaleValue.Text);
                varOpenMarketValue = Convert.ToDouble(OpenMarketValue.Text);


                robot.Update(OwnershipLink.Text, Location.Text, Convert.ToInt32(state_id.SelectedValue), Name_ColDocument.Text, RefNo_ColDocument.Text, AddressWithLandMark.Text, Convert.ToInt32(PropertyType_id.SelectedValue), Convert.ToDouble(ForceSaleValue.Text), Convert.ToDouble(OpenMarketValue.Text), NameOfValuer.SelectedValue, Convert.ToDateTime(DateOfValuation.Value), Convert.ToInt32(PropertyDevelopmentStatus.SelectedValue), OccupancyStatus_id.SelectedValue, collateralId, Smart.GetEmployeeID(), Convert.ToInt32(NameOfValuer.SelectedValue), -1, property_desc.Text, "NULL", collateraldetailsid);


                //insert values into CollateralType_Property and retrieve max id as 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 varPeriodOfInsuranceCover = 0; double varAmountInsured = 0;
                //varPeriodOfInsuranceCover = Convert.ToInt32(PeriodOfInsuranceCover.Text.ToString());
                //varAmountInsured = Convert.ToDouble(AmountInsured.Text);
                if (insuranceStatusId.SelectedValue == "2")
                {

                    robotInsuranceTable.Update(Convert.ToInt32(insuranceStatusId.SelectedValue), null, collateraldetailsid, CollateralTypeId,
                        null, null, null, null, null, Smart.GetEmployeeID(), null, Convert.ToInt32(InsuranceID.Value));
                }
                else
                {
                    robotInsuranceTable.Update(Convert.ToInt32(insuranceStatusId.SelectedValue), Convert.ToInt32(InsuranceCover_id.SelectedValue), collateraldetailsid, CollateralTypeId,
                    InsuranceCompany.Text, Convert.ToDateTime(DateOfInsurance.Value), Convert.ToInt32(PeriodOfInsuranceCover.Text.ToString()), Convert.ToDouble(AmountInsured.Text), keyClause.Text, Smart.GetEmployeeID(), Convert.ToInt32(InsuranceCompany.SelectedValue), Convert.ToInt32(InsuranceID.Value));
                }

                ///Taking care of the checkboxes
                //

                //initialize values

                int CollateralDetailsId = Convert.ToInt32(hiddenDetailsId.Text);


                RobotTableAdapters.documents_submittedTableAdapter robotDocs = new RobotTableAdapters.documents_submittedTableAdapter();
                RobotTableAdapters.documents_attachmentTableAdapter robotAttachment = new RobotTableAdapters.documents_attachmentTableAdapter();

                //delete should happen before insert, just incase the guy goes back to check or uncheck documents in the checklist tab

                robotDocs.DeleteExistingCheckedDocs(collateralId, CollateralDetailsId, CollateralTypeId);
                DataTable checkDocs = robotDocs.getSubmitedDocumentsById(collateralId, CollateralDetailsId, CollateralTypeId);

                foreach (DataRow row in checkDocs.Rows)
                {
                    foreach (ListItem item in CheckBoxList1.Items)
                    {


                        if (row["document_id"].ToString() == item.Value)
                            item.Selected = true;
                    }


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

                //documenttype_id.SelectedIndex = 2;
                ASPxPageControl1.ActiveTabIndex = 1;
                CheckBoxList1_Load();
            }
            catch (Exception ex)
            {
                _errorMessageProperty.Text = ex.Message;
            }
        }
        catch (Exception _ex)
        {
            _errorMessageProperty_1.Text = _ex.Message;
        }
    }        
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            ValidateIssurance();
            //  new RobotTableAdapters.InsuranceCompanyTableAdapter().Insert();
            CheckBoxList1_Load();
            RobotTableAdapters.CollateralType_SalaryContractTableAdapter robot = new RobotTableAdapters.CollateralType_SalaryContractTableAdapter();
            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 varValueOfContract = 0; double varAPG = 0;

            varValueOfContract = Convert.ToDouble(ValueOfContract.Text);
            varAPG = Convert.ToDouble(APG.Text);

            //insert values into CollateralType_Cash  and retrieve max id as collateralDetailsId

            robot.Update(NameOfInsuringBody.Text, OriginalContractor.Text, DateTime.Now,
                                    PurposeOfContract.Text, RefNo.Text, varValueOfContract, varAPG, TenureOfContract.Text, DateTime.Now,
                                    collateralId, Smart.GetEmployeeID(), thirdparty.Text, "NULL", Convert.ToInt32(contratType.SelectedValue), collateraldetailsid);

            hiddenDetailsId.Text = collateraldetailsid.ToString();
            int insureID = Convert.ToInt32(InsuranceID.Value);
            //see if he filled the insurance form, then run the block of code that will do the insrt into insurance table
            int varPeriodOfInsuranceCover = 0; double varAmountInsured = 0;
            varPeriodOfInsuranceCover = Convert.ToInt32(FinPeriodofInsuranceCover.Text);
            varAmountInsured = Convert.ToDouble(FinAmountInsured.Text);
            if (FinInsuranceStatus_id.SelectedValue == "2")
            {
                robotInsuranceTable.Update(Convert.ToInt32(FinInsuranceStatus_id.SelectedValue), null, collateraldetailsid, CollateralTypeId,
                   null, null, null, null, null, Smart.GetEmployeeID(), null, insureID);

            }
            else
            {
                robotInsuranceTable.Update(Convert.ToInt32(FinInsuranceStatus_id.SelectedValue), Convert.ToInt32(InsuranceCover.SelectedValue), collateraldetailsid, CollateralTypeId,
                     FinInsuranceCompany.Text, Convert.ToDateTime(FinDateOfInsurance.Value), Convert.ToInt32(FinPeriodofInsuranceCover.Text), Convert.ToDouble(FinAmountInsured.Text), FinKeyClause.Text, Smart.GetEmployeeID(), Convert.ToInt32(FinInsuranceCompany.SelectedValue), insureID);
            }

            int CollateralDetailsId = Convert.ToInt32(hiddenDetailsId.Text);

            RobotTableAdapters.documents_submittedTableAdapter robotDocs = new RobotTableAdapters.documents_submittedTableAdapter();
            RobotTableAdapters.documents_attachmentTableAdapter robotAttachment = new RobotTableAdapters.documents_attachmentTableAdapter();

            //delete should happen before insert, just incase the guy goes back to check or uncheck documents in the checklist tab

            robotDocs.DeleteExistingCheckedDocs(collateralId, CollateralDetailsId, CollateralTypeId);
            DataTable checkDocs = robotDocs.getSubmitedDocumentsById(collateralId, CollateralDetailsId, CollateralTypeId);

            foreach (DataRow row in checkDocs.Rows)
            {
                foreach (ListItem item in CheckBoxList1.Items)
                {
                    if (row["document_id"].ToString() == item.Value)
                        item.Selected = true;
                }
            }

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

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

        if (!IsPostBack)
        {
          //  FinInsuranceStatus_id.SelectedIndex = 1;
           
            ASPxPageControl1.TabPages[0].Enabled = true;
            ASPxPageControl1.TabPages[1].Enabled = true;
            ASPxPageControl1.TabPages[2].Enabled = false;
            ASPxPageControl1.TabPages[3].Enabled = false;
             
            ASPxPageControl1.ActiveTabIndex = 0;
            int collateraldetailsid = Convert.ToInt32(Request.QueryString["collateraldetails_id"]);

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


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

            //TEXTBOXES
            NameOfInsuringBody.Text = returnedData.Rows[0]["NameOfInsuringBody"].ToString();
            thirdparty.Text = returnedData.Rows[0]["thirdparty"].ToString();
           
            DateTime dt;
            dt = Convert.ToDateTime(returnedData.Rows[0]["ContractAwardDate"].ToString());
            ContractAwardDate.Value = ((DateTime)dt).ToString("MM/dd/yyyy");

            RefNo.Text = returnedData.Rows[0]["RefNo"].ToString();
            APG.Text = returnedData.Rows[0]["APG"].ToString();
            OriginalContractor.Text = returnedData.Rows[0]["OriginalContractor"].ToString();
            PurposeOfContract.Text = returnedData.Rows[0]["PurposeOfContract"].ToString();
            ValueOfContract.Text = returnedData.Rows[0]["ValueOfContract"].ToString();
            TenureOfContract.Text = returnedData.Rows[0]["TenorOfContract"].ToString();
            //documenttype_id.SelectedValue = "";//(returnedData.Rows[0]["documenttype_id"].ToString()=="-1") ? "-1" : returnedData.Rows[0]["documenttype_id"].ToString() ;
            //documenttype_id.SelectedValue = returnedData.Rows[0]["documenttype_id"].ToString();
            if(returnedData.Rows[0]["documenttype_id"].ToString() != "-1")
                documenttype_id.SelectedValue = returnedData.Rows[0]["documenttype_id"].ToString();
            //DROPDOWN

            contratType.SelectedValue = returnedData.Rows[0]["contractTypeID"].ToString();


        try
        {

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


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

            //TEXTBOXES

			 FinInsuranceStatus_id.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")
            {
			
				FinPeriodofInsuranceCover.Text = InsuranceData.Rows[0]["PeriodOfInsuranceCover"].ToString();
				FinKeyClause.Text = InsuranceData.Rows[0]["KeyClause"].ToString();
				FinAmountInsured.Text = InsuranceData.Rows[0]["AmountInsured"].ToString();
           // FinDateOfInsurance.Value = InsuranceData.Rows[0]["DateOfInsurance"].ToString();

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

            //DROPDOWNS

				FinInsuranceCompany.SelectedValue = InsuranceData.Rows[0]["InsuranceCompany"].ToString();
				InsuranceCover.SelectedValue = InsuranceData.Rows[0]["InsuranceCover_id"].ToString();
			}
        }
        catch (Exception)
        {


        }
        }
       
        CheckBoxList1_Load();
    }
    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();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        String collateraldetails_id = Request.QueryString["collateraldetails_id"];
        int collateralId = Convert.ToInt32(Request.QueryString["collateralId"]);
        int collateraldetailsid = Convert.ToInt32(Request.QueryString["collateraldetails_id"]);
        int CollateralTypeId = Convert.ToInt32(Request.QueryString["CollateralTypeId"]);
        //this code is for population of fields when update mode is set
           
        RobotTableAdapters.CollateralType_StockHypoTableAdapter Engine = new RobotTableAdapters.CollateralType_StockHypoTableAdapter();
        DataTable returnedData = Engine.getStockHypoById(Convert.ToInt32(collateraldetails_id));
        if (!IsPostBack)
        {
            //insuranceStatusId.SelectedIndex = 1;
            ASPxPageControl1.TabPages[0].Enabled = true;
            ASPxPageControl1.TabPages[1].Enabled = true;
            ASPxPageControl1.TabPages[2].Enabled = false;
            ASPxPageControl1.TabPages[3].Enabled = false;
            ASPxPageControl1.ActiveTabIndex = 0;
            
            hiddenDetailsId.Text = collateraldetailsid.ToString();
            //TextBOXES
            InvoiceNo.Text = returnedData.Rows[0]["InvoiceNo"].ToString();
            ValueOfStock_total.Text = returnedData.Rows[0]["ValueOfStock_total"].ToString();
            // DateOfValuation.Text = returnedData.Rows[0]["DateOfValuation"].ToString();

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

            ListOfStock.Text = returnedData.Rows[0]["ListOfStock"].ToString();
            NameOfStockValuer.Text = returnedData.Rows[0]["NameOfStockValuer"].ToString();
            MethodOfValuation.Text = returnedData.Rows[0]["MethodOfValuation"].ToString();
            FrequencyOfValuation.SelectedValue = returnedData.Rows[0]["ValuationID"].ToString();
            //DROPDOWN
            TypeOfStock_id.SelectedValue = returnedData.Rows[0]["TypeOfStock_id"].ToString();
            // TypeOfStock_id.SelectedValue = returnedData.Rows[0]["TypeOfStock_id"].ToString();
            if (returnedData.Rows[0]["documenttype_id"].ToString() != "-1")
            { documenttype_id.SelectedValue = returnedData.Rows[0]["documenttype_id"].ToString(); }
            try
            {
                RobotTableAdapters.InsuranceTableAdapter InsuranceEngine = new RobotTableAdapters.InsuranceTableAdapter();
                DataTable InsuranceData = InsuranceEngine.proc_getInsuranceById(Convert.ToInt32(collateraldetails_id), 3);

                //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")
                {

                    StockPeriodOfInsuranceCover.Text = InsuranceData.Rows[0]["PeriodOfInsuranceCover"].ToString();
                    StockKeyClause.Text = InsuranceData.Rows[0]["KeyClause"].ToString();
                    StockAmountInsured.Text = InsuranceData.Rows[0]["AmountInsured"].ToString();
                    //  StockDateOfInsurance.Value = InsuranceData.Rows[0]["DateOfInsurance"].ToString();

                    DateTime dt1;
                    dt1 = Convert.ToDateTime(InsuranceData.Rows[0]["DateOfInsurance"].ToString());
                    StockDateOfInsurance.Value = ((DateTime)dt1).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();                    

    }