Beispiel #1
0
    private void CalculatePremiumTotalValues()
    {
        TextBox tbYearlyPremiumValueForLifeEuro     = (TextBox)PoliciesDetailsView.FindControl("tbYearlyPremiumValueForLifeEuro");
        TextBox tbYearlyPremiumValueForAccidentEuro = (TextBox)PoliciesDetailsView.FindControl("tbYearlyPremiumValueForAccidentEuro");
        TextBox tbTotalPremumValueEuro            = (TextBox)PoliciesDetailsView.FindControl("tbTotalPremumValueEuro");
        decimal totalYearlyPremiumValueEuro       = 0;
        decimal yearlyPremiumValueForLifeEuro     = 0;
        decimal yearlyPremiumValueForAccidentEuro = 0;

        decimal.TryParse(tbYearlyPremiumValueForLifeEuro.Text, out yearlyPremiumValueForLifeEuro);
        decimal.TryParse(tbYearlyPremiumValueForAccidentEuro.Text, out yearlyPremiumValueForAccidentEuro);
        totalYearlyPremiumValueEuro = PolicyDurationYears * (yearlyPremiumValueForLifeEuro + yearlyPremiumValueForAccidentEuro);
        tbTotalPremumValueEuro.Text = totalYearlyPremiumValueEuro.ToString();

        TextBox tbYearlyPremiumValueForLife     = (TextBox)PoliciesDetailsView.FindControl("tbYearlyPremiumValueForLife");
        TextBox tbYearlyPremiumValueForAccident = (TextBox)PoliciesDetailsView.FindControl("tbYearlyPremiumValueForAccident");
        TextBox tbTotalPremumValue            = (TextBox)PoliciesDetailsView.FindControl("tbTotalPremumValue");
        decimal totalYearlyPremiumValue       = 0;
        decimal yearlyPremiumValueForLife     = 0;
        decimal yearlyPremiumValueForAccident = 0;

        decimal.TryParse(tbYearlyPremiumValueForLife.Text, out yearlyPremiumValueForLife);
        decimal.TryParse(tbYearlyPremiumValueForAccident.Text, out yearlyPremiumValueForAccident);
        totalYearlyPremiumValue = PolicyDurationYears * (yearlyPremiumValueForLife + yearlyPremiumValueForAccident);
        tbTotalPremumValue.Text = totalYearlyPremiumValue.ToString();
    }
Beispiel #2
0
    protected void tbPolicyNumber_Changed(object sender, EventArgs e)
    {
        //TextBox tbPolicyNumber = (TextBox)sender;
        TextBox      tbPolicyNumber      = (TextBox)PoliciesDetailsView.FindControl("tbPolicyNumber");
        string       policyNumber        = tbPolicyNumber.Text;
        DropDownList ddlInsuranceCompany = PoliciesDetailsView.FindControl("ddlInsuranceCompany") as DropDownList;
        //Distribution distribution = Distribution.GetByNumberAndSubTypeAndCompany(InsuranceSubtypeID, policyNumber, Convert.ToInt32(ddlInsuranceCompany.SelectedValue));
        Distribution distribution = Distribution.GetByNumberAndSubTypeAndCompanyIsAccepted(InsuranceSubtypeID, policyNumber, Convert.ToInt32(ddlInsuranceCompany.SelectedValue), this.PageUser.BranchID);

        if (distribution != null)
        {
            if (distribution.IsUsed)
            {
                RegisterStartupScript("myAlert", "<script>alert('ПОЛИСАТА Е ИСКОРИСТЕНА!')</script>");
                //PoliciesDetailsView.Enabled = false;
            }
            else
            {
                //PoliciesDetailsView.Enabled = true;
            }
        }
        else
        {
            RegisterStartupScript("myAlert", "<script>alert('НЕМА ЗАДОЛЖУВАЊЕ СО ОВОЈ БРОЈ НА ПОЛИСА!')</script>");
            //PoliciesDetailsView.Enabled = false;
        }
    }
Beispiel #3
0
    private void CalculateInsuranceCoverageTotalValues()
    {
        TextBox tbInsuranceCoverageOne      = (TextBox)PoliciesDetailsView.FindControl("tbInsuranceCoverageOne");
        TextBox tbInsuranceCoverageTwo      = (TextBox)PoliciesDetailsView.FindControl("tbInsuranceCoverageTwo");
        TextBox tbTotalInsuranceCoverageSum = (TextBox)PoliciesDetailsView.FindControl("tbTotalInsuranceCoverageSum");
        decimal totalInsuranceCoverage      = 0;
        decimal insuranceCoverageOne        = 0;
        decimal insuranceCoverageTwo        = 0;

        decimal.TryParse(tbInsuranceCoverageOne.Text, out insuranceCoverageOne);
        decimal.TryParse(tbInsuranceCoverageTwo.Text, out insuranceCoverageTwo);
        totalInsuranceCoverage           = PolicyDurationYears * (insuranceCoverageOne + insuranceCoverageTwo);
        tbTotalInsuranceCoverageSum.Text = totalInsuranceCoverage.ToString();

        TextBox tbInsuranceCoverageOneEuro      = (TextBox)PoliciesDetailsView.FindControl("tbInsuranceCoverageOneEuro");
        TextBox tbInsuranceCoverageTwoEuro      = (TextBox)PoliciesDetailsView.FindControl("tbInsuranceCoverageTwoEuro");
        TextBox tbTotalInsuranceCoverageSumEuro = (TextBox)PoliciesDetailsView.FindControl("tbTotalInsuranceCoverageSumEuro");
        decimal totalInsuranceCoverageEuro      = 0;
        decimal insuranceCoverageOneEuro        = 0;
        decimal insuranceCoverageTwoEuro        = 0;

        decimal.TryParse(tbInsuranceCoverageOneEuro.Text, out insuranceCoverageOneEuro);
        decimal.TryParse(tbInsuranceCoverageTwoEuro.Text, out insuranceCoverageTwoEuro);
        totalInsuranceCoverageEuro           = PolicyDurationYears * (insuranceCoverageOneEuro + insuranceCoverageTwoEuro);
        tbTotalInsuranceCoverageSumEuro.Text = totalInsuranceCoverageEuro.ToString();
    }
Beispiel #4
0
 protected void GXGridView1_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     PolicyID = Convert.ToInt32(GXGridView1.SelectedValue);
     if (e.CommandName == "SingleClick")
     {
         btnPreviewPolicy.Enabled = true;
         int selIndex = Convert.ToInt32(e.CommandArgument);
         GXGridView1.SelectedIndex = selIndex;
         GXGridView1SelectedValue  = Convert.ToInt32(GXGridView1.SelectedValue);
         PoliciesDetailsView.DataBind();
         DetailsViewPolicyForAttachments.DataBind();
     }
     if (e.CommandName == "DoubleClick")
     {
         int selIndex = Convert.ToInt32(e.CommandArgument);
         GXGridView1.SelectedIndex = selIndex;
         mvMain.SetActiveView(viewEdit);
         GXGridView1SelectedValue = Convert.ToInt32(GXGridView1.SelectedValue);
         //PoliciesDetailsView.DataBind();
         //DetailsViewPolicyForAttachments.DataBind();
         //OnInit(e);
         //CreateChildControls();
         //mvPolicyItem.ActiveViewIndex = 0;
         //btnPreviewPolicy.CssClass = "prikaz_Active";
         //btnPreview.CssClass = "osvezi";
         //btnReport.CssClass = "izvestaj";
         //btnSearch.CssClass = "prebaraj";
         //btnAttachments.CssClass = "dokumenti";
         btnPreviewPolicy_Click(null, null);
     }
 }
Beispiel #5
0
    protected void btnPreviewPolicy_Click(object sender, EventArgs e)
    {
        if (GXGridView1.SelectedIndex != -1)
        {
            if (GXGridView1.SelectedDataKey != null)
            {
                int GXgvSelectedValue = Convert.ToInt32(GXGridView1.SelectedValue);
                PolicyID = Convert.ToInt32(GXGridView1.SelectedValue);
                dvDataSourcePolicyDetails.SelectParameters.Clear();
                dvDataSourcePolicyDetails.SelectParameters.Add("id", GXgvSelectedValue.ToString());
                PoliciesDetailsView.DataBind();
            }
            else
            {
                int GXgvSelectedValue = GXGridView1SelectedValue;
                PolicyID = GXGridView1SelectedValue;
                dvDataSourcePolicyDetails.SelectParameters.Clear();
                dvDataSourcePolicyDetails.SelectParameters.Add("id", GXgvSelectedValue.ToString());
                PoliciesDetailsView.DataBind();
            }

            btnAttachments.CssClass   = "dokumenti";
            btnPreview.CssClass       = "osvezi";
            btnReport.CssClass        = "izvestaj";
            btnSearch.CssClass        = "prebaraj";
            btnPreviewPolicy.CssClass = "prikaz_Active";
            mvMain.SetActiveView(viewEdit);
            OnInit(e);
            CreateChildControls();
            mvPolicyItem.ActiveViewIndex = 0;
        }
    }
Beispiel #6
0
    protected void ddlDealsSelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList ddlInsuranceSubType = PoliciesDetailsView.FindControl("ddlInsuranceSubTypes") as DropDownList;
        DropDownList ddlDeals            = (DropDownList)sender;

        DealID             = int.Parse(ddlDeals.SelectedValue);
        InsuranceSubtypeID = int.Parse(ddlInsuranceSubType.SelectedValue);
    }
 protected void OwnerDetailsView_ItemCommand(object sender, DetailsViewCommandEventArgs e)
 {
     if (e.CommandName == "Cancel")
     {
         Panel pnl = PoliciesDetailsView.FindControl("pnlOwner") as Panel;
         pnl.Visible = false;
     }
 }
Beispiel #8
0
 protected void ClientDetailsView_ItemCommand(object sender, DetailsViewCommandEventArgs e)
 {
     if (e.CommandName == "Cancel")
     {
         //  mvMain.SetActiveView(viewGrid);
         Panel pnl = PoliciesDetailsView.FindControl("pnlClient") as Panel;
         pnl.Visible = false;
     }
 }
 protected void ddlInsuranceCompanyIndexChanged(object sender, EventArgs e)
 {
     dvDataSource.SelectParameters.Clear();
     dvDataSource.SelectParameters.Add("policyNumber", "");
     dvDataSource.SelectParameters.Add("insuranceSubTypeID", "0");
     dvDataSource.SelectParameters.Add("insuranceCompanyID", "0");
     PoliciesDetailsView.DataBind();
     //CreateChildControls();
     btnUpdate.Visible = false;
 }
Beispiel #10
0
 protected void tbInsuranceCoverageTwoEuro_TextChanged(object sender, EventArgs e)
 {
     try {
         TextBox tbInsuranceCoverageTwoEuro = (TextBox)PoliciesDetailsView.FindControl("tbInsuranceCoverageTwoEuro");
         TextBox tbInsuranceCoverageTwo     = (TextBox)PoliciesDetailsView.FindControl("tbInsuranceCoverageTwo");
         tbInsuranceCoverageTwo.Text = (Convert.ToDecimal(tbInsuranceCoverageTwoEuro.Text) * EuroValue).ToString();
         CalculateInsuranceCoverageTotalValues();
     } catch {
     }
 }
Beispiel #11
0
 protected void tbYearlyPremiumValueForAccidentEuro_TextChanged(object sender, EventArgs e)
 {
     try {
         TextBox tbYearlyPremiumValueForAccidentEuro = (TextBox)PoliciesDetailsView.FindControl("tbYearlyPremiumValueForAccidentEuro");
         TextBox tbYearlyPremiumValueForAccident     = (TextBox)PoliciesDetailsView.FindControl("tbYearlyPremiumValueForAccident");
         tbYearlyPremiumValueForAccident.Text = (Convert.ToDecimal(tbYearlyPremiumValueForAccidentEuro.Text) * EuroValue).ToString();
         CalculatePremiumTotalValues();
     } catch {
     }
 }
Beispiel #12
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         PolicyMultiView.SetActiveView(MainView);
         Button btnDiscard = (Button)PoliciesDetailsView.FindControl("btnDiscard");
         btnDiscard.Attributes.Add("onclick", "return confirm_delete();");
         TextBox tbEuroValue = (TextBox)PoliciesDetailsView.FindControl("tbEuroValue");
         tbEuroValue.Text = EuroValue.ToString();
     }
 }
 protected void btnNewChange_Click(object sender, EventArgs e)
 {
     btnSearch.Enabled = true;
     dvDataSource.SelectParameters.Clear();
     dvDataSource.SelectParameters.Add("policyNumber", "");
     dvDataSource.SelectParameters.Add("insuranceSubTypeID", "0");
     dvDataSource.SelectParameters.Add("insuranceCompanyID", "0");
     PoliciesDetailsView.DataBind();
     //CreateChildControls();
     btnUpdate.Visible = false;
 }
Beispiel #14
0
 protected void btnOwnerToClient_Click(object sender, EventArgs e)
 {
     if (ViewState["OwnerID"] != null)
     {
         TextBox tbEmbg             = PoliciesDetailsView.FindControl("tbClientEMBG") as TextBox;
         TextBox tbName             = PoliciesDetailsView.FindControl("tbClientName") as TextBox;
         int     ownerID            = int.Parse(ViewState["OwnerID"].ToString());
         Broker.DataAccess.Client c = Broker.DataAccess.Client.Get(ownerID);
         tbEmbg.Text           = c.EMBG;
         tbName.Text           = c.Name;
         ViewState["ClientID"] = ownerID;
     }
 }
Beispiel #15
0
    protected void ddlInsuranceCompanyIndexChanged(object sender, EventArgs e)
    {
        DropDownList ddlInsuranceSubType = PoliciesDetailsView.FindControl("ddlInsuranceSubTypes") as DropDownList;
        DropDownList ddlDeals            = PoliciesDetailsView.FindControl("ddlDeals") as DropDownList;

        ddlInsuranceSubType.DataBind();
        ddlDeals.DataBind();

        //DealID = int.Parse(ddlDeals.SelectedValue);
        if (ddlDeals.SelectedValue != null)
        {
            int dealID = DealID;
            int.TryParse(ddlDeals.SelectedValue, out dealID);
            DealID = dealID;
        }
        InsuranceSubtypeID = int.Parse(ddlInsuranceSubType.SelectedValue);
    }
Beispiel #16
0
    void CalculateDurationYears()
    {
        try {
            TextBox  tbStartDate = (TextBox)PoliciesDetailsView.FindControl("tbStartDate");
            TextBox  tbEndDate   = (TextBox)PoliciesDetailsView.FindControl("tbEndDate");
            DateTime startDate   = Convert.ToDateTime(tbStartDate.Text);
            DateTime endDate     = Convert.ToDateTime(tbEndDate.Text);
            TimeSpan ts          = endDate - startDate;
            int      years       = Convert.ToInt32(ts.Days / 365.25);
            PolicyDurationYears = years;
        } catch {
            PolicyDurationYears = 0;
        }
        TextBox tbPolicyDurationYears = (TextBox)PoliciesDetailsView.FindControl("tbPolicyDurationYears");

        tbPolicyDurationYears.Text = PolicyDurationYears.ToString();
    }
Beispiel #17
0
 protected void OwnerDetailsView_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
 {
     if (e.Exception != null)
     {
         e.ExceptionHandled = true;
         e.KeepInInsertMode = true;
         ValidationUtility.ShowValidationErrors(this, e.Exception);
     }
     else
     {
         string embg = e.Values["EMBG"].ToString();
         Broker.DataAccess.Client o = Broker.DataAccess.Client.GetByEmbg(embg);
         ViewState["OwnerID"] = o.ID;
         TextBox tbName = PoliciesDetailsView.FindControl("tbOwnerName") as TextBox;
         tbName.Text = o.Name;
         Panel pnl = PoliciesDetailsView.FindControl("pnlOwner") as Panel;
         pnl.Visible = false;
     }
 }
Beispiel #18
0
    void SetInsuranceDurationInYears()
    {
        if (this.PageUser.Role.Name == RolesInfo.BROKERAdmin)
        {
            pnlBrokerageInformationsPerYears.Visible = true;
        }
        else
        {
            pnlBrokerageInformationsPerYears.Visible = false;
        }
        TextBox tbPolicyDurationYears = (TextBox)PoliciesDetailsView.FindControl("tbPolicyDurationYears");

        if (GXGridView1SelectedValue > 0)
        {
            LifePolicy p = LifePolicy.Get(GXGridView1SelectedValue);
            tbPolicyDurationYears.Text = ((p.EndDate - p.StartDate).Days / 365.15).ToString();
            gvLifePolicyPremiumValue.DataBind();
            gvLifePolicyBrokerage.DataBind();
        }
    }
Beispiel #19
0
    protected void dvDataSource_Inserting(object sender, ObjectDataSourceMethodEventArgs e)
    {
        if ((ViewState["ClientID"] == null) || (ViewState["OwnerID"] == null))
        {
            RegisterStartupScript("myAlert", "<script>alert('НЕ Е ИЗБРАН ДОГОВОРУВАЧ ИЛИ ОСИГУРЕНИК!')</script>");
            return;
        }
        LifePolicy p = e.InputParameters["entityToInsert"] as LifePolicy;

        p.InsertDate         = DateTime.Now;
        p.BranchID           = this.PageUser.BranchID;
        p.ClientID           = (int)ViewState["ClientID"];
        p.OwnerID            = (int)ViewState["OwnerID"];
        p.InsuranceSubTypeID = InsuranceSubtypeID;
        p.UserID             = this.PageUser.ID;
        p.LifeDealID         = DealID;
        TextBox tbPolicyNumber = PoliciesDetailsView.FindControl("tbPolicyNumber") as TextBox;

        p.PolicyNumber = tbPolicyNumber.Text;
        p.ValidateSinglePolicyNumber(p.InsuranceCompanyID, InsuranceSubtypeID, p.PolicyNumber, p.BranchID);
    }
Beispiel #20
0
    protected void ddlInsuranceSubType_selecteIndexChanged(object sender, EventArgs e)
    {
        DropDownList ddlDeals            = PoliciesDetailsView.FindControl("ddlDeals") as DropDownList;
        DropDownList ddlInsuranceSubType = (DropDownList)sender;
        DropDownList ddlInsuranceCompany = PoliciesDetailsView.FindControl("ddlInsuranceCompany") as DropDownList;

        List <LifeDeal> dealList = LifeDeal.GetActiveDealsForCompanyAndInsuranceSubType(int.Parse(ddlInsuranceCompany.SelectedValue), int.Parse(ddlInsuranceSubType.SelectedValue));

        InsuranceSubtypeID = int.Parse(ddlInsuranceSubType.SelectedValue);

        if (dealList.Count != 0)
        {
            DealID = dealList[0].ID;
        }
        //else {
        //dealList = Deal.GetBySubType(int.Parse(ddlInsuranceSubType.SelectedValue));
        //DealID = dealList[0].ID;
        //}
        //FakeBinder.SimulateBindingContext(this.Page, ddlInsuranceCompany);
        //ddlInsuranceCompany.DataBind();
        ddlDeals.DataBind();
    }
    protected void btnClientEMBGSearch_Click(object sender, EventArgs e)
    {
        Panel            pnlClient          = PoliciesDetailsView.FindControl("pnlClient") as Panel;
        DetailsView      clientDetailsView  = pnlClient.FindControl("ClientDetailsView") as DetailsView;
        ObjectDataSource clientdvDataSource = pnlClient.FindControl("ClientdvDataSource") as ObjectDataSource;

        if (PoliciesDetailsView.SelectedValue != null)
        {
            int        policyItemID = Convert.ToInt32(PoliciesDetailsView.SelectedValue);
            PolicyItem policyItem   = PolicyItem.Get(policyItemID);
            string     clientEMBG   = policyItem.Policy.Client.EMBG;
            pnlClient.Visible = true;
            clientdvDataSource.SelectParameters.Clear();
            clientdvDataSource.SelectParameters.Add("embg", clientEMBG);
            clientDetailsView.DataBind();
        }
        else
        {
            pnlClient.Visible = false;
            clientdvDataSource.SelectParameters.Clear();
            clientDetailsView.DataBind();
        }
    }
Beispiel #22
0
    protected void tbEndDate_TextChanged(object sender, EventArgs e)
    {
        TextBox tbEndDate         = (TextBox)sender;
        TextBox tbApplicationDate = (TextBox)PoliciesDetailsView.FindControl("tbApplicationDate");

        try {
            DateTime endDate = Convert.ToDateTime(tbEndDate.Text);
            CalculateDurationYears();
            CalculateTotalValues();
            tbApplicationDate.Focus();
            return;
        } catch {
        }
        try {
            DateTime endDate = new DateTime(Convert.ToInt32(tbEndDate.Text.Substring(4, 4)), Convert.ToInt32(tbEndDate.Text.Substring(2, 2)), Convert.ToInt32(tbEndDate.Text.Substring(0, 2)));
            tbEndDate.Text = endDate.ToShortDateString();
            CalculateDurationYears();
            CalculateTotalValues();
            tbApplicationDate.Focus();
            return;
        } catch {
        }
    }
Beispiel #23
0
    protected void btnOwnerEMBGSearch_Click(object sender, EventArgs e)
    {
        TextBox tbEmbg = PoliciesDetailsView.FindControl("tbOwnerEMBG") as TextBox;

        Broker.DataAccess.Client o = Broker.DataAccess.Client.GetByEmbg(tbEmbg.Text);
        Panel ownerPanel           = PoliciesDetailsView.FindControl("pnlOwner") as Panel;

        if (o != null)
        {
            ViewState["OwnerID"] = o.ID;
            TextBox tbName = PoliciesDetailsView.FindControl("tbOwnerName") as TextBox;
            tbName.Text        = o.Name;
            ownerPanel.Visible = false;
        }
        else
        {
            ownerPanel.Visible = true;
            DetailsView OwnerDetailsView = ownerPanel.FindControl("OwnerDetailsView") as DetailsView;
            TextBox     tbOwnerEMBG      = OwnerDetailsView.FindControl("tbEMBG") as TextBox;
            tbOwnerEMBG.Text     = tbEmbg.Text;
            tbOwnerEMBG.ReadOnly = true;
        }
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        int    insuranceCompanyID = Convert.ToInt32(ddlInsuranceCompany.SelectedValue);
        int    insuranceTypeID    = Convert.ToInt32(ddlInsuranceType.SelectedValue);
        int    insuranceSubTypeID = Convert.ToInt32(ddlInsuranceSubTypes.SelectedValue);
        string policyNumber       = tbPolicyNumber.Text;

        dvDataSource.SelectParameters.Clear();
        dvDataSource.SelectParameters.Add("policyNumber", policyNumber);
        dvDataSource.SelectParameters.Add("insuranceSubTypeID", insuranceSubTypeID.ToString());
        dvDataSource.SelectParameters.Add("insuranceCompanyID", insuranceCompanyID.ToString());
        PoliciesDetailsView.DataBind();
        PolicyItem pi = PolicyItem.GetByNumberAndInsuranceSubType(policyNumber, insuranceSubTypeID, insuranceCompanyID);

        if (pi != null)
        {
            btnUpdate.Visible = true;
            CreateChildControls();
        }
        else
        {
            btnUpdate.Visible = false;
        }
    }
Beispiel #25
0
    protected void btnClientEMBGSearch_Click(object sender, EventArgs e)
    {
        TextBox tbClientEmbg = PoliciesDetailsView.FindControl("tbClientEMBG") as TextBox;
        string  embg         = tbClientEmbg.Text;

        Broker.DataAccess.Client c = Broker.DataAccess.Client.GetByEmbg(embg);
        Panel pnlClient            = PoliciesDetailsView.FindControl("pnlClient") as Panel;

        if (c != null)
        {
            TextBox tbClientName = PoliciesDetailsView.FindControl("tbClientName") as TextBox;
            ViewState["ClientID"] = c.ID;
            tbClientName.Text     = c.Name;
            pnlClient.Visible     = false;
        }
        else
        {
            pnlClient.Visible = true;
            DetailsView ClientDetailsView = pnlClient.FindControl("ClientDetailsView") as DetailsView;
            TextBox     tbClientEMBG      = ClientDetailsView.FindControl("tbEMBG") as TextBox;
            tbClientEMBG.Text     = embg;
            tbClientEMBG.ReadOnly = true;
        }
    }
    protected override void CreateChildControls()
    {
        if (PoliciesDetailsView.SelectedValue != null)
        {
            int        policyItemID      = Convert.ToInt32(PoliciesDetailsView.SelectedValue);
            PolicyItem policyItem        = PolicyItem.Get(policyItemID);
            Panel      pnlExtendControls = PoliciesDetailsView.FindControl("pnlExtendControls") as Panel;
            int        j = 0;
            List <Broker.DataAccess.Control> listControls = Broker.DataAccess.Control.GetByInsuranceSubType(policyItem.InsuranceSubTypeID);

            pnlExtendControls.Controls.Clear();
            lblFieldNames = new List <Label>();
            tbValues      = new List <TextBox>();

            HtmlTable titleTable = new HtmlTable();
            titleTable.Width = "695px";
            HtmlTableRow firstTitleTableRow = new HtmlTableRow();
            titleTable.Rows.Add(firstTitleTableRow);
            HtmlTableCell firstCellFirstRowInTitleTable = new HtmlTableCell();
            firstTitleTableRow.Cells.Add(firstCellFirstRowInTitleTable);
            Label lblPremiumBrokerageTitle = new Label();
            lblPremiumBrokerageTitle.ID        = "lblPremiumBrokerageTitle";
            lblPremiumBrokerageTitle.Font.Bold = true;
            lblPremiumBrokerageTitle.Text      = "Премија и брокеража";
            firstCellFirstRowInTitleTable.Controls.Add(lblPremiumBrokerageTitle);
            pnlExtendControls.Controls.Add(titleTable);

            HtmlTable defaultTable = new HtmlTable();
            defaultTable.Width = "695px";

            HtmlTableRow fourthDefaultTableRow = new HtmlTableRow();
            fourthDefaultTableRow.BgColor = "#FAFAF8";
            defaultTable.Rows.Add(fourthDefaultTableRow);
            HtmlTableCell firstCellFourthRowInDefaultTable = new HtmlTableCell();
            firstCellFourthRowInDefaultTable.Width = "160px";
            fourthDefaultTableRow.Cells.Add(firstCellFourthRowInDefaultTable);
            Label lblPolicyValue = new Label();
            lblPolicyValue.ID   = "lblPolicyValue" + (j + 1).ToString();
            lblPolicyValue.Text = "Премија";
            firstCellFourthRowInDefaultTable.Controls.Add(lblPolicyValue);
            HtmlTableCell secondCellFourthRowInDefaultTable = new HtmlTableCell();
            secondCellFourthRowInDefaultTable.Width = "187px";
            fourthDefaultTableRow.Cells.Add(secondCellFourthRowInDefaultTable);
            TextBox tbPolicyValue = new TextBox();
            tbPolicyValue.ID           = "tbPolicyValue" + (j + 1).ToString();
            tbPolicyValue.AutoPostBack = true;
            tbPolicyValue.Text         = policyItem.PremiumValue.ToString();
            tbPolicyValue.ReadOnly     = true;

            tbPolicyValue.TextChanged += new EventHandler(tbPolicyValue_TextChanged);
            RequiredFieldValidator rfvPolicyValue = new RequiredFieldValidator();
            rfvPolicyValue.ID                = "rfvPolicyValue" + (j + 1).ToString();
            rfvPolicyValue.ErrorMessage      = "*";
            rfvPolicyValue.Display           = ValidatorDisplay.Dynamic;
            rfvPolicyValue.ControlToValidate = tbPolicyValue.ID;
            CompareValidator cvPolicyValue = new CompareValidator();
            cvPolicyValue.ID                = "cvPolicyValue" + (j + 1).ToString();
            cvPolicyValue.ErrorMessage      = "*";
            cvPolicyValue.Display           = ValidatorDisplay.Dynamic;
            cvPolicyValue.ControlToValidate = tbPolicyValue.ID;
            cvPolicyValue.Operator          = ValidationCompareOperator.DataTypeCheck;
            cvPolicyValue.Type              = ValidationDataType.Double;
            secondCellFourthRowInDefaultTable.Controls.Add(tbPolicyValue);
            secondCellFourthRowInDefaultTable.Controls.Add(rfvPolicyValue);
            secondCellFourthRowInDefaultTable.Controls.Add(cvPolicyValue);
            HtmlTableCell thirdCellFourthRowInDefaultTable = new HtmlTableCell();
            thirdCellFourthRowInDefaultTable.Width = "160px";
            fourthDefaultTableRow.Cells.Add(thirdCellFourthRowInDefaultTable);
            HtmlTableCell fourthCellFourthRowInDefaultTable = new HtmlTableCell();
            fourthCellFourthRowInDefaultTable.Width = "187px";
            fourthDefaultTableRow.Cells.Add(fourthCellFourthRowInDefaultTable);

            HtmlTableRow fifthDefaultTableRow = new HtmlTableRow();
            defaultTable.Rows.Add(fifthDefaultTableRow);
            HtmlTableCell firstCellFifthRowInDefaultTable = new HtmlTableCell();
            firstCellFifthRowInDefaultTable.Width = "160px";
            fifthDefaultTableRow.Cells.Add(firstCellFifthRowInDefaultTable);
            Label lblBrokeragePercentage = new Label();
            lblBrokeragePercentage.ID   = "lblBrokeragePercentage" + (j + 1).ToString();
            lblBrokeragePercentage.Text = "Процент на брокеража";
            firstCellFifthRowInDefaultTable.Controls.Add(lblBrokeragePercentage);
            HtmlTableCell secondCellFifthRowInDefaultTable = new HtmlTableCell();
            secondCellFifthRowInDefaultTable.Width = "187px";
            fifthDefaultTableRow.Cells.Add(secondCellFifthRowInDefaultTable);
            TextBox tbBrokeragePercentage = new TextBox();
            tbBrokeragePercentage.ID       = "tbBrokeragePercentage" + (j + 1).ToString();
            tbBrokeragePercentage.Text     = policyItem.BrokeragePercentage.ToString();
            tbBrokeragePercentage.ReadOnly = true;
            secondCellFifthRowInDefaultTable.Controls.Add(tbBrokeragePercentage);
            HtmlTableCell thirdCellFifthRowInDefaultTable = new HtmlTableCell();
            thirdCellFifthRowInDefaultTable.Width = "160px";
            fifthDefaultTableRow.Cells.Add(thirdCellFifthRowInDefaultTable);
            HtmlTableCell fourthCellFifthRowInDefaultTable = new HtmlTableCell();
            fourthCellFifthRowInDefaultTable.Width = "187px";
            fifthDefaultTableRow.Cells.Add(fourthCellFifthRowInDefaultTable);

            HtmlTableRow sixthDefaultTableRow = new HtmlTableRow();
            sixthDefaultTableRow.BgColor = "#FAFAF8";
            defaultTable.Rows.Add(sixthDefaultTableRow);
            HtmlTableCell firstCellSixthRowInDefaultTable = new HtmlTableCell();
            firstCellSixthRowInDefaultTable.Width = "160px";
            sixthDefaultTableRow.Cells.Add(firstCellSixthRowInDefaultTable);
            Label lblBrokerageValue = new Label();
            lblBrokerageValue.ID   = "lblBrokerageValue" + (j + 1).ToString();
            lblBrokerageValue.Text = "Брокеража";
            firstCellSixthRowInDefaultTable.Controls.Add(lblBrokerageValue);
            HtmlTableCell secondCellSixthRowInDefaultTable = new HtmlTableCell();
            secondCellSixthRowInDefaultTable.Width = "187px";
            sixthDefaultTableRow.Cells.Add(secondCellSixthRowInDefaultTable);
            TextBox tbBrokerageValue = new TextBox();
            tbBrokerageValue.ID       = "tbBrokerageValue" + (j + 1).ToString();
            tbBrokerageValue.ReadOnly = true;
            tbBrokerageValue.Text     = policyItem.BrokerageValue.ToString();
            secondCellSixthRowInDefaultTable.Controls.Add(tbBrokerageValue);
            HtmlTableCell thirdCellSixthRowInDefaultTable = new HtmlTableCell();
            thirdCellSixthRowInDefaultTable.Width = "160px";
            sixthDefaultTableRow.Cells.Add(thirdCellSixthRowInDefaultTable);
            HtmlTableCell fourthCellSixthRowInDefaultTable = new HtmlTableCell();
            fourthCellSixthRowInDefaultTable.Width = "187px";
            sixthDefaultTableRow.Cells.Add(fourthCellSixthRowInDefaultTable);

            pnlExtendControls.Controls.Add(defaultTable);

            HtmlTable titlePolicyTable = new HtmlTable();
            titlePolicyTable.Width = "695px";
            HtmlTableRow firstTitlePolicyTableRow = new HtmlTableRow();
            titlePolicyTable.Rows.Add(firstTitlePolicyTableRow);
            HtmlTableCell firstCellFirstRowInTitlePolicyTable = new HtmlTableCell();
            firstTitlePolicyTableRow.Cells.Add(firstCellFirstRowInTitlePolicyTable);
            Label lblPolicyDetailsTitle = new Label();
            lblPolicyDetailsTitle.ID        = "lblPolicyDetailsTitle";
            lblPolicyDetailsTitle.Font.Bold = true;
            lblPolicyDetailsTitle.Text      = "Детални информации за полиса";
            firstCellFirstRowInTitlePolicyTable.Controls.Add(lblPolicyDetailsTitle);
            pnlExtendControls.Controls.Add(titlePolicyTable);

            HtmlTable table = new HtmlTable();
            table.Width = "695px";
            int counter = 0;
            foreach (Broker.DataAccess.Control c in listControls)
            {
                if (c.IsActive)
                {
                    PolicyExtendInformation policyExtendInformation = PolicyExtendInformation.GetByPolicyItemAndControl(policyItem.ID, c.ID);
                    if (listControls.Count == 1)
                    {
                        HtmlTableRow tableRow = new HtmlTableRow();
                        tableRow.BgColor = "#FAFAF8";
                        table.Rows.Add(tableRow);
                        HtmlTableCell tableCell = new HtmlTableCell();
                        tableCell.Width = "160px";
                        tableRow.Cells.Add(tableCell);
                        Label label = new Label();
                        label.ID   = c.LabelID;
                        label.Text = c.LabelName;
                        lblFieldNames.Add(label);
                        tableCell.Controls.Add(label);
                        HtmlTableCell tableCellSecond = new HtmlTableCell();
                        tableCellSecond.Width = "187px";
                        tableRow.Cells.Add(tableCellSecond);
                        TextBox textbox = new TextBox();
                        textbox.ID = c.TextBoxID;
                        if (policyExtendInformation != null)
                        {
                            textbox.Text = policyExtendInformation.Value;
                        }
                        if (c.IsLatin != null)
                        {
                            if ((bool)c.IsLatin == true)
                            {
                                textbox.Attributes.Add("onkeyup", "toEnglish(this.id)");
                            }
                        }
                        tbValues.Add(textbox);
                        tableCellSecond.Controls.Add(textbox);
                        if (c.HasRequredFieldValidator)
                        {
                            RequiredFieldValidator rfv = new RequiredFieldValidator();
                            rfv.ID                = "rfv" + textbox.ID;
                            rfv.ErrorMessage      = "*";
                            rfv.Display           = ValidatorDisplay.Dynamic;
                            rfv.ControlToValidate = textbox.ID;
                            tableCellSecond.Controls.Add(rfv);
                        }
                        if (c.HasCompareValidator)
                        {
                            CompareValidator cv = new CompareValidator();
                            cv.ID                = "cv" + textbox.ID;
                            cv.ErrorMessage      = "*";
                            cv.Display           = ValidatorDisplay.Dynamic;
                            cv.ControlToValidate = textbox.ID;
                            cv.Operator          = ValidationCompareOperator.DataTypeCheck;
                            cv.Type              = Broker.DataAccess.VariableType.GetForVariableType(c.VariableTypeID);
                            tableCellSecond.Controls.Add(cv);
                        }
                        HtmlTableCell tableCellThird = new HtmlTableCell();
                        tableCellThird.Width = "160px";
                        tableRow.Cells.Add(tableCellThird);
                        HtmlTableCell tableCellForth = new HtmlTableCell();
                        tableCellForth.Width = "187px";
                        tableRow.Cells.Add(tableCellForth);
                    }
                    else
                    {
                        if (counter % 2 == 0)
                        {
                            HtmlTableRow tableRow = new HtmlTableRow();
                            if ((counter % 4 == 0) || (counter % 4 == 1))
                            {
                                tableRow.BgColor = "#FAFAF8";
                            }
                            table.Rows.Add(tableRow);
                            HtmlTableCell tableCell = new HtmlTableCell();
                            tableCell.Width = "160px";
                            tableRow.Cells.Add(tableCell);
                            Label label = new Label();
                            label.ID   = c.LabelID;
                            label.Text = c.LabelName;
                            lblFieldNames.Add(label);
                            tableCell.Controls.Add(label);
                            HtmlTableCell tableCellSecond = new HtmlTableCell();
                            tableCellSecond.Width = "187px";
                            tableRow.Cells.Add(tableCellSecond);
                            TextBox textbox = new TextBox();
                            textbox.ID = c.TextBoxID;
                            if (policyExtendInformation != null)
                            {
                                textbox.Text = policyExtendInformation.Value;
                            }
                            if (c.IsLatin != null)
                            {
                                if ((bool)c.IsLatin == true)
                                {
                                    textbox.Attributes.Add("onkeyup", "toEnglish(this.id)");
                                }
                            }
                            tbValues.Add(textbox);
                            tableCellSecond.Controls.Add(textbox);
                            if (c.HasRequredFieldValidator)
                            {
                                RequiredFieldValidator rfv = new RequiredFieldValidator();
                                rfv.ID                = "rfv" + textbox.ID;
                                rfv.ErrorMessage      = "*";
                                rfv.Display           = ValidatorDisplay.Dynamic;
                                rfv.ControlToValidate = textbox.ID;
                                tableCellSecond.Controls.Add(rfv);
                            }
                            if (c.HasCompareValidator)
                            {
                                CompareValidator cv = new CompareValidator();
                                cv.ID                = "cv" + textbox.ID;
                                cv.ErrorMessage      = "*";
                                cv.Display           = ValidatorDisplay.Dynamic;
                                cv.ControlToValidate = textbox.ID;
                                cv.Operator          = ValidationCompareOperator.DataTypeCheck;
                                cv.Type              = Broker.DataAccess.VariableType.GetForVariableType(c.VariableTypeID);
                                tableCellSecond.Controls.Add(cv);
                            }
                        }
                        else if (counter % 2 == 1)
                        {
                            HtmlTableRow tableRow = table.Rows[counter / 2];
                            if ((counter % 4 == 0) || (counter % 4 == 1))
                            {
                                tableRow.BgColor = "#FAFAF8";
                            }
                            HtmlTableCell tableCellThird = new HtmlTableCell();
                            tableCellThird.Width = "160px";
                            tableRow.Cells.Add(tableCellThird);
                            Label label = new Label();
                            label.ID   = c.LabelID;
                            label.Text = c.LabelName;
                            lblFieldNames.Add(label);
                            tableCellThird.Controls.Add(label);
                            HtmlTableCell tableCellForth = new HtmlTableCell();
                            tableCellForth.Width = "187px";
                            tableRow.Cells.Add(tableCellForth);
                            TextBox textbox = new TextBox();
                            textbox.ID = c.TextBoxID;
                            if (policyExtendInformation != null)
                            {
                                textbox.Text = policyExtendInformation.Value;
                            }
                            if (c.IsLatin != null)
                            {
                                if ((bool)c.IsLatin)
                                {
                                    textbox.Attributes.Add("onkeyup", "toEnglish(this.id)");
                                }
                            }
                            tbValues.Add(textbox);
                            tableCellForth.Controls.Add(textbox);
                            if (c.HasRequredFieldValidator)
                            {
                                RequiredFieldValidator rfv = new RequiredFieldValidator();
                                rfv.ID                = "rfv" + textbox.ID;
                                rfv.ErrorMessage      = "*";
                                rfv.Display           = ValidatorDisplay.Dynamic;
                                rfv.ControlToValidate = textbox.ID;
                                tableCellForth.Controls.Add(rfv);
                            }
                            if (c.HasCompareValidator)
                            {
                                CompareValidator cv = new CompareValidator();
                                cv.ID                = "cv" + textbox.ID;
                                cv.ErrorMessage      = "*";
                                cv.Display           = ValidatorDisplay.Dynamic;
                                cv.ControlToValidate = textbox.ID;
                                cv.Operator          = ValidationCompareOperator.DataTypeCheck;
                                cv.Type              = Broker.DataAccess.VariableType.GetForVariableType(c.VariableTypeID);
                                tableCellForth.Controls.Add(cv);
                            }
                        }
                    }
                    counter++;
                }
            }
            pnlExtendControls.Controls.Add(table);
        }
    }
 protected void btnUpdate_Click(object sender, EventArgs e)
 {
     if (PoliciesDetailsView.SelectedValue != null)
     {
         int          policyItemID = Convert.ToInt32(PoliciesDetailsView.SelectedValue);
         PolicyItem   policyItem   = PolicyItem.Get(policyItemID);
         DropDownList ddlStatuses  = PoliciesDetailsView.FindControl("ddlStatuses") as DropDownList;
         policyItem.StatusID = Convert.ToInt32(ddlStatuses.SelectedValue);
         Policy  policy            = Policy.Get(policyItem.PolicyID);
         TextBox tbStartDate       = PoliciesDetailsView.FindControl("tbStartDate") as TextBox;
         TextBox tbEndDate         = PoliciesDetailsView.FindControl("tbEndDate") as TextBox;
         TextBox tbApplicationDate = PoliciesDetailsView.FindControl("tbApplicationDate") as TextBox;
         policy.StartDate       = Convert.ToDateTime(tbStartDate.Text);
         policy.EndDate         = Convert.ToDateTime(tbEndDate.Text);
         policy.ApplicationDate = Convert.ToDateTime(tbApplicationDate.Text);
         Policy.Table.Context.SubmitChanges();
         Panel pnlExtendControls = PoliciesDetailsView.FindControl("pnlExtendControls") as Panel;
         List <Broker.DataAccess.Control> listControls = Broker.DataAccess.Control.GetActiveByInsuranceSubType(policyItem.InsuranceSubTypeID);
         foreach (Broker.DataAccess.Control c in listControls)
         {
             PolicyExtendInformation pei = PolicyExtendInformation.GetByPolicyItemAndControl(policyItem.ID, c.ID);
             TextBox           tbControl = (TextBox)pnlExtendControls.FindControl(c.TextBoxID);
             ControlCollection cc        = pnlExtendControls.Controls;
             if (pei != null)
             {
                 pei.Value = tbControl.Text;
                 if (c.HasCompareValidator)
                 {
                     CompareValidator cv = (CompareValidator)pnlExtendControls.FindControl("cv" + c.TextBoxID);
                     if (cv.Type == ValidationDataType.Double)
                     {
                         if (tbControl.Text == string.Empty)
                         {
                             pei.Value = "0";
                         }
                     }
                 }
                 PolicyExtendInformation.Table.Context.SubmitChanges();
             }
             else
             {
                 PolicyExtendInformation newpei = new PolicyExtendInformation();
                 newpei.ControlID    = c.ID;
                 newpei.PolicyItemID = policyItem.ID;
                 newpei.Value        = tbControl.Text;
                 if (c.HasCompareValidator)
                 {
                     CompareValidator cv = (CompareValidator)pnlExtendControls.FindControl("cv" + c.TextBoxID);
                     if (cv.Type == ValidationDataType.Double)
                     {
                         if (tbControl.Text == string.Empty)
                         {
                             pei.Value = "0";
                         }
                     }
                 }
                 pei.Insert();
             }
             btnSearch.Enabled = false;
         }
     }
 }