protected void SubmitCheckedDoc_Click(object sender, EventArgs e)
    {
        //initialize values
        int collateralId = Convert.ToInt32(Request.QueryString["collateralId"]);
        int CollateralTypeId = Convert.ToInt32(Request.QueryString["CollateralTypeId"]);
              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);
        foreach (ListItem item in CheckBoxList1.Items)
        {
            if (item.Selected)
            {
                        robotDocs.Insert(Convert.ToInt32(item.Value), collateralId, CollateralDetailsId, CollateralTypeId, 1,Smart.GetEmployeeID());
            }
        }

        //popolate the documents for attachment
       // robotAttachment.proc_DeleteAlreadyPopulatedDocsBeforeInsert(collateralId, CollateralDetailsId, CollateralTypeId);
       // robotAttachment.Proc_populateDocumentsAttachment(collateralId.ToString(), CollateralDetailsId.ToString(), CollateralTypeId.ToString());

           ASPxGridView1.DataBind();
           ASPxGridView2.DataBind();

        //enable and move focus to next tab, disable current tab
        ASPxPageControl1.TabPages[2].Enabled = true;
        ASPxPageControl1.TabPages[1].Enabled = true;
        ASPxPageControl1.TabPages[0].Enabled = true;
        ASPxPageControl1.ActiveTabIndex = 2;
    }
    protected void CheckBoxList1_Load()
    {
        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"]);
        RobotTableAdapters.documents_submittedTableAdapter docsub = new RobotTableAdapters.documents_submittedTableAdapter();
        Robot.documents_submittedDataTable docVals = docsub.getSubmitedDocumentsById(collateraldetailsid, collateralId, CollateralTypeId);
        ArrayList selectVals = new ArrayList();
        foreach (DataRow dr in docVals.Rows)
        {
            selectVals.Add(dr["document_id"].ToString());
        }

        foreach (ListItem li in CheckBoxList1.Items)
        {
            if (selectVals.Contains(li.Value))
                li.Selected = true;
        }
    }
    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 SubmitCheckedDoc_Click(object sender, EventArgs e)
    {
        //initialize values
        int collateralId = Convert.ToInt32(Request.QueryString["collateralId"]);
        int CollateralTypeId = Convert.ToInt32(Request.QueryString["CollateralTypeId"]);
        int CollateralDetailsId = Convert.ToInt32(hiddenDetailsId.Text);


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

        foreach (ListItem item in CheckBoxList1.Items)
        {
            if (item.Selected)
            {
                robotDocs.Insert(Convert.ToInt32(item.Value), collateralId, CollateralDetailsId, CollateralTypeId, 1, Smart.GetEmployeeID());
            }
        }

           ASPxGridView1.DataBind();
        //enable and move focus to next tab, disable current tab
        ASPxPageControl1.TabPages[2].Enabled = true;
        ASPxPageControl1.TabPages[1].Enabled = true;
        ASPxPageControl1.TabPages[0].Enabled = true;

        ASPxPageControl1.ActiveTabIndex = 2;

    }