Exemplo n.º 1
0
        public void ExportInExcel()
        {
            DataTable dt = CreateDataTable();

            foreach (DataGridViewRow row in _dgv.Rows)
            {
                if (row.Visible)
                {
                    object[] items = new object[row.Cells.Count];

                    foreach (DataGridViewCell cell in row.Cells)
                    {
                        items[cell.ColumnIndex] = cell.Value.ToString();
                    }

                    dt.Rows.Add(items);
                }
            }

            CreateExcel excel = new CreateExcel(dt);
            excel.Show();
        }
Exemplo n.º 2
0
        private void Export(Language lang)
        {
            PersonList personList = PersonList.GetUniqueInstance();

            string[] columnNames = (lang == Language.Rus) ? _columnNamesRus : _columnNamesEng;

            DataTable dt = CreateDataTable(columnNames);

            HistoryList historyList = HistoryList.GetUniqueInstance();

            foreach (var person in personList)
            {
                History created = historyList.GetItem(person, HistoryAction.Создал);
                History modifed = historyList.GetItem(person, HistoryAction.Редактировал);
                string modifedAuthor = (modifed != null) ? modifed.Author : string.Empty;
                string modifedDatetime = (modifed != null) ? modifed.datetime : string.Empty;

                object[] row;

                if (lang == Language.Rus)
                {
                    row = new object[] { person.ID, person.Organization.ID, person.LastName, person.FirstName,
                        person.SecondName, GetTitle(lang, person.Appeal), person.GetOrganizationName(), person.GetSubOrganizationName(),
                        person.Position.GetName(lang), person.MainSpecPerson.GetName(lang), person.AcademTitle.GetName(lang),
                        person.Email, person.Mobile, person.Phone, person.Comment, created.Author, created.datetime,
                        modifedAuthor, modifedDatetime };
                }
                else
                {
                    row = new object[] { person.ID, person.Organization.ID, person.LastName, person.FirstName, person.SecondName,
                        GetTitle(lang, person.Appeal), person.Position.GetName(lang), person.MainSpecPerson.GetName(lang),
                        person.AcademTitle.GetName(lang), person.Email, person.Mobile, person.Phone, person.Comment };
                }

                dt.Rows.Add(row);
            }

            CreateExcel excel = new CreateExcel(dt);
            excel.Show();
        }
        private void Export(Language lang)
        {
            OrganizationList organizationList = OrganizationList.GetUniqueInstance();

            string[] columnNames = (lang == Language.Rus) ? _columnNamesRus : _columnNamesEng;

            DataTable dt = CreateDataTable(columnNames);

            HistoryList historyList = HistoryList.GetUniqueInstance();

            foreach (var item in organizationList.List)
            {
                Organization organization = item.Value;

                LPU lpu = (organization.TypeOrg == TypeOrg.ЛПУ) ? (organization as LPU) : null;

                int parentID = (organization.ParentOrganization == null) ? organization.ID : organization.ParentOrganization.ID;
                string recordType = GetRecordType(organization);

                string inn = (organization.INN == "") ? "" : "'" + organization.INN;
                string kpp = (organization.KPP == "") ? "" : "'" + organization.KPP;
                string realRegionName = (organization.RealRegion == null) ? "" : organization.RealRegion.Name;
                string postIndex = organization.PostIndex;

                string pharmacy = ((organization.TypeOrg == TypeOrg.Аптека) && (organization.ParentOrganization == null)) ? (organization as Organization).Pharmacy : string.Empty;
                string mainSpec = (organization.MainSpec != null) ? organization.MainSpec.GetName(lang) : string.Empty;

                string typeLPU = string.Empty;
                string ownership = string.Empty;
                string adminLevel = string.Empty;
                string typeFin = string.Empty;

                if (lpu != null)
                {
                    typeLPU = lpu.TypeLPU.GetName(lang);
                    ownership = lpu.Ownership.GetName(lang);
                    adminLevel = lpu.AdmLevel.GetName(lang);
                    typeFin = lpu.TypeFin.GetName(lang);
                }

                object[] row;

                if (lang == Language.Rus)
                {
                    string street = organization.Street;

                    string idLpuRR = string.Empty;
                    string idLpuRR2 = string.Empty;

                    if (lpu != null)
                    {
                        idLpuRR = ((lpu.ParentOrganization == null) || ((lpu.ParentOrganization != null) && (lpu.LpuRR.ID != 0))) ? lpu.LpuRR.ID.ToString() : string.Empty;
                        idLpuRR2 = (lpu.LpuRR2.ID != 0) ? lpu.LpuRR2.ID.ToString() : string.Empty;
                    }

                    History created = historyList.GetItem(organization, HistoryAction.Создал);
                    History modifed = historyList.GetItem(organization, HistoryAction.Редактировал);
                    string createdAuthor = (created != null) ? created.Author : string.Empty;
                    string createdDatetime = (created != null) ? created.datetime : string.Empty;
                    string modifedAuthor = (modifed != null) ? modifed.Author : string.Empty;
                    string modifedDatetime = (modifed != null) ? modifed.datetime : string.Empty;

                    row = new object[] { organization.ID, parentID, organization.NumberSF, recordType, GetFormatTypeOrg(organization), GetClientType(organization),
                               organization.Name, organization.ShortName, inn, kpp, realRegionName, organization.City, postIndex, street,
                               organization.Email, organization.Website, organization.Phone, pharmacy, typeLPU, ownership, adminLevel, typeFin, mainSpec,
                               lpu.SubRegion, idLpuRR, idLpuRR2,
                               (lpu != null) ? lpu.BedsTotal : string.Empty, (lpu != null) ? lpu.BedsIC : string.Empty, (lpu != null) ? lpu.BedsSurgical : string.Empty,
                               (lpu != null) ? lpu.Operating : string.Empty,
                               organization.MachineGD, organization.MachineGDF, organization.MachineCRRT, organization.Shift, organization.PatientGD,
                               organization.PatientPD, organization.PatientCRRT, createdAuthor, createdDatetime, modifedAuthor, modifedDatetime };
                }
                else
                {
                    string MachineGD = string.Empty;
                    string MachineGDF = string.Empty;
                    string MachineCRRT = string.Empty;
                    string Shift = string.Empty;
                    string PatientGD = string.Empty;
                    string PatientPD = string.Empty;
                    string PatientCRRT = string.Empty;

                    if ((lpu != null) && (lpu.IsHaveDepartment()))
                    {
                        OrganizationList organizationoList = OrganizationList.GetUniqueInstance();

                        var childList = from child in organizationoList.GetChildList(lpu)
                                        where child.TypeOrg == TypeOrg.Отделение
                                        select new
                                        {
                                            MachineGD = string.IsNullOrEmpty(child.MachineGD) ? 0 : Convert.ToInt32(child.MachineGD),
                                            MachineGDF = string.IsNullOrEmpty(child.MachineGDF) ? 0 : Convert.ToInt32(child.MachineGDF),
                                            MachineCRRT = string.IsNullOrEmpty(child.MachineCRRT) ? 0 : Convert.ToInt32(child.MachineCRRT),
                                            Shift = string.IsNullOrEmpty(child.Shift) ? 0 : Convert.ToInt32(child.Shift),
                                            PatientGD = string.IsNullOrEmpty(child.PatientGD) ? 0 : Convert.ToInt32(child.PatientGD),
                                            PatientPD = string.IsNullOrEmpty(child.PatientPD) ? 0 : Convert.ToInt32(child.PatientPD),
                                            PatientCRRT = string.IsNullOrEmpty(child.PatientCRRT) ? 0 : Convert.ToInt32(child.PatientCRRT)
                                        };

                        MachineGD = childList.Sum(child => child.MachineGD).ToString();
                        if (MachineGD == "0")
                            MachineGD = string.Empty;

                        MachineGDF = childList.Sum(child => child.MachineGDF).ToString();
                        if (MachineGDF == "0")
                            MachineGDF = string.Empty;

                        MachineCRRT = childList.Sum(child => child.MachineCRRT).ToString();
                        if (MachineCRRT == "0")
                            MachineCRRT = string.Empty;

                        Shift = childList.Sum(child => child.Shift).ToString();
                        if (Shift == "0")
                            Shift = string.Empty;

                        PatientGD = childList.Sum(child => child.PatientGD).ToString();
                        if (PatientGD == "0")
                            PatientGD = string.Empty;

                        PatientPD = childList.Sum(child => child.PatientPD).ToString();
                        if (PatientPD == "0")
                            PatientPD = string.Empty;

                        PatientCRRT = childList.Sum(child => child.PatientCRRT).ToString();
                        if (PatientCRRT == "0")
                            PatientCRRT = string.Empty;
                    }
                    else
                    {
                        MachineGD = organization.MachineGD;
                        MachineGDF = organization.MachineGDF;
                        MachineCRRT = organization.MachineCRRT;
                        Shift = organization.Shift;
                        PatientGD = organization.PatientGD;
                        PatientPD = organization.PatientPD;
                        PatientCRRT = organization.PatientCRRT;
                    }

                    row = new object[] { organization.ID, parentID, recordType,
                               organization.Name, organization.ShortName, inn, kpp, realRegionName, organization.City, postIndex, GetAddressWithDistrict(organization),
                               organization.Email, organization.Website, organization.Phone, pharmacy, GetClientType(organization), typeLPU, ownership, adminLevel,
                               typeFin, mainSpec, lpu.SubRegion,
                               (lpu != null) ? lpu.BedsTotal : string.Empty, (lpu != null) ? lpu.BedsIC : string.Empty, (lpu != null) ? lpu.BedsSurgical : string.Empty,
                               (lpu != null) ? lpu.Operating : string.Empty, MachineGD, MachineGDF, MachineCRRT, Shift, PatientGD, PatientPD, PatientCRRT };
                }

                dt.Rows.Add(row);
            }

            CreateExcel excel = new CreateExcel(dt);
            excel.Show();
        }