Ejemplo n.º 1
0
        public void LoadUsers()
        {
            SqlConnection connection = new SqlConnection(MyProject.Properties.Settings.Default.Connection);
            try
            {
                connection.Open();
            }
            catch (Exception ex)
            {
                connection = new SqlConnection(MyProject.Properties.Settings.Default.Connection);
                connection.Open();
                SqlCommand command = connection.CreateCommand();
                using (FileStream fstream = File.OpenRead("SQLQuery2.sql"))
                {
                    // преобразуем строку в байты
                    byte[] array = new byte[fstream.Length];
                    // считываем данные
                    fstream.Read(array, 0, array.Length);
                    // декодируем байты в строку
                    string textFromFile = Encoding.Default.GetString(array);
                    command.CommandText = textFromFile;
                    command.ExecuteNonQuery();
                }
            }
            finally
            {
                string select = $"select * from PACIENT ";
                SqlCommand command = new SqlCommand(select, connection);
                using (SqlDataReader reader = command.ExecuteReader())
                {

                    while (reader.Read())
                    {
                        Admin pacients = new Admin(reader.GetInt32(0));
                        pacients.IDpacient = reader.GetInt32(0);
                        pacients.Name = reader.GetString(3);
                        pacients.Surname = reader.GetString(4);
                        if (reader.GetString(5).Equals("Man"))
                            pacients.Gender = Gender.Man;
                        else
                            pacients.Gender = Gender.Woman;
                        pacients.Email = reader.GetString(6);
                        PACIENT.Add(pacients);
                    }

                }
                connection.Close();
            }           
        }
Ejemplo n.º 2
0
        private void LoadHAction_Execute(object sender, SimpleActionExecuteEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                using (Stream stream = dialog.OpenFile())
                {
                    UnitOfWork uow = new UnitOfWork(((DevExpress.ExpressApp.Xpo.XPObjectSpace)ObjectSpace).Session.DataLayer);
                    XDocument  doc = XDocument.Load(stream);
                    if (doc.Root.Name != "ZL_LIST")
                    {
                        throw new ArgumentException("ZL_LIST");
                    }
                    //ZL_LIST zl_list = ObjectSpace.CreateObject<ZL_LIST>();
                    var zl_list = new ZL_LIST(uow);

                    //заголовок
                    XElement xzglv = doc.Root.Element("ZGLV");
                    if (xzglv != null)
                    {
                        var zglv = new ZGLV(uow);
                        //var zglv = ObjectSpace.CreateObject<ZGLV>();
                        zglv.VERSION  = GetString(xzglv.Element("VERSION"), true);
                        zglv.DATA     = GetString(xzglv.Element("DATA"), true);
                        zglv.FILENAME = GetString(xzglv.Element("FILENAME"), true);
                        //zglv.FILENAME1 = GetString(xzglv.Element("FILENAME1"), false);

                        zl_list.ZGLV = zglv;
                    }
                    else
                    {
                        throw new ArgumentException("ZGLV");
                    }

                    //счет
                    XElement xschet = doc.Root.Element("SCHET");
                    if (xschet != null)
                    {
                        var schet = new SCHET(uow);
                        //SCHET schet = ObjectSpace.CreateObject<SCHET>();
                        schet.CODE      = GetString(xschet.Element("CODE"), true);
                        schet.CODE_MO   = GetString(xschet.Element("CODE_MO"), true);
                        schet.YEAR      = GetString(xschet.Element("YEAR"), false);
                        schet.MONTH     = GetString(xschet.Element("MONTH"), false);
                        schet.NSCHET    = GetString(xschet.Element("NSCHET"), false);
                        schet.DSCHET    = GetString(xschet.Element("DSCHET"), false);
                        schet.PLAT      = GetString(xschet.Element("PLAT"), false);
                        schet.SUMMAV    = GetString(xschet.Element("SUMMAV"), false);
                        schet.COMENTS   = GetString(xschet.Element("COMENTS"), false);
                        schet.SUMMAP    = GetString(xschet.Element("SUMMAP"), false);
                        schet.SANK_MEK  = GetString(xschet.Element("SANK_MEK"), false);
                        schet.SANK_MEE  = GetString(xschet.Element("SANK_MEE"), false);
                        schet.SANK_EKMP = GetString(xschet.Element("SANK_EKMP"), false);
                        zl_list.SCHET   = schet;
                    }

                    int counter = 0;
                    //Список записей
                    foreach (var xzap in doc.Root.Elements("ZAP"))
                    {
                        //var zap = ObjectSpace.CreateObject<ZAP>();
                        var zap = new ZAP(uow);

                        zap.N_ZAP  = GetString(xzap.Element("N_ZAP"), true);
                        zap.PR_NOV = GetString(xzap.Element("PR_NOV"), true);

                        var xpacient = xzap.Element("PACIENT");
                        if (xpacient != null)
                        {
                            //PACIENT pacient = ObjectSpace.CreateObject<PACIENT>();
                            var pacient = new PACIENT(uow);

                            pacient.ID_PAC   = GetString(xpacient.Element("ID_PAC"), true);
                            pacient.VPOLIS   = GetString(xpacient.Element("VPOLIS"), true);
                            pacient.SPOLIS   = GetString(xpacient.Element("SPOLIS"), false);
                            pacient.NPOLIS   = GetString(xpacient.Element("NPOLIS"), true);
                            pacient.ST_OKATO = GetString(xpacient.Element("ST_OKATO"), false);
                            pacient.SMO      = GetString(xpacient.Element("SMO"), false);
                            pacient.SMO_OGRN = GetString(xpacient.Element("SMO_OGRN"), false);
                            pacient.SMO_OK   = GetString(xpacient.Element("SMO_OK"), false);
                            pacient.SMO_NAM  = GetString(xpacient.Element("SMO_NAM"), false);
                            pacient.NOVOR    = GetString(xpacient.Element("NOVOR"), false);
                            pacient.VNOV_D   = GetString(xpacient.Element("VNOV_D"), false);

                            zap.PACIENT = pacient;
                        }

                        foreach (var xsluch in xzap.Elements("SLUCH"))
                        {
                            var sluch = new SLUCH(uow);
                            //SLUCH sluch = ObjectSpace.CreateObject<SLUCH>();

                            sluch.IDCASE   = GetString(xsluch.Element("IDCASE"), true);
                            sluch.USL_OK   = GetString(xsluch.Element("USL_OK"), false);
                            sluch.VIDPOM   = GetString(xsluch.Element("VIDPOM"), false);
                            sluch.FOR_POM  = GetString(xsluch.Element("FOR_POM"), false);
                            sluch.NPR_MO   = GetString(xsluch.Element("NPR_MO"), false);
                            sluch.EXTR     = GetString(xsluch.Element("EXTR"), false);
                            sluch.LPU      = GetString(xsluch.Element("LPU"), false);
                            sluch.LPU_1    = GetString(xsluch.Element("LPU_1"), false);
                            sluch.PODR     = GetString(xsluch.Element("PODR"), false);
                            sluch.PROFIL   = GetString(xsluch.Element("PROFIL"), false);
                            sluch.DET      = GetString(xsluch.Element("DET"), false);
                            sluch.NHISTORY = GetString(xsluch.Element("NHISTORY"), false);
                            sluch.DATE_1   = GetString(xsluch.Element("DATE_1"), false);
                            sluch.DATE_2   = GetString(xsluch.Element("DATE_2"), false);
                            sluch.DS0      = GetString(xsluch.Element("DS0"), false);
                            sluch.DS1      = GetString(xsluch.Element("DS1"), false);
                            //sluch.DS2 = GetString(xsluch.Element("DS2"), false);
                            //sluch.DS3 = GetString(xsluch.Element("DS3"), false);
                            sluch.VNOV_M    = GetString(xsluch.Element("VNOV_M"), false);
                            sluch.CODE_MES1 = GetString(xsluch.Element("CODE_MES1"), false);
                            sluch.CODE_MES2 = GetString(xsluch.Element("CODE_MES2"), false);
                            sluch.RSLT      = GetString(xsluch.Element("RSLT"), false);
                            sluch.ISHOD     = GetString(xsluch.Element("ISHOD"), false);
                            sluch.PRVS      = GetString(xsluch.Element("PRVS"), false);
                            sluch.VERS_SPEC = GetString(xsluch.Element("VERS_SPEC"), false);
                            sluch.IDDOKT    = GetString(xsluch.Element("IDDOKT"), false);
                            sluch.OS_SLUCH  = GetString(xsluch.Element("OS_SLUCH"), false);
                            sluch.IDSP      = GetString(xsluch.Element("IDSP"), false);
                            sluch.ED_COL    = GetString(xsluch.Element("ED_COL"), false);
                            sluch.TARIF     = GetString(xsluch.Element("TARIF"), false);
                            sluch.SUMV      = GetString(xsluch.Element("SUMV"), false);
                            sluch.OPLATA    = GetString(xsluch.Element("OPLATA"), false);
                            sluch.SUMP      = GetString(xsluch.Element("SUMP"), false);
                            sluch.SANK_IT   = GetString(xsluch.Element("SANK_IT"), false);
                            sluch.SANK      = GetString(xsluch.Element("SANK"), false);
                            sluch.COMENTSL  = GetString(xsluch.Element("COMENTSL"), false);

                            foreach (var xusl in xsluch.Elements("USL"))
                            {
                                var usl = new USL(uow);
                                //USL usl = ObjectSpace.CreateObject<USL>();

                                usl.IDSERV   = GetString(xusl.Element("IDSERV"), true);
                                usl.LPU      = GetString(xusl.Element("LPU"), false);
                                usl.LPU_1    = GetString(xusl.Element("LPU_1"), false);
                                usl.PODR     = GetString(xusl.Element("PODR"), false);
                                usl.PROFIL   = GetString(xusl.Element("PROFIL"), false);
                                usl.VID_VME  = GetString(xusl.Element("VID_VME"), false);
                                usl.DET      = GetString(xusl.Element("DET"), false);
                                usl.DATE_IN  = GetString(xusl.Element("DATE_IN"), false);
                                usl.DATE_OUT = GetString(xusl.Element("DATE_OUT"), false);
                                usl.DS       = GetString(xusl.Element("DS"), false);
                                usl.CODE_USL = GetString(xusl.Element("CODE_USL"), false);
                                usl.KOL_USL  = GetString(xusl.Element("KOL_USL"), false);
                                usl.TARIF    = GetString(xusl.Element("TARIF"), false);
                                usl.SUMV_USL = GetString(xusl.Element("SUMV_USL"), false);
                                usl.PRVS     = GetString(xusl.Element("PRVS"), false);
                                usl.CODE_MD  = GetString(xusl.Element("CODE_MD"), false);
                                usl.COMENTU  = GetString(xusl.Element("COMENTU"), false);

                                sluch.USL.Add(usl);
                            }

                            zap.SLUCH.Add(sluch);
                        }
                        zl_list.ZAPS.Add(zap);

                        counter++;
                        if (counter % 1000 == 0)
                        {
                            uow.CommitChanges();
                            uow.Dispose();
                            uow     = new UnitOfWork(((DevExpress.ExpressApp.Xpo.XPObjectSpace)ObjectSpace).Session.DataLayer);
                            zl_list = uow.GetObjectByKey <ZL_LIST>(zl_list.Oid);
                            //ObjectSpace.CommitChanges();
                        }
                    }
                    uow.CommitChanges();
                    //ObjectSpace.CommitChanges();
                    MessageBox.Show("Загрузка завершена. Всего записей : " + counter);
                }
            }
        }