Ejemplo n.º 1
0
        private void LoadTitle(SelectionWell selectionWell)
        {
            Substitute = new CellExchange_Class(sheet);
            Accredit accredit = AdditionnTable.GetAccredit();

            Substitute.AddExchange(mark.acred, $"{accredit.Text}\nВыдан {accredit.YMDFrom}", 0);
            Worker work = AdditionnTable.GetSigner(data.ETypeTemplate.Protocol, "Протокол");

            Substitute.AddExchange(mark.fio_nac, work.FIO, 0);
            Substitute.AddExchange(mark.number_prot, selectionWell.FormatNumber, 0);
            Substitute.AddExchange(mark.abon, selectionWell.Objecte.Client.Detail.FullName, 0);
            Substitute.AddExchange(mark.yr_adr, Helpers.LogicHelper.AdresLogic.FirstModel(selectionWell.Objecte.Client.Detail.AdresLegalID).Adr.CutAdres(false), 0);
            Substitute.AddExchange(mark.type_well, G.TypeWell.Rows.Get <string>(selectionWell.Well.TypeWellID, C.TypeWell.FullName), 0);
            Substitute.AddExchange(mark.select_adr, selectionWell.Objecte.Adres.CutAdres(false), 0);
            Substitute.AddExchange(mark.date_select, MyTools.StringDate_From_YMDHMS(selectionWell.YMDHM, MyTools.EInputDate.YMDHM, MyTools.EInputDate.YMD), 0);
            Substitute.AddExchange(mark.time_select, MyTools.StringDate_From_YMDHMS(selectionWell.YMDHM, MyTools.EInputDate.YMDHM, MyTools.EInputDate.YMDHM), 0);
            Substitute.AddExchange(mark.repres, new Representative(selectionWell.Sample.RepresentativeID).Post_FIO, 0);
            Substitute.AddExchange(mark.year, DateControl_Class.SelectYear, 0);
            MonthYear();
            NumberFolder(_selectionWells.Select(x => x.Objecte.NumberFolder).ToArray());
            work = AdditionnTable.GetSigner(data.ETypeTemplate.Protocol, "Протокол");
            Substitute.AddExchange(mark.fio, work.FIO, 0);
            Substitute.AddExchange(mark.job, work.Post, 0);
            int day, month;

            MyTools.Y_M_D_From_YMD(StaticDate.SelectDate, out month, out month, out day);
            Substitute.AddExchange(mark.day, day, 0);
            Substitute.AddExchange(mark.month, MyTools.Month_From_M_C_R(month, Reg: MyTools.ERegistor.ToLower), 0);
            Substitute.AddExchange(mark._month, month.ToString("00"), 0);
            Substitute.Exchange();
        }
Ejemplo n.º 2
0
        /// <summary>Приложение</summary>
        private void Applications()
        {
            foreach (var one in selections)
            {
                Well well = one.Well;

                ISheet sheet = book.GetSheet("Приложение").CopySheet(well.PresentNumber != string.Empty ? well.PresentNumber : "без_номера");
                Substitute = new CellExchange_Class(sheet);
                //Substitute.AddExchange("{объект}", obj.Adres + ' ' + well.PresentNumber, 0);
                Substitute.AddExchange("{абонент}", client.Detail.FullName, 0);
                Substitute.AddExchange("{колодец}", $"{well.FullName} - {well.PresentNumber}", 0);
                Substitute.AddExchange("{адрес}", (client.Objects.Any() ? obj.Adres.CutAdres(false) : string.Empty), 0);
                Substitute.AddExchange("{номер отбора}", one.FormatNumber, 0);
                {
                    var works = AdditionnTable.GetSigner(data.ETypeTemplate.Extract, "Приложение");
                    Substitute.AddExchange("{должность}", works.Post, 0);
                    Substitute.AddExchange("{фио}", works.FIO, 0);
                }
                tableSelection = new TableSelection(obj, sample);
                tableSelection.CreateTable(SearchCellFromMark(sheet, "{таблица}", false), one);
                tableSelection.Signature(SearchCellFromMark(sheet, "{пример}", false), Substitute);
                Substitute.AddExchange("{полное наименование колодца}", well.FullName + ' ' + well.PresentNumber, 0);
                Substitute.Exchange();
            }
            book.RemoveSheetAt(book.GetSheetIndex("Приложение"));
        }
Ejemplo n.º 3
0
        private void LoadTitle()
        {
            sheet      = book.GetSheet("Титульник");
            Substitute = new CellExchange_Class(sheet);
            Worker worker = AdditionnTable.GetSigner(data.ETypeTemplate.Journal, "Титульник");

            Substitute.AddExchange(mark.fio, worker.FIO, 1);
            Substitute.AddExchange(mark.job, worker.Post, 1);

            Substitute.Exchange();
        }
Ejemplo n.º 4
0
        /// <summary>Заполнение текста из базы</summary>
        /// <param name="ListName">имя листа</param>
        protected void LoadTextTemplate(ISheet sheet, string ListName, int count = 0)
        {
            CellExchange_Class ex = new CellExchange_Class(sheet);

            foreach (var one in TemplateStorage.textFromTP.Where(x => x.ListName == ListName))
            {
                var        texts    = one.Text.Split('\n').ToList();
                ICellStyle defStyle = null;
                IRow       Defrow   = SearchRowFromMark(sheet, one.ThisTemplate);
                if (texts.FirstOrDefault(x => x.Contains(StyleTarget.DefStyle)) != null)
                {
                    defStyle = LoadStyle(texts.First(x => x.Contains(StyleTarget.DefStyle)));
                    texts.Remove(texts.First(x => x.Contains(StyleTarget.DefStyle)));
                }
                if (texts.Count > 1)
                {
                    foreach (var text in texts)
                    {
                        Defrow = Defrow.CopyRowTo(Defrow.RowNum + 1);
                        IRow   row    = sheet.GetRow(Defrow.RowNum - 1);
                        string stroka = text;
                        if (text.Contains(StyleTarget.Style))
                        {
                            ICellStyle style = LoadStyle(text.Substring(text.IndexOf(StyleTarget.Style)));
                            foreach (var cell in row.Cells)
                            {
                                cell.CellStyle = style;
                            }
                            stroka = text.Substring(0, text.IndexOf(StyleTarget.Style));
                        }
                        else if (defStyle != null)
                        {
                            foreach (var cell in row.Cells)
                            {
                                cell.CellStyle = defStyle;
                            }
                        }
                        stroka = stroka.StringDivision(80);
                        ex.AddExchange(one.ThisTemplate, (e) => e.Row.Height = (short)(300 / 11 * 12 * stroka.Split('\n').Length), 1);
                        ex.AddExchange(one.ThisTemplate, stroka, 1);
                    }
                }
                else
                {
                    ex.AddExchange(one.ThisTemplate, one.Text, count);
                }
                ex.AddExchange(one.ThisTemplate, (e) => { sheet.RemoveRow(e.Row); }, 1);
            }
            ex.Exchange();
        }
Ejemplo n.º 5
0
        static CellExchange_Class GetProtokolsExchanges(NPOI.SS.UserModel.ISheet Sheet
                                                        , int Year
                                                        , string ProtokolNumber
                                                        , string Object
                                                        , string ObjectType
                                                        , string ProbeType
                                                        , string Location
                                                        , string DateO
                                                        , string DateP
                                                        , string TimeO
                                                        , string Sampler
                                                        , string Cause
                                                        , string Probes
                                                        , string Day
                                                        , string MonthName
                                                        , string MonthNumber
                                                        , string Methods
                                                        , string PoPoS
                                                        , string PodrFull
                                                        , string PodrShort
                                                        , string PodrAdress
                                                        , int ActNumber)
        {
            var Exchanges = new CellExchange_Class(Sheet);

            Exchanges.AddExchange("{год}", Year.ToString(), 5);
            Exchanges.AddExchange("{Номер протокола}", ProtokolNumber, 5);
            Exchanges.AddExchange("{объект}", Object, 5);
            Exchanges.AddExchange("{Тип объекта}", ObjectType, 5);
            Exchanges.AddExchange("{тип пробы}", ProbeType, 5);
            Exchanges.AddExchange("{Место отбора проб}", Location, 5);
            Exchanges.AddExchange("{дата отбора}", DateO, 5);
            Exchanges.AddExchange("{время отбора}", TimeO, 5);
            Exchanges.AddExchange("{дата испытаний}", DateP, 5);
            Exchanges.AddExchange("{Пробоотборщик}", Sampler, 5);
            Exchanges.AddExchange("{Цель испытания}", Cause, 5);
            Exchanges.AddExchange("{Маркировка}", Probes, 5);
            Exchanges.AddExchange("{День месяца}", Day, 5);
            Exchanges.AddExchange("{Месяц}", MonthName, 5);
            Exchanges.AddExchange("{Месяц номер}", MonthNumber, 5);
            Exchanges.AddExchange("{Методы}", Methods, 1);
            Exchanges.AddExchange("{Подразделение краткое}", PodrShort, 1);
            Exchanges.AddExchange("{Подразделение полное}", PodrFull, 1);
            Exchanges.AddExchange("{Адрес подразделения}", PodrAdress, 1);
            Exchanges.AddExchange("{План и место}", PoPoS, 1);
            Exchanges.AddExchange("{Акт отбора}", (ActNumber == 0) ? "" : "№" + ActNumber.ToString() + "-" + PodrShort + "/" + Year.ToString() + " от " + DateO, 5);

            return(Exchanges);
        }
Ejemplo n.º 6
0
        /// <summary>Обработка письма</summary>
        private void Letter()
        {
            Substitute = new CellExchange_Class(book.GetSheet("Письмо"));
            ClientName(client);
            ObjectAdres(obj, true);
            MonthYearSelect();
            NumberFolder(obj.NumberFolder);
            Substitute.AddExchange("{год месячного объёма}", DateControl_Class.SelectYear - 1, 0);
            Substitute.AddExchange("{листов}", selections.Length, 0);
            NumberFolder(obj.NumberFolder);
            var works = AdditionnTable.GetSigner(data.ETypeTemplate.Extract, "Письмо");

            Substitute.AddExchange("{должность}", works.Post, 0);
            Substitute.AddExchange("{фио}", works.FIO, 0);
            Substitute.Exchange();
        }
Ejemplo n.º 7
0
        private void Letter()
        {
            sheet = book.GetSheet("Письмо");
            if (!R621 && !R644)
            {
                book.RemoveSheetAt(book.GetSheetIndex("Письмо"));
                return;
            }
            Substitute = new CellExchange_Class(sheet);
            ClientName(obj.Client);
            ObjectAdres(obj, true);
            MonthYearSelect();

            NumberFolder(obj.NumberFolder);

            var worker = AdditionnTable.GetSigner(data.ETypeTemplate.CalculationFees, "Письмо");

            Substitute.AddExchange(mark.job, worker.Post, 1);
            Substitute.AddExchange(mark.fio, worker.FIO, 1);

            int Radder621 = SearchRowFromMark(sheet, mark.adder621).RowNum;

            Resolution resolution = PollutionBase_Class.AllResolution.First(x => x.CurtName.Contains("621"));

            ResolutionClarify(resolution, R621);
            if (R621)
            {
                Substitute.AddExchange(mark.adder621, GetNormDoc(resolution), 1);
            }
            else
            {
                Substitute.AddExchange(mark.adder621, e => { e.Row.ZeroHeight = true; }, 1);
            }

            resolution = PollutionBase_Class.AllResolution.First(x => x.CurtName.Contains("644"));
            ResolutionClarify(resolution, R644);
            if (R644)
            {
                Substitute.AddExchange(mark.adder644, GetNormDoc(resolution), 1);
            }
            else
            {
                Substitute.AddExchange(mark.adder644, e => { e.Row.ZeroHeight = true; }, 1);
            }
            Substitute.Exchange();
            ResizeHeight(sheet, Radder621, Radder621 + 3);
        }
Ejemplo n.º 8
0
        protected override void internalStart()
        {
            {
                CP = new Control_Print();
                CP.Elems.SetRowFromGrid(MyTools.GL_Auto);
                var DateSelect = new DateSelector(_negotiationAssistant.YMD);
                CP.Elems.SetFromGrid(DateSelect.View);
                CP.ShowDialog();

                if (_negotiationAssistant.WorkerID == 0)
                {
                    MessageBox.Show("Не выбран пробоотборщик!");
                    return;
                }

                _negotiationAssistant.YMD = MyTools.YMD_From_DateTime(DateSelect.dateTime);
            }

            Objecte  obj     = _negotiationAssistant.Objecte;
            Accredit acc     = AdditionnTable.GetAccredit();
            string   sampler = _negotiationAssistant.Worker.Post_FIO;

            foreach (var one in obj.Wells)
            {
                book       = TemplateStorage.WorkBook;
                Substitute = new CellExchange_Class(book.GetSheetAt(0));
                var Details = obj.Client.Detail;
                Substitute.AddExchange("{абонент}", Details.FullName, 0);
                if (obj.Separate)
                {
                    Substitute.AddExchange("{юридический адрес}", obj.Detail.LegalAdres, 0);
                }
                else
                {
                    Substitute.AddExchange("{юридический адрес}", Helpers.LogicHelper.AdresLogic.FirstModel(Details.AdresLegalID).Adr, 0);
                }
                Substitute.AddExchange("{тип колодца}", new TypeWell(one.TypeWellID).FullName + " " + new TypeWell(one.TypeWellID).CurtName + '-' + one.Number, 0);
                Substitute.AddExchange("{место отбора}", obj.Adres.CutAdres(false), 0);
                Substitute.AddExchange("{аккредитация}", acc.Text, 0);
                Substitute.AddExchange("{дата аккредитации}", acc.YMDFrom, 0);
                Substitute.AddExchange("{пробоотборщик}", sampler, 0);
                //Substitute.AddExchange("{представитель абонента}", sample == null ? string.empty : sample.IDRepresentative > 0 ? new Representative(sample.IDRepresentative).Post_FIO : string.empty, 0);
                Substitute.Exchange();
                Print("Акты", "акт отбора пробы " + new TypeWell(one.TypeWellID).FullName + ' ' + one.Number, EPathPrint.Documents);
            }
        }
Ejemplo n.º 9
0
        private void LoadCap(string name)
        {
            Substitute = new CellExchange_Class(sheet);
            Substitute.AddExchange("{месяц}", MyTools.Month_From_M_C_R(MyTools.M_From_YM(DateControl_Class.SelectMonth), Reg: MyTools.ERegistor.ToLower), 0);
            Substitute.AddExchange("{год}", DateControl_Class.SelectYear, 0);
            MonthYear();

            Worker workers = AdditionnTable.GetSigner(data.ETypeTemplate.Registry, "директор");

            Substitute.AddExchange("{должность директора}", workers.Post, 0);
            Substitute.AddExchange("{фио директора}", workers.rFIO, 0);
            workers = AdditionnTable.GetSigner(data.ETypeTemplate.Registry, "подписывающий");
            Substitute.AddExchange("{должность}", workers.Post, 0);
            Substitute.AddExchange("{фио}", workers.FIO, 0);
            LoadTextTemplate(sheet, name, 1);
            Substitute.AddExchange("{итоговая сумма}", summa.ToMoney(), 0);
            Substitute.Exchange();
        }
Ejemplo n.º 10
0
        public void Signature(ICell cell, CellExchange_Class Substitute)
        {
            //cell.Sheet.CopyRow(cell.RowIndex, cell.RowIndex + 1);
            //Substitute.AddExchange("{пример}", "*12 345 E-6 читай 12 345 x 10^-^6".SymbolConverter(), 1);
            Resolution resolution = PollutionBase_Class.AllResolution.First(x => x.CurtName.Contains("621"));

            if (obj.CanResolution(resolution.ID))
            {
                Substitute.AddExchange("{пример}", "колонки 7, 9, 13 согласно: " + resolution.GetResolutionClarify.FullName, 1);
                cell.Sheet.CopyRow(cell.RowIndex, cell.RowIndex + 1);
            }
            resolution = PollutionBase_Class.AllResolution.First(x => x.CurtName.Contains("644"));
            if (obj.CanResolution(resolution.ID))
            {
                Substitute.AddExchange("{пример}", "колонки 8, 10, 14 согласно: " + resolution.GetResolutionClarify.FullName, 1);
                cell.Sheet.CopyRow(cell.RowIndex, cell.RowIndex + 1);
            }
            Substitute.AddExchange("{пример}", "колонка 15=5/11", 1);
        }
Ejemplo n.º 11
0
        private void LoadTable()
        {
            sheet      = book.GetSheet("Таблица");
            Substitute = new CellExchange_Class(sheet);
            IRow row = SearchRowFromMark(sheet, StaticMark.abonent, false);

            var selectionWells = Helpers.LogicHelper.SelectionWellLogic.Find(DateControl_Class.SelectMonth, 1);

            foreach (var selectionWell in selectionWells)
            {
                sheet.ShiftRows(row.RowNum + 3, sheet.LastRowNum, 0);
                row.CopyRowTo(row.RowNum + 3);
                sheet.GetRow(row.RowNum + 1).CopyRowTo(row.RowNum + 4);
                sheet.GetRow(row.RowNum + 2).CopyRowTo(row.RowNum + 5);
            }

            foreach (var selectionWell in selectionWells.OrderBy(x => x.Number))
            {
                Client client = selectionWell.Objecte.Client;

                ClientName(client, false);
                WellNumber(selectionWell);
                Substitute.AddExchange(mark.number_sample,
                                       $"{selectionWell.Number}-С-{MyTools.YearMonth_From_YM(MyTools.YM_From_YMDHM(selectionWell.YMDHM), MyTools.EDateTimeTypes.DivisionSymbol, DivisionSymbol: "/")}",
                                       1);
                row            = SearchRowFromMark(sheet, "{таблица}");
                tableSelection = new TableSelection(selectionWell.Objecte, selectionWell.Sample);
                tableSelection.CreateTable(SearchCellFromMark(sheet, "{таблица}", false), selectionWell);
            }

            tableSelection.Signature(SearchCellFromMark(sheet, "{пример}", false), Substitute);
            ResizeWidth(sheet, MyTools.ETypeFormatBook.Horizontal, tableSelection.table);
            MonthYearSelect();
            Worker worker = AdditionnTable.GetSigner(data.ETypeTemplate.Journal, "Таблица");

            Substitute.AddExchange(mark.fio, worker.FIO, 1);
            Substitute.AddExchange(mark.job, worker.Post, 1);
            Substitute.Exchange();
        }
Ejemplo n.º 12
0
        protected override void internalStart()
        {
            Objecte obj = _negotiationAssistant.Objecte;

            book = TemplateStorage.WorkBook;

            Substitute = new CellExchange_Class(book.GetSheetAt(0));
            ClientName(_negotiationAssistant.Objecte.Client);
            NumberFolder(obj.NumberFolder);

            #region Подписывающий
            var works = AdditionnTable.GetSigner(data.ETypeTemplate.LetterNotification, "Письмо");
            Substitute.AddExchange("{должность}", works.Post, 0);
            Substitute.AddExchange("{ФИО}", works.FIO, 0);
            #endregion

            #region адрес/дата
            ObjectAdres(obj, true);
            CP = new Control_Print();
            CP.Elems.SetRowFromGrid(MyTools.GL_Auto);
            var DateSelect = new DateSelector(_negotiationAssistant.YMD);
            CP.Elems.SetFromGrid(DateSelect.View);
            CP.ShowDialog();

            if (DateSelect.dateTime == null)
            {
                return;
            }

            _negotiationAssistant.YMD = MyTools.YMD_From_DateTime(DateSelect.dateTime);
            Substitute.AddExchange("{дата отбора}", MyTools.YearMonthDay_From_YMD(DateSelect.dateTime), 0);
            #endregion

            Substitute.AddExchange("{адрес отбора}", obj.Adres, 0);
            Substitute.Exchange();
            Print("Письма", "Письмо", EPathPrint.Documents);
        }
Ejemplo n.º 13
0
        private void LoadTitle()
        {
            Substitute = new CellExchange_Class(sheet);

            ClientName(this._selectionWell.Objecte.Client, false);
            ClientAdres(this._selectionWell.Objecte.Client, false);
            ObjectAdres(this._selectionWell.Objecte, false);
            Substitute.AddExchange(mark.period,
                                   $"{MyTools.YearMonth_From_YM(StartYM, MyTools.EDateTimeTypes.BeautifulWords)} - {MyTools.YearMonth_From_YM(StartYM + MonthCount - 1, MyTools.EDateTimeTypes.BeautifulWords)}",
                                   0);
            Worker worker = AdditionnTable.GetSigner(data.ETypeTemplate.InspectionResult, "Результат");

            Substitute.AddExchange(mark.fio, worker.FIO, 0);
            Substitute.AddExchange(mark.job, worker.Post, 0);
            sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(8, 8, 6, 8 + (MonthCount > 6 ? MonthCount / 2 : 0) + (ShowNorms ? 2 : 0)));

            Substitute.Exchange();
            int span = 2 + MonthCount + (ShowNorms ? 2 : 0);

            for (int i = 0; i < 5; i++)
            {
                sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(i, i, 0, span));
            }
        }
Ejemplo n.º 14
0
        public static bool OtchProtokolAquaAurat_KOCA(Protokols_class.SGroup_class.Protokol_class Protokol, bool CreateNew = true, bool Open = true)
        {
            if (Protokol.SampleCount != 1)
            {
                MessageBox.Show("Не верное количество замеров в протоколе:" + Protokol.SampleCount.ToString() + ". Должен быть 1", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(false);
            }

            {
                var MsgErr = "";

                for (int i = 0; i < Protokol.MarkCount; i++)
                {
                    var PAMIndex = -1;

                    for (int j = 0; j < Protokol.SampleCount; j++)
                    {
                        if (Protokol[j][i].LocalAlow && Protokol[j][i].Method.Length > 0)
                        {
                            if (PAMIndex < 0)
                            {
                                PAMIndex = j;
                            }
                            else if (Protokol[j][i].Method != Protokol[PAMIndex][i].Method)
                            {
                                MsgErr += '\n' + Protokol[j][i].Mark + " имеет различные методы у нормативов " + T.Object.Rows.Get <string>(Protokol[j].ObjectID, C.Object.Norm, C.Norm.Name) + " и " + T.Object.Rows.Get <string>(Protokol[PAMIndex].ObjectID, C.Object.Norm, C.Norm.Name);
                            }
                        }
                    }
                }

                if (MsgErr.Length > 0)
                {
                    MessageBox.Show(MsgErr, "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(false);
                }
            }

            string NewFileName;

            {
                int Month, Year;

                ATMisc.GetYearMonthFromYM(Employe_Form.SPoints.YM, out Year, out Month);

                {
                    NewFileName = Application.StartupPath + "\\Отчеты\\";

                    if (!Directory.Exists(NewFileName))
                    {
                        Directory.CreateDirectory(NewFileName);
                    }

                    NewFileName += T.Podr.Rows.Get <string>(Protokol.PodrID, C.Podr.ShrName) + "\\";

                    if (!Directory.Exists(NewFileName))
                    {
                        Directory.CreateDirectory(NewFileName);
                    }

                    NewFileName += ATMisc.GetMonthName1(Month) + "\\";

                    if (!Directory.Exists(NewFileName))
                    {
                        Directory.CreateDirectory(NewFileName);
                    }
                }

                NewFileName += ProtokolFileName(Protokol);
            }

            if (CreateNew || !File.Exists(NewFileName))
            {
                var WorkBook = ATMisc.GetGenericExcel(Protokol.TemplateFileName());

                if (WorkBook == null)
                {
                    return(false);
                }

                var TitleSheet = WorkBook.GetSheet("Заголовок");
                NPOI.SS.UserModel.ISheet ByPodrSheet;

                if (TitleSheet == null)
                {
                    MessageBox.Show("В шаблоне не найден лист \"Заголовок\", вывод невозможен.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(false);
                }

                if (Protokol.MarkCount == 0)
                {
                    MessageBox.Show("Заполненые показатели не найдены.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(false);
                }

                var Font = WorkBook.CreateFont();
                Font.Color              = NPOI.HSSF.Util.HSSFColor.OliveGreen.Index;
                Font.IsStrikeout        = false;
                Font.FontHeightInPoints = 11;
                Font.FontName           = "Times New Roman";
                Font.Color              = short.MaxValue;

                var StyleLRTD_CC = WorkBook.CreateCellStyle();
                StyleLRTD_CC.BorderBottom      = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRTD_CC.BorderLeft        = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRTD_CC.BorderRight       = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRTD_CC.BorderTop         = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRTD_CC.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Center;
                StyleLRTD_CC.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                StyleLRTD_CC.SetFont(Font);
                StyleLRTD_CC.WrapText = true;

                var ExpStyle = WorkBook.CreateCellStyle();
                ExpStyle.BorderBottom      = NPOI.SS.UserModel.BorderStyle.Thin;
                ExpStyle.BorderLeft        = NPOI.SS.UserModel.BorderStyle.Thin;
                ExpStyle.BorderRight       = NPOI.SS.UserModel.BorderStyle.Thin;
                ExpStyle.BorderTop         = NPOI.SS.UserModel.BorderStyle.Thin;
                ExpStyle.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Center;
                ExpStyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                ExpStyle.SetFont(Font);
                ExpStyle.WrapText   = true;
                ExpStyle.DataFormat = WorkBook.CreateDataFormat().GetFormat("0.00E+00");

                var StyleLRTD_LC = WorkBook.CreateCellStyle();
                StyleLRTD_LC.BorderBottom      = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRTD_LC.BorderLeft        = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRTD_LC.BorderRight       = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRTD_LC.BorderTop         = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRTD_LC.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Left;
                StyleLRTD_LC.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                StyleLRTD_LC.SetFont(Font);
                StyleLRTD_LC.WrapText = true;

                var StyleLRD_CC = WorkBook.CreateCellStyle();
                StyleLRD_CC.BorderLeft        = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRD_CC.BorderRight       = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRD_CC.BorderBottom      = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRD_CC.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Center;
                StyleLRD_CC.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                StyleLRD_CC.SetFont(Font);
                StyleLRD_CC.WrapText = true;

                var StyleLRT_CC = WorkBook.CreateCellStyle();
                StyleLRT_CC.BorderTop         = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRT_CC.BorderLeft        = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRT_CC.BorderRight       = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRT_CC.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Center;
                StyleLRT_CC.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                StyleLRT_CC.SetFont(Font);
                StyleLRT_CC.WrapText = true;

                var StyleRTD_CC = WorkBook.CreateCellStyle();
                StyleRTD_CC.BorderBottom      = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleRTD_CC.BorderRight       = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleRTD_CC.BorderTop         = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleRTD_CC.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Center;
                StyleRTD_CC.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                StyleRTD_CC.SetFont(Font);
                StyleRTD_CC.WrapText = true;

                var StyleLTD_CC = WorkBook.CreateCellStyle();
                StyleLTD_CC.BorderBottom      = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLTD_CC.BorderLeft        = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLTD_CC.BorderTop         = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLTD_CC.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Center;
                StyleLTD_CC.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                StyleLTD_CC.SetFont(Font);
                StyleLTD_CC.WrapText = true;

                var StyleTD_CC = WorkBook.CreateCellStyle();
                StyleTD_CC.BorderTop         = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleTD_CC.BorderBottom      = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleTD_CC.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Center;
                StyleTD_CC.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                StyleTD_CC.SetFont(Font);
                StyleTD_CC.WrapText = true;

                var Objects   = Protokol[0].SPointName + ", " + Protokol.Objects;
                var ProbeType = T.PType.Rows.Get <string>(Protokol[0].PTypeID, C.PType.Name);
                var Location  = Protokol.ObjectsLocations;

                var    Cause = Protokol.SCause;
                string UnDeleteSheetName;
                var    AddInSheetName = T.Podr.Rows.Get <string>(Protokol.PodrID, C.Podr.PSG, C.PSG.Name);

                //Location = T.Object.Rows.Get<string>(Protokol[0].ObjectID, C.Object.OLocationFrom, C.OLocation.Name);
                Location = T.SPoint.Rows.Get <string>(Protokol[0].SPointID, C.SPoint.Name);

                var Probes = Protokol.Numbers;
                var NormID = Protokol[0].NormID;

                UnDeleteSheetName = "Концентрации";
                {
                    int Index = WorkBook.GetSheetIndex(UnDeleteSheetName);
                    ByPodrSheet = WorkBook.GetSheetAt(Index);
                    WorkBook.SetSheetName(Index, "Концентрации");
                }

                if (ByPodrSheet == null)
                {
                    MessageBox.Show("В шаблоне не найден лист \"" + UnDeleteSheetName + "\", вывод невозможен.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(false);
                }

                var OEdTypeIndex   = new SColumn_struct(-1, null);
                var OMethodIndex   = new SColumn_struct(-1, null);
                var OMarkNameIndex = new SColumn_struct(-1, null);
                var NumberIndex    = new SColumn_struct(-1, null);
                var ResultIndex    = new SColumn_struct(-1, null);
                var LimitIndex     = new SColumn_struct(-1, null);

                int RowIndex = -1;
                {
                    var OEdTypeRowIndex   = -1;
                    var OMethodRowIndex   = -1;
                    var OMarkNameRowIndex = -1;
                    var NumberRowIndex    = -1;
                    var ResultRowIndex    = -1;
                    var LimitRowIndex     = -1;

                    var ExistColumn = new CellExchange_Class(ByPodrSheet);

                    ExistColumn.AddExchange("{Метка пробы}", "№ " + T.Sample.Rows.Get <string>(Protokol[0].SampleID, C.Sample.Number), 5);
                    if (NormID > 0)
                    {
                        ExistColumn.AddExchange("{Норматив}", T.Norm.Rows.Get <string>(NormID, C.Norm.Name), 5);
                    }
                    ExistColumn.AddExchange("{номер п/п}", (Cell) =>
                    {
                        NumberRowIndex = Cell.RowIndex;
                        NumberIndex    = new SColumn_struct(Cell);
                    }, 5);
                    ExistColumn.AddExchange("{показатель}", (Cell) =>
                    {
                        OMarkNameRowIndex = Cell.RowIndex;
                        OMarkNameIndex    = new SColumn_struct(Cell);
                    }, 5);
                    ExistColumn.AddExchange("{ед.изм.}", (Cell) =>
                    {
                        OEdTypeRowIndex = Cell.RowIndex;
                        OEdTypeIndex    = new SColumn_struct(Cell);
                    }, 5);
                    ExistColumn.AddExchange("{методика}", (Cell) =>
                    {
                        OMethodRowIndex = Cell.RowIndex;
                        OMethodIndex    = new SColumn_struct(Cell);
                    }, 5);
                    ExistColumn.AddExchange("{результат}", (Cell) =>
                    {
                        ResultRowIndex = Cell.RowIndex;
                        ResultIndex    = new SColumn_struct(Cell);

                        CopyStyleFromCell(ExpStyle, Cell);
                    }, 5);
                    ExistColumn.AddExchange("{лимит}", (Cell) =>
                    {
                        LimitRowIndex = Cell.RowIndex;
                        LimitIndex    = new SColumn_struct(Cell);
                    }, 5);


                    ExistColumn.Exchange(0, 25, 0, 25);

                    if (NumberRowIndex == -1 || OMarkNameRowIndex == -1 || OEdTypeRowIndex == -1 || OMethodRowIndex == -1 || ResultRowIndex == -1)
                    {
                        MessageBox.Show("Не все табличные метки найдены.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return(false);
                    }

                    if (LimitRowIndex > -1 && LimitRowIndex != NumberRowIndex || NumberRowIndex != OMarkNameRowIndex || OMarkNameRowIndex != OEdTypeRowIndex || OEdTypeRowIndex != OMethodRowIndex || OMethodRowIndex != ResultRowIndex)
                    {
                        MessageBox.Show("Все табличные метки должны распологаться в одной строке.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return(false);
                    }

                    if (NormID == 0 && LimitRowIndex > -1)
                    {
                        ByPodrSheet.SetColumnWidth(ResultIndex.Index, ByPodrSheet.GetColumnWidth(ResultIndex.Index) + ByPodrSheet.GetColumnWidth(LimitIndex.Index));
                        ByPodrSheet.SetColumnHidden(LimitIndex.Index, true);
                    }

                    RowIndex = NumberRowIndex;
                }

                ByPodrSheet.ShiftRows(RowIndex, ByPodrSheet.LastRowNum, Protokol.MarkCount - 1);

                int ONumber = 0;

                for (int i = 0; i < Protokol.MarkCount; i++)
                {
                    var Row = ByPodrSheet.CreateRow(RowIndex++);

                    if (RowIndex > -1)
                    {
                        ATMisc.SetValue(Row, ++ONumber, NumberIndex.Index, NumberIndex.Style);
                    }

                    if (LimitIndex.Index > -1)
                    {
                        var Norm = RCache.Marks[Protokol.GetMarkID(i)].GetNorm(Protokol.GetNormID(i));

                        switch (Norm.NType)
                        {
                        case data.NType.Mark:
                            ATMisc.SetValue(Row, Norm.Range.Range, LimitIndex.Index, LimitIndex.Style);
                            break;

                        case data.NType.PodrV:
                        case data.NType.PodrK:
                        case data.NType.PodrAll:
                            var PIndex = RCache.Marks.Norms.GetPodrIndex(Norm.NormID, T.SPoint.Rows.Get_UnShow <uint>(Protokol[0].SPointID, C.SPoint.Podr));
                            ATMisc.SetValue(Row, Norm.Station(PIndex).Range, LimitIndex.Index, LimitIndex.Style);
                            break;

                        case data.NType.Volume:
                            var VIndex = RCache.Marks.Norms.GetVolumeIndex(Norm.NormID, T.SPoint.Rows.Get_UnShow <uint>(Protokol[0].SPointID, C.SPoint.Object, C.Object.OLocationFrom));
                            ATMisc.SetValue(Row, Norm.Volume(VIndex).Range, LimitIndex.Index, LimitIndex.Style);
                            break;
                        }

                        ATMisc.SetValue(Row, Protokol.GetMarkAmount(i), ResultIndex.Index, ResultIndex.Style);
                    }
                    else
                    {
                        if (Protokol.IsSpetialOut(i))
                        {
                            ATMisc.SetValue(Row, Protokol.GetSpetialOut(i), ResultIndex.Index, ResultIndex.Style);
                        }
                        else
                        {
                            ATMisc.SetValue(Row, Protokol.GetMarkAmount(i), ResultIndex.Index, ResultIndex.Style);
                        }
                    }

                    ATMisc.SetValue(Row, Protokol.GetMethod(i), OMethodIndex.Index, OMethodIndex.Style);
                    ATMisc.SetValue(Row, Protokol.GetMarkName(i), OMarkNameIndex.Index, OMarkNameIndex.Style);
                    ATMisc.SetValue(Row, Protokol.GetMarkEdType(i), OEdTypeIndex.Index, OEdTypeIndex.Style);

                    //Вывожу концентрацию как есть
                }

                for (int i = 0; i < WorkBook.NumberOfSheets; i++)
                {
                    if (WorkBook.GetSheetAt(i).SheetName.ToLower() != "заголовок" && WorkBook.GetSheetAt(i).SheetName.ToLower() != "концентрации")
                    {
                        WorkBook.RemoveSheetAt(i);
                        i--;
                    }
                }

                string PeopleNames;

                {
                    var Ppls = new List <uint>();

                    for (int i = 0; i < Protokol.SampleCount; i++)
                    {
                        for (int j = 0; j < Ppls.Count; j++)
                        {
                            if (Ppls[j] == Protokol[i].PeopleID)
                            {
                                goto Finded;
                            }
                        }

                        Ppls.Add(Protokol[i].PeopleID);

                        Finded :;
                    }

                    PeopleNames = Misc.GetShortFIO(Ppls[0]);

                    for (int i = 1; i < Ppls.Count; i++)
                    {
                        PeopleNames += ", " + Misc.GetShortFIO(Ppls[i]);
                    }
                }

                DateTime DT;
                {
                    int Year, Month;

                    ATMisc.GetYearMonthFromYM(Protokol.YM, out Year, out Month);

                    DT = new DateTime(Year, Month, Protokol.Day);
                }

                var ProtokolNum = ProtokolNumber(Protokol);

                GetProtokolsExchanges(TitleSheet
                                      , DT.Year
                                      , ProtokolNum
                                      , Objects
                                      , Objects
                                      , ProbeType
                                      , Location
                                      , Protokol.DateOstr
                                      , Protokol.DateP
                                      , Protokol.StrTime
                                      , PeopleNames
                                      , Cause
                                      , Probes
                                      , DT.Day.ToString()
                                      , ATMisc.GetMonthName2(DT.Month)
                                      , DT.Month.ToString()
                                      , RCache.PSG.GetMethodName(Protokol.PodrID)
                                      , T.PaPoS.Rows.Get <string>(Protokol.PaPoSID, C.PaPoS.Name)
                                      , T.Podr.Rows.Get <string>(Protokol.PodrID, C.Podr.FllName)
                                      , T.Podr.Rows.Get <string>(Protokol.PodrID, C.Podr.ShrName)
                                      , T.Podr.Rows.Get <string>(Protokol.PodrID, C.Podr.Contact)
                                      , Protokol.Act).Exchange(0, 25, 0, 25);
                {
                    var Exchanges = new CellExchange_Class(TitleSheet);

                    Exchanges.ClearExchanges();

                    Exchanges.AddColumn("{имя свойства}");
                    Exchanges.AddColumn("{ед. свойства}");
                    Exchanges.AddColumn("{значение свойства}");
                }
                {
                    var Exchanges = new CellExchange_Class(ByPodrSheet);

                    Exchanges.AddExchange("{должность ответственного}", T.People.Rows.Get <string>(RCache.PSG.GetPeopleID((data.PSG)T.Podr.Rows.Get_UnShow <uint>(Protokol[0].PodrID, C.Podr.PSG)), C.People.Prfssn, C.Prfssn.Name), 5);
                    Exchanges.AddExchange("{ФИО ответственного}", Misc.GetShortFIO(RCache.PSG.GetPeopleID((data.PSG)T.Podr.Rows.Get_UnShow <uint>(Protokol[0].PodrID, C.Podr.PSG))), 5);
                    Exchanges.AddExchange("{Номер протокола}", ProtokolNum, 5);
                    Exchanges.AddExchange("{Дата}", DT.ToShortDateString(), 5);

                    SetResp(Exchanges, Protokol.PodrID, data.TResp.LaboratoryProtokol);
                }

                return(SaveExcel(WorkBook, NewFileName, Open));
            }
            else
            {
                if (Open)
                {
                    System.Diagnostics.Process.Start(NewFileName);
                }

                return(true);
            }
        }
Ejemplo n.º 15
0
        public static bool OtchProtokolType2(Protokols_class.SGroup_class.Protokol_class Protokol, bool CreateNew = true, bool Open = true)
        {
            {
                var MsgErr = "";

                for (int i = 0; i < Protokol.MarkCount; i++)
                {
                    var PAMIndex = -1;

                    for (int j = 0; j < Protokol.SampleCount; j++)
                    {
                        if (Protokol[j][i].LocalAlow && Protokol[j][i].Method.Length > 0)
                        {
                            if (PAMIndex < 0)
                            {
                                PAMIndex = j;
                            }
                            else if (Protokol[j][i].Method != Protokol[PAMIndex][i].Method)
                            {
                                MsgErr += '\n' + Protokol[j][i].Mark + " имеет различные методы у нормативов " + T.Object.Rows.Get <string>(Protokol[j].ObjectID, C.Object.Norm, C.Norm.Name) + " и " + T.Object.Rows.Get <string>(Protokol[PAMIndex].ObjectID, C.Object.Norm, C.Norm.Name);
                            }
                        }
                    }
                }

                if (MsgErr.Length > 0)
                {
                    MessageBox.Show(MsgErr, "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(false);
                }
            }

            string NewFileName;

            {
                int Month, Year;

                ATMisc.GetYearMonthFromYM(Employe_Form.SPoints.YM, out Year, out Month);
                {
                    NewFileName = Application.StartupPath + "\\Отчеты\\";

                    if (!Directory.Exists(NewFileName))
                    {
                        Directory.CreateDirectory(NewFileName);
                    }

                    NewFileName += T.Podr.Rows.Get <string>(Protokol.PodrID, C.Podr.ShrName) + "\\";

                    if (!Directory.Exists(NewFileName))
                    {
                        Directory.CreateDirectory(NewFileName);
                    }

                    NewFileName += ATMisc.GetMonthName1(Month) + "\\";

                    if (!Directory.Exists(NewFileName))
                    {
                        Directory.CreateDirectory(NewFileName);
                    }
                }

                NewFileName += ProtokolFileName(Protokol);
            }

            if (CreateNew || !File.Exists(NewFileName))
            {
                var WorkBook = ATMisc.GetGenericExcel("Протокол испытаний тип 2.xls");

                if (WorkBook == null)
                {
                    return(false);
                }

                var TitleSheet = WorkBook.GetSheet("Заголовок");
                NPOI.SS.UserModel.ISheet Sheet1;

                if (TitleSheet == null)
                {
                    MessageBox.Show("В шаблоне не найден лист \"Заголовок\", вывод невозможен.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(false);
                }

                var DT = Protokol.Date;

                GetProtokolsExchanges(TitleSheet
                                      , ATMisc.GetDateTimeFromYM(Employe_Form.SPoints.YM).Year
                                      , Protokol.Number.ToString() + "-АВ-" + DT.Month.ToString() + "/" + DT.Year.ToString()
                                      , Protokol.Objects + ' ' + T.Podr.Rows.Get <string>(Protokol.PodrID, C.Podr.ShrName)
                                      , Protokol.Objects
                                      , Protokol.ProtoType
                                      , Protokol.ObjectsLocations
                                      , Protokol.DateOstr
                                      , Protokol.DateP
                                      , Protokol.StrTime
                                      , Protokol.Peoples
                                      , Protokol.Causes
                                      , Protokol.Numbers
                                      , Protokol.Day.ToString()
                                      , ATMisc.GetMonthName2(DT.Month)
                                      , DT.Month.ToString()
                                      , RCache.PSG.GetMethodName(Protokol.PodrID)
                                      , T.PaPoS.Rows.Get <string>(Protokol.PaPoSID, C.PaPoS.Name)
                                      , T.Podr.Rows.Get <string>(Protokol.PodrID, C.Podr.FllName)
                                      , T.Podr.Rows.Get <string>(Protokol.PodrID, C.Podr.ShrName)
                                      , T.Podr.Rows.Get <string>(Protokol.PodrID, C.Podr.Contact)
                                      , 0).Exchange();

                {
                    var Exchanges = new CellExchange_Class(TitleSheet);

                    Exchanges.ClearExchanges();

                    Exchanges.AddColumn("{имя свойства}");
                    Exchanges.AddColumn("{ед. свойства}");
                    Exchanges.AddColumn("{значение свойства}");

                    if (Exchanges.CheckTableColumns())
                    {
                        for (int i = 0; i < Protokol[0].TCSCount; i++)
                        {
                            var Values = new object[3];

                            Values[0] = Protokol[0].TCSName(i);
                            Values[1] = Protokol[0].TCSEdType(i);
                            Values[2] = Protokol[0].TCSValue(i);

                            Exchanges.SetRow(Values);
                        }
                    }
                }

                if (Protokol.MarkCount == 0)
                {
                    MessageBox.Show("Заполненые показатели не найдены.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(false);
                }

                string UnDeleteSheetName;

                switch (Protokol.SGroup)
                {
                case data.SGroup.Group2:

                    UnDeleteSheetName = "Изначальный";
                    {
                        int Index = WorkBook.GetSheetIndex(UnDeleteSheetName);
                        Sheet1 = WorkBook.GetSheetAt(Index);
                        WorkBook.SetSheetName(Index, "Концентрации");
                    }

                    if (Sheet1 == null)
                    {
                        MessageBox.Show("В шаблоне не найден лист \"" + UnDeleteSheetName + "\", вывод невозможен.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return(false);
                    }

                    var SPointIndex    = new SColumn_struct(-1, null);
                    var OEdTypeIndex   = new SColumn_struct(-1, null);
                    var OMethodIndex   = new SColumn_struct(-1, null);
                    var OMarkNameIndex = new SColumn_struct(-1, null);
                    var NumberIndex    = new SColumn_struct(-1, null);
                    var ResultIndex    = new SColumn_struct(-1, null);
                    var ProbeIndex     = new SColumn_struct(-1, null);
                    int RowIndex       = -1;

                    var SPStyle = new NPOI.SS.UserModel.ICellStyle[3];     //верх, середина, низ
                    var PStyle  = new NPOI.SS.UserModel.ICellStyle[3];     //верх, середина, низ
                    {
                        var OEdTypeRowIndex   = -1;
                        var OMethodRowIndex   = -1;
                        var OMarkNameRowIndex = -1;
                        var NumberRowIndex    = -1;
                        var SPointRowIndex    = -1;
                        var ResultRowIndex    = -1;
                        var ProbeRowIndex     = -1;

                        var ExistColumn = new CellExchange_Class(Sheet1);

                        ExistColumn.AddExchange("{номер п/п}", (Cell) =>
                        {
                            NumberRowIndex = Cell.RowIndex;
                            NumberIndex    = new SColumn_struct(Cell);
                        }, 5);
                        ExistColumn.AddExchange("{место отбора}", (Cell) =>
                        {
                            SPointRowIndex = Cell.RowIndex;
                            SPointIndex    = new SColumn_struct(Cell);

                            SPStyle[0] = Sheet1.Workbook.CreateCellStyle();     //верх
                            CopyStyleFromCell(SPStyle[0], Cell); SPStyle[0].BorderBottom = NPOI.SS.UserModel.BorderStyle.None;
                            SPStyle[1] = Sheet1.Workbook.CreateCellStyle();     //середина
                            CopyStyleFromCell(SPStyle[1], Cell); SPStyle[1].BorderBottom = SPStyle[1].BorderTop = NPOI.SS.UserModel.BorderStyle.None;
                            SPStyle[2] = Sheet1.Workbook.CreateCellStyle();     //низ
                            CopyStyleFromCell(SPStyle[2], Cell); SPStyle[2].BorderTop = NPOI.SS.UserModel.BorderStyle.None;
                        }, 5);
                        ExistColumn.AddExchange("{показатель}", (Cell) =>
                        {
                            OMarkNameRowIndex = Cell.RowIndex;
                            OMarkNameIndex    = new SColumn_struct(Cell);
                        }, 5);
                        ExistColumn.AddExchange("{проба}", (Cell) =>
                        {
                            ProbeRowIndex = Cell.RowIndex;
                            ProbeIndex    = new SColumn_struct(Cell);

                            PStyle[0] = Sheet1.Workbook.CreateCellStyle();     //верх
                            CopyStyleFromCell(PStyle[0], Cell); PStyle[0].BorderBottom = NPOI.SS.UserModel.BorderStyle.None;
                            PStyle[1] = Sheet1.Workbook.CreateCellStyle();     //середина
                            CopyStyleFromCell(PStyle[1], Cell); PStyle[1].BorderBottom = PStyle[1].BorderTop = NPOI.SS.UserModel.BorderStyle.None;
                            PStyle[2] = Sheet1.Workbook.CreateCellStyle();     //низ
                            CopyStyleFromCell(PStyle[2], Cell); PStyle[2].BorderTop = NPOI.SS.UserModel.BorderStyle.None;
                        }, 5);
                        ExistColumn.AddExchange("{ед.изм.}", (Cell) =>
                        {
                            OEdTypeRowIndex = Cell.RowIndex;
                            OEdTypeIndex    = new SColumn_struct(Cell);
                        }, 5);
                        ExistColumn.AddExchange("{методика}", (Cell) =>
                        {
                            OMethodRowIndex = Cell.RowIndex;
                            OMethodIndex    = new SColumn_struct(Cell);
                        }, 5);
                        ExistColumn.AddExchange("{результат}", (Cell) =>
                        {
                            ResultRowIndex = Cell.RowIndex;
                            ResultIndex    = new SColumn_struct(Cell);
                        }, 5);
                        ExistColumn.AddExchange("{Дата}", DT.ToShortDateString(), 5);
                        ExistColumn.AddExchange("{Номер протокола}", Protokol.Number.ToString() + "-АВ-" + DT.Month.ToString() + "/" + DT.Year.ToString(), 5);

                        SetResp(ExistColumn, Protokol.PodrID, data.TResp.LaboratoryProtokol);

                        if (SPointRowIndex == -1 || OMarkNameRowIndex == -1 || OEdTypeRowIndex == -1 || OMethodRowIndex == -1 || ResultRowIndex == -1)
                        {
                            MessageBox.Show("Не все табличные метки найдены.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return(false);
                        }

                        if (ProbeRowIndex > -1 && ProbeRowIndex != OMarkNameRowIndex || NumberRowIndex > -1 && NumberRowIndex != OMarkNameRowIndex || SPointRowIndex != OMarkNameRowIndex || OMarkNameRowIndex != OEdTypeRowIndex || OEdTypeRowIndex != OMethodRowIndex || OMethodRowIndex != ResultRowIndex)
                        {
                            MessageBox.Show("Все табличные метки должны распологаться в одной строке.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return(false);
                        }

                        RowIndex = SPointRowIndex;
                    }

                    Sheet1.ShiftRows(RowIndex, Sheet1.LastRowNum, Protokol.TableCount * Protokol.MarkCount - 1);

                    int ONumber = 0;

                    for (int i = 0; i < Protokol.TableCount; i++)
                    {
                        NPOI.SS.UserModel.IRow Row;

                        for (int j = 0; j < Protokol.MarkCount; j++)
                        {
                            Row = Sheet1.CreateRow(RowIndex++);

                            if (NumberIndex.Index > -1)
                            {
                                ATMisc.SetValue(Row, ++ONumber, NumberIndex.Index, NumberIndex.Style);
                            }

                            if (ProbeIndex.Index > -1)
                            {
                                ATMisc.SetValue(Row, Protokol[i].Number, ProbeIndex.Index, ProbeIndex.Style);
                            }

                            ATMisc.SetValue(Row, Protokol.GetMethod(j), OMethodIndex.Index, OMethodIndex.Style);
                            ATMisc.SetValue(Row, Protokol.GetMarkName(j), OMarkNameIndex.Index, OMarkNameIndex.Style);
                            ATMisc.SetValue(Row, Protokol.GetMarkEdType(j), OEdTypeIndex.Index, OEdTypeIndex.Style);

                            if (Protokol.IsSpetialOut(j, i))
                            {
                                ATMisc.SetValue(Row, Protokol.GetSpetialOut(j, i), ResultIndex.Index, ResultIndex.Style);
                            }
                            else
                            {
                                ATMisc.SetValue(Row, Protokol.GetMarkAmount(j, i), ResultIndex.Index, ResultIndex.Style);
                            }
                        }

                        Row = Sheet1.GetRow(RowIndex - Protokol.MarkCount);

                        switch (Protokol.MarkCount)
                        {
                        case 1:
                            ATMisc.SetValue(Row, Protokol.GetTableName(i), SPointIndex.Index, SPointIndex.Style);
                            break;

                        case 2:
                            Sheet1.AddMergedRegion(new CellRangeAddress(RowIndex - Protokol.MarkCount, RowIndex - 1, SPointIndex.Index, SPointIndex.Index));
                            ATMisc.SetValue(Row, Protokol.GetTableName(i), SPointIndex.Index, SPStyle[0]);
                            Sheet1.GetRow(RowIndex - 1).CreateCell(SPointIndex.Index).CellStyle = SPStyle[2];

                            if (ProbeIndex.Index > -1)
                            {
                                Sheet1.GetRow(RowIndex - 1).CreateCell(ProbeIndex.Index).CellStyle = PStyle[2];
                                Sheet1.AddMergedRegion(new CellRangeAddress(RowIndex - Protokol.MarkCount, RowIndex - 1, ProbeIndex.Index, ProbeIndex.Index));
                            }
                            break;

                        default:
                            Sheet1.AddMergedRegion(new CellRangeAddress(RowIndex - Protokol.MarkCount, RowIndex - 1, SPointIndex.Index, SPointIndex.Index));

                            ATMisc.SetValue(Row, Protokol.GetTableName(i), SPointIndex.Index, SPStyle[0]);

                            if (ProbeIndex.Index > -1)
                            {
                                Sheet1.GetRow(RowIndex - 1).CreateCell(ProbeIndex.Index).CellStyle  = PStyle[2];
                                Sheet1.GetRow(RowIndex - 1).CreateCell(SPointIndex.Index).CellStyle = PStyle[2];
                                Sheet1.AddMergedRegion(new CellRangeAddress(RowIndex - Protokol.MarkCount, RowIndex - 1, ProbeIndex.Index, ProbeIndex.Index));

                                for (int s = Protokol.MarkCount - 2; s > 1; s--)
                                {
                                    Sheet1.GetRow(RowIndex - 1 - s).GetCell(ProbeIndex.Index).CellStyle = PStyle[1];
                                    //Sheet1.GetRow(RowIndex - 1 - s).GetCell(SPointIndex.Index).CellStyle = SPStyle[1];    //это тут лишнее
                                }

                                Sheet1.GetRow(RowIndex - 1).CreateCell(ProbeIndex.Index).CellStyle = PStyle[2];
                                Sheet1.GetRow(RowIndex - 1).GetCell(SPointIndex.Index).CellStyle   = SPStyle[2];
                            }
                            else
                            {
                                for (int s = Protokol.MarkCount - 2; s > 1; s--)
                                {
                                    Sheet1.GetRow(RowIndex - 1 - s).GetCell(SPointIndex.Index).CellStyle = SPStyle[1];
                                }

                                Sheet1.GetRow(RowIndex - 1).GetCell(SPointIndex.Index).CellStyle = SPStyle[2];
                            }
                            break;
                        }
                    }
                    break;

                default: throw new Exception("Не верный тип протокола");
                }

                for (int i = 0; i < WorkBook.NumberOfSheets; i++)
                {
                    if (WorkBook.GetSheetAt(i).SheetName.ToLower() != "заголовок" && WorkBook.GetSheetAt(i).SheetName.ToLower() != "концентрации")
                    {
                        WorkBook.RemoveSheetAt(i);
                        i--;
                    }
                }

                return(SaveExcel(WorkBook, NewFileName, Open));
            }
            else
            {
                if (Open)
                {
                    System.Diagnostics.Process.Start(NewFileName);
                }

                return(true);
            }
        }
Ejemplo n.º 16
0
        public static bool OtchMassOutgo(uint PodrID, int YMFrom, Podrs_class.PeriodType pt, uint OTypeID, bool ShowErrorMessage = true, bool CreateNew = true, bool Open = true)
        {
            bool Returning = false;

            RCache.Podrs = new RCache.Podrs_class();
            var Podrs = new Podrs_class(PodrID, pt, YMFrom, OTypeID);

            int Year, Month;

            ATMisc.GetYearMonthFromYM(YMFrom, out Year, out Month);
            if (Podrs.MarksCount == 0)
            {
                if (ShowErrorMessage)
                {
                    MessageBox.Show("Показатели не обнаружены", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                return(false);
            }

            {
                int tMCount = 0;

                for (int i = 0; i < Podrs.MarkCount; i++)
                {
                    if (Podrs.ShowMark(i))
                    {
                        tMCount++;
                    }
                }

                if (tMCount == 0)
                {
                    if (ShowErrorMessage)
                    {
                        MessageBox.Show("Показатели не обнаружены", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    return(false);
                }
            }

            G.OPType.QUERRY().SHOW.DO();

            var StylesEDType = new NPOI.SS.UserModel.ICellStyle[G.OPType.Rows.Count];

            if (!Directory.Exists(Application.StartupPath + "\\Отчеты"))
            {
                Directory.CreateDirectory(Application.StartupPath + "\\Отчеты");
            }

            for (int i = 0; i < Podrs.Count; i++)   //подразделения
            {
                if (Podrs[i].MarksCount > 0)
                {
                    var NewFileName = Application.StartupPath + "\\Отчеты\\Расчет массы " + Podrs.PeriodName() + ' ' + Year.ToString() + ' ' + T.Podr.Rows.Get <string>(Podrs[i].PodrID, C.Podr.ShrName) + ".xls";

                    if (CreateNew || !File.Exists(NewFileName))
                    {
                        var WorkBook = ATMisc.GetGenericExcel("Расчет массы.xls");

                        if (WorkBook == null)
                        {
                            return(false);
                        }

                        var Sheet1 = WorkBook.GetSheet("Таблица");

                        if (Sheet1 == null)
                        {
                            if (ShowErrorMessage)
                            {
                                MessageBox.Show("В шаблоне не найден лист \"Заголовок\", вывод невозможен.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                            return(false);
                        }

                        var Exchanges = new CellExchange_Class(Sheet1);

                        NPOI.SS.UserModel.ICellStyle NumberStyle = null
                        , NameStyle   = null
                        , EdTypeStyle = null
                        , CodeStyle   = null
                        , FactStyle   = null
                        , BackStyle   = null
                        , CalcStyle   = null
                        , MassStyle   = null;

                        var Podr = RCache.Podrs[Podrs[i].PodrID];

                        Exchanges.AddExchange("{сооружение}", Podr.ShortName, 2);

                        for (int s = 0; s < Podrs[i].Count; s++)
                        {
                            if (Podrs[i][s].ObjectID > 0)
                            {
                                Exchanges.AddExchange("{объект}", T.Object.Rows.Get <string>(Podrs[i][s].ObjectID, C.Object.OType, C.OType.Name).ToLower(), 2);
                                break;
                            }
                        }

                        if (Podr.Ppls.Count == 0 || (data.PnMean)Podr.Ppls[0].PnMeanID != data.PnMean.Nachalnic)
                        {
                            if (ShowErrorMessage)
                            {
                                MessageBox.Show("У сооружения " + Podr.ShortName + " нет начальника.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                            return(false);
                        }

                        Exchanges.AddExchange("{начальник сооружения}", Podr.Ppls[0].PeopleName, 2);
                        Exchanges.AddExchange("{профессия начальника}", Podr.Ppls[0].Profession, 2);
                        {
                            var PeopleID = RCache.PSG.GetPeopleID(Podr.PSG);

                            Exchanges.AddExchange("{профессия ответственного}", T.People.Rows.Get <string>(PeopleID, C.People.Prfssn, C.Prfssn.Name), 2);
                            Exchanges.AddExchange("{ФИО ответственного}", Misc.GetShortFIO(PeopleID), 2);
                        }
                        Exchanges.AddExchange("{год}", Year.ToString(), 5);

                        int NumberIndex = -1, NameIndex = -1, EdTypeIndex = -1, CodeIndex = -1, FactIndex = -1, BackIndex = -1, CalcIndex = -1, MassIndex = -1, RowIndex = -1;
                        {
                            int NumberRowIndex = -1, NameRowIndex = -1, EdTypeRowIndex = -1, CodeRowIndex = -1, FactRowIndex = -1, BackRowIndex = -1, CalcRowIndex = -1, MassRowIndex = -1;

                            Exchanges.AddExchange("{выпуск}", Cell =>
                            {
                                NumberIndex    = Cell.ColumnIndex;
                                NumberRowIndex = Cell.RowIndex;
                                NumberStyle    = Cell.CellStyle;
                            }, 1);
                            Exchanges.AddExchange("{имя}",
                                                  Cell =>
                            {
                                NameIndex    = Cell.ColumnIndex;
                                NameRowIndex = Cell.RowIndex;
                                NameStyle    = Cell.CellStyle;
                            }, 1);
                            Exchanges.AddExchange("{едизм}",
                                                  Cell =>
                            {
                                EdTypeIndex    = Cell.ColumnIndex;
                                EdTypeRowIndex = Cell.RowIndex;
                                EdTypeStyle    = Cell.CellStyle;
                            }, 1);
                            Exchanges.AddExchange("{код}",
                                                  Cell =>
                            {
                                CodeIndex    = Cell.ColumnIndex;
                                CodeRowIndex = Cell.RowIndex;
                                CodeStyle    = Cell.CellStyle;
                            }, 1);
                            Exchanges.AddExchange("{факт}",
                                                  Cell =>
                            {
                                FactIndex    = Cell.ColumnIndex;
                                FactRowIndex = Cell.RowIndex;
                                FactStyle    = Cell.CellStyle;
                            }, 1);
                            Exchanges.AddExchange("{фон}",
                                                  Cell =>
                            {
                                BackIndex    = Cell.ColumnIndex;
                                BackRowIndex = Cell.RowIndex;
                                BackStyle    = Cell.CellStyle;
                            }, 1);
                            Exchanges.AddExchange("{расчет}",
                                                  Cell =>
                            {
                                CalcIndex    = Cell.ColumnIndex;
                                CalcRowIndex = Cell.RowIndex;
                                CalcStyle    = Cell.CellStyle;
                            }, 1);
                            Exchanges.AddExchange("{масса}",
                                                  Cell =>
                            {
                                MassIndex    = Cell.ColumnIndex;
                                MassRowIndex = Cell.RowIndex;

                                MassStyle = Cell.CellStyle;

                                for (int j = 0; j < StylesEDType.Length; j++)
                                {
                                    StylesEDType[j] = WorkBook.CreateCellStyle();
                                    CopyStyleFromCell(StylesEDType[j], Cell);
                                    StylesEDType[j].DataFormat = WorkBook.CreateDataFormat().GetFormat("#,##0.000\" " + G.OPType.Rows.Get <string>(j, C.OPType.EdTypeT, C.EdType.Name) + "\"");
                                }
                            }, 1);

                            Exchanges.AddExchange("{период}", Podrs.PeriodName(), 2);

                            SetResp(Exchanges, Podr.ID, data.TResp.LaboratoryProtokol);

                            if (NameRowIndex == NumberRowIndex && NumberRowIndex == FactRowIndex && NumberRowIndex == BackRowIndex && BackRowIndex == CalcRowIndex && NumberRowIndex == MassRowIndex)
                            {
                                if (MassRowIndex == -1)
                                {
                                    if (ShowErrorMessage)
                                    {
                                        MessageBox.Show("Критически важные колонки таблицы не найдены(выпуск,наименование, факт, фон, расчет, масса).", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                    }
                                    return(false);
                                }
                            }
                            else
                            {
                                if (ShowErrorMessage)
                                {
                                    MessageBox.Show("Метки всех колонок должны находиться на одной строке.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                }
                                return(false);
                            }

                            RowIndex = NumberRowIndex;

                            Sheet1.ShiftRows(RowIndex + 1, Sheet1.LastRowNum, -1);
                        }

                        Sheet1.SetColumnHidden(BackIndex, !Podrs.AllowBack);
                        Sheet1.SetColumnHidden(CalcIndex, !Podrs.AllowBack);

                        if (!Podrs.AllowBack)
                        {
                            int NewWidth = Sheet1.GetColumnWidth(BackIndex) + Sheet1.GetColumnWidth(FactIndex) + Sheet1.GetColumnWidth(CalcIndex);
                            Sheet1.SetColumnWidth(FactIndex, NewWidth);
                        }

                        for (int j = 0; j < Podrs[i].Count; j++)   //выпуск
                        {
                            Sheet1.ShiftRows(RowIndex, Sheet1.LastRowNum, Podrs[i][j].Count + 2);

                            var LastRow = Sheet1.CreateRow(RowIndex + Podrs[i][j].Count);

                            if (EdTypeIndex > -1)
                            {
                                ATMisc.SetValue(LastRow, "тыс.м3", EdTypeIndex, EdTypeStyle);
                            }

                            ATMisc.SetValue(LastRow, T.Object.Rows.Get <string>(Podrs[i][j].ObjectID, C.Object.OLocationTo, C.OLocation.Name), MassIndex, MassStyle);

                            if (Podrs[i][j].Count > 0)
                            {
                                for (int k = 0; k < Podrs[i][j].Count; k++)
                                {
                                    var MarkID = Podrs[i][j].MarkID(k);

                                    var Row = Sheet1.CreateRow(RowIndex++);
                                    if (NameIndex > -1)
                                    {
                                        ATMisc.SetValue(Row, T.Mark.Rows.Get <string>(MarkID, C.Mark.Name), NameIndex, NameStyle);
                                    }
                                    if (EdTypeIndex > -1)
                                    {
                                        ATMisc.SetValue(Row, T.Mark.Rows.Get <string>(MarkID, C.Mark.EdType, C.EdType.Name), EdTypeIndex, EdTypeStyle);
                                    }
                                    if (CodeIndex > -1)
                                    {
                                        ATMisc.SetValue(Row, T.Mark.Rows.Get <int>(MarkID, C.Mark.Code), CodeIndex, CodeStyle);
                                    }

                                    double Front = RCache.Marks[MarkID].GetRound(Podrs[i][j][k].FMiddle)
                                    , Back       = RCache.Marks[MarkID].GetRound(Podrs[i][j][k].BMiddle);

                                    ATMisc.SetValue(Row, Front, FactIndex, FactStyle);

                                    ATMisc.SetValue(Row, Back, BackIndex, BackStyle);

                                    ATMisc.SetFormula(Row, "if(" + GetColCharName(FactIndex) + RowIndex.ToString() + "<=" + GetColCharName(BackIndex) + RowIndex.ToString() + ", \"<=фон\", " + GetColCharName(FactIndex) + RowIndex.ToString() + "-" + GetColCharName(BackIndex) + RowIndex.ToString() + ")", CalcIndex, CalcStyle);
                                    ATMisc.SetFormula(Row, "if(" + GetColCharName(CalcIndex) + RowIndex.ToString() + "=\"<=фон\",\"\", " + GetColCharName(CalcIndex) + RowIndex.ToString() + "*" + GetColCharName(FactIndex) + (LastRow.RowNum + 1).ToString() + "*" + DTSF(RCache.Marks[MarkID].Multyply) + ")", MassIndex, StylesEDType[G.OPType.Rows.GetIndex(RCache.Marks[MarkID].OPTypeID)]);

                                    if (NumberIndex > -1)
                                    {
                                        ATMisc.SetValue(Row, "", NumberIndex, NumberStyle);
                                    }
                                }

                                if (NumberIndex > -1)
                                {
                                    ATMisc.SetValue(Sheet1.GetRow(RowIndex - Podrs[i][j].Count), Podrs[i][j].VShortName + " [" + (j + 1).ToString() + "]", NumberIndex, NumberStyle);
                                }

                                if (NumberIndex > -1)
                                {
                                    ATMisc.SetValue(LastRow, "", NumberIndex, NumberStyle);
                                }
                            }
                            else
                            {
                                if (NumberIndex > -1)
                                {
                                    ATMisc.SetValue(LastRow, Podrs[i][j].VShortName + " [" + (j + 1).ToString() + "]", NumberIndex, NumberStyle);
                                }
                            }
                            RowIndex++;

                            ATMisc.SetValue(LastRow, Podrs[i][j].VolumeSumm, FactIndex, FactStyle);
                            ATMisc.SetValue(LastRow, "Объём сброшеных вод", NameIndex, NameStyle);

                            if (EdTypeIndex > -1)
                            {
                                ATMisc.SetValue(LastRow, "тыс.м3", EdTypeIndex, EdTypeStyle);
                            }

                            if (CodeIndex > -1)
                            {
                                ATMisc.SetValue(LastRow, "", CodeIndex, CodeStyle);
                            }

                            ATMisc.SetValue(LastRow, "", BackIndex, BackStyle);
                            ATMisc.SetValue(LastRow, "", CalcIndex, CalcStyle);

                            Sheet1.CreateRow(RowIndex++).Height = 50;
                        }

                        Returning = Returning || SaveExcel(WorkBook, NewFileName, Open);
                    }
                    else if (Open && File.Exists(NewFileName))
                    {
                        System.Diagnostics.Process.Start(NewFileName);
                        Returning = true;
                    }
                }
            }

            return(Returning);
        }
Ejemplo n.º 17
0
        public static bool OtchProtokolType1(Protokols_class.SGroup_class.Protokol_class Protokol, bool CreateNew = true, bool Open = true)
        {
            {
                var MsgErr = "";

                for (int i = 0; i < Protokol.MarkCount; i++)
                {
                    var PAMIndex = -1;

                    for (int j = 0; j < Protokol.SampleCount; j++)
                    {
                        if (Protokol[j][i].LocalAlow && Protokol[j][i].Method.Length > 0)
                        {
                            if (PAMIndex < 0)
                            {
                                PAMIndex = j;
                            }
                            else if (Protokol[j][i].Method != Protokol[PAMIndex][i].Method)
                            {
                                MsgErr += '\n' + Protokol[j][i].Mark + " имеет различные методы у нормативов " + T.Object.Rows.Get <string>(Protokol[j].ObjectID, C.Object.Norm, C.Norm.Name) + " и " + T.Object.Rows.Get <string>(Protokol[PAMIndex].ObjectID, C.Object.Norm, C.Norm.Name);
                            }
                        }
                    }
                }

                if (MsgErr.Length > 0)
                {
                    MessageBox.Show(MsgErr, "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(false);
                }
            }

            string NewFileName;

            {
                int Month, Year;

                ATMisc.GetYearMonthFromYM(Protokol.Parent.YM, out Year, out Month);

                {
                    NewFileName = Application.StartupPath + "\\Отчеты\\";

                    if (!Directory.Exists(NewFileName))
                    {
                        Directory.CreateDirectory(NewFileName);
                    }

                    NewFileName += T.Podr.Rows.Get <string>(Protokol.PodrID, C.Podr.ShrName) + "\\";

                    if (!Directory.Exists(NewFileName))
                    {
                        Directory.CreateDirectory(NewFileName);
                    }

                    NewFileName += ATMisc.GetMonthName1(Month) + "\\";

                    if (!Directory.Exists(NewFileName))
                    {
                        Directory.CreateDirectory(NewFileName);
                    }
                }

                NewFileName += ProtokolFileName(Protokol);
            }

            if (CreateNew || !File.Exists(NewFileName))
            {
                var WorkBook = ATMisc.GetGenericExcel("Протокол испытаний тип 1.xls");

                if (WorkBook == null)
                {
                    return(false);
                }

                var TitleSheet = WorkBook.GetSheet("Заголовок");
                NPOI.SS.UserModel.ISheet ByPodrSheet;

                if (TitleSheet == null)
                {
                    MessageBox.Show("В шаблоне не найден лист \"Заголовок\", вывод невозможен.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(false);
                }

                if (Protokol.MarkCount == 0)
                {
                    MessageBox.Show("Заполненые показатели не найдены.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(false);
                }

                var Font = WorkBook.CreateFont();
                Font.Color              = NPOI.HSSF.Util.HSSFColor.OliveGreen.Index;
                Font.IsStrikeout        = false;
                Font.FontHeightInPoints = 11;
                Font.FontName           = "Times New Roman";
                Font.Color              = short.MaxValue;

                var StyleLRTD_CC = WorkBook.CreateCellStyle();
                StyleLRTD_CC.BorderBottom      = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRTD_CC.BorderLeft        = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRTD_CC.BorderRight       = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRTD_CC.BorderTop         = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRTD_CC.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Center;
                StyleLRTD_CC.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                StyleLRTD_CC.SetFont(Font);
                StyleLRTD_CC.WrapText = true;

                var ExpStyle = WorkBook.CreateCellStyle();
                ExpStyle.BorderBottom      = NPOI.SS.UserModel.BorderStyle.Thin;
                ExpStyle.BorderLeft        = NPOI.SS.UserModel.BorderStyle.Thin;
                ExpStyle.BorderRight       = NPOI.SS.UserModel.BorderStyle.Thin;
                ExpStyle.BorderTop         = NPOI.SS.UserModel.BorderStyle.Thin;
                ExpStyle.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Center;
                ExpStyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                ExpStyle.SetFont(Font);
                ExpStyle.WrapText   = true;
                ExpStyle.DataFormat = WorkBook.CreateDataFormat().GetFormat("0.00E+00");

                var StyleLRTD_LC = WorkBook.CreateCellStyle();
                StyleLRTD_LC.BorderBottom      = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRTD_LC.BorderLeft        = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRTD_LC.BorderRight       = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRTD_LC.BorderTop         = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRTD_LC.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Left;
                StyleLRTD_LC.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                StyleLRTD_LC.SetFont(Font);
                StyleLRTD_LC.WrapText = true;

                var StyleLRD_CC = WorkBook.CreateCellStyle();
                StyleLRD_CC.BorderLeft        = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRD_CC.BorderRight       = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRD_CC.BorderBottom      = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRD_CC.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Center;
                StyleLRD_CC.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                StyleLRD_CC.SetFont(Font);
                StyleLRD_CC.WrapText = true;

                var StyleLRT_CC = WorkBook.CreateCellStyle();
                StyleLRT_CC.BorderTop         = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRT_CC.BorderLeft        = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRT_CC.BorderRight       = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRT_CC.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Center;
                StyleLRT_CC.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                StyleLRT_CC.SetFont(Font);
                StyleLRT_CC.WrapText = true;

                var StyleRTD_CC = WorkBook.CreateCellStyle();
                StyleRTD_CC.BorderBottom      = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleRTD_CC.BorderRight       = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleRTD_CC.BorderTop         = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleRTD_CC.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Center;
                StyleRTD_CC.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                StyleRTD_CC.SetFont(Font);
                StyleRTD_CC.WrapText = true;

                var StyleLTD_CC = WorkBook.CreateCellStyle();
                StyleLTD_CC.BorderBottom      = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLTD_CC.BorderLeft        = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLTD_CC.BorderTop         = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLTD_CC.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Center;
                StyleLTD_CC.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                StyleLTD_CC.SetFont(Font);
                StyleLTD_CC.WrapText = true;

                var StyleTD_CC = WorkBook.CreateCellStyle();
                StyleTD_CC.BorderTop         = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleTD_CC.BorderBottom      = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleTD_CC.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Center;
                StyleTD_CC.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                StyleTD_CC.SetFont(Font);
                StyleTD_CC.WrapText = true;

                string UnDeleteSheetName;
                var    AddInSheetName = T.Podr.Rows.Get <string>(Protokol.PodrID, C.Podr.PSG, C.PSG.Name);
                var    NormID         = Protokol[0].NormID;

                var ObjectsLocations = Protokol.ObjectsLocations;

                switch (Protokol.SGroup)
                {
                case data.SGroup.Middle1:

                    UnDeleteSheetName = "Усредненный";
                    {
                        int Index = WorkBook.GetSheetIndex(UnDeleteSheetName);
                        ByPodrSheet = WorkBook.GetSheetAt(Index);
                        WorkBook.SetSheetName(Index, "Концентрации");
                    }

                    if (ByPodrSheet == null)
                    {
                        MessageBox.Show("В шаблоне не найден лист \"" + UnDeleteSheetName + "\", вывод невозможен.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return(false);
                    }

                    var Exchange = new CellExchange_Class(ByPodrSheet);
                    {
                        var NumC  = new ATMisc.CellMark_struct("{номер}");
                        var NameC = new ATMisc.CellMark_struct("{имя точки отбора}");
                        var MarkC = new ATMisc.CellMark_struct("{показатели}");
                        var SMC   = new ATMisc.CellMark_struct("{концентрации}");

                        Exchange.AddExchange(NumC.Mark, (Cell) => { NumC.ColumnIndex = Cell.ColumnIndex; NumC.RowIndex = Cell.RowIndex; }, 1);
                        Exchange.AddExchange(NameC.Mark, (Cell) => { NameC.ColumnIndex = Cell.ColumnIndex; NameC.RowIndex = Cell.RowIndex; }, 1);
                        Exchange.AddExchange(MarkC.Mark, (Cell) => { MarkC.ColumnIndex = Cell.ColumnIndex; MarkC.RowIndex = Cell.RowIndex; }, 1);
                        Exchange.AddExchange(SMC.Mark, (Cell) => { SMC.ColumnIndex = Cell.ColumnIndex; SMC.RowIndex = Cell.RowIndex; }, 1);

                        Exchange.Exchange();

                        if (!NumC.Check() || !NameC.Check() || !MarkC.Check() || !SMC.Check())
                        {
                            return(false);
                        }

                        if (MarkC.ColumnIndex != SMC.ColumnIndex)
                        {
                            MessageBox.Show("Метки показатели и концентрации должны распологаться в одной колонке", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return(false);
                        }

                        if (MarkC.RowIndex > SMC.RowIndex)
                        {
                            MessageBox.Show("Метка показателей добжна распологаться выше метки концентраций", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return(false);
                        }

                        if (NumC.RowIndex != NameC.RowIndex || NameC.RowIndex != SMC.RowIndex)
                        {
                            MessageBox.Show("Метки номер, имя точки отбора и концентрации, должны распологаться на одной строке", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return(false);
                        }

                        if (Protokol.MarkCount > 1)
                        {
                            var MRow  = ByPodrSheet.GetRow(MarkC.RowIndex);
                            var SMRow = ByPodrSheet.GetRow(SMC.RowIndex);

                            var MStyle  = MRow.GetCell(MarkC.ColumnIndex).CellStyle;
                            var SMStyle = SMRow.GetCell(SMC.ColumnIndex).CellStyle;

                            ATMisc.BreakColumn(ByPodrSheet, MarkC.ColumnIndex, Protokol.MarkCount);

                            for (int i = 0; i < ByPodrSheet.NumMergedRegions; i++)
                            {
                                var mrg = ByPodrSheet.GetMergedRegion(i);

                                if ((mrg.FirstRow <= SMC.RowIndex && mrg.LastRow >= SMC.RowIndex ||
                                     (mrg.FirstRow <= MarkC.RowIndex && mrg.LastRow >= MarkC.RowIndex)) &&
                                    mrg.FirstColumn <= MarkC.ColumnIndex && mrg.LastColumn >= MarkC.ColumnIndex)
                                {
                                    ByPodrSheet.RemoveMergedRegion(i);
                                    i--;
                                }
                            }


                            for (int i = 0; i < Protokol.MarkCount; i++)
                            {
                                {
                                    var Cell = MRow.GetCell(MarkC.ColumnIndex + i);

                                    if (Cell == null)
                                    {
                                        Cell = MRow.CreateCell(MarkC.ColumnIndex + i);
                                    }

                                    Cell.CellStyle = MStyle;
                                }
                                {
                                    var Cell = SMRow.GetCell(SMC.ColumnIndex + i);

                                    if (Cell == null)
                                    {
                                        Cell = SMRow.CreateCell(SMC.ColumnIndex + i);
                                    }

                                    Cell.CellStyle = MStyle;
                                }
                            }
                        }

                        Exchange.AddColumn(NumC.RowIndex, NumC.ColumnIndex);
                        Exchange.AddColumn(NameC.RowIndex, NameC.ColumnIndex);

                        var Row = ByPodrSheet.GetRow(MarkC.RowIndex);

                        for (int i = 0; i < Protokol.MarkCount; i++)
                        {
                            Row.GetCell(MarkC.ColumnIndex + i).SetCellValue(Protokol.GetMarkName(i) + ", " + Protokol.GetMarkEdType(i));

                            Exchange.AddColumn(SMC.RowIndex, SMC.ColumnIndex + i);
                        }

                        Exchange.CheckTableColumns();
                    }

                    for (int i = 0; i < Protokol.TableCount; i++)
                    {
                        var Values = new object[2 + Protokol.MarkCount];

                        Values[0] = i + 1;
                        Values[1] = Protokol.GetTableName(i);

                        for (int j = 0; j < Protokol.MarkCount; j++)
                        {
                            if (Protokol.IsSpetialOut(j, i, false))
                            {
                                Values[2 + j] = Protokol.GetSpetialOut(j, i);
                            }
                            else
                            {
                                Values[2 + j] = Protokol.GetMarkAmount(j, i);
                            }
                        }

                        Exchange.SetRow(Values);
                    }
                    break;

                case data.SGroup.NotGroup1:
                {
                    ObjectsLocations = Protokol[0].SPointName;

                    UnDeleteSheetName = "Изначальный";
                    {
                        int Index = WorkBook.GetSheetIndex(UnDeleteSheetName);
                        ByPodrSheet = WorkBook.GetSheetAt(Index);
                        WorkBook.SetSheetName(Index, "Концентрации");
                    }

                    if (ByPodrSheet == null)
                    {
                        MessageBox.Show("В шаблоне не найден лист \"" + UnDeleteSheetName + "\", вывод невозможен.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return(false);
                    }

                    var OEdTypeIndex   = new SColumn_struct(-1, null);
                    var OMethodIndex   = new SColumn_struct(-1, null);
                    var OMarkNameIndex = new SColumn_struct(-1, null);
                    var NumberIndex    = new SColumn_struct(-1, null);
                    var ResultIndex    = new SColumn_struct(-1, null);
                    var LimitIndex     = new SColumn_struct(-1, null);

                    int RowIndex = -1;
                    {
                        var OEdTypeRowIndex   = -1;
                        var OMethodRowIndex   = -1;
                        var OMarkNameRowIndex = -1;
                        var NumberRowIndex    = -1;
                        var ResultRowIndex    = -1;
                        var LimitRowIndex     = -1;

                        var ExistColumn = new CellExchange_Class(ByPodrSheet);

                        ExistColumn.AddExchange("{Метка пробы}", "№ " + T.Sample.Rows.Get <string>(Protokol[0].SampleID, C.Sample.Number), 5);
                        if (NormID > 0)
                        {
                            ExistColumn.AddExchange("{Норматив}", T.Norm.Rows.Get <string>(NormID, C.Norm.Name), 5);
                        }
                        ExistColumn.AddExchange("{номер п/п}", (Cell) =>
                            {
                                NumberRowIndex = Cell.RowIndex;
                                NumberIndex    = new SColumn_struct(Cell);
                            }, 5);
                        ExistColumn.AddExchange("{показатель}", (Cell) =>
                            {
                                OMarkNameRowIndex = Cell.RowIndex;
                                OMarkNameIndex    = new SColumn_struct(Cell);
                            }, 5);
                        ExistColumn.AddExchange("{ед.изм.}", (Cell) =>
                            {
                                OEdTypeRowIndex = Cell.RowIndex;
                                OEdTypeIndex    = new SColumn_struct(Cell);
                            }, 5);
                        ExistColumn.AddExchange("{методика}", (Cell) =>
                            {
                                OMethodRowIndex = Cell.RowIndex;
                                OMethodIndex    = new SColumn_struct(Cell);
                            }, 5);
                        ExistColumn.AddExchange("{результат}", (Cell) =>
                            {
                                ResultRowIndex = Cell.RowIndex;
                                ResultIndex    = new SColumn_struct(Cell);

                                CopyStyleFromCell(ExpStyle, Cell);
                            }, 5);
                        ExistColumn.AddExchange("{лимит}", (Cell) =>
                            {
                                LimitRowIndex = Cell.RowIndex;
                                LimitIndex    = new SColumn_struct(Cell);
                            }, 5);


                        ExistColumn.Exchange(0, 25, 0, 25);

                        if (NumberRowIndex == -1 || OMarkNameRowIndex == -1 || OEdTypeRowIndex == -1 || OMethodRowIndex == -1 || ResultRowIndex == -1)
                        {
                            MessageBox.Show("Не все табличные метки найдены.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return(false);
                        }

                        if (LimitRowIndex > -1 && LimitRowIndex != NumberRowIndex || NumberRowIndex != OMarkNameRowIndex || OMarkNameRowIndex != OEdTypeRowIndex || OEdTypeRowIndex != OMethodRowIndex || OMethodRowIndex != ResultRowIndex)
                        {
                            MessageBox.Show("Все табличные метки должны распологаться в одной строке.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return(false);
                        }

                        if (NormID == 0 && LimitRowIndex > -1)
                        {
                            ByPodrSheet.SetColumnWidth(ResultIndex.Index, ByPodrSheet.GetColumnWidth(ResultIndex.Index) + ByPodrSheet.GetColumnWidth(LimitIndex.Index));
                            ByPodrSheet.SetColumnHidden(LimitIndex.Index, true);
                        }

                        RowIndex = NumberRowIndex;
                    }

                    ByPodrSheet.ShiftRows(RowIndex, ByPodrSheet.LastRowNum, Protokol.MarkCount - 1);

                    int ONumber = 0;

                    for (int i = 0; i < Protokol.MarkCount; i++)
                    {
                        var Row = ByPodrSheet.CreateRow(RowIndex++);

                        if (RowIndex > -1)
                        {
                            ATMisc.SetValue(Row, ++ONumber, NumberIndex.Index, NumberIndex.Style);
                        }

                        if (LimitIndex.Index > -1)
                        {
                            var Norm = RCache.Marks[Protokol.GetMarkID(i)].GetNorm(Protokol[0].NormID);

                            switch (Norm.NType)
                            {
                            case data.NType.Mark:
                                ATMisc.SetValue(Row, Norm.Range.Range, LimitIndex.Index, LimitIndex.Style);
                                break;

                            case data.NType.PodrV:
                            case data.NType.PodrK:
                            case data.NType.PodrAll:
                                var PIndex = RCache.Marks.Norms.GetPodrIndex(Norm.NormID, T.SPoint.Rows.Get_UnShow <uint>(Protokol[0].SPointID, C.SPoint.Podr));
                                ATMisc.SetValue(Row, Norm.Station(PIndex).Range, LimitIndex.Index, LimitIndex.Style);
                                break;

                            case data.NType.Volume:
                                var VIndex = RCache.Marks.Norms.GetVolumeIndex(Norm.NormID, T.SPoint.Rows.Get_UnShow <uint>(Protokol[0].SPointID, C.SPoint.Object, C.Object.OLocationFrom));
                                ATMisc.SetValue(Row, Norm.Volume(VIndex).Range, LimitIndex.Index, LimitIndex.Style);
                                break;
                            }
                        }

                        if (Protokol.IsSpetialOut(i))
                        {
                            ATMisc.SetValue(Row, Protokol.GetSpetialOut(i), ResultIndex.Index, ResultIndex.Style);
                        }
                        else
                        {
                            ATMisc.SetValue(Row, Protokol.GetMarkAmount(i), ResultIndex.Index, ResultIndex.Style);
                        }

                        ATMisc.SetValue(Row, Protokol.GetMethod(i), OMethodIndex.Index, OMethodIndex.Style);
                        ATMisc.SetValue(Row, Protokol.GetMarkName(i), OMarkNameIndex.Index, OMarkNameIndex.Style);
                        ATMisc.SetValue(Row, Protokol.GetMarkEdType(i), OEdTypeIndex.Index, OEdTypeIndex.Style);
                    }
                }
                break;

                case data.SGroup.Group1:
                {
                    UnDeleteSheetName = "Изначальный";
                    {
                        int Index = WorkBook.GetSheetIndex(UnDeleteSheetName);
                        ByPodrSheet = WorkBook.GetSheetAt(Index);
                        WorkBook.SetSheetName(Index, "Концентрации");
                    }

                    if (ByPodrSheet == null)
                    {
                        MessageBox.Show("В шаблоне не найден лист \"" + UnDeleteSheetName + "\", вывод невозможен.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return(false);
                    }

                    var OEdTypeIndex   = new SColumn_struct(-1, null);
                    var OMethodIndex   = new SColumn_struct(-1, null);
                    var OMarkNameIndex = new SColumn_struct(-1, null);
                    var NumberIndex    = new SColumn_struct(-1, null);
                    var ResultIndex    = new SColumn_struct(-1, null);
                    var ProbeIndex     = new SColumn_struct(-1, null);
                    var LimitIndex     = new SColumn_struct(-1, null);
                    int ProbeRowIndex  = -1;
                    int RowIndex       = -1;
                    {
                        var OEdTypeRowIndex   = -1;
                        var OMethodRowIndex   = -1;
                        var OMarkNameRowIndex = -1;
                        var NumberRowIndex    = -1;
                        var ResultRowIndex    = -1;
                        var LimitRowIndex     = -1;

                        var ExistColumn = new CellExchange_Class(ByPodrSheet);

                        if (NormID > 0)
                        {
                            ExistColumn.AddExchange("{Норматив}", T.Norm.Rows.Get <string>(NormID, C.Norm.Name), 5);
                        }
                        ExistColumn.AddExchange("{Метка пробы}", (Cell) =>
                            {
                                ProbeRowIndex = Cell.RowIndex;
                                ProbeIndex    = new SColumn_struct(Cell);
                            }, 5);
                        ExistColumn.AddExchange("{номер п/п}", (Cell) =>
                            {
                                NumberRowIndex = Cell.RowIndex;
                                NumberIndex    = new SColumn_struct(Cell);
                            }, 5);
                        ExistColumn.AddExchange("{показатель}", (Cell) =>
                            {
                                OMarkNameRowIndex = Cell.RowIndex;
                                OMarkNameIndex    = new SColumn_struct(Cell);
                            }, 5);
                        ExistColumn.AddExchange("{ед.изм.}", (Cell) =>
                            {
                                OEdTypeRowIndex = Cell.RowIndex;
                                OEdTypeIndex    = new SColumn_struct(Cell);
                            }, 5);
                        ExistColumn.AddExchange("{методика}", (Cell) =>
                            {
                                OMethodRowIndex = Cell.RowIndex;
                                OMethodIndex    = new SColumn_struct(Cell);
                            }, 5);
                        ExistColumn.AddExchange("{результат}", (Cell) =>
                            {
                                ResultRowIndex = Cell.RowIndex;
                                ResultIndex    = new SColumn_struct(Cell);

                                CopyStyleFromCell(ExpStyle, Cell);

                                ExpStyle.DataFormat = WorkBook.CreateDataFormat().GetFormat("0.00E+00");
                            }, 5);
                        ExistColumn.AddExchange("{лимит}", (Cell) =>
                            {
                                LimitRowIndex = Cell.RowIndex;
                                LimitIndex    = new SColumn_struct(Cell);
                            }, 5);

                        ExistColumn.Exchange(0, 25, 0, 25);

                        if (ProbeRowIndex == -1 || NumberRowIndex == -1 || OMarkNameRowIndex == -1 || OEdTypeRowIndex == -1 || OMethodRowIndex == -1 || ResultRowIndex == -1)
                        {
                            MessageBox.Show("Не все табличные метки найдены.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return(false);
                        }

                        if (LimitRowIndex > -1 && LimitRowIndex != NumberRowIndex || NumberRowIndex != OMarkNameRowIndex || OMarkNameRowIndex != OEdTypeRowIndex || OEdTypeRowIndex != OMethodRowIndex || OMethodRowIndex != ResultRowIndex)
                        {
                            MessageBox.Show("Все табличные метки должны распологаться в одной строке.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return(false);
                        }

                        if (LimitRowIndex > -1)
                        {
                            ByPodrSheet.SetColumnWidth(ResultIndex.Index, ByPodrSheet.GetColumnWidth(ResultIndex.Index) + ByPodrSheet.GetColumnWidth(LimitIndex.Index));
                            ByPodrSheet.SetColumnHidden(LimitIndex.Index, true);
                        }

                        RowIndex = NumberRowIndex;
                    }

                    ByPodrSheet.ShiftRows(RowIndex, ByPodrSheet.LastRowNum, Protokol.MarkCount - 1);

                    int Width = ByPodrSheet.GetColumnWidth(ResultIndex.Index) / Protokol.SampleCount;
                    ByPodrSheet.AddMergedRegion(new CellRangeAddress(RowIndex - 2, RowIndex - 2, ResultIndex.Index, ResultIndex.Index + Protokol.SampleCount - 1));

                    {
                        var Row = ByPodrSheet.GetRow(ProbeRowIndex);

                        //проверяю одинаковые ли типы воды, если да, тогда проверяю одинаковые ли места, если нет то пишу места, если да, то пишу тип

                        for (int j = 1; j < Protokol.SampleCount; j++)
                        {
                            if (T.Object.Rows.Get_UnShow <uint>(Protokol[j].ObjectID, C.Object.OType) != T.Object.Rows.Get_UnShow <uint>(Protokol[0].ObjectID, C.Object.OType))
                            {
                                goto UseOType;
                            }
                        }

                        for (int j = 1; j < Protokol.SampleCount; j++)
                        {
                            if (T.Object.Rows.Get_UnShow <uint>(Protokol[j].ObjectID, C.Object.OLocationTo) == T.Object.Rows.Get_UnShow <uint>(Protokol[0].ObjectID, C.Object.OLocationTo))
                            {
                                goto UseOType;
                            }
                        }

                        for (int j = 0; j < Protokol.SampleCount; j++)
                        {
                            ByPodrSheet.SetColumnWidth(ResultIndex.Index + j, Width);
                            ATMisc.SetValue(Row, T.Object.Rows.Get <string>(Protokol[j].ObjectID, C.Object.OLocationTo, C.OLocation.Name), ProbeIndex.Index + j, ProbeIndex.Style);
                        }

                        goto IFilled;

                        UseOType :;

                        for (int j = 0; j < Protokol.SampleCount; j++)
                        {
                            ByPodrSheet.SetColumnWidth(ResultIndex.Index + j, Width);
                            ATMisc.SetValue(Row, T.Object.Rows.Get <string>(Protokol[j].ObjectID, C.Object.OType, C.OType.Name) + " №" + Protokol[j].Number.ToString(), ProbeIndex.Index + j, ProbeIndex.Style);
                        }

                        IFilled :;

                        {           //костыльности вот прям тут. т.к. не особенно общая вещь делается: клепается объединение ячеек там где сейчас "результаты испытаний"
                            var PrevRow = ByPodrSheet.GetRow(RowIndex - 2);

                            PrevRow.GetCell(ResultIndex.Index).CellStyle = StyleLTD_CC;

                            for (int j = Protokol.SampleCount - 2; j > 0; j--)
                            {
                                PrevRow.CreateCell(ResultIndex.Index + j).CellStyle = StyleTD_CC;
                            }

                            PrevRow.CreateCell(ResultIndex.Index + Protokol.SampleCount - 1).CellStyle = StyleRTD_CC;
                        }

                        int MergeCount = ByPodrSheet.NumMergedRegions;
                        for (int i = 0; i < MergeCount; i++)
                        {
                            var Merge = ByPodrSheet.GetMergedRegion(i);

                            if (Merge.LastColumn == ResultIndex.Index)
                            {
                                ByPodrSheet.RemoveMergedRegion(i);

                                MergeCount--; i--;

                                ByPodrSheet.AddMergedRegion(new CellRangeAddress(Merge.FirstRow, Merge.LastRow, Merge.FirstColumn, ResultIndex.Index + Protokol.SampleCount - 1));
                            }
                        }
                    }

                    int TNumber = 0;

                    for (int i = 0; i < Protokol.MarkCount; i++)
                    {
                        var Row = ByPodrSheet.CreateRow(RowIndex++);

                        if (LimitIndex.Index > -1)
                        {
                            var Norm = RCache.Marks[Protokol.GetMarkID(i)].GetNorm(Protokol.GetNormID(i));

                            switch (Norm.NType)
                            {
                            case data.NType.Mark:
                                ATMisc.SetValue(Row, Norm.Range.Range, LimitIndex.Index, LimitIndex.Style);
                                break;

                            case data.NType.PodrV:
                            case data.NType.PodrK:
                            case data.NType.PodrAll:
                                var PIndex = RCache.Marks.Norms.GetPodrIndex(Norm.NormID, T.SPoint.Rows.Get_UnShow <uint>(Protokol[0].SPointID, C.SPoint.Podr));
                                ATMisc.SetValue(Row, Norm.Station(PIndex).Range, LimitIndex.Index, LimitIndex.Style);
                                break;

                            case data.NType.Volume:
                                var VIndex = RCache.Marks.Norms.GetVolumeIndex(Norm.NormID, T.SPoint.Rows.Get_UnShow <uint>(Protokol[0].SPointID, C.SPoint.Object, C.Object.OLocationTo));
                                ATMisc.SetValue(Row, Norm.Volume(VIndex).Range, LimitIndex.Index, LimitIndex.Style);
                                break;
                            }

                            for (int j = 0; j < Protokol.TableCount; j++)
                            {
                                if (Protokol.IsSpetialOut(i, j, true))
                                {
                                    ATMisc.SetValue(Row, Protokol.GetSpetialOut(i, j), ResultIndex.Index + j, ResultIndex.Style);
                                }
                                else
                                {
                                    ATMisc.SetValue(Row, Protokol.GetMarkAmount(i, j), ResultIndex.Index + j, ResultIndex.Style);
                                }
                            }
                        }
                        else
                        {
                            for (int j = 0; j < Protokol.TableCount; j++)
                            {
                                if (Protokol.IsSpetialOut(i, j))
                                {
                                    ATMisc.SetValue(Row, Protokol.GetSpetialOut(i, j), ResultIndex.Index + j, ResultIndex.Style);
                                }
                                else
                                {
                                    ATMisc.SetValue(Row, Protokol.GetMarkAmount(i, j), ResultIndex.Index + j, ResultIndex.Style);
                                }
                            }
                        }


                        ATMisc.SetValue(Row, ++TNumber, NumberIndex.Index, NumberIndex.Style);
                        ATMisc.SetValue(Row, Protokol.GetMethod(i), OMethodIndex.Index, OMethodIndex.Style);
                        ATMisc.SetValue(Row, Protokol.GetMarkName(i), OMarkNameIndex.Index, OMarkNameIndex.Style);
                        ATMisc.SetValue(Row, Protokol.GetMarkEdType(i), OEdTypeIndex.Index, OEdTypeIndex.Style);
                    }
                }
                break;

                default: throw new Exception("Неизвестный тип протокола");
                }

                for (int i = 0; i < WorkBook.NumberOfSheets; i++)
                {
                    if (WorkBook.GetSheetAt(i).SheetName.ToLower() != "заголовок" && WorkBook.GetSheetAt(i).SheetName.ToLower() != "концентрации")
                    {
                        WorkBook.RemoveSheetAt(i);
                        i--;
                    }
                }

                string PeopleNames;

                {
                    var Ppls = new List <uint>();

                    for (int i = 0; i < Protokol.SampleCount; i++)
                    {
                        for (int j = 0; j < Ppls.Count; j++)
                        {
                            if (Ppls[j] == Protokol[i].PeopleID)
                            {
                                goto Finded;
                            }
                        }

                        Ppls.Add(Protokol[i].PeopleID);

                        Finded :;
                    }

                    PeopleNames = Misc.GetShortFIO(Ppls[0]);

                    for (int i = 1; i < Ppls.Count; i++)
                    {
                        PeopleNames += ", " + Misc.GetShortFIO(Ppls[i]);
                    }
                }

                string DateO;
                string DateP;
                var    DTMin = T.Sample.Rows.Get <int>(Protokol[0].SampleID, C.Sample.CYMD);
                for (int i = 1; i < Protokol.SampleCount; i++)
                {
                    if (DTMin > T.Sample.Rows.Get <int>(Protokol[i].SampleID, C.Sample.CYMD))
                    {
                        DTMin = T.Sample.Rows.Get <int>(Protokol[i].SampleID, C.Sample.CYMD);
                    }
                }

                var DTMax = T.Sample.Rows.Get <int>(Protokol[0].SampleID, C.Sample.CYMD);
                for (int i = 1; i < Protokol.SampleCount; i++)
                {
                    if (DTMax < T.Sample.Rows.Get <int>(Protokol[i].SampleID, C.Sample.CYMD))
                    {
                        DTMax = T.Sample.Rows.Get <int>(Protokol[i].SampleID, C.Sample.CYMD);
                    }
                }
                if (DTMax == DTMin)
                {
                    DateO = ATMisc.GetDateTime(DTMax).ToShortDateString();
                }
                else
                {
                    DateO = ATMisc.GetDateTime(DTMin).ToShortDateString() + " - " + ATMisc.GetDateTime(DTMax).ToShortDateString();
                }

                DTMin = T.Sample.Rows.Get <int>(Protokol[0].SampleID, C.Sample.AYMD);
                for (int i = 1; i < Protokol.SampleCount; i++)
                {
                    if (DTMin > T.Sample.Rows.Get <int>(Protokol[i].SampleID, C.Sample.AYMD))
                    {
                        DTMin = T.Sample.Rows.Get <int>(Protokol[i].SampleID, C.Sample.AYMD);
                    }
                }

                DTMax = T.Sample.Rows.Get <int>(Protokol[0].SampleID, C.Sample.AYMD);
                for (int i = 1; i < Protokol.SampleCount; i++)
                {
                    if (DTMax < T.Sample.Rows.Get <int>(Protokol[i].SampleID, C.Sample.AYMD))
                    {
                        DTMax = T.Sample.Rows.Get <int>(Protokol[i].SampleID, C.Sample.AYMD);
                    }
                }
                if (DTMax == DTMin)
                {
                    DateP = ATMisc.GetDateTime(DTMax).ToShortDateString();
                }
                else
                {
                    DateP = ATMisc.GetDateTime(DTMin).ToShortDateString() + " - " + ATMisc.GetDateTime(DTMax).ToShortDateString();
                }

                var DT = Protokol.Date;

                GetProtokolsExchanges(TitleSheet
                                      , ATMisc.GetDateTimeFromYM(Protokol.Parent.YM).Year
                                      , Protokol.Number.ToString() + "-" + T.Podr.Rows.Get <string>(Protokol.PodrID, C.Podr.ShrName) + " - " + DT.Month.ToString() + "/" + DT.Year.ToString()
                                      , Protokol.Objects
                                      , Protokol.Objects
                                      , Protokol.PTypes
                                      , ObjectsLocations
                                      , DateO
                                      , DateP
                                      , Protokol.StrTime
                                      , PeopleNames
                                      , Protokol.Causes
                                      , Protokol.Numbers
                                      , DT.Day.ToString()
                                      , ATMisc.GetMonthName2(DT.Month)
                                      , DT.Month.ToString()
                                      , RCache.PSG.GetMethodName(Protokol.PodrID)
                                      , T.PaPoS.Rows.Get <string>(Protokol.PaPoSID, C.PaPoS.Name)
                                      , T.Podr.Rows.Get <string>(Protokol.PodrID, C.Podr.FllName)
                                      , T.Podr.Rows.Get <string>(Protokol.PodrID, C.Podr.ShrName)
                                      , T.Podr.Rows.Get <string>(Protokol.PodrID, C.Podr.Contact)
                                      , Protokol.Act).Exchange(0, 25, 0, 25);
                {
                    var Exchanges = new CellExchange_Class(TitleSheet);

                    Exchanges.ClearExchanges();

                    Exchanges.AddColumn("{имя свойства}");
                    Exchanges.AddColumn("{ед. свойства}");
                    Exchanges.AddColumn("{значение свойства}");
                }
                {
                    var Exchanges = new CellExchange_Class(ByPodrSheet);

                    Exchanges.AddExchange("{должность ответственного}", T.People.Rows.Get <string>(RCache.PSG.GetPeopleID((data.PSG)T.Podr.Rows.Get_UnShow <uint>(Protokol[0].PodrID, C.Podr.PSG)), C.People.Prfssn, C.Prfssn.Name), 5);
                    Exchanges.AddExchange("{ФИО ответственного}", Misc.GetShortFIO(RCache.PSG.GetPeopleID((data.PSG)T.Podr.Rows.Get_UnShow <uint>(Protokol[0].PodrID, C.Podr.PSG))), 5);
                    Exchanges.AddExchange("{Номер протокола}", Protokol.Number.ToString() + "-" + T.Podr.Rows.Get <string>(Protokol.PodrID, C.Podr.ShrName) + " - " + DT.Month.ToString() + "/" + DT.Year.ToString(), 5);
                    Exchanges.AddExchange("{Дата}", DT.ToShortDateString(), 5);

                    SetResp(Exchanges, Protokol.PodrID, data.TResp.LaboratoryProtokol);
                }

                return(SaveExcel(WorkBook, NewFileName, Open));
            }
            else
            {
                if (Open)
                {
                    System.Diagnostics.Process.Start(NewFileName);
                }

                return(true);
            }
        }
Ejemplo n.º 18
0
        public static bool OtchMiddleMarks(MiddleMarks_class Marks, bool ShowErrorMessage = true, bool Open = true)
        {
            var WorkBook = ATMisc.GetGenericExcel("Средние концентрации за год.xls");

            if (WorkBook == null)
            {
                return(false);
            }

            var Sheet = WorkBook.GetSheet("печать");

            if (Sheet == null)
            {
                if (ShowErrorMessage)
                {
                    MessageBox.Show("В шаблоне не найден лист с именем \"печать\"", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                return(false);
            }

            var Exchange = new CellExchange_Class(Sheet);

            if (Marks.PodrID == 0)
            {
                Exchange.AddExchange("{подразделение}", "Все подразделения", 5);
            }
            else
            {
                Exchange.AddExchange("{подразделение}", T.Podr.Rows.Get <string>(Marks.PodrID, C.Podr.ShrName), 5);
            }

            var ObjectName = (Marks.ObjectID == 0 ? T.Object.Rows.Get <string>(Marks.ObjectID, C.Object.Name) : "Все");

            Exchange.AddExchange("{объект}", ObjectName, 5);

            Exchange.AddExchange("{год}", Marks.Year.ToString(), 5);

            var MarkNameIndex       = new SColumn_struct(-1, null);
            var VGIndex             = new SColumn_struct(-1, null);
            var EdTypeIndex         = new SColumn_struct(-1, null);
            var MiddlesMonthIndexes = new SColumn_struct[12];
            var MiddlesQIndexes     = new SColumn_struct[4];
            var MiddleYearMarkIndex = new SColumn_struct(-1, null);

            int MarkRowIndex = -1;
            int VGRowIndex   = -1;

            {
                int MarkNameRowIndex       = -1;
                int EdTypeRowIndex         = -1;
                var MiddlesMonthRowIndexes = new int[12];
                var MiddlesQRowIndexes     = new int[4];
                int MiddleYearMarkRowIndex = -1;

                var MiddlesMonthVGRowIndexes = new int[12];
                var MiddlesQVGRowIndexes     = new int[4];

                Exchange.AddExchange("{показатель}", Cell =>
                {
                    MarkNameIndex    = new SColumn_struct(Cell.ColumnIndex, Cell.CellStyle);
                    MarkNameRowIndex = Cell.RowIndex;
                }, 1);

                Exchange.AddExchange("{выпуск}", Cell =>
                {
                    VGIndex    = new SColumn_struct(Cell.ColumnIndex, Cell.CellStyle);
                    VGRowIndex = Cell.RowIndex;
                }, 1);

                Exchange.AddExchange("{едизм}", Cell =>
                {
                    EdTypeIndex    = new SColumn_struct(Cell.ColumnIndex, Cell.CellStyle);
                    EdTypeRowIndex = Cell.RowIndex;
                }, 1);

                Exchange.AddExchange("{средний за Январь}", Cell =>
                {
                    MiddlesMonthIndexes[0]    = new SColumn_struct(Cell.ColumnIndex, Cell.CellStyle);
                    MiddlesMonthRowIndexes[0] = Cell.RowIndex;
                }, 1);

                Exchange.AddExchange("{средний за Февраль}", Cell =>
                {
                    MiddlesMonthIndexes[1]    = new SColumn_struct(Cell.ColumnIndex, Cell.CellStyle);
                    MiddlesMonthRowIndexes[1] = Cell.RowIndex;
                }, 1);

                Exchange.AddExchange("{средний за Март}", Cell =>
                {
                    MiddlesMonthIndexes[2]    = new SColumn_struct(Cell.ColumnIndex, Cell.CellStyle);
                    MiddlesMonthRowIndexes[2] = Cell.RowIndex;
                }, 1);

                Exchange.AddExchange("{средний за 1 кв.}", Cell =>
                {
                    MiddlesQIndexes[0]    = new SColumn_struct(Cell.ColumnIndex, Cell.CellStyle);
                    MiddlesQRowIndexes[0] = Cell.RowIndex;
                }, 1);

                Exchange.AddExchange("{средний за Апрель}", Cell =>
                {
                    MiddlesMonthIndexes[3]    = new SColumn_struct(Cell.ColumnIndex, Cell.CellStyle);
                    MiddlesMonthRowIndexes[3] = Cell.RowIndex;
                }, 1);

                Exchange.AddExchange("{средний за Май}", Cell =>
                {
                    MiddlesMonthIndexes[4]    = new SColumn_struct(Cell.ColumnIndex, Cell.CellStyle);
                    MiddlesMonthRowIndexes[4] = Cell.RowIndex;
                }, 1);

                Exchange.AddExchange("{средний за Июнь}", Cell =>
                {
                    MiddlesMonthIndexes[5]    = new SColumn_struct(Cell.ColumnIndex, Cell.CellStyle);
                    MiddlesMonthRowIndexes[5] = Cell.RowIndex;
                }, 1);

                Exchange.AddExchange("{средний за 2 кв.}", Cell =>
                {
                    MiddlesQIndexes[1]    = new SColumn_struct(Cell.ColumnIndex, Cell.CellStyle);
                    MiddlesQRowIndexes[1] = Cell.RowIndex;
                }, 1);

                Exchange.AddExchange("{средний за Июль}", Cell =>
                {
                    MiddlesMonthIndexes[6]    = new SColumn_struct(Cell.ColumnIndex, Cell.CellStyle);
                    MiddlesMonthRowIndexes[6] = Cell.RowIndex;
                }, 1);

                Exchange.AddExchange("{средний за Август}", Cell =>
                {
                    MiddlesMonthIndexes[7]    = new SColumn_struct(Cell.ColumnIndex, Cell.CellStyle);
                    MiddlesMonthRowIndexes[7] = Cell.RowIndex;
                }, 1);

                Exchange.AddExchange("{средний за Сентябрь}", Cell =>
                {
                    MiddlesMonthIndexes[8]    = new SColumn_struct(Cell.ColumnIndex, Cell.CellStyle);
                    MiddlesMonthRowIndexes[8] = Cell.RowIndex;
                }, 1);

                Exchange.AddExchange("{средний за 3 кв.}", Cell =>
                {
                    MiddlesQIndexes[2]    = new SColumn_struct(Cell.ColumnIndex, Cell.CellStyle);
                    MiddlesQRowIndexes[2] = Cell.RowIndex;
                }, 1);

                Exchange.AddExchange("{средний за Октябрь}", Cell =>
                {
                    MiddlesMonthIndexes[9]    = new SColumn_struct(Cell.ColumnIndex, Cell.CellStyle);
                    MiddlesMonthRowIndexes[9] = Cell.RowIndex;
                }, 1);

                Exchange.AddExchange("{средний за Ноябрь}", Cell =>
                {
                    MiddlesMonthIndexes[10]    = new SColumn_struct(Cell.ColumnIndex, Cell.CellStyle);
                    MiddlesMonthRowIndexes[10] = Cell.RowIndex;
                }, 1);

                Exchange.AddExchange("{средний за Декабрь}", Cell =>
                {
                    MiddlesMonthIndexes[11]    = new SColumn_struct(Cell.ColumnIndex, Cell.CellStyle);
                    MiddlesMonthRowIndexes[11] = Cell.RowIndex;
                }, 1);

                Exchange.AddExchange("{средний за 4 кв.}", Cell =>
                {
                    MiddlesQIndexes[3]    = new SColumn_struct(Cell.ColumnIndex, Cell.CellStyle);
                    MiddlesQRowIndexes[3] = Cell.RowIndex;
                }, 1);

                Exchange.AddExchange("{средний за За год}", Cell =>
                {
                    MiddleYearMarkIndex    = new SColumn_struct(Cell.ColumnIndex, Cell.CellStyle);
                    MiddleYearMarkRowIndex = Cell.RowIndex;
                }, 1);

                if (Marks.PodrID > 0)
                {
                    Exchange.AddExchange("{должность ответственного}", T.People.Rows.Get <string>(RCache.PSG.GetPeopleID((data.PSG)T.Podr.Rows.Get_UnShow <uint>(Marks.PodrID, C.Podr.PSG)), C.People.Prfssn, C.Prfssn.Name), 5);
                    Exchange.AddExchange("{ФИО ответственного}", Misc.GetShortFIO(RCache.PSG.GetPeopleID((data.PSG)T.Podr.Rows.Get_UnShow <uint>(Marks.PodrID, C.Podr.PSG))), 5);
                }
                else
                {
                    Exchange.AddExchange("{должность ответственного}", "", 5);
                    Exchange.AddExchange("{ФИО ответственного}", "", 5);
                }

                SetResp(Exchange, Marks.PodrID, data.TResp.LaboratoryProtokol);

                if (MarkNameRowIndex == EdTypeRowIndex &&
                    EdTypeRowIndex == MiddlesMonthRowIndexes[0] &&
                    EdTypeRowIndex == MiddlesMonthRowIndexes[1] &&
                    EdTypeRowIndex == MiddlesMonthRowIndexes[2] &&
                    EdTypeRowIndex == MiddlesMonthRowIndexes[3] &&
                    EdTypeRowIndex == MiddlesMonthRowIndexes[4] &&
                    EdTypeRowIndex == MiddlesMonthRowIndexes[5] &&
                    EdTypeRowIndex == MiddlesMonthRowIndexes[6] &&
                    EdTypeRowIndex == MiddlesMonthRowIndexes[7] &&
                    EdTypeRowIndex == MiddlesMonthRowIndexes[8] &&
                    EdTypeRowIndex == MiddlesMonthRowIndexes[9] &&
                    EdTypeRowIndex == MiddlesMonthRowIndexes[10] &&
                    EdTypeRowIndex == MiddlesMonthRowIndexes[11] &&
                    EdTypeRowIndex == MiddlesQRowIndexes[0] &&
                    EdTypeRowIndex == MiddlesQRowIndexes[1] &&
                    EdTypeRowIndex == MiddlesQRowIndexes[2] &&
                    EdTypeRowIndex == MiddlesQRowIndexes[3] &&
                    EdTypeRowIndex == MiddleYearMarkRowIndex)
                {
                    MarkRowIndex = EdTypeRowIndex;
                }
                else
                {
                    if (ShowErrorMessage)
                    {
                        MessageBox.Show("Не все колонки показателей были найдены или не все из них расположены на одной строке.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    return(false);
                }
            }

            Sheet.ShiftRows(MarkRowIndex + 1, Sheet.LastRowNum, -1);  //затираю метки

            int RowIndex = MarkRowIndex;

            for (int i = 0; i < Marks.MarkCount; i++)
            {
                var Mark = RCache.Marks[Marks.MarkID(i)];

                if (Marks.GetMarkEnabled(i) && (Marks.YearSumm(i) > 0 || Mark.ShowZero))
                {
                    Sheet.ShiftRows(RowIndex, Sheet.LastRowNum, 1);

                    var Row = Sheet.CreateRow(RowIndex++);
                    //выпуск
                    ATMisc.SetValue(Row, "", VGIndex.Index, VGIndex.Style);
                    //наименование
                    ATMisc.SetValue(Row, Marks.MarkName(i), MarkNameIndex.Index, MarkNameIndex.Style);
                    //едизм
                    ATMisc.SetValue(Row, Marks.EdName(i), EdTypeIndex.Index, EdTypeIndex.Style);
                    //месяцы
                    for (byte j = 0; j < MiddlesMonthIndexes.Length; j++)
                    {
                        ATMisc.SetValue(Row, Mark.GetRoundedVolume(Marks.MonthSumm(i, j)), MiddlesMonthIndexes[j].Index, MiddlesMonthIndexes[j].Style);
                    }
                    //кварталы
                    for (byte j = 0; j < MiddlesQIndexes.Length; j++)
                    {
                        ATMisc.SetValue(Row, Mark.GetRoundedVolume(Marks.QuartalSumm(i, j)), MiddlesQIndexes[j].Index, MiddlesQIndexes[j].Style);
                    }
                    //за год
                    ATMisc.SetValue(Row, Mark.GetRoundedVolume(Marks.YearSumm(i)), MiddleYearMarkIndex.Index, MiddleYearMarkIndex.Style);
                }
            }

            string PodrName;

            if (Marks.PodrID > 0)
            {
                PodrName = ' ' + T.Podr.Rows.Get <string>(Marks.PodrID, C.Podr.ShrName);
            }
            else
            {
                PodrName = "все";
            }

            if (!Directory.Exists(Application.StartupPath + "\\Отчеты"))
            {
                Directory.CreateDirectory(Application.StartupPath + "\\Отчеты");
            }

            return(SaveExcel(WorkBook, Application.StartupPath + "\\Отчеты\\СП " + PodrName + ", " + ObjectName + ", " + Marks.Year.ToString() + ".xls", Open, ShowErrorMessage));
        }
Ejemplo n.º 19
0
        public static bool OtchProtokolToxicity1(Protokols_class.SGroup_class.Protokol_class Protokol, bool CreateNew = true, bool Open = true)
        {
            if (Protokol.SampleCount != 1)
            {
                MessageBox.Show("Не верное количество замеров в протоколе:" + Protokol.SampleCount.ToString() + ". Должен быть 1", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(false);
            }

            string NewFileName;

            {
                int Month, Year;

                ATMisc.GetYearMonthFromYM(Employe_Form.SPoints.YM, out Year, out Month);

                {
                    NewFileName = Application.StartupPath + "\\Отчеты\\";

                    if (!Directory.Exists(NewFileName))
                    {
                        Directory.CreateDirectory(NewFileName);
                    }

                    NewFileName += T.Podr.Rows.Get <string>(Protokol.PodrID, C.Podr.ShrName) + "\\";

                    if (!Directory.Exists(NewFileName))
                    {
                        Directory.CreateDirectory(NewFileName);
                    }

                    NewFileName += ATMisc.GetMonthName1(Month) + "\\";

                    if (!Directory.Exists(NewFileName))
                    {
                        Directory.CreateDirectory(NewFileName);
                    }
                }

                NewFileName += ProtokolFileName(Protokol);
            }

            if (CreateNew || !File.Exists(NewFileName))
            {
                var WorkBook = ATMisc.GetGenericExcel(Protokol.TemplateFileName());

                if (WorkBook == null)
                {
                    return(false);
                }

                var TitleSheet = WorkBook.GetSheet("Заголовок");
                NPOI.SS.UserModel.ISheet ByPodrSheet;

                if (TitleSheet == null)
                {
                    MessageBox.Show("В шаблоне не найден лист \"Заголовок\", вывод невозможен.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(false);
                }

                if (Protokol.MarkCount == 0)
                {
                    MessageBox.Show("Заполненые показатели не найдены.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(false);
                }

                if (Protokol.MarkCount != 2)
                {
                    MessageBox.Show("Не верное количество показателей.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(false);
                }

                var Font = WorkBook.CreateFont();
                Font.Color              = NPOI.HSSF.Util.HSSFColor.OliveGreen.Index;
                Font.IsStrikeout        = false;
                Font.FontHeightInPoints = 11;
                Font.FontName           = "Times New Roman";
                Font.Color              = short.MaxValue;

                var StyleLRTD_CC = WorkBook.CreateCellStyle();
                StyleLRTD_CC.BorderBottom      = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRTD_CC.BorderLeft        = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRTD_CC.BorderRight       = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRTD_CC.BorderTop         = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRTD_CC.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Center;
                StyleLRTD_CC.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                StyleLRTD_CC.SetFont(Font);
                StyleLRTD_CC.WrapText = true;

                var ExpStyle = WorkBook.CreateCellStyle();
                ExpStyle.BorderBottom      = NPOI.SS.UserModel.BorderStyle.Thin;
                ExpStyle.BorderLeft        = NPOI.SS.UserModel.BorderStyle.Thin;
                ExpStyle.BorderRight       = NPOI.SS.UserModel.BorderStyle.Thin;
                ExpStyle.BorderTop         = NPOI.SS.UserModel.BorderStyle.Thin;
                ExpStyle.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Center;
                ExpStyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                ExpStyle.SetFont(Font);
                ExpStyle.WrapText   = true;
                ExpStyle.DataFormat = WorkBook.CreateDataFormat().GetFormat("0.00E+00");

                var StyleLRTD_LC = WorkBook.CreateCellStyle();
                StyleLRTD_LC.BorderBottom      = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRTD_LC.BorderLeft        = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRTD_LC.BorderRight       = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRTD_LC.BorderTop         = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRTD_LC.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Left;
                StyleLRTD_LC.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                StyleLRTD_LC.SetFont(Font);
                StyleLRTD_LC.WrapText = true;

                var StyleLRD_CC = WorkBook.CreateCellStyle();
                StyleLRD_CC.BorderLeft        = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRD_CC.BorderRight       = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRD_CC.BorderBottom      = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRD_CC.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Center;
                StyleLRD_CC.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                StyleLRD_CC.SetFont(Font);
                StyleLRD_CC.WrapText = true;

                var StyleLRT_CC = WorkBook.CreateCellStyle();
                StyleLRT_CC.BorderTop         = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRT_CC.BorderLeft        = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRT_CC.BorderRight       = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRT_CC.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Center;
                StyleLRT_CC.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                StyleLRT_CC.SetFont(Font);
                StyleLRT_CC.WrapText = true;

                var StyleRTD_CC = WorkBook.CreateCellStyle();
                StyleRTD_CC.BorderBottom      = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleRTD_CC.BorderRight       = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleRTD_CC.BorderTop         = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleRTD_CC.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Center;
                StyleRTD_CC.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                StyleRTD_CC.SetFont(Font);
                StyleRTD_CC.WrapText = true;

                var StyleLTD_CC = WorkBook.CreateCellStyle();
                StyleLTD_CC.BorderBottom      = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLTD_CC.BorderLeft        = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLTD_CC.BorderTop         = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLTD_CC.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Center;
                StyleLTD_CC.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                StyleLTD_CC.SetFont(Font);
                StyleLTD_CC.WrapText = true;

                var StyleTD_CC = WorkBook.CreateCellStyle();
                StyleTD_CC.BorderTop         = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleTD_CC.BorderBottom      = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleTD_CC.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Center;
                StyleTD_CC.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                StyleTD_CC.SetFont(Font);
                StyleTD_CC.WrapText = true;

                var Objects   = Protokol.Objects;
                var ProbeType = T.PType.Rows.Get <string>(Protokol[0].PTypeID, C.PType.Name);
                var Location  = Protokol.ObjectsLocations;

                var    Cause = Protokol.SCause;
                string UnDeleteSheetName;
                var    AddInSheetName = T.Podr.Rows.Get <string>(Protokol.PodrID, C.Podr.PSG, C.PSG.Name);

                Location = T.SPoint.Rows.Get <string>(Protokol[0].SPointID, C.SPoint.Name);

                var Probes = Protokol.Numbers;
                var NormID = Protokol[0].NormID;

                UnDeleteSheetName = "Концентрации";
                {
                    int Index = WorkBook.GetSheetIndex(UnDeleteSheetName);
                    ByPodrSheet = WorkBook.GetSheetAt(Index);
                    WorkBook.SetSheetName(Index, "Концентрации");
                }

                if (ByPodrSheet == null)
                {
                    MessageBox.Show("В шаблоне не найден лист \"" + UnDeleteSheetName + "\", вывод невозможен.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(false);
                }

                var Cells = new ATMisc.CellMark_struct[Protokol.MarkCount];

                var Exchange = new CellExchange_Class(ByPodrSheet);

                /*for (int i = 0; i < Protokol.MarkCount; i++)
                 * {
                 *  Cells[i] = new ATMisc.CellMark_struct("{Оценка " + Protokol.GetMarkName(i) + '}');
                 *
                 *  int Index = i;
                 *  Exchange.AddExchange(Cells[i].Mark, (Cell) =>
                 *  { Cells[Index].ColumnIndex = Cell.ColumnIndex; Cells[Index].RowIndex = Cell.RowIndex; }, 1);
                 * }*/

                Cells[0] = new ATMisc.CellMark_struct("{4 дня " + Protokol.GetMarkName(0) + '}');

                Exchange.AddExchange(Cells[0].Mark, (Cell) =>
                                     { Cells[0].ColumnIndex = Cell.ColumnIndex; Cells[0].RowIndex = Cell.RowIndex; }, 1);

                Cells[1] = new ATMisc.CellMark_struct("{3 дня " + Protokol.GetMarkName(1) + '}');

                Exchange.AddExchange(Cells[1].Mark, (Cell) =>
                                     { Cells[1].ColumnIndex = Cell.ColumnIndex; Cells[1].RowIndex = Cell.RowIndex; }, 1);

                if (Exchange.Exchange())
                {
                    for (int i = 0; i < Cells.Length; i++)
                    {
                        if (!Cells[i].Check())
                        {
                            return(false);
                        }
                    }

                    var tmpDT = ATMisc.GetDateTime(Protokol[0].AYMD);

                    var Tm = new DataBase.Time(Protokol.Time);

                    tmpDT = tmpDT.AddDays(4).AddHours(Tm.Hours).AddMinutes((Protokol.SGroup == data.SGroup.Toxicity2 ? Tm.Minutes + 4 * 60 : Tm.Minutes));

                    //if (tmpDT.DayOfWeek == DayOfWeek.Saturday || tmpDT.DayOfWeek == DayOfWeek.Sunday)
                    //{ throw new Exception("День окончания проведения испытаний приходится на выходной."); }

                    ByPodrSheet.GetRow(Cells[0].RowIndex).GetCell(Cells[0].ColumnIndex).SetCellValue(ATMisc.GetDateTime(Protokol[0].AYMD).ToShortDateString() + '-' + tmpDT.ToShortDateString() + ' ' + (tmpDT.Hour > 9 ? tmpDT.Hour.ToString() : '0' + tmpDT.Hour.ToString()) + ':' + (tmpDT.Minute > 9 ? tmpDT.Minute.ToString() : '0' + tmpDT.Minute.ToString()));

                    tmpDT = ATMisc.GetDateTime(Protokol[0].AYMD).AddDays(3).AddHours(Tm.Hours).AddMinutes((Protokol.SGroup == data.SGroup.Toxicity2 ? Tm.Minutes + 4 * 60 : Tm.Minutes));

                    //if (tmpDT.DayOfWeek == DayOfWeek.Saturday || tmpDT.DayOfWeek == DayOfWeek.Sunday)
                    //{ throw new Exception("День окончания проведения испытаний приходится на выходной."); }

                    ByPodrSheet.GetRow(Cells[1].RowIndex).GetCell(Cells[1].ColumnIndex).SetCellValue(ATMisc.GetDateTime(Protokol[0].AYMD).ToShortDateString() + '-' + tmpDT.ToShortDateString() + ' ' + (tmpDT.Hour > 9 ? tmpDT.Hour.ToString() : '0' + tmpDT.Hour.ToString()) + ':' + (tmpDT.Minute > 9 ? tmpDT.Minute.ToString() : '0' + tmpDT.Minute.ToString()));
                }

                for (int i = WorkBook.NumberOfSheets - 1; i > -1; i--)
                {
                    if (WorkBook.GetSheetAt(i).SheetName.ToLower() != "заголовок" && WorkBook.GetSheetAt(i).SheetName.ToLower() != "концентрации")
                    {
                        WorkBook.RemoveSheetAt(i);
                    }
                }

                string PeopleNames;

                {
                    var Ppls = new List <uint>();

                    for (int i = 0; i < Protokol.SampleCount; i++)
                    {
                        for (int j = 0; j < Ppls.Count; j++)
                        {
                            if (Ppls[j] == Protokol[i].PeopleID)
                            {
                                goto Finded;
                            }
                        }

                        Ppls.Add(Protokol[i].PeopleID);

                        Finded :;
                    }

                    PeopleNames = Misc.GetShortFIO(Ppls[0]);

                    for (int i = 1; i < Ppls.Count; i++)
                    {
                        PeopleNames += ", " + Misc.GetShortFIO(Ppls[i]);
                    }
                }

                var DT = Protokol.Date;

                var ProtokolNum = ProtokolNumber(Protokol);

                GetProtokolsExchanges(TitleSheet
                                      , DT.Year
                                      , ProtokolNum
                                      , Objects
                                      , Objects
                                      , ProbeType
                                      , Location
                                      , Protokol.DateOstr
                                      , Protokol.DateP
                                      , Protokol.StrTime
                                      , PeopleNames
                                      , Cause
                                      , Probes
                                      , DT.Day.ToString()
                                      , ATMisc.GetMonthName2(DT.Month)
                                      , DT.Month.ToString()
                                      , RCache.PSG.GetMethodName(data.PSG.Income)
                                      , T.PaPoS.Rows.Get <string>(Protokol.PaPoSID, C.PaPoS.Name)
                                      , T.Podr.Rows.Get <string>(Protokol.PodrID, C.Podr.FllName)
                                      , T.Podr.Rows.Get <string>(Protokol.PodrID, C.Podr.ShrName)
                                      , T.Podr.Rows.Get <string>(Protokol.PodrID, C.Podr.Contact)
                                      , Protokol.Act).Exchange(0, 25, 0, 25);

                var Exchanges = new CellExchange_Class(TitleSheet);

                Exchanges.ClearExchanges();

                Exchanges.AddColumn("{имя свойства}");
                Exchanges.AddColumn("{ед. свойства}");
                Exchanges.AddColumn("{значение свойства}");

                if (Exchanges.CheckTableColumns())
                {
                    for (int i = 0; i < Protokol[0].TCSCount; i++)
                    {
                        var Values = new object[3];

                        Values[0] = Protokol[0].TCSName(i);
                        Values[1] = Protokol[0].TCSEdType(i);
                        Values[2] = Protokol[0].TCSValue(i);

                        Exchanges.SetRow(Values);
                    }
                }

                Exchanges = new CellExchange_Class(ByPodrSheet);

                Exchanges.AddExchange("{должность ответственного}", T.People.Rows.Get <string>(RCache.PSG.GetPeopleID((data.PSG)T.Podr.Rows.Get_UnShow <uint>(Protokol[0].PodrID, C.Podr.PSG)), C.People.Prfssn, C.Prfssn.Name), 5);
                Exchanges.AddExchange("{ФИО ответственного}", Misc.GetShortFIO(RCache.PSG.GetPeopleID((data.PSG)T.Podr.Rows.Get_UnShow <uint>(Protokol[0].PodrID, C.Podr.PSG))), 5);
                Exchanges.AddExchange("{Номер протокола}", ProtokolNum, 5);
                Exchanges.AddExchange("{Дата}", DT.ToShortDateString(), 5);

                SetResp(Exchanges, Protokol.PodrID, data.TResp.LaboratoryProtokol);

                return(SaveExcel(WorkBook, NewFileName, Open));
            }
            else
            {
                if (Open)
                {
                    System.Diagnostics.Process.Start(NewFileName);
                }

                return(true);
            }
        }
Ejemplo n.º 20
0
        /// <summary>Получить ответственных по типу ответственности для подразделения</summary>
        static void SetResp(CellExchange_Class Exchange, uint PodrID, data.TResp RespType)
        {
            var Prffn = new SColumn_struct(-1, null);
            var FIO   = new SColumn_struct(-1, null);
            int RowIndex;

            {
                int PrffnRowIndex = -1;
                int FIORowIndex   = -1;

                Exchange.AddExchange("{Профессии ответственных по подразделению}", Cell =>
                {
                    Prffn         = new SColumn_struct(Cell.ColumnIndex, Cell.CellStyle);
                    PrffnRowIndex = Cell.RowIndex;
                }, 5);
                Exchange.AddExchange("{ФИО ответственных по подразделению}", Cell =>
                {
                    FIO         = new SColumn_struct(Cell.ColumnIndex, Cell.CellStyle);
                    FIORowIndex = Cell.RowIndex;
                }, 5);
                Exchange.Exchange(0, 50, 0, Exchange.sheet.LastRowNum + 1);

                if (PrffnRowIndex == FIORowIndex && FIORowIndex < 0)
                {
                    return;
                }

                if (PrffnRowIndex > -1 && FIORowIndex > -1 && FIORowIndex != PrffnRowIndex)
                {
                    return;
                }

                RowIndex = PrffnRowIndex;
            }

            CellRangeAddress FIOMerge   = null;
            CellRangeAddress PrffnMerge = null;

            G.Resp.QUERRY()
            .SHOW.WHERE
            .ARC(C.Resp.PodrPpl, C.PodrPpl.Podr).EQUI.BV(PodrID)
            .AND.C(C.Resp.TResp, (uint)RespType)
            .DO();

            if (G.Resp.Rows.Count > 0)
            {
                for (int i = 0; i < Exchange.sheet.NumMergedRegions; i++)
                {
                    var Merge = Exchange.sheet.GetMergedRegion(i);
                    if (Merge.FirstRow <= RowIndex && Merge.LastRow >= RowIndex)
                    {
                        if (Merge.FirstColumn <= FIO.Index && Merge.LastColumn >= FIO.Index)
                        {
                            FIOMerge = Merge;
                        }
                        else if (Merge.FirstColumn <= Prffn.Index && Merge.LastColumn >= Prffn.Index)
                        {
                            PrffnMerge = Merge;
                        }
                    }
                }

                Exchange.sheet.ShiftRows(RowIndex + 1, Exchange.sheet.LastRowNum, G.Resp.Rows.Count - 1);

                G.Resp.Sort((it1, it2) =>
                {
                    var ret1 = T.Resp.Rows.Get_UnShow <uint>(it1.ID, C.Resp.PodrPpl, C.PodrPpl.People, C.People.Prfssn, C.Prfssn.PnMean)
                               .CompareTo(T.Resp.Rows.Get_UnShow <uint>(it2.ID, C.Resp.PodrPpl, C.PodrPpl.People, C.People.Prfssn, C.Prfssn.PnMean));

                    return(ret1 == 0 ? it1.ID.CompareTo(it2.ID) : ret1);
                });

                if (Prffn.Index > -1)
                {
                    var Row  = Exchange.sheet.GetRow(RowIndex);
                    var Cell = Row.GetCell(Prffn.Index);

                    Cell.SetCellValue(G.Resp.Rows.Get <string>(0, C.Resp.PodrPpl, C.PodrPpl.People, C.People.Prfssn, C.Prfssn.Name));
                }

                if (FIO.Index > -1)
                {
                    var Row  = Exchange.sheet.GetRow(RowIndex);
                    var Cell = Row.GetCell(FIO.Index);

                    Cell.SetCellValue(Misc.GetShortFIO(G.Resp.Rows.Get_UnShow <uint>(0, C.Resp.PodrPpl, C.PodrPpl.People)));
                }

                for (int i = 1; i < G.Resp.Rows.Count; i++)
                {
                    var Row = Exchange.sheet.CreateRow(RowIndex + i);

                    if (Prffn.Index > -1)
                    {
                        var Cell = Row.CreateCell(Prffn.Index);
                        Cell.CellStyle = Prffn.Style;
                        Cell.SetCellValue(G.Resp.Rows.Get <string>(i, C.Resp.PodrPpl, C.PodrPpl.People, C.People.Prfssn, C.Prfssn.Name));

                        if (PrffnMerge != null)
                        {
                            Exchange.sheet.AddMergedRegion(new CellRangeAddress(Row.RowNum, Row.RowNum, PrffnMerge.FirstColumn, PrffnMerge.LastColumn));
                        }
                    }

                    if (FIO.Index > -1)
                    {
                        var Cell = Row.CreateCell(FIO.Index);
                        Cell.CellStyle = FIO.Style;
                        Cell.SetCellValue(Misc.GetShortFIO(G.Resp.Rows.Get_UnShow <uint>(i, C.Resp.PodrPpl, C.PodrPpl.People)));

                        if (FIOMerge != null)
                        {
                            Exchange.sheet.AddMergedRegion(new CellRangeAddress(Row.RowNum, Row.RowNum, FIOMerge.FirstColumn, FIOMerge.LastColumn));
                        }
                    }
                }
            }
            else
            {
                Exchange.sheet.ShiftRows(RowIndex + 1, Exchange.sheet.LastRowNum, G.Resp.Rows.Count - 1);
            }
        }
Ejemplo n.º 21
0
        protected override void internalStart()
        {
            book = TemplateStorage.WorkBook;
            if (!CreateStyle())
            {
                return;
            }
            string ListName = "621";

            #region 621
            Resolution resolution = PollutionBase_Class.AllResolution.First(x => x.CurtName.Contains(ListName));
            if (obj.CanResolution(resolution.ID))
            {
                GeneralSumma = new List <decimal>();

                var index = book.GetSheetIndex("Расчёт");

                sheet = book.CloneSheet(index);

                book.SetSheetName(book.NumberOfSheets - 1, ListName);
                Substitute = new CellExchange_Class(sheet);
                LoadTextTemplate(sheet, ListName);
                ClientLoad();
                Table621_1(resolution);
                if (!Table621_2(resolution))
                {
                    Substitute.AddExchange(mark.blok2, e => e.Row.ZeroHeight = true, 0);
                }
                else
                {
                    Substitute.AddExchange(mark.blok2, "", 0);
                }
                ResizeHeight(sheet, 3, sheet.LastRowNum);
                Substitute.AddExchange(mark.pay, GeneralSumma.Sum().ToMoney(), 1);
                R621 = GeneralSumma.Sum() > AdditionnTable.GetPeriod.MinLimits;
                Substitute.Exchange();
                ClearRowFromMark(sheet, mark.job);
            }
            #endregion
            #region 644
            ListName   = "644";
            resolution = PollutionBase_Class.AllResolution.First(x => x.CurtName.Contains(ListName));
            if (obj.CanResolution(resolution.ID))
            {
                GeneralSumma = new List <decimal>();
                sheet        = book.CloneSheet(book.GetSheetIndex("Расчёт"));
                book.SetSheetName(book.NumberOfSheets - 1, ListName);
                Substitute = new CellExchange_Class(sheet);
                LoadTextTemplate(sheet, ListName);
                ClientLoad();
                if (Table644(resolution))
                {
                    Substitute.AddExchange(mark.pay, GeneralSumma.Sum().ToMoney(), 1);
                    R644 = GeneralSumma.Sum() > AdditionnTable.GetPeriod.MinLimits;
                    Substitute.Exchange();
                    ClearRowFromMark(sheet, mark.job);
                }
                else
                {
                    book.RemoveSheetAt(book.NumberOfSheets - 1);
                }
            }
            #endregion
            book.RemoveSheetAt(book.GetSheetIndex("Расчёт"));
            Letter();
            Print("Расчёты платы", "Расчёт платы", EPathPrint.Documents);
        }
Ejemplo n.º 22
0
        public static bool OtchProtokolType4(Protokols_class.SGroup_class.Protokol_class Protokol, bool CreateNew = true, bool Open = true)
        {
            {
                var MsgErr = "";

                for (int i = 0; i < Protokol.MarkCount; i++)
                {
                    var PAMIndex = -1;

                    for (int j = 0; j < Protokol.SampleCount; j++)
                    {
                        if (Protokol[j][i].LocalAlow && Protokol[j][i].Method.Length > 0)
                        {
                            if (PAMIndex < 0)
                            {
                                PAMIndex = j;
                            }
                            else if (Protokol[j][i].Method != Protokol[PAMIndex][i].Method)
                            {
                                MsgErr += '\n' + Protokol[j][i].Mark + " имеет различные методы у нормативов " + T.Object.Rows.Get <string>(Protokol[j].ObjectID, C.Object.Norm, C.Norm.Name) + " и " + T.Object.Rows.Get <string>(Protokol[PAMIndex].ObjectID, C.Object.Norm, C.Norm.Name);
                            }
                        }
                    }
                }

                if (MsgErr.Length > 0)
                {
                    MessageBox.Show(MsgErr, "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(false);
                }
            }

            string NewFileName;

            {
                int Month, Year;

                ATMisc.GetYearMonthFromYM(Employe_Form.SPoints.YM, out Year, out Month);

                {
                    NewFileName = Application.StartupPath + "\\Отчеты\\";

                    if (!Directory.Exists(NewFileName))
                    {
                        Directory.CreateDirectory(NewFileName);
                    }

                    NewFileName += T.Podr.Rows.Get <string>(Protokol.PodrID, C.Podr.ShrName) + "\\";

                    if (!Directory.Exists(NewFileName))
                    {
                        Directory.CreateDirectory(NewFileName);
                    }

                    NewFileName += ATMisc.GetMonthName1(Month) + "\\";

                    if (!Directory.Exists(NewFileName))
                    {
                        Directory.CreateDirectory(NewFileName);
                    }
                }

                NewFileName += ProtokolFileName(Protokol);
            }

            if (CreateNew || !File.Exists(NewFileName))
            {
                var WorkBook = ATMisc.GetGenericExcel("Протокол испытаний тип 4.xls");

                if (WorkBook == null)
                {
                    return(false);
                }

                var TitleSheet = WorkBook.GetSheet("Заголовок");
                NPOI.SS.UserModel.ISheet ByPodrSheet;

                if (TitleSheet == null)
                {
                    MessageBox.Show("В шаблоне не найден лист \"Заголовок\", вывод невозможен.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(false);
                }

                if (Protokol.MarkCount == 0)
                {
                    MessageBox.Show("Заполненые показатели не найдены.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(false);
                }

                var Font = WorkBook.CreateFont();
                Font.Color              = NPOI.HSSF.Util.HSSFColor.OliveGreen.Index;
                Font.IsStrikeout        = false;
                Font.FontHeightInPoints = 11;
                Font.FontName           = "Times New Roman";
                Font.Color              = short.MaxValue;

                var StyleLRTD_CC = WorkBook.CreateCellStyle();
                StyleLRTD_CC.BorderBottom      = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRTD_CC.BorderLeft        = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRTD_CC.BorderRight       = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRTD_CC.BorderTop         = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRTD_CC.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Center;
                StyleLRTD_CC.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                StyleLRTD_CC.SetFont(Font);
                StyleLRTD_CC.WrapText = true;

                var ExpStyle = WorkBook.CreateCellStyle();
                ExpStyle.BorderBottom      = NPOI.SS.UserModel.BorderStyle.Thin;
                ExpStyle.BorderLeft        = NPOI.SS.UserModel.BorderStyle.Thin;
                ExpStyle.BorderRight       = NPOI.SS.UserModel.BorderStyle.Thin;
                ExpStyle.BorderTop         = NPOI.SS.UserModel.BorderStyle.Thin;
                ExpStyle.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Center;
                ExpStyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                ExpStyle.SetFont(Font);
                ExpStyle.WrapText   = true;
                ExpStyle.DataFormat = WorkBook.CreateDataFormat().GetFormat("0.00E+00");

                var StyleLRTD_LC = WorkBook.CreateCellStyle();
                StyleLRTD_LC.BorderBottom      = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRTD_LC.BorderLeft        = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRTD_LC.BorderRight       = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRTD_LC.BorderTop         = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRTD_LC.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Left;
                StyleLRTD_LC.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                StyleLRTD_LC.SetFont(Font);
                StyleLRTD_LC.WrapText = true;

                var StyleLRD_CC = WorkBook.CreateCellStyle();
                StyleLRD_CC.BorderLeft        = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRD_CC.BorderRight       = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRD_CC.BorderBottom      = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRD_CC.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Center;
                StyleLRD_CC.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                StyleLRD_CC.SetFont(Font);
                StyleLRD_CC.WrapText = true;

                var StyleLRT_CC = WorkBook.CreateCellStyle();
                StyleLRT_CC.BorderTop         = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRT_CC.BorderLeft        = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRT_CC.BorderRight       = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLRT_CC.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Center;
                StyleLRT_CC.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                StyleLRT_CC.SetFont(Font);
                StyleLRT_CC.WrapText = true;

                var StyleLR_CC = WorkBook.CreateCellStyle();
                StyleLR_CC.BorderLeft        = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLR_CC.BorderRight       = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLR_CC.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Center;
                StyleLR_CC.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                StyleLR_CC.SetFont(Font);
                StyleLR_CC.WrapText = true;

                var StyleRTD_CC = WorkBook.CreateCellStyle();
                StyleRTD_CC.BorderBottom      = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleRTD_CC.BorderRight       = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleRTD_CC.BorderTop         = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleRTD_CC.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Center;
                StyleRTD_CC.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                StyleRTD_CC.SetFont(Font);
                StyleRTD_CC.WrapText = true;

                var StyleLTD_CC = WorkBook.CreateCellStyle();
                StyleLTD_CC.BorderBottom      = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLTD_CC.BorderLeft        = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLTD_CC.BorderTop         = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleLTD_CC.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Center;
                StyleLTD_CC.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                StyleLTD_CC.SetFont(Font);
                StyleLTD_CC.WrapText = true;

                var StyleTD_CC = WorkBook.CreateCellStyle();
                StyleTD_CC.BorderTop         = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleTD_CC.BorderBottom      = NPOI.SS.UserModel.BorderStyle.Thin;
                StyleTD_CC.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.Center;
                StyleTD_CC.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
                StyleTD_CC.SetFont(Font);
                StyleTD_CC.WrapText = true;

                string UnDeleteSheetName;
                string AddInSheetName = T.Podr.Rows.Get <string>(Protokol.PodrID, C.Podr.PSG, C.PSG.Name);

                switch (Protokol.SGroup)
                {
                case data.SGroup.Middle4:

                    UnDeleteSheetName = "Усредненный";
                    {
                        int Index = WorkBook.GetSheetIndex(UnDeleteSheetName);
                        ByPodrSheet = WorkBook.GetSheetAt(Index);
                        WorkBook.SetSheetName(Index, "Концентрации");
                    }

                    if (ByPodrSheet == null)
                    {
                        MessageBox.Show("В шаблоне не найден лист \"" + UnDeleteSheetName + "\", вывод невозможен.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return(false);
                    }

                    //ищу метку
                    int TableLocation = -1;
                    int ColumnsCount  = 0;
                    for (int i = 0; i < ByPodrSheet.LastRowNum + 1; i++)
                    {
                        var R = ByPodrSheet.GetRow(i);

                        if (R != null)
                        {
                            if (ColumnsCount < R.LastCellNum)
                            {
                                ColumnsCount = R.LastCellNum;
                            }

                            for (int j = 0; j < R.LastCellNum + 1; j++)
                            {
                                var Col = R.GetCell(j);
                                if (Col != null)
                                {
                                    if (Col.CellType == NPOI.SS.UserModel.CellType.String && Col.StringCellValue.ToLower() == "{таблица}")
                                    {
                                        if (j > 0)
                                        {
                                            MessageBox.Show("В листе \"" + UnDeleteSheetName + "\", положение метки таблицы не находится в первой ячейке", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                            return(false);
                                        }
                                        TableLocation = i;

                                        goto FindIt;
                                    }
                                }
                            }
                        }
                    }

                    MessageBox.Show("В листе \"" + UnDeleteSheetName + "\", не найдена метка таблицы", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(false);

                    FindIt :;

                    var SGrps = new List <List <Protokols_class.SGroup_class.Protokol_class.Sample_class> >();
                    SGrps.Add(new List <Protokols_class.SGroup_class.Protokol_class.Sample_class>());
                    SGrps[0].Add(Protokol[0]);

                    for (int i = 1; i < Protokol.SampleCount; i++)
                    {
                        for (int j = 0; j < SGrps.Count; j++)
                        {
                            if (SGrps[j][0].OLocationToID == Protokol[i].OLocationToID)
                            {
                                SGrps[j].Add(Protokol[i]);
                                goto FindedIt;
                            }
                        }

                        SGrps.Add(new List <Protokols_class.SGroup_class.Protokol_class.Sample_class>());
                        SGrps[SGrps.Count - 1].Add(Protokol[i]);

                        FindedIt :;
                    }

                    var Grps = new Grp_class[SGrps.Count];

                    for (int i = 0; i < Grps.Length; i++)
                    {
                        Grps[i] = new Grp_class(SGrps[i], ByPodrSheet.GetColumnWidth(4));
                    }
                    {       //Разбиватель ячеек
                            //Нужно посчитать длины и объединения такого количество ячеек, чтобы их объединения умещались друг под другом как цельное кол-во ячеек
                            //к примеру 1 и 3: первую нужно распилить на три одинаковые по длине

                        /*
                         |__.___._|
                         |__|__|__|
                         * 2 и 3
                         |__._|_.__|
                         |__|_._|__|
                         * при условии ограниченной суммарной длины ячеек и равной длины ячеек каждой группы
                         */
                        //в принципе алгоритм обобщенный, можно задавать их произвольное количество

                        int StartCell = 0;

                        while (true)
                        {
                            int MinWidth = 0;
                            for (int i = 1; i < Grps.Length; i++)
                            {
                                if (Grps[i].CellWidth(StartCell) < Grps[MinWidth].CellWidth(StartCell))
                                {
                                    MinWidth = i;
                                }
                            }
                            for (int i = 0; i < Grps.Length; i++)
                            {
                                if (Grps[i].CellCount - 1 != StartCell)
                                {
                                    goto TryNext;
                                }
                            }
                            break;
                            TryNext :;

                            for (int i = 0; i < Grps.Length; i++)
                            {
                                if (i != MinWidth)
                                {
                                    Grps[i].CellSplit(StartCell, Grps[MinWidth].CellWidth(StartCell));
                                }
                            }

                            StartCell++;
                        }
                    }
                    {
                        //заношу полученные длины колонок

                        for (int i = 0; i < Grps[0].CellCount; i++)
                        {
                            ByPodrSheet.SetColumnWidth(4 + i, Grps[0].CellWidth(i));
                        }

                        {
                            int LastColumnIndex = 4 + Grps[0].CellCount;

                            for (int i = ByPodrSheet.NumMergedRegions - 1; i > -1; i--)
                            {
                                var Merged = ByPodrSheet.GetMergedRegion(i);

                                if (Merged.FirstColumn > 3 && Merged.LastColumn > 3)
                                {
                                    ByPodrSheet.AddMergedRegion(
                                        new CellRangeAddress(Merged.FirstRow
                                                             , Merged.LastRow
                                                             , NewColumnIndex(Merged.FirstColumn, ColumnsCount, LastColumnIndex)
                                                             , NewColumnIndex(Merged.LastColumn, ColumnsCount, LastColumnIndex)));

                                    ByPodrSheet.RemoveMergedRegion(i);
                                }
                                else if (Merged.LastColumn > 3)
                                {
                                    ByPodrSheet.AddMergedRegion(
                                        new CellRangeAddress(Merged.FirstRow
                                                             , Merged.LastRow
                                                             , Merged.FirstColumn
                                                             , NewColumnIndex(Merged.LastColumn, ColumnsCount, LastColumnIndex)));

                                    ByPodrSheet.RemoveMergedRegion(i);
                                }
                            }

                            for (int i = 0; i < ByPodrSheet.LastRowNum + 1; i++)
                            {
                                var R = ByPodrSheet.GetRow(i);

                                if (R != null)
                                {
                                    for (int j = R.LastCellNum - 1; j > 3; j--)
                                    {
                                        var Col = R.GetCell(j);

                                        if (Col != null)
                                        {
                                            int NewIndex = NewColumnIndex(Col.ColumnIndex, ColumnsCount, LastColumnIndex);

                                            if (NewIndex != Col.ColumnIndex)
                                            {
                                                var TCell = R.GetCell(NewIndex);      //баг в библиотеке
                                                if (TCell == null)
                                                {
                                                    TCell = R.CreateCell(NewIndex);
                                                }

                                                R.RemoveCell(TCell);

                                                R.MoveCell(Col, NewIndex);
                                            }
                                        }
                                    }
                                }
                            }

                            ByPodrSheet.ShiftRows(TableLocation, ByPodrSheet.LastRowNum, Protokol.MarkCount * SGrps.Count + 3 * SGrps.Count + SGrps.Count - 2);      //количество показателей в таблицах + заголовки и расстояния между таблицами
                        }

                        int StartRowIndex = TableLocation;

                        for (int i = 0; i < Grps.Length; i++)
                        {
                            var Row = ByPodrSheet.CreateRow(StartRowIndex);
                            //Основной заголовок
                            ATMisc.SetValue(Row, "№ п/п", 0, StyleLRT_CC);
                            ByPodrSheet.AddMergedRegion(new CellRangeAddress(StartRowIndex, StartRowIndex + 2, 0, 0));

                            ATMisc.SetValue(Row, "Показатели", 1, StyleLRT_CC);
                            ByPodrSheet.AddMergedRegion(new CellRangeAddress(StartRowIndex, StartRowIndex + 2, 1, 1));

                            ATMisc.SetValue(Row, "Ед.изм.", 2, StyleLRT_CC);
                            ByPodrSheet.AddMergedRegion(new CellRangeAddress(StartRowIndex, StartRowIndex + 2, 2, 2));

                            ATMisc.SetValue(Row, "НД на методику", 3, StyleLRT_CC);
                            ByPodrSheet.AddMergedRegion(new CellRangeAddress(StartRowIndex, StartRowIndex + 2, 3, 3));

                            ATMisc.SetValue(Row, "Результаты испытаний", 4, Grps[i].CellCount + 3, StyleLTD_CC, StyleTD_CC, StyleRTD_CC);

                            Row = ByPodrSheet.CreateRow(++StartRowIndex);
                            ATMisc.SetValue(Row, "", 0, StyleLR_CC);
                            ATMisc.SetValue(Row, "", 1, StyleLR_CC);
                            ATMisc.SetValue(Row, "", 2, StyleLR_CC);
                            ATMisc.SetValue(Row, "", 3, StyleLR_CC);
                            ATMisc.SetValue(Row, Grps[i].OLocationName, 4, Grps[i].CellCount + 3, StyleLTD_CC, StyleTD_CC, StyleRTD_CC);

                            Row = ByPodrSheet.CreateRow(++StartRowIndex);
                            ATMisc.SetValue(Row, "", 0, StyleLR_CC);
                            ATMisc.SetValue(Row, "", 1, StyleLR_CC);
                            ATMisc.SetValue(Row, "", 2, StyleLR_CC);
                            ATMisc.SetValue(Row, "", 3, StyleLR_CC);

                            {    //Заголовки замеров
                                int s = 0;

                                for (int k = 0; k < Grps[i].SampleCount; k++)
                                {
                                    int KNum = s;

                                    for (s = KNum + 1; s < Grps[i].CellCount; s++)
                                    {
                                        if (Grps[i].GetSetIn(s))
                                        {
                                            break;
                                        }
                                    }

                                    if (KNum < s - 1)
                                    {
                                        ATMisc.SetValue(Row, "№ " + Grps[i].GetSample(k).Number.ToString(), 4 + KNum, 3 + s, StyleLTD_CC, StyleTD_CC, StyleRTD_CC);
                                    }
                                    else
                                    {
                                        ATMisc.SetValue(Row, "№ " + Grps[i].GetSample(k).Number.ToString(), 4 + KNum, StyleLRTD_CC);
                                    }
                                }
                            }
                            int MarkNumber = 0;

                            for (int j = 0; j < Protokol.TotalMarkCount; j++)
                            {
                                if (Protokol.GetTotalAlowedMark(j))
                                {
                                    MarkNumber++;
                                    Row = ByPodrSheet.CreateRow(++StartRowIndex);
                                    int s = 0;

                                    for (int k = 0; k < Grps[i].SampleCount; k++)
                                    {
                                        //заношу данные показателя
                                        ATMisc.SetValue(Row, MarkNumber, 0, StyleLRTD_CC);
                                        ATMisc.SetValue(Row, Protokol.GetTotalMarkName(j), 1, StyleLRTD_CC);
                                        ATMisc.SetValue(Row, Protokol.GetTotalMarkEdType(j), 2, StyleLRTD_CC);
                                        ATMisc.SetValue(Row, RCache.Marks[Protokol.GetTotalMarkID(j)].GetNorm(Grps[i].GetSample(k).NormID).MethodName, 3, StyleLRTD_CC);

                                        //заношу данные концентраций
                                        int KNum = s;

                                        for (s = KNum + 1; s < Grps[i].CellCount; s++)
                                        {
                                            if (Grps[i].GetSetIn(s))
                                            {
                                                break;
                                            }
                                        }

                                        if (KNum < s - 1)
                                        {
                                            ATMisc.SetValue(Row, Grps[i].GetSample(k)[j].Amount, 4 + KNum, 3 + s, StyleLTD_CC, StyleTD_CC, StyleRTD_CC);
                                        }
                                        else
                                        {
                                            ATMisc.SetValue(Row, Grps[i].GetSample(k)[j].Amount, 4 + KNum, StyleLRTD_CC);
                                        }
                                    }
                                }
                            }

                            StartRowIndex += 2;
                        }
                    }

                    break;

                default: throw new Exception("Неизвестный тип протокола");
                }

                for (int i = 0; i < WorkBook.NumberOfSheets; i++)
                {
                    if (WorkBook.GetSheetAt(i).SheetName.ToLower() != "заголовок" && WorkBook.GetSheetAt(i).SheetName.ToLower() != "концентрации")
                    {
                        WorkBook.RemoveSheetAt(i);
                        i--;
                    }
                }

                var         DT      = Protokol.Date;
                SelectHuman _shuman = new SelectHuman();
                Dictionary <string, int> _prtObject = new Dictionary <string, int>(); // Нужно для сверки имя объекта
                G.Object.QUERRY().SHOW.DO();
                int    _objC    = G.Object.Rows.Count;
                string _Papos   = string.Empty;
                string _Address = string.Empty;
                string _objName = string.Empty;
                string _object  = string.Empty;
                string _norm    = string.Empty;
                int    OTypeID  = 0;
                int    count    = 0;
                for (int i = 0; i < _objC; i++)
                {
                    _prtObject.Add(G.Object.Rows.Get_UnShow <string>(i, C.Object.Name).ToLower(),
                                   G.Object.Rows.Get_UnShow <int>(i, C.Object.OType)
                                   );
                    if (Protokol.ProtoType == "Колодец\\Шламонакопитель")
                    {
                        _objName = Protokol.Objects.Remove(Protokol.Objects.IndexOf(','));
                    }
                    if (_prtObject.ContainsKey(_objName))
                    {
                        OTypeID = _prtObject[_objName];
                    }
                    if (OTypeID == 6)
                    {
                        G.PlaceSelection.QUERRY().SHOW.
                        WHERE.
                        C(C.PlaceSelection.OType, OTypeID).AND.
                        C(C.PlaceSelection.Object, Protokol.ObjectID).AND.
                        C(C.PlaceSelection.Podr, Protokol.PodrID).DO();
                        count    = G.PlaceSelection.Rows.Count;
                        _Address = G.PlaceSelection.Rows.Get_UnShow <string>(0, C.PlaceSelection.Adress);
                        _Papos   = G.PaPoS.Rows.Get_UnShow <string>(G.PlaceSelection.Rows.Get_UnShow <int>(0, C.PlaceSelection.PaPoS) - 1, C.PaPoS.Name);
                        _norm    = G.Norm.Rows.Get_UnShow <string>(G.PlaceSelection.Rows.Get_UnShow <int>(0, C.PlaceSelection.Norm) - 1, C.Norm.Name);
                    }
                }
                _shuman.ShowDialog();
                if (_object == "")
                {
                    _object = G.Object.Rows.Get_UnShow <string>(Protokol.ObjectID, C.Object.OType, C.OType.Name);
                }
                GetProtokolsExchanges(TitleSheet
                                      , ATMisc.GetDateTimeFromYM(Employe_Form.SPoints.YM).Year
                                      , Protokol.Number.ToString() + "-" + T.Podr.Rows.Get <string>(Protokol.PodrID, C.Podr.ShrName) + " - " + DT.Month.ToString() + "/" + DT.Year.ToString()
                                      , _object.ToLower()
                                      , _object.ToLower()
                                      , Protokol.PTypes.ToLower()
                                      , _Address
                                      , Protokol.DateOstr
                                      , Protokol.DateP
                                      , Protokol.StrTime
                                      , _probsHuman
                                      , Protokol.Causes
                                      , Protokol.Numbers
                                      , DT.Day.ToString()
                                      , ATMisc.GetMonthName2(DT.Month)
                                      , DT.Month.ToString()
                                      , _norm
                                      , _Papos
                                      , T.Podr.Rows.Get <string>(Protokol.PodrID, C.Podr.FllName)
                                      , T.Podr.Rows.Get <string>(Protokol.PodrID, C.Podr.ShrName)
                                      , T.Podr.Rows.Get <string>(Protokol.PodrID, C.Podr.Contact)
                                      , 0).Exchange(0, 25, 0, 25);
                {
                    var Exchanges = new CellExchange_Class(TitleSheet);

                    Exchanges.ClearExchanges();

                    Exchanges.AddColumn("{имя свойства}");
                    Exchanges.AddColumn("{ед. свойства}");
                    Exchanges.AddColumn("{значение свойства}");
                }

                {
                    var Exchanges = new CellExchange_Class(ByPodrSheet);

                    Exchanges.AddExchange("{должность ответственного}", T.People.Rows.Get <string>(RCache.PSG.GetPeopleID((data.PSG)T.Podr.Rows.Get_UnShow <uint>(Protokol[0].PodrID, C.Podr.PSG)), C.People.Prfssn, C.Prfssn.Name), 5);
                    Exchanges.AddExchange("{ФИО ответственного}", Misc.GetShortFIO(RCache.PSG.GetPeopleID((data.PSG)T.Podr.Rows.Get_UnShow <uint>(Protokol[0].PodrID, C.Podr.PSG))), 5);
                    Exchanges.AddExchange("{Номер протокола}", Protokol.Number.ToString() + "-" + T.Podr.Rows.Get <string>(Protokol.PodrID, C.Podr.ShrName) + " - " + DT.Month.ToString() + "/" + DT.Year.ToString(), 5);
                    Exchanges.AddExchange("{Дата}", DT.ToShortDateString(), 5);
                    Exchanges.AddExchange("{должность ответственного 2}", _secondSubsPosition, 5);
                    Exchanges.AddExchange("{ФИО ответственного 2}", _secondSubsPFIO, 5);

                    SetResp(Exchanges, Protokol.PodrID, data.TResp.LaboratoryProtokol);
                }

                return(SaveExcel(WorkBook, NewFileName, Open));
            }
            else
            {
                if (Open)
                {
                    System.Diagnostics.Process.Start(NewFileName);
                }

                return(true);
            }
        }