private bool CreateGroupWbkAndWriteGroupDesc(ExcelApplicationEx excelApp, string wbkTemplateFullPath, string wbkFullPath, ICompDesc compDesc, IGroupItem groupDesc, out string message) { message = null; if (!File.Exists(wbkTemplateFullPath)) { message = $"error in CreateGroupWbkAndWriteGroupDesc: {wbkTemplateFullPath} is not existed"; return(false); } File.Copy(wbkTemplateFullPath, wbkFullPath, true); return(RunWbkOperation <bool>(excelApp, wbkFullPath, false, true, wbk => { try { #region WorkbookDataFileWrapper var dataFileWrapper = new WorkbookDataFileWrapper(compDesc.DestCompFolder); #endregion #region SetupWorksheetHelper var wshHelper = new SetupWorksheetHelper(dataFileWrapper, wbk); wshHelper.CompName = compDesc.Name; wshHelper.MainJudge = compDesc.MainJudge; wshHelper.MainSecretary = compDesc.MainSecretary; wshHelper.Row6 = compDesc.ShowRow6 ? compDesc.Row6 : null; wshHelper.StartCompDate = groupDesc.StartDate; wshHelper.EndCompDate = groupDesc.EndDate; wshHelper.StartGroupYear = groupDesc.StartYear; wshHelper.EndGroupYear = groupDesc.EndYear; #endregion string errorMessage; if (!dataFileWrapper.Save(out errorMessage)) { return new RunWbkActionResult <bool>(false, errorMessage); } #region Заполняем FLAGS var flagsHelper = new WorkbookFlagsWrapper() { Value = wshHelper.FLAGS }; flagsHelper.SetFlagsByCompDates(groupDesc.StartDate, groupDesc.EndDate); flagsHelper.SecondColNameType = compDesc.SecondColNameType; flagsHelper.ShowRow6 = compDesc.ShowRow6; lock (DBManagerApp.m_AppSettings.m_SettingsSyncObj) { var availableGroupName = DBManagerApp .m_AppSettings .m_Settings .AvailableGroupNames .First(arg => string.Compare(arg.GroupName, groupDesc.Name, true) == 0); flagsHelper.Sex = availableGroupName.Sex; flagsHelper.GroupYearsAreNeeded = availableGroupName.YearsRangeCanBeSet; flagsHelper.GroupIndexValue = availableGroupName.ValueInWbkFlags; } flagsHelper.WorkbookIsOpenedFirstTime = false; wshHelper.FLAGS = flagsHelper.Value; #endregion wshHelper.SaveAllFlags(); wbk.Save(); wshHelper.SendRequestToFillWbkBasedOnSetupSheet(); return new RunWbkActionResult <bool>(true); } catch (Exception ex) { return new RunWbkActionResult <bool>(false, $"exception in CreateGroupWbkAndWriteGroupDesc: {ex.Message}"); } }, out message)); }