Example #1
0
        public void UpdateOlympicsDictionary()
        {
            Dictionary <uint, FIS_Olympic_TEMP> fisDictionaryItems = FIS_Connector.GetOlympicsDictionaryItems(
                _FIS_Address,
                _FIS_Login,
                _FIS_Password,
                _DB_Helper.GetDictionaryItemID(FIS_Dictionary.OLYMPICS_PROFILES, "физика"),
                _DB_Helper.GetDictionaryItemID(FIS_Dictionary.OLYMPICS_PROFILES, "математика")
                );
            Dictionary <uint, FIS_Olympic_TEMP> dbDictionaryItems = _DB_Helper.GetOlympicsDictionaryItems();

            string addedReport   = "В справочник №" + 19 + " \"" + "Олимпиады" + "\" добавлены элементы:";
            ushort addedCount    = 0;
            string deletedReport = "";

            foreach (var olymp in fisDictionaryItems)
            {
                if (dbDictionaryItems.ContainsKey(olymp.Key))
                {
                    if (olymp.Value.Year != dbDictionaryItems[olymp.Key].Year && SharedClasses.Utility.ShowChoiceMessageWithConfirmation(
                            "В ФИС изменился год олимпиады " + olymp.Key + " \"" + dbDictionaryItems[olymp.Key].Name + "\""
                            + ":\nC \"" + dbDictionaryItems[olymp.Key].Year + "\"\nна \"" + olymp.Value.Year +
                            "\".\n\nОбновить значение в БД?",
                            "Действие"
                            ))
                    {
                        _DB_Connection.Update(DB_Table.DICTIONARY_19_ITEMS,
                                              new Dictionary <string, object> {
                            { "year", olymp.Value.Year }
                        },
                                              new Dictionary <string, object> {
                            { "olympic_id", olymp.Key }
                        }
                                              );
                    }

                    if (olymp.Value.Number != dbDictionaryItems[olymp.Key].Number && SharedClasses.Utility.ShowChoiceMessageWithConfirmation(
                            "В ФИС изменился номер олимпиады " + olymp.Key + " \"" + dbDictionaryItems[olymp.Key].Name + "\""
                            + ":\nC \"" + dbDictionaryItems[olymp.Key].Number + "\"\nна \"" + olymp.Value.Number +
                            "\".\n\nОбновить значение в БД?",
                            "Действие"
                            ))
                    {
                        _DB_Connection.Update(DB_Table.DICTIONARY_19_ITEMS,
                                              new Dictionary <string, object> {
                            { "olympic_number", olymp.Value.Number }
                        },
                                              new Dictionary <string, object> {
                            { "olympic_id", olymp.Key }
                        }
                                              );
                    }

                    if (olymp.Value.Name != dbDictionaryItems[olymp.Key].Name && SharedClasses.Utility.ShowChoiceMessageWithConfirmation(
                            "В ФИС изменилось имя олимпиады с кодом "
                            + olymp.Key + ":\nC \"" + dbDictionaryItems[olymp.Key].Name + "\"\nна \"" + olymp.Value.Name +
                            "\".\n\nОбновить значение в БД?",
                            "Действие"
                            ))
                    {
                        _DB_Connection.Update(DB_Table.DICTIONARY_19_ITEMS,
                                              new Dictionary <string, object> {
                            { "olympic_name", olymp.Value.Name }
                        },
                                              new Dictionary <string, object> {
                            { "olympic_id", olymp.Key }
                        }
                                              );
                    }

                    foreach (var prof in olymp.Value.Profiles)
                    {
                        if (dbDictionaryItems[olymp.Key].Profiles.ContainsKey(prof.Key))
                        {
                            if (prof.Value.LevelID != dbDictionaryItems[olymp.Key].Profiles[prof.Key].LevelID && SharedClasses.Utility.ShowChoiceMessageWithConfirmation(
                                    "В ФИС изменился код уровня для профиля с кодом " + prof.Key.Item2 + " олимпиады " + olymp.Key
                                    + " \"" + dbDictionaryItems[olymp.Key].Name + "\"" + ":\nC \"" + dbDictionaryItems[olymp.Key].Profiles[prof.Key].LevelID + "\"\nна \"" + prof.Value.LevelID +
                                    "\".\n\nОбновить значение в БД?",
                                    "Действие"
                                    ))
                            {
                                _DB_Connection.Update(DB_Table.DICTIONARY_OLYMPIC_PROFILES,
                                                      new Dictionary <string, object> {
                                    { "level_id", prof.Value.LevelID }
                                },
                                                      new Dictionary <string, object>
                                {
                                    { "olympic_id", olymp.Key },
                                    { "profile_dict_id", prof.Key.Item1 },
                                    { "profile_id", prof.Key.Item2 }
                                }
                                                      );
                            }

                            foreach (System.Tuple <uint, uint> subj in prof.Value.Subjects)
                            {
                                if (!dbDictionaryItems[olymp.Key].Profiles[prof.Key].Subjects.Contains(subj))
                                {
                                    _DB_Connection.Insert(DB_Table._DICTIONARY_OLYMPIC_PROFILES_HAS_DICTIONARIES_ITEMS,
                                                          new Dictionary <string, object>
                                    {
                                        { "dictionary_olympic_profiles_olympic_id", olymp.Key },
                                        { "dictionary_olympic_profiles_profile_dict_id", prof.Key.Item1 },
                                        { "dictionary_olympic_profiles_profile_id", prof.Key.Item2 },
                                        { "dictionaries_items_dictionary_id", subj.Item1 },
                                        { "dictionaries_items_item_id", subj.Item2 }
                                    }
                                                          );
                                }
                            }
                        }
                        else
                        {
                            InsertProfileWithSubjects(olymp, prof);
                        }
                    }
                }
                else
                {
                    _DB_Connection.Insert(DB_Table.DICTIONARY_19_ITEMS,
                                          new Dictionary <string, object>
                    {
                        { "olympic_id", olymp.Key },
                        { "year", olymp.Value.Year },
                        { "olympic_number", olymp.Value.Number },
                        { "olympic_name", olymp.Value.Name }
                    }
                                          );

                    foreach (var prof in olymp.Value.Profiles)
                    {
                        InsertProfileWithSubjects(olymp, prof);
                    }

                    addedReport += "\n" + olymp.Key;
                    addedCount++;
                }
            }

            foreach (var olymp in dbDictionaryItems)
            {
                if (!fisDictionaryItems.ContainsKey(olymp.Key))
                {
                    deletedReport += "олимпиада - " + olymp.Key + ", ";
                }
                else
                {
                    foreach (var prof in olymp.Value.Profiles)
                    {
                        if (!fisDictionaryItems[olymp.Key].Profiles.ContainsKey(prof.Key))
                        {
                            deletedReport += "олимпиада - " + olymp.Key + " -> профиль - " + prof.Key + ", ";
                        }
                        else
                        {
                            foreach (System.Tuple <uint, uint> subj in prof.Value.Subjects)
                            {
                                if (!fisDictionaryItems[olymp.Key].Profiles[prof.Key].Subjects.Contains(subj))
                                {
                                    deletedReport += "олимпиада - " + olymp.Key + " -> профиль - " + prof.Key + " -> дисциплина - " + subj.Item2 + ", ";
                                }
                            }
                        }
                    }
                }
            }

            if (addedCount == 0)
            {
                addedReport = "Новых олимпиад нет.";
            }
            else
            {
                addedReport += "\nВсего: " + addedCount;
            }

            if (deletedReport != "")
            {
                deletedReport = "\n\nВнимание: в ФИС отсутствуют объекты с ID: " + deletedReport.Remove(deletedReport.Length - 2);
            }

            ShowUpdateMessage(addedReport);
        }