Exemple #1
0
 private void btSave_Click(object sender, EventArgs e)
 {
     if (cbDirections.SelectedIndex == -1)
     {
         MessageBox.Show("Не выбрано направление.");
     }
     else if (cbFaculties.SelectedIndex == -1)
     {
         MessageBox.Show("Не выбран факультет.");
     }
     else if (tbName.Text == "")
     {
         MessageBox.Show("Не указано название профиля.");
     }
     else if (tbShortName.Text == "")
     {
         MessageBox.Show("Не указано сокращенное название профиля.");
     }
     else if (rbMag.Checked && tbKafedra.Text == "")
     {
         MessageBox.Show("Не указана кафедра.");
     }
     else if (_DB_Connection.Select(DB_Table.PROFILES, new string[] { "direction_id" }, new List <Tuple <string, Relation, object> >
     {
         new Tuple <string, Relation, object>("short_name", Relation.EQUAL, tbShortName.Text)
     }).Count > 0)
     {
         MessageBox.Show("Профиль/программа с таким сокращением уже существует.");
     }
     else
     {
         if (rbMag.Checked)
         {
             _DB_Connection.Insert(DB_Table.PROFILES, new Dictionary <string, object> {
                 { "faculty_short_name", cbFaculties.SelectedItem.ToString() },
                 { "direction_id", (cbDirections.SelectedValue as Tuple <uint, string>).Item1 },
                 { "name", tbName.Text + "|" + tbKafedra.Text }, { "short_name", tbShortName.Text }
             });
         }
         else
         {
             _DB_Connection.Insert(DB_Table.PROFILES, new Dictionary <string, object> {
                 { "faculty_short_name", cbFaculties.SelectedItem.ToString() },
                 { "direction_id", (cbDirections.SelectedValue as Tuple <uint, string>).Item1 },
                 { "name", tbName.Text }, { "short_name", tbShortName.Text }
             });
         }
         tbKafedra.Text       = "";
         tbName.Text          = "";
         tbShortName.Text     = "";
         btAddProfile.Enabled = true;
         EnableDisableControls(false);
         UpdateTable();
     }
 }
Exemple #2
0
        private void btSave_Click(object sender, EventArgs e)
        {
            if ((tbFacultyName.Text.Length == 0) || (tbFacultyShortName.Text.Length == 0))
            {
                MessageBox.Show("Одно из текстовых полей пусто");
            }
            else if (_Updating)
            {
                _DB_Connection.Update(DB_Table.FACULTIES,
                                      new Dictionary <string, object> {
                    { "name", tbFacultyName.Text }, { "short_name", tbFacultyShortName.Text }
                },
                                      new Dictionary <string, object> {
                    { "short_name", name }
                });
                _Updating = false;
                ShowHideControls(false);

                UpdateTable();
                tbFacultyName.Clear();
                tbFacultyShortName.Clear();
            }
            else if (_DB_Connection.Select(DB_Table.FACULTIES, new string[] { "name" },
                                           new List <Tuple <string, Relation, object> >
            {
                new Tuple <string, Relation, object>("short_name", Relation.EQUAL, tbFacultyShortName.Text)
            }).Count != 0)
            {
                MessageBox.Show("Факультет с таким сокращением уже существует");
            }
            else if (_DB_Connection.Select(DB_Table.FACULTIES, new string[] { "short_name" },
                                           new List <Tuple <string, Relation, object> >
            {
                new Tuple <string, Relation, object>("name", Relation.EQUAL, tbFacultyName.Text)
            }).Count != 0)
            {
                MessageBox.Show("Факультет с таким названием уже существует");
            }
            else
            {
                _DB_Connection.Insert(DB_Table.FACULTIES,
                                      new Dictionary <string, object> {
                    { "name", tbFacultyName.Text }, { "short_name", tbFacultyShortName.Text }
                });

                ShowHideControls(false);
                UpdateTable();
                tbFacultyName.Clear();
                tbFacultyShortName.Clear();
            }
        }
Exemple #3
0
        private void AssureConstants()
        {
            string[] fields = { "min_math_mark", "min_russian_mark", "min_physics_mark", "min_social_mark", "min_foreign_mark" };

            List <object[]> buf = _DB_Connection.Select(DB_Table.CONSTANTS, fields);

            if (buf.Count == 0)
            {
                _DB_Connection.Insert(
                    DB_Table.CONSTANTS,
                    System.Linq.Enumerable.ToDictionary(fields, k => k, e => (object)0)
                    );
            }
        }
Exemple #4
0
        private void btSave_Click(object sender, EventArgs e)
        {
            if (!_UpdatingCode.HasValue)
            {
                _DB_Connection.Insert(DB_Table.TARGET_ORGANIZATIONS,
                                      new Dictionary <string, object> {
                    { "name", rtbOrganizationName.Text }
                });
            }
            else
            {
                _DB_Connection.Update(DB_Table.TARGET_ORGANIZATIONS,
                                      new Dictionary <string, object> {
                    { "name", rtbOrganizationName.Text }
                },
                                      new Dictionary <string, object> {
                    { "id", _UpdatingCode }
                });
            }

            DialogResult = DialogResult.OK;
        }
Exemple #5
0
        private void bImport_Click(object sender, EventArgs e)
        {
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                string[] subjects = new string[]
                {
                    DB_Helper.SubjectMath,
                    DB_Helper.SubjectRus,
                    DB_Helper.SubjectPhis,
                    DB_Helper.SubjectObsh,
                    DB_Helper.SubjectForen,
                    "Английский язык",
                    "Немецкий язык",
                    "Французский язык"
                };

                Cursor.Current = Cursors.WaitCursor;

                List <string[]> lines = new List <string[]>();
                using (System.IO.StreamReader reader = new System.IO.StreamReader(openFileDialog.FileName, System.Text.Encoding.GetEncoding(1251)))
                {
                    while (!reader.EndOfStream)
                    {
                        lines.Add(reader.ReadLine().Split('%'));
                    }
                }

                var importedResults = lines.Where(s => subjects.Contains(s[5])).Select(s =>
                {
                    if (s[5] != "Русский язык" && s[5].Contains(" язык"))
                    {
                        s[5] = "Иностранный язык";
                    }

                    return(new
                    {
                        LastName = s[0],
                        FirstName = s[1],
                        MiddleName = s[2],
                        Series = s[3],
                        Number = s[4],
                        Subject = _DB_Helper.GetDictionaryItemID(FIS_Dictionary.SUBJECTS, s[5]),
                        Value = ushort.Parse(s[6]),
                        Year = ushort.Parse(s[7])
                    });
                });

                uint            insertCount  = 0;
                uint            updateCount  = 0;
                List <string[]> notFoundList = new List <string[]>();

                List <EGE_Result> savedResults = GetEgeResults().ToList();
                var identities = _DB_Connection.Select(DB_Table.APPLICATIONS, "id", "entrant_id").Join(
                    _DB_Connection.Select(DB_Table.ENTRANTS_VIEW, "id", "series", "number"),
                    k1 => k1[1],
                    k2 => k2[0],
                    (s1, s2) => new
                {
                    ApplID = (uint)s1[0],
                    Series = s2[1] as string,
                    Number = s2[2].ToString()
                });

                try
                {
                    foreach (var res in importedResults)
                    {
                        //Стоит ли проверять имена вообще?
                        IEnumerable <uint> applIDs = savedResults.Where(s =>
                                                                        s.LastName.Equals(res.LastName, StringComparison.OrdinalIgnoreCase) &&
                                                                        //s.FirstName.Equals(res.FirstName, StringComparison.OrdinalIgnoreCase) &&
                                                                        //s.MiddleName.Equals(res.MiddleName, StringComparison.OrdinalIgnoreCase) &&
                                                                        s.Series == res.Series &&
                                                                        s.Number == res.Number
                                                                        ).GroupBy(k => k.ApplID, (k, g) => k).Concat(identities.Where(s => s.Series == res.Series && s.Number == res.Number).Select(s => s.ApplID)).Distinct();

                        if (applIDs.Count() == 0)
                        {
                            notFoundList.Add(new string[] { res.LastName, res.FirstName, res.MiddleName, res.Series, res.Number });
                        }

                        foreach (uint applID in applIDs)
                        {
                            EGE_Result foundResult = savedResults.SingleOrDefault(s => s.ApplID == applID && s.SubjectID == res.Subject);

                            if (foundResult != null)
                            {
                                if (!foundResult.Checked || foundResult.Value < res.Value)
                                {
                                    _DB_Connection.Update(
                                        DB_Table.APPLICATION_EGE_RESULTS,
                                        new Dictionary <string, object>
                                    {
                                        { "series", res.Series },
                                        { "number", res.Number },
                                        { "year", res.Year },
                                        { "value", res.Value },
                                        { "checked", true }
                                    },
                                        new Dictionary <string, object>
                                    {
                                        { "application_id", applID },
                                        { "subject_dict_id", (uint)FIS_Dictionary.SUBJECTS },
                                        { "subject_id", res.Subject }
                                    });

                                    savedResults.Remove(foundResult);

                                    savedResults.Add(new EGE_Result(
                                                         applID,
                                                         res.Series,
                                                         res.Number,
                                                         res.LastName,
                                                         //res.FirstName,
                                                         //res.MiddleName,
                                                         res.Subject,
                                                         res.Value,
                                                         true
                                                         ));

                                    updateCount++;
                                }
                            }
                            else
                            {
                                _DB_Connection.Insert(
                                    DB_Table.APPLICATION_EGE_RESULTS,
                                    new Dictionary <string, object>
                                {
                                    { "application_id", applID },
                                    { "subject_dict_id", (uint)FIS_Dictionary.SUBJECTS },
                                    { "subject_id", res.Subject },
                                    { "series", res.Series },
                                    { "number", res.Number },
                                    { "year", res.Year },
                                    { "value", res.Value },
                                    { "checked", true }
                                });

                                savedResults.Add(new EGE_Result(
                                                     applID,
                                                     res.Series,
                                                     res.Number,
                                                     res.LastName,
                                                     //res.FirstName,
                                                     //res.MiddleName,
                                                     res.Subject,
                                                     res.Value,
                                                     true
                                                     ));

                                insertCount++;
                            }
                        }
                    }
                }
                finally
                {
                    Cursor.Current = Cursors.Default;

                    MessageBox.Show("Новых результатов: " + insertCount +
                                    "\nОбновлённых результатов: " + updateCount +
                                    (notFoundList.Count != 0 ? "\nНе найдено соответсвий для:\n" + string.Join("\n", notFoundList.Select(s => string.Join(" ", s))) : ""), "Результаты загружены", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
Exemple #6
0
        private void bSave_Click(object sender, EventArgs e)
        {
            if (!AssureSave())
            {
                return;
            }

            Cursor.Current = Cursors.WaitCursor;

            Dictionary <string, object> data = new Dictionary <string, object>
            {
                { "subject_dict_id", (uint)FIS_Dictionary.SUBJECTS },
                { "subject_id", _DB_Helper.GetDictionaryItemID(FIS_Dictionary.SUBJECTS, cbSubject.Text) },
                { "date", dtpDate.Value },
                { "reg_start_date", dtpRegStartDate.Value },
                { "reg_end_date", dtpRegEndDate.Value }
            };

            using (MySql.Data.MySqlClient.MySqlTransaction transaction = _DB_Connection.BeginTransaction())
            {
                uint id;
                if (_ID.HasValue)
                {
                    _DB_Connection.Update(DB_Table.EXAMINATIONS, data, new Dictionary <string, object> {
                        { "id", _ID }
                    }, transaction);
                    id = _ID.Value;
                }
                else
                {
                    id = _DB_Connection.Insert(DB_Table.EXAMINATIONS, data, transaction);
                }

                string[]        fields  = { "examination_id", "number", "capacity", "priority" };
                List <object[]> oldList = _DB_Connection.Select(
                    DB_Table.EXAMINATIONS_AUDIENCES,
                    fields,
                    new List <Tuple <string, Relation, object> > {
                    new Tuple <string, Relation, object>("examination_id", Relation.EQUAL, id)
                }
                    );

                List <object[]> newList = new List <object[]>();
                foreach (DataGridViewRow row in dataGridView.Rows)
                {
                    if (!row.IsNewRow)
                    {
                        newList.Add(new object[] { id, row.Cells[0].Value, row.Cells[1].Value, row.Index });
                    }
                }

                _DB_Helper.UpdateData(DB_Table.EXAMINATIONS_AUDIENCES, oldList, newList, fields, new string[] { "examination_id", "number" }, transaction);

                transaction.Commit();
            }

            Cursor.Current = Cursors.Default;

            SharedClasses.Utility.ShowChangesSavedMessage();
            DialogResult = DialogResult.OK;
        }
Exemple #7
0
        private uint SaveBasic(MySql.Data.MySqlClient.MySqlTransaction transaction)
        {
            List <object[]> passportFound = _DB_Connection.Select(DB_Table.DOCUMENTS, new string[] { "id" }, new List <Tuple <string, Relation, object> >
            {
                new Tuple <string, Relation, object>("type", Relation.EQUAL, "identity"),
                new Tuple <string, Relation, object>("series", Relation.EQUAL, tbIDDocSeries.Text),
                new Tuple <string, Relation, object>("number", Relation.EQUAL, tbIDDocNumber.Text)
            });

            if (passportFound.Count > 0)
            {
                _EntrantID = (uint)_DB_Connection.Select(DB_Table.APPLICATIONS, new string[] { "entrant_id" }, new List <Tuple <string, Relation, object> >
                {
                    new Tuple <string, Relation, object>("id", Relation.EQUAL, (uint)_DB_Connection.Select(DB_Table._APPLICATIONS_HAS_DOCUMENTS,
                                                                                                           new string[] { "applications_id" }, new List <Tuple <string, Relation, object> >
                    {
                        new Tuple <string, Relation, object>("documents_id", Relation.EQUAL, (uint)passportFound[0][0])
                    })[0][0])
                })[0][0];
            }
            else
            {
                char[] passwordChars  = { 'a', 'b', 'c', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
                int    passwordLength = 6;
                string password       = "";
                Random rand           = new Random();
                for (int i = 0; i < passwordLength; i++)
                {
                    password += passwordChars[rand.Next(passwordChars.Length)];
                }
                _EntrantID = _DB_Connection.Insert(DB_Table.ENTRANTS, new Dictionary <string, object>
                {
                    { "email", mtbEMail.Text },
                    { "home_phone", tbHomePhone.Text },
                    { "mobile_phone", tbMobilePhone.Text },
                    { "personal_password", password }
                }, transaction);
            }

            uint applID = _DB_Connection.Insert(DB_Table.APPLICATIONS, new Dictionary <string, object>
            {
                { "entrant_id", _EntrantID.Value },
                { "registration_time", DateTime.Now },
                { "needs_hostel", false },
                { "registrator_login", _RegistratorLogin },
                { "campaign_id", _CurrCampainID },
                { "language", cbForeignLanguage.SelectedItem.ToString() },
                { "priority_right", false },
                { "special_conditions", false },
                { "master_appl", false },
                { "first_high_edu", true },
                { "comment", tbReturnAdress.Text.Trim() }
            }, transaction);

            uint idDocUid = _DB_Connection.Insert(DB_Table.DOCUMENTS, new Dictionary <string, object>
            {
                { "type", "identity" },
                { "series", tbIDDocSeries.Text.Trim() },
                { "number", tbIDDocNumber.Text.Trim() },
                { "date", dtpIDDocDate.Value },
                { "organization", tbIssuedBy.Text.Trim() }
            }, transaction);

            _DB_Connection.Insert(DB_Table._APPLICATIONS_HAS_DOCUMENTS, new Dictionary <string, object>
            {
                { "applications_id", applID },
                { "documents_id", idDocUid }
            }, transaction);

            _DB_Connection.Insert(DB_Table.IDENTITY_DOCS_ADDITIONAL_DATA, new Dictionary <string, object>
            {
                { "document_id", idDocUid },
                { "last_name", tbLastName.Text.Trim() },
                { "first_name", tbFirstName.Text.Trim() },
                { "middle_name", tbMiddleName.Text.Trim() },
                { "gender_dict_id", (uint)FIS_Dictionary.GENDER },
                { "gender_id", _DB_Helper.GetDictionaryItemID(FIS_Dictionary.GENDER, cbSex.SelectedItem.ToString()) },
                { "subdivision_code", mtbSubdivisionCode.MaskFull? mtbSubdivisionCode.Text: null },
                { "type_dict_id", (uint)FIS_Dictionary.IDENTITY_DOC_TYPE },
                { "type_id", _DB_Helper.GetDictionaryItemID(FIS_Dictionary.IDENTITY_DOC_TYPE, cbIDDocType.SelectedItem.ToString()) },
                { "nationality_dict_id", (uint)FIS_Dictionary.COUNTRY },
                { "nationality_id", _DB_Helper.GetDictionaryItemID(FIS_Dictionary.COUNTRY, cbNationality.SelectedItem.ToString()) },
                { "birth_date", dtpDateOfBirth.Value },
                { "birth_place", tbPlaceOfBirth.Text.Trim() },
                { "reg_region", cbRegion.Text },
                { "reg_district", cbDistrict.Text },
                { "reg_town", cbTown.Text },
                { "reg_street", cbStreet.Text },
                { "reg_house", cbHouse.Text },
                { "reg_index", tbPostcode.Text },
                { "reg_flat", tbAppartment.Text }
            }, transaction);

            if (cbPhotos.Checked)
            {
                uint otherDocID = _DB_Connection.Insert(DB_Table.DOCUMENTS, new Dictionary <string, object>
                {
                    { "type", "photos" }
                }, transaction);
                _DB_Connection.Insert(DB_Table._APPLICATIONS_HAS_DOCUMENTS, new Dictionary <string, object>
                {
                    { "applications_id", applID },
                    { "documents_id", otherDocID }
                }, transaction);
            }
            return(applID);
        }
        private void btSave_Click(object sender, EventArgs e)
        {
            List <object[]> select = _DB_Connection.Select(DB_Table.DIRECTIONS,
                                                           "faculty_short_name", "direction_id");
            bool stop = false;

            foreach (DataGridViewRow r in dgvDirections_.Rows)
            {
                bool found = false;
                if (((bool)r.Cells[1].Value) && ((r.Cells[5].Value == null) || (r.Cells[5].Value.ToString() == "")))
                {
                    MessageBox.Show("Не указано сокразение для направления " + r.Cells[3].Value + " \"" + r.Cells[2].Value + "\".");
                    stop = true;
                }

                else if ((select.Count == 0) && ((bool)r.Cells[1].Value))
                {
                    _DB_Connection.Insert(DB_Table.DIRECTIONS, new Dictionary <string, object>
                    {
                        { "faculty_short_name", _FacultyShortName }, { "direction_id", r.Cells[0].Value }, { "short_name", r.Cells[5].Value.ToString() }
                    });
                }
                else
                {
                    found = select.Exists(x => (x[0].ToString() == _FacultyShortName) && (x[1].ToString() == r.Cells[0].Value.ToString()));

                    if (((bool)r.Cells[1].Value) && (!found))
                    {
                        _DB_Connection.Insert(DB_Table.DIRECTIONS, new Dictionary <string, object>
                        {
                            { "faculty_short_name", _FacultyShortName }, { "direction_id", r.Cells[0].Value }, { "short_name", r.Cells[5].Value.ToString() }
                        });
                    }

                    else if ((!(bool)r.Cells[1].Value) && (found))
                    {
                        try
                        {
                            _DB_Connection.Delete(DB_Table.DIRECTIONS, new Dictionary <string, object>
                            {
                                { "faculty_short_name", _FacultyShortName }, { "direction_id", r.Cells[0].Value }
                            });
                        }
                        catch (MySql.Data.MySqlClient.MySqlException ex)
                        {
                            if (ex.Number == 1217 || ex.Number == 1451)
                            {
                                List <object[]> appEntrances = _DB_Connection.Select(DB_Table.APPLICATIONS_ENTRANCES, new string[] { "application_id" }, new List <Tuple <string, Relation, object> >
                                {
                                    new Tuple <string, Relation, object>("faculty_short_name", Relation.EQUAL, _FacultyShortName),
                                    new Tuple <string, Relation, object>("direction_id", Relation.EQUAL, r.Cells[0].Value)
                                });
                                if (appEntrances.Count > 0)
                                {
                                    MessageBox.Show("На направление \"" + r.Cells[dgvDirections_Name.Index].Value + "\" подано заявление. Удаление невозможно.");
                                    stop = true;
                                }
                                else if (SharedClasses.Utility.ShowChoiceMessageWithConfirmation("Направление имеет профиль или включено в кампанию. Выполнить удаление направления и связанных профилей?",
                                                                                                 "Связь с кампанией"))
                                {
                                    using (MySql.Data.MySqlClient.MySqlTransaction transaction = _DB_Connection.BeginTransaction())
                                    {
                                        _DB_Connection.Delete(DB_Table.CAMPAIGNS_PROFILES_DATA, new Dictionary <string, object>
                                        {
                                            { "profiles_direction_faculty", _FacultyShortName }, { "profiles_direction_id", r.Cells[0].Value }
                                        }, transaction);
                                        _DB_Connection.Delete(DB_Table.PROFILES, new Dictionary <string, object>
                                        {
                                            { "faculty_short_name", _FacultyShortName }, { "direction_id", r.Cells[0].Value }
                                        }, transaction);
                                        _DB_Connection.Delete(DB_Table.CAMPAIGNS_DIRECTIONS_DATA, new Dictionary <string, object> {
                                            { "direction_faculty", _FacultyShortName },
                                            { "direction_id", r.Cells[0].Value }
                                        }, transaction);
                                        _DB_Connection.Delete(DB_Table.DIRECTIONS, new Dictionary <string, object> {
                                            { "faculty_short_name", _FacultyShortName },
                                            { "direction_id", r.Cells[0].Value }
                                        }, transaction);

                                        transaction.Commit();
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (!stop)
            {
                DialogResult = DialogResult.OK;
            }
        }
Exemple #9
0
        public void UpdateDictionaries()
        {
            Dictionary <uint, string> fisDictionaries = FIS_Connector.GetDictionaries(_FIS_Address, _FIS_Login, _FIS_Password);
            Dictionary <uint, string> dbDictionaries  = _DB_Connection.Select(DB_Table.DICTIONARIES).ToDictionary(d1 => (uint)d1[0], d2 => d2[1].ToString());

            string addedReport   = "Добавлены справочники:";
            ushort addedCount    = 0;
            string deletedReport = "";

            foreach (var d in fisDictionaries)
            {
                if (d.Key != 10 && d.Key != 19)
                {
                    var fisDictionaryItems = FIS_Connector.GetDictionaryItems(_FIS_Address, _FIS_Login, _FIS_Password, d.Key);

                    if (dbDictionaries.ContainsKey(d.Key))
                    {
                        if (d.Value == dbDictionaries[d.Key])
                        {
                            UpdateDictionaryItems((FIS_Dictionary)d.Key, d.Value, fisDictionaryItems);
                        }
                        else if (SharedClasses.Utility.ShowChoiceMessageWithConfirmation(
                                     "В ФИС изменилось наименование справочника с кодом " + d.Key +
                                     ":\nC \"" + dbDictionaries[d.Key] + "\"\nна \"" + d.Value +
                                     "\".\n\nОбновить наименование в БД?\nВ случае отказа изменения элементов этого справочника проверятся не будут.", //TODO Нужен мягкий знак "проверятся"?
                                     "Действие"
                                     ))
                        {
                            _DB_Connection.Update(DB_Table.DICTIONARIES,
                                                  new Dictionary <string, object> {
                                { "name", d.Value }
                            },
                                                  new Dictionary <string, object> {
                                { "id", d.Key }
                            }
                                                  );
                            UpdateDictionaryItems((FIS_Dictionary)d.Key, d.Value, fisDictionaryItems);
                        }
                    }
                    else
                    {
                        _DB_Connection.Insert(DB_Table.DICTIONARIES,
                                              new Dictionary <string, object> {
                            { "id", d.Key }, { "name", d.Value }
                        }
                                              );
                        foreach (var item in fisDictionaryItems)
                        {
                            _DB_Connection.Insert(DB_Table.DICTIONARIES_ITEMS,
                                                  new Dictionary <string, object> {
                                { "dictionary_id", d.Key }, { "item_id", item.Key }, { "name", item.Value }
                            }
                                                  );
                        }

                        addedReport += "\n" + d.Key + " \"" + d.Value + "\"";
                        addedCount++;
                    }
                }
            }

            foreach (var d in dbDictionaries)
            {
                if (!fisDictionaries.ContainsKey(d.Key))
                {
                    deletedReport += d.Key + ", ";
                }
            }

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

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

            MessageBox.Show(addedReport + deletedReport, "Обновление завершено", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Exemple #10
0
        private void UpdateData(DB_Table table, List <object[]> oldList, List <object[]> newList, bool autoGeneratedKey, int keysCount, string[] fieldNames)
        {
            using (MySql.Data.MySqlClient.MySqlTransaction transaction = _DB_Connection.BeginTransaction())
            {
                foreach (var oldItem in oldList)
                {
                    if (newList.Count == 0)
                    {
                        Dictionary <string, object> keyAndValues = new Dictionary <string, object>();
                        for (int i = 0; i < keysCount; i++)
                        {
                            keyAndValues.Add(fieldNames[i], oldItem[i]);
                        }

                        _DB_Connection.Delete(table, keyAndValues, transaction);
                    }
                    else
                    {
                        bool keysMatch   = true;
                        bool valuesMatch = true;
                        int  index       = -1;
                        do
                        {
                            index++;
                            object[] newItem = newList[index];
                            for (int i = 0; i < fieldNames.Length; i++)
                            {
                                if (i < keysCount)
                                {
                                    if ((keysMatch) && (newItem[i].ToString() != oldItem[i].ToString()))
                                    {
                                        keysMatch = false;
                                    }
                                }
                                else
                                if ((valuesMatch) && (newItem[i].ToString() != oldItem[i].ToString()))
                                {
                                    valuesMatch = false;
                                }
                            }
                        }while ((index < newList.Count - 1) && (!((keysMatch) && (index == keysCount - 1))));

                        if (keysMatch && valuesMatch)
                        {
                            newList.RemoveAt(index);
                        }
                        else if (keysMatch && !valuesMatch)
                        {
                            Dictionary <string, object> columnsAndValues = new Dictionary <string, object>();
                            for (int i = keysCount; i < fieldNames.Length; i++)
                            {
                                columnsAndValues.Add(fieldNames[i], newList[index][i]);
                            }

                            Dictionary <string, object> keyAndValues = new Dictionary <string, object>();
                            for (int i = 0; i < keysCount; i++)
                            {
                                keyAndValues.Add(fieldNames[i], newList[index][i]);
                            }

                            _DB_Connection.Update(table, columnsAndValues, keyAndValues, transaction);
                            newList.RemoveAt(index);
                        }
                        else
                        {
                            Dictionary <string, object> keyAndValues = new Dictionary <string, object>();
                            for (int i = 0; i < keysCount; i++)
                            {
                                keyAndValues.Add(fieldNames[i], oldItem[i]);
                            }

                            _DB_Connection.Delete(table, keyAndValues, transaction);
                        }
                    }
                }
                if (newList.Count != 0)
                {
                    foreach (var newItem in newList)
                    {
                        Dictionary <string, object> columnsAndValues = new Dictionary <string, object>();
                        if (autoGeneratedKey)
                        {
                            for (int i = keysCount; i < fieldNames.Length; i++)
                            {
                                columnsAndValues.Add(fieldNames[i], newItem[i]);
                            }
                        }
                        else
                        {
                            for (int i = 0; i < keysCount; i++)
                            {
                                columnsAndValues.Add(fieldNames[i], newItem[i]);
                            }
                            for (int i = keysCount; i < fieldNames.Length; i++)
                            {
                                columnsAndValues.Add(fieldNames[i], newItem[i]);
                            }
                        }
                        _DB_Connection.Insert(table, columnsAndValues, transaction);
                    }
                }

                transaction.Commit();
            }
        }