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)
    {
      //  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 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 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"]);
            String collateraldetails_id = Request.QueryString["collateraldetails_id"];
            int collateraldetailsid = Convert.ToInt32(Request.QueryString["collateraldetails_id"]);

            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_Stock  and retrieve max id as collateralDetailsId
            robot.Update(varTypeOfStock, ListOfStock.Text, InvoiceNo.Text,
                                        -1, varValueOfStock, NameOfStockValuer.Text, DateTime.Now, MethodOfValuation.Text, varFrequencyOfValuation,
                                        varInsuranceCover_id, collateralId, Smart.GetEmployeeID(), varFrequencyOfValuation, "NULL", collateraldetailsid);
            int insureID = Convert.ToInt32(InsuranceID.Value);
            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(StockPeriodOfInsuranceCover.Text);
            //varAmountInsured = Convert.ToDouble(StockAmountInsured.Text);

            if (insuranceStatusId.SelectedValue == "2")
            {
                robotInsuranceTable.Update(Convert.ToInt32(insuranceStatusId.SelectedValue), null, collateraldetailsid, CollateralTypeId,
                   null, null, null, null, null, Smart.GetEmployeeID(), null, insureID);
            }
            else
            {
                robotInsuranceTable.Update(Convert.ToInt32(insuranceStatusId.SelectedValue), Convert.ToInt32(InsuranceCover_id.SelectedValue), collateraldetailsid, CollateralTypeId,
                  InsuranceCompany.Text, Convert.ToDateTime(StockDateOfInsurance.Value), Convert.ToInt32(StockPeriodOfInsuranceCover.Text), Convert.ToDouble(StockAmountInsured.Text), StockKeyClause.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)
        {
            _errorMessageStock.Text = ex.Message;
        }
    }