Загрузка данных
#pragma once
namespace OSAGO_Calculator {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Globalization;
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
}
protected:
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Label^ labelTitle;
private: System::Windows::Forms::Label^ labelBaseRate;
private: System::Windows::Forms::TextBox^ textBoxBaseRate;
private: System::Windows::Forms::Label^ labelTerritory;
private: System::Windows::Forms::ComboBox^ comboBoxTerritory;
private: System::Windows::Forms::Label^ labelClass;
private: System::Windows::Forms::TextBox^ textBoxClass;
private: System::Windows::Forms::Label^ labelAccidents;
private: System::Windows::Forms::TextBox^ textBoxAccidents;
private: System::Windows::Forms::Label^ labelAgeExperience;
private: System::Windows::Forms::ComboBox^ comboBoxAgeExperience;
private: System::Windows::Forms::CheckBox^ checkBoxLimitedDrivers;
private: System::Windows::Forms::Label^ labelPower;
private: System::Windows::Forms::ComboBox^ comboBoxPower;
private: System::Windows::Forms::Label^ labelPeriod;
private: System::Windows::Forms::ComboBox^ comboBoxPeriod;
private: System::Windows::Forms::Button^ buttonOK;
private: System::Windows::Forms::Button^ buttonCancel;
private: System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
this->labelTitle = (gcnew System::Windows::Forms::Label());
this->labelBaseRate = (gcnew System::Windows::Forms::Label());
this->textBoxBaseRate = (gcnew System::Windows::Forms::TextBox());
this->labelTerritory = (gcnew System::Windows::Forms::Label());
this->comboBoxTerritory = (gcnew System::Windows::Forms::ComboBox());
this->labelClass = (gcnew System::Windows::Forms::Label());
this->textBoxClass = (gcnew System::Windows::Forms::TextBox());
this->labelAccidents = (gcnew System::Windows::Forms::Label());
this->textBoxAccidents = (gcnew System::Windows::Forms::TextBox());
this->labelAgeExperience = (gcnew System::Windows::Forms::Label());
this->comboBoxAgeExperience = (gcnew System::Windows::Forms::ComboBox());
this->checkBoxLimitedDrivers = (gcnew System::Windows::Forms::CheckBox());
this->labelPower = (gcnew System::Windows::Forms::Label());
this->comboBoxPower = (gcnew System::Windows::Forms::ComboBox());
this->labelPeriod = (gcnew System::Windows::Forms::Label());
this->comboBoxPeriod = (gcnew System::Windows::Forms::ComboBox());
this->buttonOK = (gcnew System::Windows::Forms::Button());
this->buttonCancel = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// labelTitle
//
this->labelTitle->AutoSize = true;
this->labelTitle->Location = System::Drawing::Point(20, 20);
this->labelTitle->Name = L"labelTitle";
this->labelTitle->Size = System::Drawing::Size(550, 65);
this->labelTitle->TabIndex = 0;
this->labelTitle->Text = L"Расчет тарифа по обязательному страхованию гражданской\r\nответственности владельца транспортного средства\r\n(физического лица владельца легкового автомобиля)";
//
// labelBaseRate
//
this->labelBaseRate->AutoSize = true;
this->labelBaseRate->Location = System::Drawing::Point(20, 110);
this->labelBaseRate->Name = L"labelBaseRate";
this->labelBaseRate->Size = System::Drawing::Size(280, 13);
this->labelBaseRate->TabIndex = 1;
this->labelBaseRate->Text = L"Базовая ставка страхового тарифа (руб.):";
//
// textBoxBaseRate
//
this->textBoxBaseRate->Location = System::Drawing::Point(320, 107);
this->textBoxBaseRate->Name = L"textBoxBaseRate";
this->textBoxBaseRate->Size = System::Drawing::Size(100, 20);
this->textBoxBaseRate->TabIndex = 2;
this->textBoxBaseRate->Text = L"1980";
//
// labelTerritory
//
this->labelTerritory->AutoSize = true;
this->labelTerritory->Location = System::Drawing::Point(20, 145);
this->labelTerritory->Name = L"labelTerritory";
this->labelTerritory->Size = System::Drawing::Size(290, 13);
this->labelTerritory->TabIndex = 3;
this->labelTerritory->Text = L"Территория преимущественного использования:";
//
// comboBoxTerritory
//
this->comboBoxTerritory->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList;
this->comboBoxTerritory->FormattingEnabled = true;
this->comboBoxTerritory->Items->AddRange(gcnew cli::array< System::Object^ >(5) {
L"Москва", L"Санкт-Петербург", L"Другие города с населением > 1 млн",
L"Другие города с населением < 1 млн", L"Сельская местность"
});
this->comboBoxTerritory->Location = System::Drawing::Point(320, 142);
this->comboBoxTerritory->Name = L"comboBoxTerritory";
this->comboBoxTerritory->Size = System::Drawing::Size(250, 21);
this->comboBoxTerritory->TabIndex = 4;
this->comboBoxTerritory->SelectedIndex = 0;
//
// labelClass
//
this->labelClass->AutoSize = true;
this->labelClass->Location = System::Drawing::Point(20, 180);
this->labelClass->Name = L"labelClass";
this->labelClass->Size = System::Drawing::Size(140, 13);
this->labelClass->TabIndex = 5;
this->labelClass->Text = L"Класс предыдущего года:";
//
// textBoxClass
//
this->textBoxClass->Location = System::Drawing::Point(180, 177);
this->textBoxClass->Name = L"textBoxClass";
this->textBoxClass->Size = System::Drawing::Size(60, 20);
this->textBoxClass->TabIndex = 6;
this->textBoxClass->Text = L"3";
//
// labelAccidents
//
this->labelAccidents->AutoSize = true;
this->labelAccidents->Location = System::Drawing::Point(280, 180);
this->labelAccidents->Name = L"labelAccidents";
this->labelAccidents->Size = System::Drawing::Size(180, 13);
this->labelAccidents->TabIndex = 7;
this->labelAccidents->Text = L"Количество страховых случаев:";
//
// textBoxAccidents
//
this->textBoxAccidents->Location = System::Drawing::Point(480, 177);
this->textBoxAccidents->Name = L"textBoxAccidents";
this->textBoxAccidents->Size = System::Drawing::Size(60, 20);
this->textBoxAccidents->TabIndex = 8;
this->textBoxAccidents->Text = L"0";
//
// labelAgeExperience
//
this->labelAgeExperience->AutoSize = true;
this->labelAgeExperience->Location = System::Drawing::Point(20, 215);
this->labelAgeExperience->Name = L"labelAgeExperience";
this->labelAgeExperience->Size = System::Drawing::Size(85, 13);
this->labelAgeExperience->TabIndex = 9;
this->labelAgeExperience->Text = L"Возраст и стаж:";
//
// comboBoxAgeExperience
//
this->comboBoxAgeExperience->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList;
this->comboBoxAgeExperience->FormattingEnabled = true;
this->comboBoxAgeExperience->Items->AddRange(gcnew cli::array< System::Object^ >(4) {
L"До 22 лет, стаж до 3 лет", L"22-25 лет, стаж до 3 лет",
L"Старше 25 лет, стаж до 3 лет", L"Старше 25 лет, стаж более 3 лет"
});
this->comboBoxAgeExperience->Location = System::Drawing::Point(180, 212);
this->comboBoxAgeExperience->Name = L"comboBoxAgeExperience";
this->comboBoxAgeExperience->Size = System::Drawing::Size(330, 21);
this->comboBoxAgeExperience->TabIndex = 10;
this->comboBoxAgeExperience->SelectedIndex = 3;
//
// checkBoxLimitedDrivers
//
this->checkBoxLimitedDrivers->AutoSize = true;
this->checkBoxLimitedDrivers->Checked = true;
this->checkBoxLimitedDrivers->CheckState = System::Windows::Forms::CheckState::Checked;
this->checkBoxLimitedDrivers->Location = System::Drawing::Point(23, 250);
this->checkBoxLimitedDrivers->Name = L"checkBoxLimitedDrivers";
this->checkBoxLimitedDrivers->Size = System::Drawing::Size(450, 17);
this->checkBoxLimitedDrivers->TabIndex = 11;
this->checkBoxLimitedDrivers->Text = L"ограничение количества лиц, допущенных к управлению ТС";
this->checkBoxLimitedDrivers->UseVisualStyleBackColor = true;
//
// labelPower
//
this->labelPower->AutoSize = true;
this->labelPower->Location = System::Drawing::Point(20, 285);
this->labelPower->Name = L"labelPower";
this->labelPower->Size = System::Drawing::Size(145, 13);
this->labelPower->TabIndex = 12;
this->labelPower->Text = L"Мощность двигателя (л.с.):";
//
// comboBoxPower
//
this->comboBoxPower->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList;
this->comboBoxPower->FormattingEnabled = true;
this->comboBoxPower->Items->AddRange(gcnew cli::array< System::Object^ >(6) {
L"До 50", L"50-70", L"70-100", L"100-120", L"120-150", L"Свыше 150"
});
this->comboBoxPower->Location = System::Drawing::Point(180, 282);
this->comboBoxPower->Name = L"comboBoxPower";
this->comboBoxPower->Size = System::Drawing::Size(200, 21);
this->comboBoxPower->TabIndex = 13;
this->comboBoxPower->SelectedIndex = 2;
//
// labelPeriod
//
this->labelPeriod->AutoSize = true;
this->labelPeriod->Location = System::Drawing::Point(20, 320);
this->labelPeriod->Name = L"labelPeriod";
this->labelPeriod->Size = System::Drawing::Size(140, 13);
this->labelPeriod->TabIndex = 14;
this->labelPeriod->Text = L"Период использования ТС:";
//
// comboBoxPeriod
//
this->comboBoxPeriod->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList;
this->comboBoxPeriod->FormattingEnabled = true;
this->comboBoxPeriod->Items->AddRange(gcnew cli::array< System::Object^ >(4) {
L"3 месяца", L"6 месяцев", L"9 месяцев", L"12 месяцев"
});
this->comboBoxPeriod->Location = System::Drawing::Point(180, 317);
this->comboBoxPeriod->Name = L"comboBoxPeriod";
this->comboBoxPeriod->Size = System::Drawing::Size(200, 21);
this->comboBoxPeriod->TabIndex = 15;
this->comboBoxPeriod->SelectedIndex = 3;
//
// buttonOK
//
this->buttonOK->Location = System::Drawing::Point(150, 370);
this->buttonOK->Name = L"buttonOK";
this->buttonOK->Size = System::Drawing::Size(100, 30);
this->buttonOK->TabIndex = 16;
this->buttonOK->Text = L"OK";
this->buttonOK->UseVisualStyleBackColor = true;
this->buttonOK->Click += gcnew System::EventHandler(this, &Form1::buttonOK_Click);
//
// buttonCancel
//
this->buttonCancel->DialogResult = System::Windows::Forms::DialogResult::Cancel;
this->buttonCancel->Location = System::Drawing::Point(280, 370);
this->buttonCancel->Name = L"buttonCancel";
this->buttonCancel->Size = System::Drawing::Size(100, 30);
this->buttonCancel->TabIndex = 17;
this->buttonCancel->Text = L"Отмена";
this->buttonCancel->UseVisualStyleBackColor = true;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->BackColor = System::Drawing::SystemColors::ControlLightLight;
this->CancelButton = this->buttonCancel;
this->ClientSize = System::Drawing::Size(600, 430);
this->Controls->Add(this->buttonCancel);
this->Controls->Add(this->buttonOK);
this->Controls->Add(this->comboBoxPeriod);
this->Controls->Add(this->labelPeriod);
this->Controls->Add(this->comboBoxPower);
this->Controls->Add(this->labelPower);
this->Controls->Add(this->checkBoxLimitedDrivers);
this->Controls->Add(this->comboBoxAgeExperience);
this->Controls->Add(this->labelAgeExperience);
this->Controls->Add(this->textBoxAccidents);
this->Controls->Add(this->labelAccidents);
this->Controls->Add(this->textBoxClass);
this->Controls->Add(this->labelClass);
this->Controls->Add(this->comboBoxTerritory);
this->Controls->Add(this->labelTerritory);
this->Controls->Add(this->textBoxBaseRate);
this->Controls->Add(this->labelBaseRate);
this->Controls->Add(this->labelTitle);
this->Name = L"Form1";
this->Text = L"ОСАГО";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
// Коэффициенты для расчета
private: double GetTerritoryCoefficient()
{
switch (comboBoxTerritory->SelectedIndex)
{
case 0: return 2.0; // Москва
case 1: return 1.8; // Санкт-Петербург
case 2: return 1.5; // Другие города > 1 млн
case 3: return 1.3; // Другие города < 1 млн
case 4: return 0.9; // Сельская местность
default: return 1.0;
}
}
private: double GetAgeExperienceCoefficient()
{
switch (comboBoxAgeExperience->SelectedIndex)
{
case 0: return 1.8; // До 22 лет, стаж до 3 лет
case 1: return 1.7; // 22-25 лет, стаж до 3 лет
case 2: return 1.4; // Старше 25 лет, стаж до 3 лет
case 3: return 1.0; // Старше 25 лет, стаж более 3 лет
default: return 1.0;
}
}
private: double GetPowerCoefficient()
{
switch (comboBoxPower->SelectedIndex)
{
case 0: return 0.6; // До 50
case 1: return 1.0; // 50-70
case 2: return 1.1; // 70-100
case 3: return 1.2; // 100-120
case 4: return 1.4; // 120-150
case 5: return 1.6; // Свыше 150
default: return 1.0;
}
}
private: double GetPeriodCoefficient()
{
switch (comboBoxPeriod->SelectedIndex)
{
case 0: return 0.5; // 3 месяца
case 1: return 0.7; // 6 месяцев
case 2: return 0.9; // 9 месяцев
case 3: return 1.0; // 12 месяцев
default: return 1.0;
}
}
private: double GetDriversCoefficient()
{
return checkBoxLimitedDrivers->Checked ? 1.0 : 1.8;
}
private: double GetKBMCoefficient()
{
try
{
int class_val = Int32::Parse(textBoxClass->Text);
int accidents = Int32::Parse(textBoxAccidents->Text);
double kbm = 1.0;
if (accidents > 0)
kbm = 1.0 + (accidents * 0.5);
return kbm;
}
catch (...)
{
return 1.0;
}
}
// Обработчик кнопки OK
private: System::Void buttonOK_Click(System::Object^ sender, System::EventArgs^ e)
{
try
{
double baseRate = Double::Parse(textBoxBaseRate->Text,
CultureInfo::InvariantCulture);
if (baseRate <= 0)
{
MessageBox::Show("Базовая ставка должна быть положительным числом!",
"Ошибка", MessageBoxButtons::OK, MessageBoxIcon::Warning);
return;
}
double coefficient = GetTerritoryCoefficient() *
GetAgeExperienceCoefficient() *
GetPowerCoefficient() *
GetPeriodCoefficient() *
GetDriversCoefficient() *
GetKBMCoefficient();
double totalCost = baseRate * coefficient;
String^ message = String::Format(
"Стоимость ОСАГО: {0:F2} руб.\n\n" +
"Коэффициенты:\n" +
"Территория: {1:F2}\n" +
"Возраст/стаж: {2:F2}\n" +
"Мощность: {3:F2}\n" +
"Период: {4:F2}\n" +
"Водители: {5:F2}\n" +
"КБМ: {6:F2}\n\n" +
"Итоговый коэффициент: {7:F2}",
totalCost,
GetTerritoryCoefficient(),
GetAgeExperienceCoefficient(),
GetPowerCoefficient(),
GetPeriodCoefficient(),
GetDriversCoefficient(),
GetKBMCoefficient(),
coefficient);
MessageBox::Show(message, "Результат расчета ОСАГО",
MessageBoxButtons::OK, MessageBoxIcon::Information);
}
catch (FormatException^)
{
MessageBox::Show("Пожалуйста, введите корректные числовые значения!",
"Ошибка ввода", MessageBoxButtons::OK, MessageBoxIcon::Error);
}
catch (Exception^ ex)
{
MessageBox::Show("Произошла ошибка: " + ex->Message,
"Ошибка", MessageBoxButtons::OK, MessageBoxIcon::Error);
}
}
// Обработчик кнопки Отмена
private: System::Void buttonCancel_Click(System::Object^ sender, System::EventArgs^ e)
{
this->Close();
}
};
}