Esempio n. 1
0
        public static void ImportMagAbits()
        {
            List <string> lstPersons = new List <string>();
            List <string> lstAbits   = new List <string>();

            LoadFromInet loadClass = new LoadFromInet();
            DBPriem      _bdcInet  = loadClass.BDCInet;

            using (PriemEntities context = new PriemEntities())
            {
                string  _sQuery = @"SELECT DISTINCT qAbiturient.Id, qAbiturient.PersonId, qAbiturient.Barcode AS AbitBarcode, extPerson.Barcode AS PersonBarcode
                              FROM qAbiturient INNER JOIN extPerson ON qAbiturient.PersonId = extPerson.Id WHERE StudyLevelId = 17 AND Enabled = 1 AND IsApprovedByComission = 1 AND IsImported = 0";
                DataSet ds      = _bdcInet.GetDataSet(_sQuery);

                Guid?personId;
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    int?abitBarcode = (int?)dr["AbitBarcode"];
                    if (!MainClass.CheckAbitBarcode(abitBarcode))
                    {
                        continue;
                    }


                    int?persBarcode = (int?)dr["PersonBarcode"];
                    if (!MainClass.CheckPersonBarcode(persBarcode))
                    {
                        personId = (from pers in context.extForeignPerson
                                    where pers.Barcode == persBarcode
                                    select pers.Id).FirstOrDefault();
                    }
                    else
                    {
                        extPersonAll person = loadClass.GetPersonByBarcode(persBarcode.Value);

                        if (!CheckIdent(person))
                        {
                            lstPersons.Add(persBarcode.ToString());
                            continue;
                        }

                        ObjectParameter entId = new ObjectParameter("id", typeof(Guid));
                        context.Person_Foreign_insert(person.Barcode, person.Name, person.SecondName, person.Surname, person.BirthDate, person.BirthPlace, person.PassportTypeId,
                                                      person.PassportSeries, person.PassportNumber, person.PassportAuthor, person.PassportDate, person.Sex, person.CountryId, person.NationalityId,
                                                      person.RegionId, person.Phone, person.Mobiles, person.Email,
                                                      person.Code, person.City, person.Street, person.House, person.Korpus, person.Flat,
                                                      person.CodeReal, person.CityReal, person.StreetReal, person.HouseReal, person.KorpusReal, person.FlatReal,
                                                      person.HostelAbit, false, null, false, null, person.IsExcellent,
                                                      person.LanguageId, person.SchoolCity, person.SchoolTypeId, person.SchoolName, person.SchoolNum, person.SchoolExitYear, person.SchoolAVG,
                                                      person.ForeignCountryEducId, person.RegionEducId, person.IsEqual, person.EqualDocumentNumber, person.HasTRKI, person.TRKICertificateNumber,
                                                      person.AttestatRegion, person.AttestatSeries, person.AttestatNum, person.DiplomSeries, person.DiplomNum,
                                                      person.HighEducation, person.HEProfession, person.HEQualification, person.HEEntryYear, person.HEExitYear, person.HEStudyFormId,
                                                      person.HEWork, person.Stag, person.WorkPlace, person.Privileges, person.PassportCode,
                                                      person.PersonalCode, person.PersonInfo, person.ExtraInfo, person.ScienceWork, person.StartEnglish, person.EnglishMark, entId);

                        //_bdcInet.ExecuteQuery("UPDATE Person SET IsImported = 1 WHERE Person.Barcode = " + persBarcode);

                        personId = (Guid)entId.Value;
                    }

                    qAbiturient abit = loadClass.GetAbitByBarcode(abitBarcode.Value);

                    int cnt = (from en in context.qEntry
                               where en.Id == abit.EntryId && !en.IsClosed
                               select en).Count();

                    if (cnt == 0)
                    {
                        lstAbits.Add(abitBarcode.ToString());
                        continue;
                    }

                    ObjectParameter abEntId = new ObjectParameter("id", typeof(Guid));

                    int competitionId;
                    if (abit.StudyBasisId == 1)
                    {
                        competitionId = 4;
                    }
                    else
                    {
                        competitionId = 3;
                    }

                    context.Abiturient_Insert(personId, abit.EntryId, competitionId, false, false, false, false, null, abit.DocDate, DateTime.Now,
                                              false, false, null, null, null, null, abit.LanguageId, false,
                                              abit.Priority, abit.Barcode, abit.CommitId, abit.CommitNumber, abit.IsGosLine, abEntId);

                    // _bdcInet.ExecuteQuery("UPDATE Application SET IsImported = 1 WHERE Application.Barcode = " + abitBarcode);
                }
            }
        }