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); } } }
/// <summary> /// загрузка из xml в базу /// </summary> /// <param name="ePath">путь к распакованным файлам</param> public void LoadToDB(string ePath) { string lcfname = Path.GetFileNameWithoutExtension(ePath); string lcHMfname = $"HM{lcfname}.xml"; string lcLMfname = $"LM{lcfname}.xml"; //MessageBox.Show($"{ePath}\\{lcHMfname}\n{ePath}\\{lcLMfname}"); XDocument HMfname = XDocument.Load($"{ePath}\\{lcHMfname}"); //XmlDocument HMfname = new XmlDocument(); //HMfname.Load($"{ePath}\\{lcHMfname}"); int SluchCount = (from xe in HMfname.Root.Descendants("SLUCH") select xe).Count(); Invoke(new Action(() => MainPBar.Maximum = SluchCount)); XDocument LMfname = XDocument.Load($"{ePath}\\{lcLMfname}"); // получаем счет из файла Schet schet = new Schet(); Pacient pac = new Pacient(); Person p = new Person(); foreach (XElement SE in HMfname.Element("ZL_LIST").Elements("SCHET")) { string ns = ReadXMLElementString(SE, "NSCHET"); DateTime ds = ReadXMLElementDate(SE, "DSCHET"); int ye = ReadXMLElementInt(SE, "YEAR"); int mn = ReadXMLElementInt(SE, "MONTH"); string cm = ReadXMLElementString(SE, "CODE_MO"); string pl = ReadXMLElementString(SE, "PLAT"); double sum = ReadXMLElementDouble(SE, "SUMMAV"); schet = new Schet(0, ns, ds, ye, mn, cm, pl, sum); schet.SchetID = schet.InsertToSQL(sqlConn); } // получаем ZAP из файла foreach (XElement ZAP in HMfname.Element("ZL_LIST").Elements("ZAP")) { int n_zap = ReadXMLElementInt(ZAP, "N_ZAP"); //O int pr_nov = ReadXMLElementInt(ZAP, "PR_NOV"); //O string nschet_p = ReadXMLElementString(ZAP, "NSCHET_P"); DateTime dschet_p = ReadXMLElementDate(ZAP, "DSCHET_P"); int n_zap_p = ReadXMLElementInt(ZAP, "N_ZAP_P"); foreach (XElement PACIENT in ZAP.Elements("PACIENT")) { // вычитываем инфо пациента pac.Id_pac = ReadXMLElementString(PACIENT, "ID_PAC"); pac.Vpolis = ReadXMLElementInt(PACIENT, "VPOLIS"); pac.Spolis = ReadXMLElementString(PACIENT, "SPOLIS"); pac.Npolis = ReadXMLElementString(PACIENT, "NPOLIS"); pac.St_okato = ReadXMLElementString(PACIENT, "ST_ОКАТО"); pac.Smo = ReadXMLElementString(PACIENT, "SMO"); pac.Smo_ogrn = ReadXMLElementString(PACIENT, "SMO_OGRN"); pac.Smo_ok = ReadXMLElementString(PACIENT, "SMO_OK"); pac.Smo_nam = ReadXMLElementString(PACIENT, "SMO_NAM"); pac.Inv = ReadXMLElementInt(PACIENT, "INV"); pac.Mse = ReadXMLElementInt(PACIENT, "MSE"); pac.Novor = ReadXMLElementString(PACIENT, "NOVOR"); pac.Vnov_d = ReadXMLElementInt(PACIENT, "VNOV_D"); //выколупываем из L-файла ФИО и тд. var Pers = from pers in LMfname.Element("PERS_LIST").Elements("PERS") where (string)pers.Element("ID_PAC") == pac.Id_pac select pers; // читае инфо пациента foreach (XElement xEle in Pers) { p.Id_pac = ReadXMLElementString(xEle, "ID_PAC"); p.Fam = ReadXMLElementString(xEle, "FAM"); p.Im = ReadXMLElementString(xEle, "IM"); p.Ot = ReadXMLElementString(xEle, "OT"); p.W = ReadXMLElementInt(xEle, "W"); p.Dr = ReadXMLElementDate(xEle, "DR"); p.Tel = ReadXMLElementString(xEle, "TEL"); p.Fam_p = ReadXMLElementString(xEle, "FAM_P"); p.Im_p = ReadXMLElementString(xEle, "FAM_P"); p.Ot_p = ReadXMLElementString(xEle, "OT_P"); p.W_p = ReadXMLElementInt(xEle, "W_P"); p.Dr_p = ReadXMLElementDate(xEle, "DR_P"); p.Mr = ReadXMLElementString(xEle, "MR"); p.Doctype = ReadXMLElementInt(xEle, "DOCTYPE"); p.Docser = ReadXMLElementString(xEle, "DOCSER"); p.Docnum = ReadXMLElementString(xEle, "DOCNUM"); p.Snils = ReadXMLElementString(xEle, "SNILS"); p.Okatog = ReadXMLElementString(xEle, "OKATOG"); p.Okatop = ReadXMLElementString(xEle, "OKATOP"); p.Fh = ReadXMLElementString(xEle, "FH"); p.Kat_lg = ReadXMLElementInt(xEle, "KAT_LG"); p.Commentp = ReadXMLElementString(xEle, "COMENTP"); p.Adr = ReadXMLElementString(xEle, "ADR"); pac.Pers = p; } //var items = from xe in LMfname.Element("PERS_LIST").Elements("PERS") // where (xe.Element("ID_PAC").Value == id_pac) // select new Person // { // Id_pac = xe.Element("ID_PAC").Value, // Fam = xe.Element("FAM").Value, // Im = xe.Element("IM").Value, // Ot = xe.Element("OT").Value , // Dr = DateTime.ParseExact(xe.Element("DR").Value, "yyyy-MM-dd", null) // }; //foreach (var item in items) //{ // //MessageBox.Show($"{item.ToString()}"); // //MessageBox.Show($"{item.Fam} {item.Im} {item.Ot}"); //} } // вычитываем инфо по законченному случаю foreach (XElement Z_SL in ZAP.Elements("Z_SL")) { Z_sl z = new Z_sl(); z.Pac = pac; z.Z_sl_id = ReadXMLElementInt(Z_SL, "Z_SL_ID"); z.Istochik_opl = ReadXMLElementInt(Z_SL, "ISTOCHIK_OPL"); z.Usl_ok = ReadXMLElementInt(Z_SL, "USL_OK"); z.Vidpom = ReadXMLElementInt(Z_SL, "VIDPOM"); z.For_pom = ReadXMLElementInt(Z_SL, "FOR_POM"); z.Lpu = ReadXMLElementString(Z_SL, "LPU"); z.Npr_mo = ReadXMLElementString(Z_SL, "NPR_MO"); z.Np = ReadXMLElementString(Z_SL, "NP"); z.Npr_date = ReadXMLElementDate(Z_SL, "NPR_DATE"); z.Np_iddokt = ReadXMLElementString(Z_SL, "NP_IDDOKT"); z.Date_z_1 = ReadXMLElementDate(Z_SL, "DATE_Z_1"); z.Date_z_2 = ReadXMLElementDate(Z_SL, "DATE_Z_2"); z.Kd_z = ReadXMLElementInt(Z_SL, "KD_Z"); z.Vnov_m = ReadXMLElementInt(Z_SL, "VNOV_M"); z.Rslt = ReadXMLElementInt(Z_SL, "RSLT"); z.Ishod = ReadXMLElementInt(Z_SL, "ISHOD"); z.Os_sluch = ReadXMLElementInt(Z_SL, "OS_SLUCH"); z.Vb_p = ReadXMLElementInt(Z_SL, "VB_P"); z.Idsp = ReadXMLElementInt(Z_SL, "IDSP"); z.Sum_z = ReadXMLElementDouble(Z_SL, "SUMV_Z"); z.Oplata = ReadXMLElementInt(Z_SL, "OPLATA"); z.Vbr = ReadXMLElementInt(Z_SL, "VBR"); z.Rslt_d = ReadXMLElementInt(Z_SL, "RSLT_D"); z.P_otk = ReadXMLElementInt(Z_SL, "P_OTK"); z.InsertToSQL(sqlConn, pac, schet); // перебираем случаи foreach (XElement SLUCH in Z_SL.Elements("SLUCH")) { Sluch s = new Sluch(); // вычитываем случай лечения s.N_zap = n_zap; s.Idcase = ReadXMLElementInt(SLUCH, "IDCASE"); s.Caseguid = ReadXMLElementString(SLUCH, "CASEGUID"); s.Vid_hmp = ReadXMLElementString(SLUCH, "VID_HMP"); s.Metod_hmp = ReadXMLElementInt(SLUCH, "METOD_HMP"); s.Disp = ReadXMLElementString(SLUCH, "Disp"); s.Lpu_1 = ReadXMLElementString(SLUCH, "Lpu_1"); s.Podr = ReadXMLElementInt(SLUCH, "Podr"); s.Uchastok = ReadXMLElementInt(SLUCH, "Uchastok"); s.Punkt = ReadXMLElementInt(SLUCH, "Punkt"); s.Profil = ReadXMLElementInt(SLUCH, "Profil"); s.Profil_k = ReadXMLElementInt(SLUCH, "Profil_k"); s.Det = ReadXMLElementInt(SLUCH, "Det"); s.Tal_d = ReadXMLElementDate(SLUCH, "Tal_d"); s.Tal_num = ReadXMLElementString(SLUCH, "Tal_num"); s.Tal_p = ReadXMLElementDate(SLUCH, "Tal_p"); s.Nhistory = ReadXMLElementString(SLUCH, "Nhistory"); s.Obr = ReadXMLElementString(SLUCH, "Obr"); s.P_per = ReadXMLElementInt(SLUCH, "P_per"); s.Date_1 = ReadXMLElementDate(SLUCH, "Date_1"); s.Date_2 = ReadXMLElementDate(SLUCH, "Date_2"); s.Kd = ReadXMLElementInt(SLUCH, "Kd"); s.Ds0 = ReadXMLElementString(SLUCH, "Ds0"); s.Ds1 = ReadXMLElementString(SLUCH, "Ds1"); s.Ds1_pr = ReadXMLElementInt(SLUCH, "Ds1_pr"); s.Ds1_dn = ReadXMLElementInt(SLUCH, "Ds1_dn"); s.C_zab = ReadXMLElementInt(SLUCH, "C_zab"); s.Ds_onk = ReadXMLElementInt(SLUCH, "Ds_onk"); s.Code_mes1 = ReadXMLElementString(SLUCH, "Code_mes1"); s.Code_mes2 = ReadXMLElementString(SLUCH, "Code_mes2"); s.Reab = ReadXMLElementInt(SLUCH, "Reab"); s.Prvs = ReadXMLElementInt(SLUCH, "Prvs"); s.Iddokt = ReadXMLElementString(SLUCH, "Iddokt"); s.Ed_col = ReadXMLElementDouble(SLUCH, "Ed_col"); s.Tarif = ReadXMLElementDouble(SLUCH, "Tarif"); s.Sumv = ReadXMLElementDouble(SLUCH, "Sumv"); s.Sump = ReadXMLElementDouble(SLUCH, "Sump"); s.Idcase_p = ReadXMLElementInt(SLUCH, "Idcase_p"); s.CodeRefusal = ReadXMLElementInt(SLUCH, "CodeRefusal"); s.Comentsl = ReadXMLElementString(SLUCH, "Comentsl"); s.Pr_nov = pr_nov; switch (z.For_pom) { case 1: s.PR3 = "*"; break; default: s.PR3 = null; break; } s.InsertToSQL(sqlConn, pac, schet, z); // перебираем услуги foreach (XElement USL in SLUCH.Elements("USL")) { Usl u = new Usl(); // вычитываем услуги по случаю u.IDSERV = ReadXMLElementString(USL, "IDSERV"); u.LPU = ReadXMLElementString(USL, "LPU"); u.LPU_1 = ReadXMLElementString(USL, "LPU_1"); u.PODR = ReadXMLElementInt(USL, "PODR"); u.UCHASTOK = ReadXMLElementInt(USL, "UCHASTOK"); u.PUNKT = ReadXMLElementInt(USL, "PUNKT"); u.PROFIL = ReadXMLElementInt(USL, "PROFIL"); u.VID_VME = ReadXMLElementString(USL, "VID_VME"); u.DET = ReadXMLElementInt(USL, "PROFIL"); u.DATE_IN = ReadXMLElementDate(USL, "DATE_IN"); u.DATE_OUT = ReadXMLElementDate(USL, "DATE_OUT"); u.P_OTK = ReadXMLElementInt(USL, "P_OTK"); u.DS1 = ReadXMLElementString(USL, "DS"); u.CODE_USL = ReadXMLElementString(USL, "CODE_USL"); u.KOL_USL = ReadXMLElementDouble(USL, "KOL_USL"); u.TARIF = ReadXMLElementDouble(USL, "TARIF"); u.SUMV_USL = ReadXMLElementDouble(USL, "SUMV_USL"); u.PRVS = ReadXMLElementInt(USL, "PRVS"); u.CODE_MD = ReadXMLElementString(USL, "CODE_MD"); u.NPL = ReadXMLElementInt(USL, "NPL"); u.DENTAL_F = ReadXMLElementInt(USL, "DENTAL_F"); u.DENT_SURFACE = ReadXMLElementString(USL, "DENT_SURFACE"); u.COMENTU = ReadXMLElementString(USL, "COMENTU"); u.InserToSQL(sqlConn, schet, s); } Invoke(new Action(() => MainPBar.Value += 1)); } } } HMfname = null; LMfname = null; Invoke(new Action(() => MainPBar.Value = 0)); }