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; } } }
protected override void CreateChildControls() { int policyID = PolicyID; List <PolicyItem> listPolicyItems = PolicyItem.Table.Where(pi => pi.PolicyID == policyID).ToList(); int n = 1; foreach (PolicyItem pItem in listPolicyItems) { Button buttonForView = new Button(); buttonForView.ID = "btnView" + n.ToString(); buttonForView.Text = pItem.InsuranceSubType.ShortDescription; buttonForView.CausesValidation = true; buttonForView.CssClass = "PacketButton"; buttonForView.Click += new EventHandler(buttonForView_Click); //pnlEverything.Controls.Add(buttonForView); pnlViewButtons.Controls.Add(buttonForView); n++; } int j = 0; foreach (PolicyItem pist in listPolicyItems) { List <Broker.DataAccess.Control> listControls = Broker.DataAccess.Control.GetByInsuranceSubType(pist.InsuranceSubTypeID).OrderBy(c => c.OrderNumber).ToList(); HtmlTable defaultTable = new HtmlTable(); defaultTable.Width = "690px"; defaultTable.Style.Add("padding-left", "4px"); HtmlTableRow firstDefaultTableRow = new HtmlTableRow(); defaultTable.Rows.Add(firstDefaultTableRow); HtmlTableCell firstCellFirstRowInDefaultTable = new HtmlTableCell(); firstCellFirstRowInDefaultTable.Width = "172px"; firstDefaultTableRow.Cells.Add(firstCellFirstRowInDefaultTable); Label lblPolicyNumber = new Label(); lblPolicyNumber.ID = "lblPolicyNumber" + (j + 1).ToString(); lblPolicyNumber.Text = "Број на полиса"; firstCellFirstRowInDefaultTable.Controls.Add(lblPolicyNumber); HtmlTableCell secondCellFirstRowInDefaultTable = new HtmlTableCell(); firstDefaultTableRow.Cells.Add(secondCellFirstRowInDefaultTable); TextBox tbPolicyNumber = new TextBox(); tbPolicyNumber.ID = "tbPolicyNumber" + (j + 1).ToString(); tbPolicyNumber.ReadOnly = true; tbPolicyNumber.Font.Bold = true; tbPolicyNumber.Text = pist.PolicyNumber; RequiredFieldValidator rfvPolicyNumber = new RequiredFieldValidator(); rfvPolicyNumber.ID = "rfvPolicyNumber" + (j + 1).ToString(); rfvPolicyNumber.ErrorMessage = "*"; rfvPolicyNumber.Display = ValidatorDisplay.Dynamic; rfvPolicyNumber.ControlToValidate = tbPolicyNumber.ID; secondCellFirstRowInDefaultTable.Controls.Add(tbPolicyNumber); secondCellFirstRowInDefaultTable.Controls.Add(rfvPolicyNumber); HtmlTableRow secondDefaultTableRow = new HtmlTableRow(); defaultTable.Rows.Add(secondDefaultTableRow); HtmlTableCell firstCellSecondRowInDefaultTable = new HtmlTableCell(); firstCellSecondRowInDefaultTable.Width = "172px"; secondDefaultTableRow.Cells.Add(firstCellSecondRowInDefaultTable); Label lblInsuranceType = new Label(); lblInsuranceType.ID = "lblInsuranceType" + (j + 1).ToString(); lblInsuranceType.Text = "Класа на осигурување"; firstCellSecondRowInDefaultTable.Controls.Add(lblInsuranceType); HtmlTableCell secondCellSecondRowInDefaultTable = new HtmlTableCell(); secondDefaultTableRow.Cells.Add(secondCellSecondRowInDefaultTable); TextBox tbInsuranceType = new TextBox(); tbInsuranceType.ID = "tbInsuranceType" + (j + 1).ToString(); tbInsuranceType.Text = pist.InsuranceSubType.InsuranceType.ShortName; tbInsuranceType.Width = 400; tbInsuranceType.ReadOnly = true; secondCellSecondRowInDefaultTable.Controls.Add(tbInsuranceType); HtmlTableRow thirdDefaultTableRow = new HtmlTableRow(); defaultTable.Rows.Add(thirdDefaultTableRow); HtmlTableCell firstCellThirdRowInDefaultTable = new HtmlTableCell(); firstCellThirdRowInDefaultTable.Width = "172px"; thirdDefaultTableRow.Cells.Add(firstCellThirdRowInDefaultTable); Label lblInsuranceSubType = new Label(); lblInsuranceSubType.ID = "lblInsuranceSubType" + (j + 1).ToString(); lblInsuranceSubType.Text = "Подкласа на осигурување"; firstCellThirdRowInDefaultTable.Controls.Add(lblInsuranceSubType); HtmlTableCell secondCellThirdRowInDefaultTable = new HtmlTableCell(); thirdDefaultTableRow.Cells.Add(secondCellThirdRowInDefaultTable); TextBox tbInsuranceSubType = new TextBox(); tbInsuranceSubType.ID = "tbInsuranceSubType" + (j + 1).ToString(); tbInsuranceSubType.Text = pist.InsuranceSubType.ShortDescription; tbInsuranceSubType.Width = 400; tbInsuranceSubType.ReadOnly = true; secondCellThirdRowInDefaultTable.Controls.Add(tbInsuranceSubType); HtmlTableRow realPolicyDefaultTableRow = new HtmlTableRow(); HtmlTableCell fifthCellFourthRowInDefaultTable = new HtmlTableCell(); fifthCellFourthRowInDefaultTable.Width = "172px"; Label lblRealPolicyValue = new Label(); lblRealPolicyValue.ID = "lblRealPolicyValue" + (j + 1).ToString(); lblRealPolicyValue.Text = "Полисирана премија"; fifthCellFourthRowInDefaultTable.Controls.Add(lblRealPolicyValue); HtmlTableCell sixthCellFourthRowInDefaultTable = new HtmlTableCell(); TextBox tbRealPolicyValue = new TextBox(); tbRealPolicyValue.ID = "tbRealPolicyValue" + (j + 1).ToString(); //tbRealPolicyValue.CssClass = "tekstPole"; tbRealPolicyValue.CssClass = "currencyClass"; tbRealPolicyValue.ReadOnly = true; tbRealPolicyValue.Text = String.Format("{0:#,0.00}", pist.RealPremiumValue); sixthCellFourthRowInDefaultTable.Controls.Add(tbRealPolicyValue); realPolicyDefaultTableRow.Cells.Add(fifthCellFourthRowInDefaultTable); realPolicyDefaultTableRow.Cells.Add(sixthCellFourthRowInDefaultTable); defaultTable.Rows.Add(realPolicyDefaultTableRow); HtmlTableRow finDiscountPolicyDefaultTableRow = new HtmlTableRow(); HtmlTableCell fifthCellfinDiscountInDefaultTable = new HtmlTableCell(); fifthCellfinDiscountInDefaultTable.Width = "172px"; Label lblFinDiscount = new Label(); lblFinDiscount.ID = "lblFinDiscount" + (j + 1).ToString(); lblFinDiscount.Text = "Финансиски попуст (%)"; fifthCellfinDiscountInDefaultTable.Controls.Add(lblFinDiscount); HtmlTableCell sixthCellfinDiscountInDefaultTable = new HtmlTableCell(); TextBox tbFinDiscountValue = new TextBox(); tbFinDiscountValue.ID = "tbFinDiscountValue" + (j + 1).ToString(); tbFinDiscountValue.CssClass = "currencyClass"; tbFinDiscountValue.ReadOnly = true; decimal finDiscountValue = 0; if (pist.RealPremiumValue > 0) { finDiscountValue = RateController.Scale5((1 - pist.PremiumValue / pist.RealPremiumValue) * 100); } tbFinDiscountValue.Text = String.Format("{0:#,0.00}", finDiscountValue); sixthCellfinDiscountInDefaultTable.Controls.Add(tbFinDiscountValue); finDiscountPolicyDefaultTableRow.Cells.Add(fifthCellfinDiscountInDefaultTable); finDiscountPolicyDefaultTableRow.Cells.Add(sixthCellfinDiscountInDefaultTable); defaultTable.Rows.Add(finDiscountPolicyDefaultTableRow); TextBox tbPolicyValue = new TextBox(); tbPolicyValue.ID = "tbPolicyValue" + (j + 1).ToString(); tbPolicyValue.CssClass = "currencyClass"; tbPolicyValue.Text = String.Format("{0:#,0.00}", pist.PremiumValue); tbPolicyValue.ReadOnly = true; HtmlTableRow fourthDefaultTableRow = new HtmlTableRow(); fourthDefaultTableRow.BgColor = "#FAFAF8"; defaultTable.Rows.Add(fourthDefaultTableRow); HtmlTableCell firstCellFourthRowInDefaultTable = new HtmlTableCell(); firstCellFourthRowInDefaultTable.Width = "172px"; fourthDefaultTableRow.Cells.Add(firstCellFourthRowInDefaultTable); Label lblPolicyValue = new Label(); lblPolicyValue.ID = "lblPolicyValue" + (j + 1).ToString(); lblPolicyValue.Text = "Премија за наплата"; firstCellFourthRowInDefaultTable.Controls.Add(lblPolicyValue); HtmlTableCell secondCellFourthRowInDefaultTable = new HtmlTableCell(); fourthDefaultTableRow.Cells.Add(secondCellFourthRowInDefaultTable); secondCellFourthRowInDefaultTable.Controls.Add(tbPolicyValue); HtmlTableRow paidValuePolicyDefaultTableRow = new HtmlTableRow(); HtmlTableCell fifthCellpaidValueInDefaultTable = new HtmlTableCell(); Label lblPaidValue = new Label(); lblPaidValue.ID = "lblPaidValue" + (j + 1).ToString(); lblPaidValue.Text = "Уплатено"; fifthCellpaidValueInDefaultTable.Width = "172px"; fifthCellpaidValueInDefaultTable.Controls.Add(lblPaidValue); HtmlTableCell sixthCellpaidValueInDefaultTable = new HtmlTableCell(); TextBox tbPaidValue = new TextBox(); tbPaidValue.ID = "tbPaidValue" + (j + 1).ToString(); tbPaidValue.CssClass = "currencyClass"; tbPaidValue.ReadOnly = true; decimal paidValue = 0; List <Payment> lst = Payment.GetByPolicyItemID(pist.ID); foreach (Payment payment in lst) { paidValue += payment.Value; } tbPaidValue.Text = String.Format("{0:#,0.00}", paidValue); sixthCellpaidValueInDefaultTable.Controls.Add(tbPaidValue); paidValuePolicyDefaultTableRow.Cells.Add(fifthCellpaidValueInDefaultTable); paidValuePolicyDefaultTableRow.Cells.Add(sixthCellpaidValueInDefaultTable); defaultTable.Rows.Add(paidValuePolicyDefaultTableRow); HtmlTableRow toPaidValuePolicyDefaultTableRow = new HtmlTableRow(); HtmlTableCell fifthCelltoPaidValueInDefaultTable = new HtmlTableCell(); Label lblToPaidValue = new Label(); lblToPaidValue.ID = "lblToPaidValue" + (j + 1).ToString(); lblToPaidValue.Text = "Должна премија"; fifthCelltoPaidValueInDefaultTable.Width = "172px"; fifthCelltoPaidValueInDefaultTable.Controls.Add(lblToPaidValue); HtmlTableCell sixthCelltoPaidValueInDefaultTable = new HtmlTableCell(); TextBox tbToPaidValue = new TextBox(); tbToPaidValue.ID = "tbToPaidValue" + (j + 1).ToString(); tbToPaidValue.CssClass = "currencyClass"; tbToPaidValue.ReadOnly = true; tbToPaidValue.Text = String.Format("{0:#,0.00}", (pist.PremiumValue - paidValue)); sixthCelltoPaidValueInDefaultTable.Controls.Add(tbToPaidValue); toPaidValuePolicyDefaultTableRow.Cells.Add(fifthCelltoPaidValueInDefaultTable); toPaidValuePolicyDefaultTableRow.Cells.Add(sixthCelltoPaidValueInDefaultTable); defaultTable.Rows.Add(toPaidValuePolicyDefaultTableRow); HtmlTableRow seventhDefaultTableRow = new HtmlTableRow(); defaultTable.Rows.Add(seventhDefaultTableRow); HtmlTableCell firstCellSeventhRowInDefaultTable = new HtmlTableCell(); seventhDefaultTableRow.Cells.Add(firstCellSeventhRowInDefaultTable); Label lblStatus = new Label(); lblStatus.ID = "lblStatus" + (j + 1).ToString(); lblStatus.Text = "Статус"; firstCellSeventhRowInDefaultTable.Width = "172px"; firstCellSeventhRowInDefaultTable.Controls.Add(lblStatus); HtmlTableCell secondCellSeventhRowInDefaultTable = new HtmlTableCell(); seventhDefaultTableRow.Cells.Add(secondCellSeventhRowInDefaultTable); TextBox tbStatus = new TextBox(); tbStatus.ID = "tbStatus" + (j + 1).ToString(); tbStatus.ReadOnly = true; tbStatus.Text = pist.Statuse.Description; secondCellSeventhRowInDefaultTable.Controls.Add(tbStatus); mvPolicyItem.Views[j].Controls.Clear(); mvPolicyItem.Views[j].Controls.Add(defaultTable); HtmlTable table = new HtmlTable(); table.Width = "690px"; table.Style.Add("padding-left", "4px"); int counter = 0; foreach (Broker.DataAccess.Control c in listControls) { if (c.IsActive) { if (c.ColumnNumber == 1) { HtmlTableRow tableRow = new HtmlTableRow(); table.Rows.Add(tableRow); HtmlTableCell tableCell = new HtmlTableCell(); tableCell.Width = "172px"; tableRow.Cells.Add(tableCell); Label label = new Label(); label.ID = c.LabelID + j.ToString(); label.Text = c.LabelName; tableCell.Controls.Add(label); HtmlTableCell tableCellSecond = new HtmlTableCell(); tableRow.Cells.Add(tableCellSecond); if (c.FieldType.Name == FieldType.CHECKBOX) { CheckBox checkBox = new CheckBox(); checkBox.ID = c.TextBoxID + j.ToString(); PolicyExtendInformation pei = PolicyExtendInformation.GetByPolicyItemAndControl(pist.ID, c.ID); if (pei != null) { if (pei.Value != null) { try { checkBox.Checked = Boolean.Parse(pei.Value); checkBox.Enabled = false; tableCellSecond.Controls.Add(checkBox); } catch { continue; } } } } else { TextBox textbox = new TextBox(); textbox.ID = c.TextBoxID + j.ToString(); textbox.ReadOnly = true; PolicyExtendInformation pei = PolicyExtendInformation.GetByPolicyItemAndControl(pist.ID, c.ID); if (pei != null) { textbox.Text = pei.Value; if (pei.Value != string.Empty) { ValidationDataType vdt = Broker.DataAccess.VariableType.GetForVariableType(c.VariableTypeID); if (vdt == ValidationDataType.Double) { textbox.CssClass = "currencyClass"; textbox.Text = String.Format("{0:#,0.00}", pei.Value); } } } tableCellSecond.Controls.Add(textbox); } } else if (c.ColumnNumber == 2) { HtmlTableRow tableRow = table.Rows[counter / 2]; if ((counter % 4 == 0) || (counter % 4 == 1)) { tableRow.BgColor = "#FAFAF8"; } HtmlTableCell tableCellThird = new HtmlTableCell(); tableCellThird.Width = "172px"; tableRow.Cells.Add(tableCellThird); Label label = new Label(); label.ID = c.LabelID + j.ToString(); label.Text = c.LabelName; tableCellThird.Controls.Add(label); HtmlTableCell tableCellForth = new HtmlTableCell(); tableCellForth.Width = "172px"; tableRow.Cells.Add(tableCellForth); if (c.FieldType.Name == FieldType.CHECKBOX) { CheckBox checkBox = new CheckBox(); checkBox.ID = c.TextBoxID + j.ToString(); PolicyExtendInformation pei = PolicyExtendInformation.GetByPolicyItemAndControl(pist.ID, c.ID); if (pei != null) { if (pei.Value != null) { try { checkBox.Checked = Boolean.Parse(pei.Value); checkBox.Enabled = false; tableCellForth.Controls.Add(checkBox); } catch { continue; } } } } else { TextBox textbox = new TextBox(); textbox.ID = c.TextBoxID + j.ToString(); textbox.ReadOnly = true; PolicyExtendInformation pei = PolicyExtendInformation.GetByPolicyItemAndControl(pist.ID, c.ID); if (pei != null) { textbox.Text = pei.Value; if (pei.Value != string.Empty) { ValidationDataType vdt = Broker.DataAccess.VariableType.GetForVariableType(c.VariableTypeID); if (vdt == ValidationDataType.Double) { textbox.CssClass = "currencyClass"; textbox.Text = String.Format("{0:#,0.00}", pei.Value); } } } tableCellForth.Controls.Add(textbox); } } } counter++; } mvPolicyItem.Views[j].Controls.Add(table); j++; } base.CreateChildControls(); }
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 btnInsert_Click(object sender, EventArgs e) { DateTime inputDate = Convert.ToDateTime(tbDateOfPayment.Text); int insuranceCompanyID = int.Parse(ddlInsuranceCompany.SelectedValue); PolicyItem pi; if (ddlInsuranceSubTypes.Items.Count > 0) { pi = PolicyItem.GetByNumberAndInsuranceSubType(tbPolicyNumber.Text, Convert.ToInt32(ddlInsuranceSubTypes.SelectedValue), insuranceCompanyID); } else { pi = PolicyItem.GetByNumber(tbPolicyNumber.Text, insuranceCompanyID); } if (inputDate.Date > DateTime.Today) { lblFeedback.Text = "Не е можно внесување на датуми поголеми од денешниот"; } else { List <Payment> listPayments = Payment.GetByPolicyItemID(pi.ID); decimal paymentTotalValue = 0; foreach (Payment payment in listPayments) { paymentTotalValue += payment.Value; } if (Convert.ToDecimal(tbValueOfPayment.Text) > (pi.PremiumValue - paymentTotalValue)) { lblFeedback.Text = "Поголем износ од преостанатиот износ за плаќање"; } else { decimal valueFromClient = Convert.ToDecimal(tbValueOfPayment.Text); while (valueFromClient > 0) { Rate currentRate = Rate.GetCurrentRateForPayment(pi.ID); Payment newPayment = new Payment(); newPayment.Date = Convert.ToDateTime(tbDateOfPayment.Text); newPayment.RateID = currentRate.ID; newPayment.IsCashReported = false; Broker.DataAccess.PaymentType pt = Broker.DataAccess.PaymentType.Get(Convert.ToInt32(ddlPaymentTypes.SelectedValue)); newPayment.PaymentTypeID = pt.ID; if (pt.Code == Broker.DataAccess.PaymentType.CREDITCARD) { newPayment.BankCreditCardID = BankCreditCard.GetByBankAndCard(Convert.ToInt32(ddlBank.SelectedValue), Convert.ToInt32(ddlCardTypes.SelectedValue)).ID; } newPayment.UserID = this.PageUser.ID; newPayment.BranchID = this.PageUser.BranchID; if (tbBankslipNumber.Text.Trim() != string.Empty) { newPayment.BankslipNumber = tbBankslipNumber.Text; newPayment.BankslipBankID = Convert.ToInt32(ddlBankslipBanks.SelectedValue); } if (valueFromClient >= currentRate.Value) { newPayment.Value = currentRate.Value - Payment.GetPaidValueForRate(currentRate.ID); newPayment.Insert(); decimal basicValue = newPayment.Value; decimal k = basicValue / newPayment.Rate.PolicyItem.PremiumValue; List <ControlAppropriateInsuranceSubType> listAppropriateIST = Broker.DataAccess.ControlAppropriateInsuranceSubType.Table.ToList(); foreach (ControlAppropriateInsuranceSubType c in listAppropriateIST) { PolicyExtendInformation pei = PolicyExtendInformation.GetByPolicyItemAndControl(pi.ID, c.ControlID); if (pei != null) { decimal peiValue = 0; decimal.TryParse(pei.Value, out peiValue); basicValue -= k * peiValue; if (peiValue > 0) { PaymentsPerInsSubType ppist = new PaymentsPerInsSubType(); ppist.PaymentID = newPayment.ID; ppist.InsuranceSubTypeID = c.InsuranceSubTypeID; ppist.PaidValue = k * peiValue; ppist.BrokerageValue = ppist.PaidValue * pi.BrokeragePercentage / 100; ppist.Insert(); } } } if (basicValue > 0) { PaymentsPerInsSubType ppist = new PaymentsPerInsSubType(); ppist.PaymentID = newPayment.ID; ppist.InsuranceSubTypeID = pi.InsuranceSubTypeID; ppist.PaidValue = basicValue; ppist.BrokerageValue = ppist.PaidValue * pi.BrokeragePercentage / 100; ppist.Insert(); } valueFromClient -= newPayment.Value; currentRate.PaidValue += newPayment.Value; Rate.Table.Context.SubmitChanges(); } else { if (valueFromClient <= (currentRate.Value - currentRate.PaidValue)) { newPayment.Value = valueFromClient; newPayment.Insert(); decimal basicValue = newPayment.Value; decimal k = basicValue / newPayment.Rate.PolicyItem.PremiumValue; List <ControlAppropriateInsuranceSubType> listAppropriateIST = Broker.DataAccess.ControlAppropriateInsuranceSubType.Table.ToList(); foreach (ControlAppropriateInsuranceSubType c in listAppropriateIST) { PolicyExtendInformation pei = PolicyExtendInformation.GetByPolicyItemAndControl(pi.ID, c.ControlID); if (pei != null) { decimal peiValue = 0; decimal.TryParse(pei.Value, out peiValue); basicValue -= k * peiValue; if (peiValue > 0) { PaymentsPerInsSubType ppist = new PaymentsPerInsSubType(); ppist.PaymentID = newPayment.ID; ppist.InsuranceSubTypeID = c.InsuranceSubTypeID; ppist.PaidValue = k * peiValue; ppist.BrokerageValue = ppist.PaidValue * pi.BrokeragePercentage / 100; ppist.Insert(); } } } if (basicValue > 0) { PaymentsPerInsSubType ppist = new PaymentsPerInsSubType(); ppist.PaymentID = newPayment.ID; ppist.InsuranceSubTypeID = pi.InsuranceSubTypeID; ppist.PaidValue = basicValue; ppist.BrokerageValue = ppist.PaidValue * pi.BrokeragePercentage / 100; ppist.Insert(); } currentRate.PaidValue += valueFromClient; Rate.Table.Context.SubmitChanges(); break; } else { newPayment.Value = (currentRate.Value - currentRate.PaidValue); newPayment.Insert(); decimal basicValue = newPayment.Value; decimal k = basicValue / newPayment.Rate.PolicyItem.PremiumValue; List <ControlAppropriateInsuranceSubType> listAppropriateIST = Broker.DataAccess.ControlAppropriateInsuranceSubType.Table.ToList(); foreach (ControlAppropriateInsuranceSubType c in listAppropriateIST) { PolicyExtendInformation pei = PolicyExtendInformation.GetByPolicyItemAndControl(pi.ID, c.ControlID); if (pei != null) { decimal peiValue = 0; decimal.TryParse(pei.Value, out peiValue); basicValue -= k * peiValue; if (peiValue > 0) { PaymentsPerInsSubType ppist = new PaymentsPerInsSubType(); ppist.PaymentID = newPayment.ID; ppist.InsuranceSubTypeID = c.InsuranceSubTypeID; ppist.PaidValue = k * peiValue; ppist.BrokerageValue = ppist.PaidValue * pi.BrokeragePercentage / 100; ppist.Insert(); } } } if (basicValue > 0) { PaymentsPerInsSubType ppist = new PaymentsPerInsSubType(); ppist.PaymentID = newPayment.ID; ppist.InsuranceSubTypeID = pi.InsuranceSubTypeID; ppist.PaidValue = basicValue; ppist.BrokerageValue = ppist.PaidValue * pi.BrokeragePercentage / 100; ppist.Insert(); } //currentRate.PaidValue += valueFromClient; //Rate.Table.Context.SubmitChanges(); currentRate.PaidValue += newPayment.Value; Rate.Table.Context.SubmitChanges(); valueFromClient -= newPayment.Value; } } } Broker.DataAccess.Facture.UpdatePaidStatusForFacture(pi.ID); } } GridViewPayments.DataSource = null; GridViewPayments.DataSourceID = odsPaidPayments.ID; odsPaidPayments.SelectParameters.Clear(); odsPaidPayments.SelectParameters.Add("policyItemID", pi.ID.ToString()); GridViewPayments.DataBind(); GridViewRates.DataSource = null; GridViewRates.DataSourceID = odsRates.ID; odsRates.SelectParameters.Clear(); odsRates.TypeName = "Broker.DataAccess.Rate"; odsRates.DataObjectTypeName = "Broker.DataAccess.Rate"; odsRates.SelectMethod = "GetByPolicyNumberAndInsuranceSubTypeIDAndInsuranceCompanyID"; odsRates.SelectParameters.Add("policyNumber", tbPolicyNumber.Text); odsRates.SelectParameters.Add("insuranceSubTypeID", pi.InsuranceSubType.ID.ToString()); odsRates.SelectParameters.Add("insuranceCompanyID", ddlInsuranceCompany.SelectedValue); //odsRates.SelectMethod = "Broker.DataAccess.PolicyItem.GetByNumberAndInsuranceSubType"; GridViewRates.DataBind(); UpdateTextBoxes(pi); }
protected void btnInsert_Click(object sender, EventArgs e) { string factureNumber = tbFactureNumber.Text; DateTime paidDate = DateTime.Now; DateTime.TryParse(tbDateOfPayment.Text, out paidDate); try { Broker.DataAccess.Facture f = Broker.DataAccess.Facture.GetByNumber(factureNumber); if (f != null) { foreach (GridViewRow gvRow in GridViewPayments.Rows) { decimal newTotValue = 0; TextBox tbPaidValue = (TextBox)gvRow.FindControl("tbValue"); TextBox tbFactureItemID = (TextBox)gvRow.FindControl("tbFactureItemID"); decimal.TryParse(tbPaidValue.Text, out newTotValue); int factureItemID = 0; int.TryParse(tbFactureItemID.Text, out factureItemID); if (factureItemID > 0) { if (newTotValue < FactureCollectedPaidValue.GetPaidValueForFactureItem(factureItemID)) { RegisterStartupScript("myAlert", "<script>alert('ВНЕСОВТЕ ПОМАЛ ИЗНОС ОД ТОА ШТО Е ПЛАТЕНО ДО СЕГА!')</script>"); return; } if (newTotValue > FactureItem.Get(factureItemID).BrokerageValue) { RegisterStartupScript("myAlert", "<script>alert('ВНЕСОВТЕ ПОГОЛЕМ ИЗНОС ОД ПРЕСМЕТАНАТА БРОКЕРАЖА!')</script>"); return; } if (FactureCollectedPaidValue.GetPaidValueForFactureItem(factureItemID) != FactureItem.Get(factureItemID).BrokerageValue) { FactureCollectedPaidValue fcpv = new FactureCollectedPaidValue(); fcpv.FactureItemID = factureItemID; fcpv.PaidDate = paidDate; fcpv.PaidValue = newTotValue - FactureCollectedPaidValue.GetPaidValueForFactureItem(factureItemID); fcpv.Insert(); FactureItem fi = FactureItem.Get(factureItemID); List <PolicyItemFactureItem> lstPIFI = PolicyItemFactureItem.GetByFactureItemID(factureItemID); decimal koef = fcpv.PaidValue / fi.BrokerageValue; List <InsuranceSubType> listAppropriateIST = Broker.DataAccess.ControlAppropriateInsuranceSubType.Table.Select(c => c.InsuranceSubType).ToList(); Dictionary <InsuranceSubType, decimal> dic = new Dictionary <InsuranceSubType, decimal>(); decimal totValue = 0; foreach (PolicyItem pi in lstPIFI.Select(c => c.PolicyItem).Where(c => c.Policy.Discard == false).ToList()) { decimal brokPercentage = 0; if (pi.BrokerageID != null) { if (pi.Policy.Client.IsLaw) { brokPercentage = pi.Brokerage.PercentageForLaws; } else { brokPercentage = pi.Brokerage.PercentageForPrivates; } } else if (pi.PacketBrokerageID != null) { if (pi.Policy.Client.IsLaw) { brokPercentage = pi.PacketsInsuranceSubType.BrokeragePecentageForLaws; } else { brokPercentage = pi.PacketsInsuranceSubType.BrokeragePecentageForPrivates; } } foreach (InsuranceSubType ist in listAppropriateIST) { List <Broker.DataAccess.Control> listControls = ControlAppropriateInsuranceSubType.GetByInsuranceSubType(ist.ID); decimal tmpValue = 0; foreach (Broker.DataAccess.Control con in listControls) { PolicyExtendInformation pei = PolicyExtendInformation.GetByPolicyItemAndControl(pi.ID, con.ID); if (pei != null) { tmpValue += Convert.ToDecimal(pei.Value); } } if (dic.Keys.Contains(ist)) { dic[ist] += (tmpValue * brokPercentage / 100); } else { dic.Add(ist, (tmpValue * brokPercentage / 100)); } } //totValue += RateController.Scale5(pi.PremiumValue * brokPercentage / 100); totValue += pi.PremiumValue * brokPercentage / 100; } totValue = RateController.Scale5(totValue); decimal addValue = 0; foreach (KeyValuePair <InsuranceSubType, decimal> kvp in dic) { if (kvp.Value > 0) { addValue += kvp.Value; FacCollPaidValuesPerInsSubType fcp = new FacCollPaidValuesPerInsSubType(); fcp.FactureCollectedPaidValueID = fcpv.ID; fcp.InsuranceSubTypeID = kvp.Key.ID; fcp.PaidValue = RateController.Scale5(fcpv.PaidValue * kvp.Value / totValue); fcp.Insert(); } } decimal baseValue = fi.BrokerageValue - addValue; FacCollPaidValuesPerInsSubType fcpBase = new FacCollPaidValuesPerInsSubType(); fcpBase.FactureCollectedPaidValueID = fcpv.ID; fcpBase.InsuranceSubTypeID = fi.InsuranceSubTypeID; fcpBase.PaidValue = RateController.Scale5(fcpv.PaidValue * baseValue / totValue); fcpBase.Insert(); } } } } else { lblFeedback.Text = "Не е пронајдена фактура!"; } } catch (Exception ex) { lblFeedback.Text = "Грешка!"; } }
void InsertPaymentsForPolicy(PolicyItem pi, decimal newPaidValue, DateTime dateOfNewPaid, string bankslipNumber, int bankslipBankID) { List <Payment> listPayments = Payment.GetByPolicyItemID(pi.ID); decimal paymentTotalValue = 0; foreach (Payment payment in listPayments) { paymentTotalValue += payment.Value; } if (newPaidValue > (pi.PremiumValue - paymentTotalValue)) { RegisterStartupScript("myAlert", "<script>alert('Поголем износ од преостанатиот износ за плаќање!')</script>"); } else { decimal valueFromClient = newPaidValue; while (valueFromClient > 0) { Rate currentRate = Rate.GetCurrentRateForPayment(pi.ID); Payment newPayment = new Payment(); newPayment.Date = dateOfNewPaid; newPayment.RateID = currentRate.ID; newPayment.IsCashReported = false; Broker.DataAccess.PaymentType pt = Broker.DataAccess.PaymentType.GetByCode(Broker.DataAccess.PaymentType.VIRMAN); newPayment.PaymentTypeID = pt.ID; newPayment.UserID = this.PageUser.ID; newPayment.BranchID = this.PageUser.BranchID; newPayment.BankslipNumber = bankslipNumber; newPayment.BankslipBankID = bankslipBankID; if (valueFromClient >= currentRate.Value) { newPayment.Value = currentRate.Value - Payment.GetPaidValueForRate(currentRate.ID); newPayment.Insert(); decimal basicValue = newPayment.Value; decimal k = basicValue / newPayment.Rate.PolicyItem.PremiumValue; List <ControlAppropriateInsuranceSubType> listAppropriateIST = Broker.DataAccess.ControlAppropriateInsuranceSubType.Table.ToList(); foreach (ControlAppropriateInsuranceSubType c in listAppropriateIST) { PolicyExtendInformation pei = PolicyExtendInformation.GetByPolicyItemAndControl(pi.ID, c.ControlID); if (pei != null) { decimal peiValue = 0; decimal.TryParse(pei.Value, out peiValue); basicValue -= k * peiValue; if (peiValue > 0) { PaymentsPerInsSubType ppist = new PaymentsPerInsSubType(); ppist.PaymentID = newPayment.ID; ppist.InsuranceSubTypeID = c.InsuranceSubTypeID; ppist.PaidValue = k * peiValue; ppist.BrokerageValue = ppist.PaidValue * pi.BrokeragePercentage / 100; ppist.Insert(); } } } if (basicValue > 0) { PaymentsPerInsSubType ppist = new PaymentsPerInsSubType(); ppist.PaymentID = newPayment.ID; ppist.InsuranceSubTypeID = pi.InsuranceSubTypeID; ppist.PaidValue = basicValue; ppist.BrokerageValue = ppist.PaidValue * pi.BrokeragePercentage / 100; ppist.Insert(); } valueFromClient -= newPayment.Value; currentRate.PaidValue += newPayment.Value; Rate.Table.Context.SubmitChanges(); } else { if (valueFromClient <= (currentRate.Value - currentRate.PaidValue)) { newPayment.Value = valueFromClient; newPayment.Insert(); decimal basicValue = newPayment.Value; decimal k = basicValue / newPayment.Rate.PolicyItem.PremiumValue; List <ControlAppropriateInsuranceSubType> listAppropriateIST = Broker.DataAccess.ControlAppropriateInsuranceSubType.Table.ToList(); foreach (ControlAppropriateInsuranceSubType c in listAppropriateIST) { PolicyExtendInformation pei = PolicyExtendInformation.GetByPolicyItemAndControl(pi.ID, c.ControlID); if (pei != null) { decimal peiValue = 0; decimal.TryParse(pei.Value, out peiValue); basicValue -= k * peiValue; if (peiValue > 0) { PaymentsPerInsSubType ppist = new PaymentsPerInsSubType(); ppist.PaymentID = newPayment.ID; ppist.InsuranceSubTypeID = c.InsuranceSubTypeID; ppist.PaidValue = k * peiValue; ppist.BrokerageValue = ppist.PaidValue * pi.BrokeragePercentage / 100; ppist.Insert(); } } } if (basicValue > 0) { PaymentsPerInsSubType ppist = new PaymentsPerInsSubType(); ppist.PaymentID = newPayment.ID; ppist.InsuranceSubTypeID = pi.InsuranceSubTypeID; ppist.PaidValue = basicValue; ppist.BrokerageValue = ppist.PaidValue * pi.BrokeragePercentage / 100; ppist.Insert(); } currentRate.PaidValue += valueFromClient; Rate.Table.Context.SubmitChanges(); break; } else { newPayment.Value = (currentRate.Value - currentRate.PaidValue); newPayment.Insert(); decimal basicValue = newPayment.Value; decimal k = basicValue / newPayment.Rate.PolicyItem.PremiumValue; List <ControlAppropriateInsuranceSubType> listAppropriateIST = Broker.DataAccess.ControlAppropriateInsuranceSubType.Table.ToList(); foreach (ControlAppropriateInsuranceSubType c in listAppropriateIST) { PolicyExtendInformation pei = PolicyExtendInformation.GetByPolicyItemAndControl(pi.ID, c.ControlID); if (pei != null) { decimal peiValue = 0; decimal.TryParse(pei.Value, out peiValue); basicValue -= k * peiValue; if (peiValue > 0) { PaymentsPerInsSubType ppist = new PaymentsPerInsSubType(); ppist.PaymentID = newPayment.ID; ppist.InsuranceSubTypeID = c.InsuranceSubTypeID; ppist.PaidValue = k * peiValue; ppist.BrokerageValue = ppist.PaidValue * pi.BrokeragePercentage / 100; ppist.Insert(); } } } if (basicValue > 0) { PaymentsPerInsSubType ppist = new PaymentsPerInsSubType(); ppist.PaymentID = newPayment.ID; ppist.InsuranceSubTypeID = pi.InsuranceSubTypeID; ppist.PaidValue = basicValue; ppist.BrokerageValue = ppist.PaidValue * pi.BrokeragePercentage / 100; ppist.Insert(); } //currentRate.PaidValue += valueFromClient; //Rate.Table.Context.SubmitChanges(); currentRate.PaidValue += newPayment.Value; Rate.Table.Context.SubmitChanges(); valueFromClient -= newPayment.Value; } } } Broker.DataAccess.Facture.UpdatePaidStatusForFacture(pi.ID); } }
public static void PrintSkadencar(DateTime fromDate, DateTime toDate, List <int> lstBranches, List <int> lstInsuranceCompanies, List <int> lstInsuranceSubTypes) { DataClassesDataContext dcdc = new DataClassesDataContext(); DateTime dt1 = fromDate; DateTime dt2 = toDate; int d1 = dt1.Day; int m1 = dt1.Month; int y1 = dt1.Year; int d2 = dt2.Day; int m2 = dt2.Month; int y2 = dt2.Year; PDFCreators pdf = new PDFCreators(false, 10, 10, 10, 10); pdf.OpenPDF(); pdf.SetTitle("Скаденцар"); pdf.SetTitle("Истек на полиса од " + fromDate.ToShortDateString() + " до " + toDate.ToShortDateString()); pdf.SetTitleLeft10("Датум и време на печатење: " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString()); string query = @"select p.id, pi.id as policyItemID, pi.policynumber, p.applicationdate, ist.shortdescription as insurancesubtypename, ic.shortname as insurancecompanyname, c.name as clientname, o.name as ownername, it.shortname as insurancetypename, p.startdate, p.enddate, ist.id as insuranceSubTypeID from policies p inner join policyitems pi on pi.policyid = p.id inner join clients c on p.clientid = c.id inner join clients o on p.ownerid = o.id inner join insurancecompanies ic on p.insurancecompanyid=ic.id inner join insurancesubtypes ist on pi.insurancesubtypeid=ist.id inner join insurancetypes it on ist.insurancetypeid=it.id where p.branchid in (" + ReportFinPolicies.GetFromIDs(lstBranches) + ") " + @" and p.insurancecompanyid in (" + ReportFinPolicies.GetFromIDs(lstInsuranceCompanies) + ") " + @" and pi.insurancesubtypeid in (" + ReportFinPolicies.GetFromIDs(lstInsuranceSubTypes) + ") " + @" and p.enddate>='" + y1 + - +m1 + - +d1 + "'" + @" and p.enddate<='" + y2 + - +m2 + - +d2 + "'" + @" and p.discard = 0 " + @" order by p.enddate"; //@" --query so marketing agent"; List <SummaryForSkadencar> lst = dcdc.ExecuteQuery <SummaryForSkadencar>(query).ToList(); int counter = 1; foreach (SummaryForSkadencar ss in lst) { string[] headers = new string[5]; headers[0] = "Р.бр.: " + counter.ToString(); headers[1] = "Полиса: " + ss.policynumber; headers[2] = "Класа: " + ss.insurancetypename; headers[3] = "Подкласа: " + ss.insurancesubtypename; headers[4] = "О.компанија: " + ss.insurancecompanyname; TypeCode[] codes = new TypeCode[headers.Length]; codes[0] = TypeCode.String; codes[1] = TypeCode.String; codes[2] = TypeCode.String; codes[3] = TypeCode.String; codes[4] = TypeCode.String; float[] policyColumnsWidths = new float[headers.Length]; policyColumnsWidths[0] = 16; policyColumnsWidths[1] = 20; policyColumnsWidths[2] = 24; policyColumnsWidths[3] = 24; policyColumnsWidths[4] = 16; pdf.CreateTableForSkadencar(headers.Count(), false, headers, "", policyColumnsWidths); object[] vals = new object[headers.Count()]; vals[0] = "Издадена на: " + ss.applicationdate.ToShortDateString(); vals[1] = "Скаденца: " + ss.startdate.ToShortDateString() + " - " + ss.enddate.ToShortDateString(); vals[2] = "Договорувач: " + ss.clientname; vals[3] = "Осигуреник: " + ss.ownername; string regNumber = ""; Broker.DataAccess.Control con = Broker.DataAccess.Control.GetByInsuranceSubTypeAndTexbBoxID(ss.insuranceSubTypeID, Broker.DataAccess.Control.REGISTRATION_NUMBER); if (con != null) { PolicyExtendInformation regNumberPEI = PolicyExtendInformation.GetByPolicyItemAndControl(ss.policyItemID, con.ID); if (regNumberPEI != null) { regNumber = regNumberPEI.Value; } } vals[4] = "Регистрација: " + regNumber; pdf.AddDataRowWithBorder(vals, headers.Count(), codes); pdf.AddTable(); counter++; } pdf.FinishPDF_FileName("Skadencar"); }