private void CheckAndChangeLastItem(string DirPath) { cmbComp.SelectionChanged -= cmbComp_SelectionChanged; CCompItem NewItem = m_dictCompItems.Values.FirstOrDefault(arg => !arg.HasInDB); if (NewItem == null) { // Все записи в словаре есть в БД => добавляем в словарь и выделяем SelectCompItem(null); // Делаем все записи не выделенными AddLastCompItem(DirPath); } else { // Нужно заменить последнюю запись и выделить её m_dictCompItems.Remove(NewItem.Dir); cmbComp.SelectionChanged -= cmbComp_SelectionChanged; cmbComp.Items[NewItem.Index] = NewItem.Dir = DirPath; cmbComp.SelectionChanged += cmbComp_SelectionChanged; m_dictCompItems.Add(NewItem.Dir, NewItem); SelectCompItem(NewItem); } cmbComp.SelectionChanged += cmbComp_SelectionChanged; }
/*----------------------------------------------------------*/ #endregion private void AddLastCompItem(string DirPath) { CCompItem Item = new CCompItem() { Dir = DirPath, Index = cmbComp.Items.Count, IsSelected = true }; m_dictCompItems.Add(DirPath, Item); cmbComp.Items.Add(Item.ToString()); cmbComp.SelectedIndex = Item.Index; }
private void SelectCompItem(CCompItem ItemToSelect) { foreach (KeyValuePair <string, CCompItem> item in m_dictCompItems) { if (item.Value == ItemToSelect) { item.Value.IsSelected = true; cmbComp.SelectionChanged -= cmbComp_SelectionChanged; cmbComp.SelectedIndex = item.Value.Index; cmbComp.SelectionChanged += cmbComp_SelectionChanged; } else { item.Value.IsSelected = false; } } }
private void btnBrowse_Click(object sender, RoutedEventArgs e) { System.Windows.Forms.FolderBrowserDialog dlg = new System.Windows.Forms.FolderBrowserDialog() { ShowNewFolderButton = true }; lock (DBManagerApp.m_AppSettings.m_SettingsSyncObj) { dlg.SelectedPath = DBManagerApp.m_AppSettings.m_Settings.CompDir; } if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { CCompItem NewItem = null; if (m_dictCompItems.Count == 0) { // Записей нет NewItem = new CCompItem() { Dir = dlg.SelectedPath, IsSelected = true }; m_dictCompItems.Add(dlg.SelectedPath, NewItem); cmbComp.Items.Add(NewItem.ToString()); cmbComp.SelectionChanged -= cmbComp_SelectionChanged; cmbComp.SelectedIndex = cmbComp.Items.Count - 1; cmbComp.SelectionChanged += cmbComp_SelectionChanged; } else { // Проверяем, есть ли запись с такой директорией в словаре if (m_dictCompItems.TryGetValue(dlg.SelectedPath, out NewItem)) { // Есть => выделяем её SelectCompItem(NewItem); } else { CheckAndChangeLastItem(dlg.SelectedPath); } } } }
private CGroupItem AddNewGroup(CCompItem Comp, long GroupId) { CGroupItem result = new CGroupItem(GroupId) { FileName = GroupId.ToString() + GlobalDefines.PUBLISHING_LOG_FILE_EXTENSION }; groups gr = DBManagerApp.m_Entities.groups.FirstOrDefault(arg => arg.id_group == GroupId); if (gr == null) { return(null); } else { CCompSettings Group = new CCompSettings(gr); result.GroupName = Group.AgeGroup.FullGroupName; } Comp.Groups.Add(result); return(result); }
public CSettingsWnd() { InitializeComponent(); HasUnsavedChanges += () => { return(Modified); }; lock (DBManagerApp.m_AppSettings.m_SettingsSyncObj) { // Ищем все соревы, имеющиеся в БД cmbComp.SelectedIndex = -1; List <descriptions> DescInDB = new List <descriptions>(DBManagerApp.m_Entities.descriptions); foreach (descriptions desc in DescInDB) { DateTime? StartDate = desc.groups.Count > 0 ? desc.groups.Min <groups, DateTime?>(arg => arg.comp_start_date) : null; DateTime? EndDate = desc.groups.Count > 0 ? desc.groups.Min <groups, DateTime?>(arg => arg.comp_end_date) : null; CCompItem Item = new CCompItem(desc.name, desc.dir, StartDate, EndDate) { Index = cmbComp.Items.Count }; m_dictCompItems.Add(desc.dir, Item); cmbComp.Items.Add(Item.ToString()); if (DBManagerApp.m_AppSettings.m_Settings.CompDir == desc.dir) { // Эта запись выбрана в настройках Item.IsSelected = true; cmbComp.SelectedIndex = Item.Index; } } if (cmbComp.SelectedIndex < 0) { // В настройках выбрана запись которой нет в БД => добавляем её в конец AddLastCompItem(DBManagerApp.m_AppSettings.m_Settings.CompDir); } cmbComp.SelectionChanged += cmbComp_SelectionChanged; chkHandleFileDeletion.IsChecked = DBManagerApp.m_AppSettings.m_Settings.HandleFileDeletion; chkAutodetectOnStart.IsChecked = DBManagerApp.m_AppSettings.m_Settings.AutodetectOnStart; cmbResultGradeCalcMethod.SelectedIndex = (int)DBManagerApp.m_AppSettings.m_Settings.ResultGradeCalcMethod; chkOnly75PercentForCalcGrades.IsChecked = DBManagerApp.m_AppSettings.m_Settings.Only75PercentForCalcGrades; txtMinAgeToCalcResultGrade.Text = DBManagerApp.m_AppSettings.m_Settings.MinAgeToCalcResultGrade.ToString(); RefreshMaxYearToCalcResultGrade(DBManagerApp.m_AppSettings.m_Settings.MinAgeToCalcResultGrade); txtWorkbookTemplateFolder.Text = DBManagerApp.m_AppSettings.m_Settings.WorkbookTemplateFolder; fntstlInvatedToStart.FontStyleSettings = DBManagerApp.m_AppSettings.m_Settings.InvitedToStartFontStyle; fntstlJustRecievedResult.FontStyleSettings = DBManagerApp.m_AppSettings.m_Settings.JustRecievedResultFontStyle; fntstlNextRoundMembersCount.FontStyleSettings = DBManagerApp.m_AppSettings.m_Settings.NextRoundMembersCountFontStyle; fntstlPreparing.FontStyleSettings = DBManagerApp.m_AppSettings.m_Settings.PreparingFontStyle; fntstlStayOnStart.FontStyleSettings = DBManagerApp.m_AppSettings.m_Settings.StayOnStartFontStyle; fntstlPlainResults.FontStyleSettings = DBManagerApp.m_AppSettings.m_Settings.PlainResultsFontStyle; fntstlFalsestart.FontStyleSettings = DBManagerApp.m_AppSettings.m_Settings.FalsestartFontStyle; fntstlGridLines.FontStyleSettings = DBManagerApp.m_AppSettings.m_Settings.GridLinesFontStyle; fntstlInvatedToStart.FontSize = fntstlJustRecievedResult.FontSize = fntstlNextRoundMembersCount.FontSize = fntstlPreparing.FontSize = fntstlStayOnStart.FontSize = fntstlPlainResults.FontSize = fntstlFalsestart.FontSize = fntstlGridLines.FontSize = DBManagerApp.m_AppSettings.m_Settings.FontSize; txtFontSize.Text = ((int)DBManagerApp.m_AppSettings.m_Settings.FontSize).ToString(); lblFontFamilyName.Content = fntstlInvatedToStart.FontFamilyName = fntstlJustRecievedResult.FontFamilyName = fntstlNextRoundMembersCount.FontFamilyName = fntstlPreparing.FontFamilyName = fntstlStayOnStart.FontFamilyName = fntstlPlainResults.FontFamilyName = fntstlFalsestart.FontFamilyName = fntstlGridLines.FontFamilyName = DBManagerApp.m_AppSettings.m_Settings.FontFamilyName; InstalledFontCollection installedFontCollection = new InstalledFontCollection(); var family = installedFontCollection.Families.FirstOrDefault(arg => arg.Name == DBManagerApp.m_AppSettings.m_Settings.FontFamilyName) ?? new System.Drawing.FontFamily(m_GlobalResources["DefaultFontFamilyName"].ToString()); m_lastSelectedFont = new Font(family, 16, System.Drawing.FontStyle.Regular, GraphicsUnit.Pixel); fntstlInvatedToStart.Modified = fntstlJustRecievedResult.Modified = fntstlNextRoundMembersCount.Modified = fntstlPreparing.Modified = fntstlStayOnStart.Modified = fntstlPlainResults.Modified = fntstlFalsestart.Modified = fntstlGridLines.Modified = false; fntstlInvatedToStart.PropertyChanged += fntstl_PropertyChanged; fntstlJustRecievedResult.PropertyChanged += fntstl_PropertyChanged; fntstlNextRoundMembersCount.PropertyChanged += fntstl_PropertyChanged; fntstlPreparing.PropertyChanged += fntstl_PropertyChanged; fntstlStayOnStart.PropertyChanged += fntstl_PropertyChanged; fntstlPlainResults.PropertyChanged += fntstl_PropertyChanged; fntstlFalsestart.PropertyChanged += fntstl_PropertyChanged; fntstlGridLines.PropertyChanged += fntstl_PropertyChanged; } GlobalDefines.TuneComboboxWidth2(cmbResultGradeCalcMethod); ModifiedFromOpen = Modified = false; }
private bool HandleFile(string FullFilePath) { CGroupItem GroupChanged = null; CCompItem Comp = null; long id = -1; string FileDir = System.IO.Path.GetDirectoryName(FullFilePath); int LastSlash = FileDir.LastIndexOf('\\'); if (long.TryParse(FileDir.Right(FileDir.Length - LastSlash - 1), out id)) { Comp = Comps.FirstOrDefault(arg => arg.id == id); if (Comp == null) { // Такого соревнования нет => его нужно добавить Comp = new CCompItem(id) { FolderName = id.ToString() + "\\" }; descriptions desc = DBManagerApp.m_Entities.descriptions.FirstOrDefault(arg => arg.id_desc == id); if (desc == null) { return(false); } else { Comp.CompName = desc.name; } if (long.TryParse(System.IO.Path.GetFileNameWithoutExtension(FullFilePath), out id)) { GroupChanged = AddNewGroup(Comp, id); if (GroupChanged == null) { return(false); } } else { // неверное название файла return(false); } Comps.Add(Comp); } else { if (long.TryParse(System.IO.Path.GetFileNameWithoutExtension(FullFilePath), out id)) { GroupChanged = Comp.Groups.FirstOrDefault(arg => arg.id == id); if (GroupChanged == null) { // Группы нет => добавляем GroupChanged = AddNewGroup(Comp, id); if (GroupChanged == null) { return(false); } } } } } else { // неверное название файла return(false); } GroupChanged.Items.Clear(); GlobalDefines.CheckPublishingDirExists(); List <CLogItem> lstItems = new List <CLogItem>(); try { using (TextReader tr = new StreamReader(string.Format("{0}{1}\\{2}{3}", GlobalDefines.STD_PUBLISHING_LOG_DIR, Comp.id, GroupChanged.id, GlobalDefines.PUBLISHING_LOG_FILE_EXTENSION))) { string line = null; CLogItem CurLogItem = null; DateTime ItemDateTime = DateTime.Now; enOnlineResultsLogItemType ItemType = enOnlineResultsLogItemType.None; do { line = tr.ReadLine(); if (line == null) { // Файл закончился break; } else { string[] Fields = line.Split(GlobalDefines.PUBLISHING_LOG_FIELDS_SEPARATOR); // Переносы строк не используем в логе для удобства, поэтому добавляем их там, где они нужны for (int i = 0; i < Fields.Length; i++) { Fields[i] = Fields[i].Replace(GlobalDefines.PUBLISHING_LOG_LFCR_SYMBOL, '\n'); } int Index = 0; if (Enum.TryParse <enOnlineResultsLogItemType>(Fields[Index++], out ItemType) && DateTime.TryParse(Fields[Index++], out ItemDateTime)) { CurLogItem = new CLogItem() { Type = ItemType, CreationDate = ItemDateTime, }; if (Fields.Length > Index) { CurLogItem.PCWbkName = Fields[Index].Trim(); } Index++; if (Fields.Length > Index) { CurLogItem.Text = Fields[Index].Trim(); } Index++; lstItems.Add(CurLogItem); } } }while (line != null); } } catch { } lstItems.Sort((lhs, rhs) => - lhs.CreationDate.CompareTo(rhs.CreationDate)); GroupChanged.Items.AddRange(lstItems); return(true); }