private void button1_Click(object sender, EventArgs e)
        {
            Microsoft.Office.Interop.Excel.Workbook    excelappworkbook;
            Microsoft.Office.Interop.Excel.Workbooks   excelappworkbooks;
            Microsoft.Office.Interop.Excel.Application excelapp;

            excelapp                     = new Microsoft.Office.Interop.Excel.Application();
            excelapp.Visible             = true;
            excelapp.SheetsInNewWorkbook = 1;
            excelapp.Workbooks.Add(Type.Missing);
            //Запрашивать сохранение
            excelapp.DisplayAlerts = true;
            //Получаем набор ссылок на объекты Workbook (на созданные книги)
            excelappworkbooks = excelapp.Workbooks;
            //Получаем ссылку на книгу 1 - нумерация от 1
            excelappworkbook = excelappworkbooks[1];
            //Ссылку можно получить и так, но тогда надо знать имена книг,
            //причем, после сохранения - знать расширение файла
            //excelappworkbook=excelappworkbooks["Книга 1"];
            //Запроса на сохранение для книги не должно быть
            excelappworkbook.Saved = true;

            Microsoft.Office.Interop.Excel.Sheets    excelsheets;
            Microsoft.Office.Interop.Excel.Worksheet excelworksheet;
            Microsoft.Office.Interop.Excel.Range     excelcells;
            excelsheets = excelappworkbook.Worksheets;
            //Получаем ссылку на лист 1
            excelworksheet = (Microsoft.Office.Interop.Excel.Worksheet)excelsheets.get_Item(1);

            excelcells = excelworksheet.get_Range("A1", "M33");
            if (client != null)
            {
                int row = excelWriteHeaderLegalPerson(excelcells, excelworksheet);

                GetAllLegalPersonPoliciesCommand command = new GetAllLegalPersonPoliciesCommand();
                List <InsurancePolicy>           list    = command.getAllLegalPersonPolicies(client);

                excelWriteMain(excelcells, excelworksheet, list, row);
            }
            if (individual != null)
            {
                int row = excelWriteHeaderIndividual(excelcells, excelworksheet);

                GetAllIndividualPoliciesCommand command = new GetAllIndividualPoliciesCommand();
                List <InsurancePolicy>          list    = command.getallIndividualPolicies(individual);
                excelWriteMain(excelcells, excelworksheet, list, row);
            }
        }
        private void policeNumberInput_TextChanged(object sender, EventArgs e)
        {
            insuranseCaseInput.Items.Clear();
            Regex regex = new Regex("[1-9]{1}[0-9]*");

            if (regex.IsMatch(policeNumberInput.Text))
            {
                GetAllIndividualPoliciesCommand command = new GetAllIndividualPoliciesCommand();
                int        individualClientId           = Int32.Parse(policeNumberInput.Text);
                Individual individualPerson             = new Individual();
                individualPerson.Id = individualClientId;
                List <InsurancePolicy> policyList = command.getallIndividualPolicies(individualPerson);
                foreach (InsurancePolicy policy in policyList)
                {
                    insuranseCaseInput.Items.AddRange(policy.InsuranceCaseList.ToArray());
                }
            }
        }
        private void fillForIndividual()
        {
            richTextBox1.ReadOnly = true;
            //Since too much string appending go for string builder
            StringBuilder tableRtf = new StringBuilder();

            //beginning of rich text format,dont customize this begining line
            tableRtf.Append(@"{\rtf1\adeflag1025\ansi\ansicpg1251\uc1\adeff31507\deff0\stshfdbch31506\stshfhich31506\stshfbi31507\deflang1049\deflangfe1049\themelang1049\themelangfe0\stshfloch31506 ");

            row(tableRtf, "Клиент:", individual.Surname + " " + individual.Name + " " + individual.SecondName);
            row(tableRtf, "УНН:", "№ " + individual.Id);
            row(tableRtf, "Адрес:", individual.Address);
            row(tableRtf, "Телефон:", "тел. " + individual.PhoneNumber);
            row(tableRtf, "Тип:", "физическое лицо");


            //beginning of rich text format,dont customize this begining line
            tableRtf.Append(@"{\rtf1\adeflag1025\ansi\ansicpg1251 ");

            tableRtf.Append(@"\trowd");
            tableRtf.Append(@"\cellx1500").AppendLine("Дата полиса");
            tableRtf.Append(@"\intbl \cell");
            tableRtf.Append(@"\cellx3500").AppendLine("Категория полиса");
            tableRtf.Append(@"\intbl \cell");
            tableRtf.Append(@"\cellx5000").AppendLine("Действоует до");
            tableRtf.Append(@"\intbl \cell");
            tableRtf.Append(@"\cellx6500").AppendLine("Сумма полича");
            tableRtf.Append(@"\intbl \cell");
            tableRtf.Append(@"\cellx8500").AppendLine("Стоимость полиса");
            tableRtf.Append(@"\intbl \cell");
            tableRtf.Append(@"\cellx11000").AppendLine("Суммарные выплаты");
            tableRtf.Append(@"\intbl \cell");
            tableRtf.Append(@"\intbl \cell \row");

            GetAllIndividualPoliciesCommand command = new GetAllIndividualPoliciesCommand();
            List <InsurancePolicy>          list    = command.getallIndividualPolicies(individual);

            decimal sumPolicyAmount = 0;
            decimal sumPoliceCost   = 0;
            decimal sumFullPayments = 0;

            foreach (InsurancePolicy l in list)
            {
                tableRtf.Append(@"{\rtf1\adeflag1025\ansi\ansicpg1251 ");

                tableRtf.Append(@"\trowd");
                //A cell with width 1500.
                tableRtf.Append(@"\cellx1500").AppendLine("/" + l.SignDate.Day + "/" + l.SignDate.Month + "/" + l.SignDate.Year);
                tableRtf.Append(@"\intbl \cell");
                //A cell with width 4000.
                tableRtf.Append(@"\cellx3500").AppendLine(l.Category.Name);
                tableRtf.Append(@"\intbl \cell");
                tableRtf.Append(@"\cellx5000").AppendLine("/" + l.ExpirationDate.Day + "/" + l.ExpirationDate.Month + "/" + l.ExpirationDate.Year);
                tableRtf.Append(@"\intbl \cell");
                tableRtf.Append(@"\cellx6500").AppendLine("$" + l.Amount);
                tableRtf.Append(@"\intbl \cell");
                tableRtf.Append(@"\cellx8500").AppendLine("$" + l.Cost);
                tableRtf.Append(@"\intbl \cell");
                tableRtf.Append(@"\cellx11000").AppendLine("$" + l.FullPayments);
                tableRtf.Append(@"\intbl \cell");
                tableRtf.Append(@"\intbl \cell \row");

                sumPoliceCost   += l.Cost;
                sumPolicyAmount += l.Amount;
                sumFullPayments += l.FullPayments;
            }


            lastRow(tableRtf, "ИТОГО", "$" + sumPolicyAmount, "$" + sumPoliceCost, "$" + sumFullPayments);

            tableRtf.Append(@"\pard");
            tableRtf.Append(@"}");

            richTextBox1.Rtf = tableRtf.ToString();
        }
Ejemplo n.º 4
0
        private void name_SelectedIndexChanged(object sender, EventArgs e)
        {
            dataGridView1.Visible = true;

            if (clientType.SelectedItem.Equals("юр. лицо"))
            {
                LegalPerson legalPerson = (LegalPerson)name.SelectedItem;
                GetAllLegalPersonPoliciesCommand command         = new GetAllLegalPersonPoliciesCommand();
                List <InsurancePolicy>           legalPolicyList = command.getAllLegalPersonPolicies(legalPerson);



                dataGridView1.Columns.Add("CategoryName", "Категория");
                dataGridView1.Columns.Add("PolicyCost", "Стоимость полиса");
                dataGridView1.Columns.Add("PolicyAmount", "Сумма полиса");
                dataGridView1.Columns.Add("SignDate", "Дата закл. договора");
                dataGridView1.Columns.Add("ExpDate", "Дата оконч. договора");
                dataGridView1.Columns.Add("Insurer", "Страховщик");
                dataGridView1.Columns.Add("CaseList", "Страховые случаи");

                dataGridView1.Rows.Clear();
                dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
                dataGridView1.MultiSelect   = false;
                dataGridView1.Dock          = DockStyle.Fill;

                legalPolicyBindList = new BindingList <InsurancePolicy>(legalPolicyList);

                foreach (InsurancePolicy policy in legalPolicyBindList)
                {
                    int rowNumber = dataGridView1.Rows.Add();

                    dataGridView1.Rows[rowNumber].Cells["CategoryName"].Value = policy.Category.Name;
                    dataGridView1.Rows[rowNumber].Cells["PolicyCost"].Value   = policy.Cost;
                    dataGridView1.Rows[rowNumber].Cells["PolicyAmount"].Value = policy.Amount;
                    dataGridView1.Rows[rowNumber].Cells["SignDate"].Value     = policy.SignDate;
                    dataGridView1.Rows[rowNumber].Cells["ExpDate"].Value      = policy.ExpirationDate;
                    dataGridView1.Rows[rowNumber].Cells["Insurer"].Value      = policy.Insurer.Name + " " + policy.Insurer.SecondName + " " + policy.Insurer.Surname;

                    String cases = "";
                    foreach (InsuranceCase cs in policy.InsuranceCaseList)
                    {
                        cases = cases + cs.InsuranceCaseName + " ";
                    }

                    dataGridView1.Rows[rowNumber].Cells["CaseList"].Value = cases;
                }
                clientType.Visible = false;
                name.Visible       = false;
            }
            if (clientType.SelectedItem.Equals("физ. лицо"))
            {
                Individual individualPerson             = (Individual)name.SelectedItem;
                GetAllIndividualPoliciesCommand command = new GetAllIndividualPoliciesCommand();
                List <InsurancePolicy>          individualPolicyList = command.getallIndividualPolicies(individualPerson);

                dataGridView1.Columns.Add("CategoryName", "Категория");
                dataGridView1.Columns.Add("PolicyCost", "Стоимость полиса");
                dataGridView1.Columns.Add("PolicyAmount", "Сумма полиса");
                dataGridView1.Columns.Add("SignDate", "Дата закл. договора");
                dataGridView1.Columns.Add("ExpDate", "Дата оконч. договора");
                dataGridView1.Columns.Add("Insurer", "Страховщик");
                dataGridView1.Columns.Add("CaseList", "Страховые случаи");

                dataGridView1.Rows.Clear();
                dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
                dataGridView1.MultiSelect   = false;
                dataGridView1.Dock          = DockStyle.Fill;

                individualPolicyBindList = new BindingList <InsurancePolicy>(individualPolicyList);

                foreach (InsurancePolicy policy in individualPolicyBindList)
                {
                    int rowNumber = dataGridView1.Rows.Add();

                    dataGridView1.Rows[rowNumber].Cells["CategoryName"].Value = policy.Category.Name;
                    dataGridView1.Rows[rowNumber].Cells["PolicyCost"].Value   = policy.Cost;
                    dataGridView1.Rows[rowNumber].Cells["PolicyAmount"].Value = policy.Amount;
                    dataGridView1.Rows[rowNumber].Cells["SignDate"].Value     = policy.SignDate;
                    dataGridView1.Rows[rowNumber].Cells["ExpDate"].Value      = policy.ExpirationDate;
                    dataGridView1.Rows[rowNumber].Cells["Insurer"].Value      = policy.Insurer.Name + " " + policy.Insurer.SecondName + " " + policy.Insurer.Surname;

                    String cases = "";
                    foreach (InsuranceCase cs in policy.InsuranceCaseList)
                    {
                        cases = cases + cs.InsuranceCaseName + " ";
                    }

                    dataGridView1.Rows[rowNumber].Cells["CaseList"].Value = cases;
                }
                clientType.Visible = false;
                name.Visible       = false;
            }
        }