Exemplo n.º 1
0
        public static void DataBaseLoad(DataBase db, StartupLogo_Form.Loading_class Loading)
        {
            if (Loading != null)
            {
                Loading.LoadingComment = "SPool";
            }

            if (data.SynchPool != null)
            {
                data.SynchPool.Prepare();
            }

            /*
             *  река(речные нормы)
             *  питьевая(питьевые нормы)
             *  разводящая(питьевые нормы)
             *  промывочная(промывочные нормы)
             *  река выше стока(речные нормы)
             *  река ниже стока(речные нормы)
             *  поступило на очистку(пдк)
             *  очищенное в воду(нормы на очищенное)
             */

            if (!AddRemote(db, Loading, "Prfssn", "Професия", ref T.Prfssn, ref G.Prfssn,
                           newTable =>
            {
                newTable.Columns.AddString("Name", "Наименование", 85);
                newTable.Columns.AddRelation(T.PnMean.GetColumn(C.PnMean.Name));

                newTable.Columns.Add_Unique("Name");
            }, false))
            {
                return;
            }

            if (!AddRemote(db, Loading, "People", "Сотрудник", ref T.People, ref G.People,
                           newTable =>
            {
                newTable.Columns.AddString("Name1", "Фамилия", 30);
                newTable.Columns.AddString("Name2", "Имя", 30);
                newTable.Columns.AddString("Name3", "Отчество", 30);
                newTable.Columns.AddRelation(T.Prfssn.GetColumn(C.Prfssn.Name));

                //newTable.Columns.Add_Unique(C.People.name1, C.People.name2, C.People.name3, C.People.Prfssn);
            }, false))
            {
                return;
            }

            if (!AddRemote(db, Loading, "PSGM", "Метод для группы", ref T.PSGM, ref G.PSGM,
                           newTable =>
            {
                newTable.Columns.AddInt32("YM", "Период начала использования");
                newTable.Columns.AddRelation(T.PSG.GetColumn(C.PSG.Name));
                newTable.Columns.AddString("Name", "Наименование", 200);
                newTable.Columns.AddRelation(T.People.GetColumn(C.People.name1));

                newTable.Columns.Add_Unique(C.PSGM.YM, C.PSGM.PSG);
            }, false))
            {
                return;
            }

            if (!AddRemote(db, Loading, "PodrPpl", "Сотрудник в подразделении", ref T.PodrPpl, ref G.PodrPpl,
                           newTable =>
            {
                newTable.Columns.AddRelation(T.Podr.GetColumn(C.Podr.ShrName));       //
                newTable.Columns.AddRelation(T.People.GetColumn(C.People.name1));     //

                newTable.Columns.Add_Unique(C.PodrPpl.People, C.PodrPpl.Podr);
            }, false))
            {
                return;
            }

            G.PodrPpl.Rows.SetEditForm(C.PodrPpl.GetEdit);
            G.PodrPpl.Rows.SetAddForm(C.PodrPpl.GetEdit);

            T.PodrPpl.Add("Сотрудник", 2, true, true,
                          (R) => { return(Misc.GetPWP(T.PodrPpl.Rows.Get_UnShow <uint>(R.ID, C.PodrPpl.People))); });
            T.PodrPpl.Add(C.PodrPpl.Podr);

            if (!AddRemote(db, Loading, "Resp", "Ответственность", ref T.Resp, ref G.Resp,
                           newTable =>
            {
                newTable.Columns.AddRelation(T.PodrPpl.GetColumn(C.PodrPpl.People)); //
                newTable.Columns.AddRelation(T.TResp.GetColumn(C.TResp.Name));       //

                newTable.Columns.Add_Unique(C.Resp.PodrPpl, C.Resp.TResp);
            }, false))
            {
                return;
            }

            T.Resp.Add("Подразделение", (R) => { return(T.Resp.Rows.Get <string>(R.ID, C.Resp.PodrPpl, C.PodrPpl.Podr, C.Podr.ShrName)); });
            T.Resp.Add("Сотрудник", (R) => { return(Misc.GetShortFIO(T.Resp.Rows.Get_UnShow <uint>(R.ID, C.Resp.PodrPpl, C.PodrPpl.People))); });
            T.Resp.Add(C.Resp.TResp);

            if (!AddSynch(db, Loading, "EdType", "Единица измерений", ref T.EdType, ref G.EdType,
                          newTable =>
            {
                newTable.Columns.AddString("Name", "Наименование", 25);
                newTable.Columns.AddString("MZero", "Значит пусто", 25);

                newTable.Columns.Add_Unique(C.EdType.Name);
            }, false))
            {
                return;
            }

            if (!AddSynch(db, Loading, "BackGrd", "Группа фона", ref T.BackGrd, ref G.BackGrd,
                          newTable =>
            {
                newTable.Columns.AddString("Name", "Наименование", 25);

                newTable.Columns.Add_Unique(C.BackGrd.Name);
            }, false))
            {
                return;
            }

            if (!AddSynch(db, Loading, "OPType", "Единица измерений вывода", ref T.OPType, ref G.OPType,
                          newTable =>
            {
                newTable.Columns.AddDOUBLE("Multy", "Множитель");
                newTable.Columns.AddRelation(T.EdType.GetColumn(C.EdType.Name), "T", "Единица измерений ввода");
                newTable.Columns.AddRelation(T.EdType.GetColumn(C.EdType.Name), "F", "Единица измерений вывода");

                newTable.Columns.Add_Unique(C.OPType.EdTypeT, C.OPType.EdTypeF);
            }, false))
            {
                return;
            }

            if (!AddSynch(db, Loading, "Mark", "Показатель", ref T.Mark, ref G.Mark,
                          newTable =>
            {
                newTable.Columns.AddInt32("Code", "Код");
                newTable.Columns.AddString("Name", "Наименование", 55);
                newTable.Columns.AddByte("Round", "Округление", 1);
                newTable.Columns.AddBool("Exp", "Экспотенциальный");
                newTable.Columns.AddRelation(T.VarType.GetColumn(C.VarType.Name));
                newTable.Columns.AddRelation(T.EdType.GetColumn(C.EdType.Name));
                newTable.Columns.AddRelation(T.OPType.GetColumn(C.OPType.EdTypeF));
                newTable.Columns.AddByte("Number", "Номер");           //позиция показателя
                newTable.Columns.AddBool("ShowZr", "Показывать ноль"); //Show Zero

                newTable.Columns.Add_Unique(C.Mark.Name);
            }, false))
            {
                return;
            }

            T.Mark.Rows.SetAddForm(C.Mark.GetEdit);
            T.Mark.Rows.SetEditForm(C.Mark.GetEdit);

            if (!AddSynch(db, Loading, "PType", "Тип пробы", ref T.PType, ref G.PType, //Probe Type
                          newTable =>
            {
                newTable.Columns.AddString("Name", "Наименование", 50);

                newTable.Columns.Add_Unique(C.PType.Name);
            }, false))
            {
                return;
            }

            if (!AddSynch(db, Loading, "SCause", "Цель испытания", ref T.SCause, ref G.SCause, //Probe Cause
                          newTable =>
            {
                newTable.Columns.AddString("Name", "Наименование", 200);

                newTable.Columns.Add_Unique(C.SCause.Name);
            }, false))
            {
                return;
            }

            if (!AddSynch(db, Loading, "Norm", "Норматив", ref T.Norm, ref G.Norm,
                          newTable =>
            {
                newTable.Columns.AddString("Name", "Наименование", 50);
                newTable.Columns.AddDATE("DFrom", "Действует от");
                newTable.Columns.AddDATE("DTo", "Действует до");
                newTable.Columns.AddRelation(T.NType.GetColumn(C.NType.Name));
                newTable.Columns.AddBool("Enabled", "Задействовать");
                newTable.Columns.AddBool("Show", "Развернуто");

                newTable.Columns.Add_Unique(C.Norm.Name);
            }, false))
            {
                return;
            }

            T.Norm.Add(C.Norm.Name);
            T.Norm.Add(C.Norm.NType);
            T.Norm.Add(C.Norm.DFrom);
            T.Norm.Add(T.Norm.GetColumn(C.Norm.DTo).AlterName, (R) =>
            {
                if (T.Norm.Rows.Get <DateTime>(R.ID, C.Norm.DTo).Ticks == 0)
                {
                    return("");
                }
                else
                {
                    return(T.Norm.Rows.Get <string>(R.ID, C.Norm.DTo));
                }
            });
            T.Norm.Add(C.Norm.Enabled);

            if (!AddSynch(db, Loading, "Method", "Метод", ref T.Method, ref G.Method,
                          newTable =>
            {
                newTable.Columns.AddString("Name", "Наименование", 55);
                newTable.Columns.AddRelation(T.Norm.GetColumn(C.Norm.Name));
                newTable.Columns.AddRelation(T.Mark.GetColumn(C.Mark.Name));

                newTable.Columns.Add_Unique(C.Method.Norm, C.Method.Mark);
            }, false))
            {
                return;
            }

            if (!AddSynch(db, Loading, "MError", "Точность измерений", ref T.MError, ref G.MError,
                          newTable =>
            {
                newTable.Columns.AddRelation(T.Norm.GetColumn(C.Norm.Name));
                newTable.Columns.AddRelation(T.Mark.GetColumn(C.Mark.Name));
                newTable.Columns.AddDOUBLE("From", "Значение от");
                newTable.Columns.AddDOUBLE("To", "Значение до");
                newTable.Columns.AddDOUBLE("Volume", "Значение");
                newTable.Columns.AddBool("Percent", "Это процент");

                newTable.Columns.Add_Unique(C.MError.Norm, C.MError.Mark, C.MError.From, C.MError.To);
            }, false))
            {
                return;
            }
            G.MError.Get_Default();

            if (!AddSynch(db, Loading, "OLocation", "Место", ref T.OLocation, ref G.OLocation,   //Object location
                          newTable =>
            {
                newTable.Columns.AddString("Name", "Наименование", 50);
                newTable.Columns.AddString("ShrName", "Краткое наименование", 5);
                newTable.Columns.AddBool("Volumed", "Использовать объём");

                newTable.Columns.Add_Unique(C.OLocation.Name);
            }, false))
            {
                return;
            }

            if (!AddSynch(db, Loading, "OType", "Тип объекта", ref T.OType, ref G.OType,   //Object Type
                          newTable =>
            {
                newTable.Columns.AddString("Name", "Наименование", 25);

                newTable.Columns.Add_Unique(C.OType.Name);
            }, false))
            {
                return;
            }

            if (!AddSynch(db, Loading, "Object", "Объект испытания", ref T.Object, ref G.Object,   //Object Type
                          newTable =>
            {
                newTable.Columns.AddString("Name", "Наименование", 100);
                newTable.Columns.AddRelation(T.OType.GetColumn(C.OType.Name));
                newTable.Columns.AddRelation(T.OLocation.GetColumn(C.OLocation.Name), "From", "Источник");
                newTable.Columns.AddRelation(T.OLocation.GetColumn(C.OLocation.Name), "To", "Сброс");
                newTable.Columns.AddRelation(T.Norm.GetColumn(C.Norm.Name));

                newTable.Columns.Add_Unique(C.Object.Name);
                newTable.Columns.Add_Unique(C.Object.Name, C.Object.OLocationFrom, C.Object.OLocationTo);
            }, false))
            {
                return;
            }

            if (!AddSynch(db, Loading, "PMNorm", "Значение нормы", ref T.PMNorm, ref G.PMNorm, //Podr Mark
                          newTable =>
            {
                newTable.Columns.AddRelation(T.Norm.GetColumn(C.Norm.Name));
                newTable.Columns.AddRelation(T.Mark.GetColumn(C.Mark.Name));
                newTable.Columns.AddRelation(T.Podr.GetColumn(C.Podr.ShrName));
                newTable.Columns.AddRelation(T.OLocation.GetColumn(C.OLocation.ShrName));
                newTable.Columns.AddDOUBLE("LFrom", "От");
                newTable.Columns.AddDOUBLE("LTo", "До");
                //newTable.Columns.AddBool("BckGrnd", "+ Фон");

                newTable.Columns.Add_Unique(C.PMNorm.Norm, C.PMNorm.Mark, C.PMNorm.Podr, C.PMNorm.OLocation);
            }, false))
            {
                return;
            }

            if (!AddSynch(db, Loading, "Area", "Район", ref T.Area, ref G.Area,
                          newTable =>
            {
                newTable.Columns.AddString("Name", "Наименование", 50);

                newTable.Columns.Add_Unique(C.Area.Name);
            }, false))
            {
                return;
            }

            if (!AddSynch(db, Loading, "MVolume", "Объём выпуска", ref T.MVolume, ref G.MVolume, //Month Group
                          newTable =>
            {
                newTable.Columns.AddRelation(T.OLocation.GetColumn(C.OLocation.Name));
                newTable.Columns.AddInt32("YM", "Номер периода");
                newTable.Columns.AddDOUBLE("Volume", "Объём");

                newTable.Columns.Add_Unique(C.MVolume.OLocation, C.MVolume.YM);
            }, false))
            {
                return;
            }

            T.MVolume.Rows.SetEditForm(C.MVolume.GetEdit);
            T.MVolume.Rows.SetAddForm(C.MVolume.GetEdit);

            T.MVolume.Add(C.MVolume.OLocation);
            T.MVolume.Add(T.MVolume.GetColumn(C.MVolume.YM).AlterName, (R) => ATMisc.GetDateTimeFromYM(G.MVolume.Rows.Get <int>(R, C.MVolume.YM)).ToShortDateString());
            T.MVolume.Add(C.MVolume.Volume);

            if (!AddSynch(db, Loading, "PaPoS", "План и место отбора образцов", ref T.PaPoS, ref G.PaPoS, //Plan and place of sampling
                          newTable =>
            {
                newTable.Columns.AddString("Name", "Наименование", 75);

                newTable.Columns.Add_Unique(C.PaPoS.Name);
            }, false))
            {
                return;
            }

            if (!AddRemote(db, Loading, "SPoint", "Точка отбора", ref T.SPoint, ref G.SPoint, //Sample point
                           newTable =>
            {                                                                                 //
                newTable.Columns.AddInt32("Number", "Номер");
                newTable.Columns.AddString("Name", "Наименование", 500);
                newTable.Columns.AddRelation(T.Area.GetColumn(C.Area.Name));
                newTable.Columns.AddBool("BckGnd", "Фоновый");         //Background
                newTable.Columns.AddBool("UsBckGnd", "Применять фон"); //Use Background
                newTable.Columns.AddRelation(T.PType.GetColumn(C.PType.Name));
                newTable.Columns.AddRelation(T.Object.GetColumn(C.Object.Name));
                newTable.Columns.AddRelation(T.Podr.GetColumn(C.Podr.ShrName));
                newTable.Columns.AddInt32("YMDS", "Начало действия");                 //Year Month Day Start
                newTable.Columns.AddInt32("YMDE", "Окончание действия");              //Year Month Day End
                newTable.Columns.AddBool("IMLst", "Игнорировать список показателей"); //Ignore Mark List
                newTable.Columns.AddRelation(T.SGroup.GetColumn(C.SGroup.Name));      //One of Two
                newTable.Columns.AddInt32("SGNum", "Номер группы");                   //Sample Point Group Name
                newTable.Columns.AddRelation(T.BackGrd.GetColumn(C.BackGrd.Name));
                newTable.Columns.AddBool("Union", "Объединена");                      //Union
                newTable.Columns.AddRelation(T.PaPoS.GetColumn(C.PaPoS.Name));
                //newTable.Columns.AddBool("CanChange", "Можно редактировать", DataBase.ColLocation.Local, true, true);

                //newTable.Columns.Add_Unique(C.SPoint.Union, C.SPoint.Name, C.SPoint.Podr, C.SPoint.YMDS);
            }, false))
            {
                return;
            }
            T.SPoint.Rows.SetEditForm(C.SPoint.GetEdit);
            T.SPoint.Rows.SetAddForm(C.SPoint.GetEdit);

            if (!AddRemote(db, Loading, "Sample", "Замер", ref T.Sample, ref G.Sample,
                           newTable =>
            {
                newTable.Columns.AddRelation(T.SPoint.GetColumn(C.SPoint.Name));
                newTable.Columns.AddInt32("Number", "Номер");                //
                newTable.Columns.AddInt32("Loc", "Порядок создания");        //
                newTable.Columns.AddInt32("CYMD", "Дата отбора");            //Creation YearMonthDay
                newTable.Columns.AddInt32("AYMD", "Дата(начала) испытаний"); //Analis YearMonthDay
                newTable.Columns.AddRelation(T.Resp.GetColumn(C.Resp.PodrPpl), "", "Пробоотборщик");
                newTable.Columns.AddRelation(T.SCause.GetColumn(C.SCause.Name));

                //newTable.Columns.Add_Unique(C.Sample.SPoint, C.Sample.Loc);
            }, false))
            {
                return;
            }

            if (!AddSynch(db, Loading, "TestCond", "Тип условия испытания", ref T.TestCond, ref G.TestCond, //Test condition
                          newTable =>
            {
                newTable.Columns.AddRelation(T.SPoint.GetColumn(C.SPoint.Name));
                newTable.Columns.AddString("Name", "Наименование", 20);
                newTable.Columns.AddRelation(T.EdType.GetColumn(C.EdType.Name));

                newTable.Columns.Add_Unique(C.TestCond.SPoint, C.TestCond.Name);
            }, false))
            {
                return;
            }

            T.TestCond.Rows.SetAddForm(C.TestCond.GetEdit);
            T.TestCond.Rows.SetEditForm(C.TestCond.GetEdit);

            if (!AddSynch(db, Loading, "TCS", "Условие испытания", ref T.TCS, ref G.TCS, //Test condition sample
                          newTable =>
            {
                newTable.Columns.AddRelation(T.Sample.GetColumn(C.Sample.CYMD));
                newTable.Columns.AddRelation(T.TestCond.GetColumn(C.TestCond.Name));
                newTable.Columns.AddString("Value", "Значение свойства", 100);

                newTable.Columns.Add_Unique(C.TCS.Sample, C.TCS.TestCond);
            }, false))
            {
                return;
            }

            T.TCS.Rows.SetAddForm(C.TCS.GetEdit);
            T.TCS.Rows.SetEditForm(C.TCS.GetEdit);

            if (!AddRemote(db, Loading, "SMS", "Показатель к точке отбора", ref T.SMS, ref G.SMS,
                           newTable =>
            {
                newTable.Columns.AddRelation(T.SPoint.GetColumn(C.SPoint.Name));
                newTable.Columns.AddRelation(T.Mark.GetColumn(C.Mark.Name));

                newTable.Columns.Add_Unique(C.SMS.SPoint, C.SMS.Mark);
            }, false))
            {
                return;
            }

            T.Sample.Rows.SetAddForm(C.Sample.GetEdit);
            T.Sample.Rows.SetEditForm(C.Sample.GetEdit);

            if (!AddRemote(db, Loading, "SM", "Концентрация к показателю", ref T.SM, ref G.SM,
                           newTable =>
            {
                newTable.Columns.AddRelation(T.Sample.GetColumn(C.Sample.AYMD));
                newTable.Columns.AddRelation(T.Mark.GetColumn(C.Mark.Name));
                newTable.Columns.AddDOUBLE("Amount", "Значение");

                newTable.Columns.Add_Unique(C.SM.Sample, C.SM.Mark);
            }, false))
            {
                return;
            }

            T.SM.Add(T.Sample.AlterName, (R) => R.ID);
            T.SM.Add(C.SM.Mark);
            T.SM.Add(C.SM.Amount);

            G.SMMiddle = T.SM.CreateSubTable();

            if (!AddRemote(db, Loading, "Prt", "Протокол", ref T.Prt, ref G.Prt,
                           newTable =>
            {
                newTable.Columns.AddInt32("YM", "Месяц");
                newTable.Columns.AddInt32("Time", "Время");
                newTable.Columns.AddInt32("Number", "Номер протокола");
                newTable.Columns.AddBool("Union", "Объединение");
                newTable.Columns.AddRelation(T.OLocation.GetColumn(C.OLocation.Name));
                newTable.Columns.AddRelation(T.Podr.GetColumn(C.Podr.ShrName));
                newTable.Columns.AddRelation(T.Area.GetColumn(C.Area.Name));
                newTable.Columns.AddRelation(T.Object.GetColumn(C.Object.Name));
                newTable.Columns.AddInt32("SCount", "Количество за период");
                newTable.Columns.AddRelation(T.SGroup.GetColumn(C.SGroup.Name));
                newTable.Columns.AddRelation(T.PaPoS.GetColumn(C.PaPoS.Name));
                newTable.Columns.AddInt32("Taos", "Акт отбора");      //the act of selection
                newTable.Columns.AddByte("Day", "День сохранения");   //

                //newTable.Columns.Add_Unique(C.Prt.YM, C.Prt.Number);
            }, false))
            {
                return;
            }

            if (!AddRemote(db, Loading, "PrtS", "Отборы протокола", ref T.PrtS, ref G.PrtS,
                           newTable =>
            {
                newTable.Columns.AddRelation(T.Prt.GetColumn(C.Prt.Number));
                newTable.Columns.AddRelation(T.Sample.GetColumn(C.Sample.CYMD));

                newTable.Columns.Add_Unique(C.PrtS.Prt, C.PrtS.Sample);
            }, false))
            {
                return;
            }

            T.PrtS.Add(T.Prt.GetColumn(C.Prt.Number).AlterName, (R) => T.PrtS.Rows.Get <int>(R.ID, C.PrtS.Prt, C.Prt.Number));
            T.PrtS.Add(T.Prt.GetColumn(C.Prt.YM).AlterName, (R) => ATMisc.GetDateTimeFromYM(T.PrtS.Rows.Get <int>(R.ID, C.PrtS.Prt, C.Prt.YM)).ToShortDateString());
            T.PrtS.Add(T.Podr.AlterName, (R) => T.PrtS.Rows.Get <string>(R.ID, C.PrtS.Prt, C.Prt.Podr, C.Podr.ShrName));
            T.PrtS.Add(T.SPoint.AlterName, (R) => T.PrtS.Rows.Get <string>(R.ID, C.PrtS.Sample, C.Sample.SPoint, C.SPoint.Name));
            T.PrtS.Add("Номер отбора", (R) => T.PrtS.Rows.Get <string>(R.ID, C.PrtS.Sample, C.Sample.Number));
            T.PrtS.Add(T.Sample.GetColumn(C.Sample.CYMD).AlterName, (R) => ATMisc.GetDateTime(T.PrtS.Rows.Get <int>(R.ID, C.PrtS.Sample, C.Sample.CYMD)).ToShortDateString());

            if (data.SynchPool != null)
            {
                data.SynchPool.Invalidate(G.UTable);
            }
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
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);
            }
        }