Ejemplo n.º 1
0
        public long InsertToSQL(SqlConnection pSqlConn, Pacient p, Schet s, Z_sl z)
        {
            long slID;

            if (this.SluchID == 0)
            {
                string     sqlExp  = @"insert into EXP_RE_EX (EXP_SCHET_EX_ID,EXP_Z_SL_ID,NSH,DSH,RE,G1,POLIS_V,POLIS_S,POLIS_N,XL,MKB1,MKU1,G131,DS1,SN1,PR3,ITOG,FAMIL,IMJA,OTCH,GR,
POL,ADRES,ADR,G9,DNL,DKL,DISMEN,POT,TR,SUM_EX,OBR_S59,PCOD_VR,NSH_UM,OS_SLUCH,COMMENTU,DOCTYPE,DOCSER,DOCNUM,OKATOG,OKATOP,ISHOD,RSLT,VID_HMP,METOD_HMP,
DS0,KSG,V006_ID,V008_ID,V010_ID,V015_CODE,V016_IDDT,V017_IDDR,V014_ID,ISTOCHIK_OPL,UOMP,VIDP,FRMMP,LPU_1,DET,VNOV_M,CODE_MES1,CODE_MES2,
RSLT_D,PRVS,ED_COL,OPLATA,ID_PAC,OT,G151,G141,G161,VBR,UCHASTOK,PUNKT,TAL_D,TAL_P,DIRECT,DELIVER,PR_D_N,INV,MSE,KSG_DK,DS1_PR,PR_NOV,PROFIL_K,TAL_NUM,KD,DS1_DN,Z_SL_ID,DS_ONK,C_ZAB,REAB) 
values(@EXP_SCHET_EX_ID,@EXP_Z_SL_ID,@NSH,@DSH,@RE,@G1,@POLIS_V,@POLIS_S,@POLIS_N,@XL,@MKB1,@MKU1,@G131,@DS1,@SN1,@PR3,@ITOG,@FAMIL,@IMJA,@OTCH,@GR,
@POL,@ADRES,@ADR,@G9,@DNL,@DKL,@DISMEN,@POT,@TR,@SUM_EX,@OBR_S59,@PCOD_VR,@NSH_UM,@OS_SLUCH,@COMMENTU,@DOCTYPE,@DOCSER,@DOCNUM,@OKATOG,@OKATOP,@ISHOD,@RSLT,@VID_HMP,@METOD_HMP,
@DS0,@KSG,@V006_ID,@V008_ID,@V010_ID,@V015_CODE,@V016_IDDT,@V017_IDDR,@V014_ID,@ISTOCHIK_OPL,@UOMP,@VIDP,@FRMMP,@LPU_1,@DET,@VNOV_M,@CODE_MES1,@CODE_MES2,
@RSLT_D,@PRVS,@ED_COL,@OPLATA,@ID_PAC,@OT,@G151,@G141,@G161,@VBR,@UCHASTOK,@PUNKT,@TAL_D,@TAL_P,@DIRECT,@DELIVER,@PR_D_N,@INV,@MSE,@KSG_DK,@DS1_PR,@PR_NOV,@PROFIL_K,@TAL_NUM,@KD,@DS1_DN,@Z_SL_ID,@DS_ONK,@C_ZAB,@REAB) 
select @@IDENTITY as sID";
                SqlCommand command = new SqlCommand(sqlExp, pSqlConn);

                SqlParameter EXP_SCHET_EX_ID = new SqlParameter("@EXP_SCHET_EX_ID", s.SchetID);
                command.Parameters.Add(EXP_SCHET_EX_ID);
                SqlParameter EXP_Z_SL_ID = new SqlParameter("@EXP_Z_SL_ID", z.Exp_z_sl_id);
                command.Parameters.Add(EXP_Z_SL_ID);
                SqlParameter NSH = new SqlParameter("@NSH", s.Nschet);
                command.Parameters.Add(NSH);
                SqlParameter DSH = new SqlParameter("@DSH", s.Dschet);
                command.Parameters.Add(DSH);
                SqlParameter RE = new SqlParameter("@RE", this.N_zap);
                command.Parameters.Add(RE);
                SqlParameter G1 = new SqlParameter("@G1", this.Idcase);
                command.Parameters.Add(G1);
                SqlParameter POLIS_V = new SqlParameter("@POLIS_V", z.Pac.Vpolis);
                command.Parameters.Add(POLIS_V);
                SqlParameter POLIS_S = new SqlParameter("@POLIS_S", z.Pac.Spolis ?? (object)DBNull.Value);
                command.Parameters.Add(POLIS_S);
                SqlParameter POLIS_N = new SqlParameter("@POLIS_N", z.Pac.Npolis);
                command.Parameters.Add(POLIS_N);
                SqlParameter XL = new SqlParameter("@XL", z.Xl);
                command.Parameters.Add(XL);
                SqlParameter MKB1 = new SqlParameter("@MKB1", this.Mkb1);
                command.Parameters.Add(MKB1);
                SqlParameter MKU1 = new SqlParameter("@MKU1", this.Mku1 ?? "");
                command.Parameters.Add(MKU1);
                SqlParameter DS1 = new SqlParameter("@DS1", this.Ds1);
                command.Parameters.Add(DS1);
                SqlParameter G131 = new SqlParameter("@G131", this.Ed_col);
                command.Parameters.Add(G131);
                command.Parameters.Add("@SN1", SqlDbType.Decimal).Value = 0;
                SqlParameter PR3 = new SqlParameter("@PR3", this.PR3 ?? (object)DBNull.Value);
                command.Parameters.Add(PR3);
                SqlParameter ITOG = new SqlParameter("@ITOG", this.Sumv);
                command.Parameters.Add(ITOG);
                SqlParameter FAMIL = new SqlParameter("@FAMIL", z.Pac.Pers.Fam ?? "");
                command.Parameters.Add(FAMIL);
                SqlParameter IMJA = new SqlParameter("@IMJA", z.Pac.Pers.Im ?? "");
                command.Parameters.Add(IMJA);
                SqlParameter OTCH = new SqlParameter("@OTCH", z.Pac.Pers.Ot ?? "");
                command.Parameters.Add(OTCH);
                SqlParameter GR = new SqlParameter("@GR", z.Pac.Pers.Dr);
                command.Parameters.Add(GR);
                SqlParameter POL = new SqlParameter("@POL", z.Pac.Pers.W);
                command.Parameters.Add(POL);
                command.Parameters.Add("@ADRES", SqlDbType.Decimal).Value = 0;
                SqlParameter ADR = new SqlParameter("@ADR", z.Pac.Pers.Adr ?? "");
                command.Parameters.Add(ADR);
                SqlParameter G9 = new SqlParameter("@G9", this.Nhistory);
                command.Parameters.Add(G9);
                SqlParameter DNL = new SqlParameter("@DNL", this.Date_1);
                command.Parameters.Add(DNL);
                SqlParameter DKL = new SqlParameter("@DKL", this.Date_2);
                command.Parameters.Add(DKL);
                SqlParameter DISMEN = new SqlParameter("@DISMEN", DateTime.Now);
                command.Parameters.Add(DISMEN);
                SqlParameter POT = new SqlParameter("@POT", this.Profil);
                command.Parameters.Add(POT);
                SqlParameter TR = new SqlParameter("@TR", this.Tarif);
                command.Parameters.Add(TR);
                SqlParameter SUM_EX = new SqlParameter("@SUM_EX", this.Sump);
                command.Parameters.Add(SUM_EX);
                SqlParameter OBR_S59 = new SqlParameter("@OBR_S59", this.Obr ?? (object)DBNull.Value);
                command.Parameters.Add(OBR_S59);
                SqlParameter PCOD_VR = new SqlParameter("@PCOD_VR", this.Iddokt ?? (object)DBNull.Value);
                command.Parameters.Add(PCOD_VR);
                SqlParameter NSH_UM = new SqlParameter("@NSH_UM", s.Nsh_um);
                command.Parameters.Add(NSH_UM);
                SqlParameter OS_SLUCH = new SqlParameter("@OS_SLUCH", z.Os_sluch == 0 ? (object)DBNull.Value : z.Os_sluch);
                command.Parameters.Add(OS_SLUCH);
                SqlParameter COMMENTU = new SqlParameter("@COMMENTU", this.Comentsl ?? (object)DBNull.Value);
                command.Parameters.Add(COMMENTU);
                SqlParameter DOCTYPE = new SqlParameter("@DOCTYPE", p.Pers.Doctype == 0 ? (object)DBNull.Value : p.Pers.Doctype);
                command.Parameters.Add(DOCTYPE);
                command.Parameters.Add("@DOCSER", SqlDbType.NChar).Value     = p.Pers.Docser ?? (object)DBNull.Value;
                command.Parameters.Add("@DOCNUM", SqlDbType.NChar).Value     = p.Pers.Docnum ?? (object)DBNull.Value;
                command.Parameters.Add("@OKATOG", SqlDbType.NChar).Value     = p.Pers.Okatog ?? (object)DBNull.Value;
                command.Parameters.Add("@OKATOP", SqlDbType.NChar).Value     = p.Pers.Okatop ?? (object)DBNull.Value;
                command.Parameters.Add("@ISHOD", SqlDbType.Decimal).Value    = z.Ishod == 0 ? (object)DBNull.Value : z.Ishod;
                command.Parameters.Add("@RSLT", SqlDbType.Decimal).Value     = z.Rslt == 0 ? (object)DBNull.Value : z.Rslt;
                command.Parameters.Add("@VID_HMP", SqlDbType.NVarChar).Value = this.Vid_hmp ?? (object)DBNull.Value;
                command.Parameters.Add("@METOD_HMP", SqlDbType.Int).Value    = this.Metod_hmp == 0 ? (object)DBNull.Value : this.Metod_hmp;
                command.Parameters.Add("@DS0", SqlDbType.NVarChar).Value     = this.Ds0 ?? (object)DBNull.Value;
                command.Parameters.Add("@KSG", SqlDbType.NVarChar).Value     = this.Ksg ?? (object)DBNull.Value;
                command.Parameters.Add("@V006_ID", SqlDbType.Int).Value      = z.Usl_ok == 0 ? (object)DBNull.Value : z.Usl_ok;
                command.Parameters.Add("@V008_ID", SqlDbType.Int).Value      = z.Vidpom == 0 ? (object)DBNull.Value : z.Vidpom;
                command.Parameters.Add("@V010_ID", SqlDbType.Int).Value      = z.Idsp == 0 ? (object)DBNull.Value : z.Idsp;
                command.Parameters.Add("@V015_CODE", SqlDbType.Int).Value    = this.Prvs == 0 ? (object)DBNull.Value : this.Prvs;
                command.Parameters.Add("@V016_IDDT", SqlDbType.NChar).Value  = this.Disp ?? (object)DBNull.Value;
                command.Parameters.Add("@V017_IDDR", SqlDbType.Int).Value    = z.Rslt_d == 0 ? (object)DBNull.Value : z.Rslt_d;
                command.Parameters.Add("@V014_ID", SqlDbType.Int).Value      = z.For_pom == 0 ? (object)DBNull.Value : z.For_pom;
                command.Parameters.Add("@ISTOCHIK_OPL", SqlDbType.Int).Value = z.Istochik_opl == 0 ? (object)DBNull.Value : z.Istochik_opl;
                command.Parameters.Add("@UOMP", SqlDbType.Int).Value         = z.Usl_ok == 0 ? (object)DBNull.Value : z.Usl_ok;
                command.Parameters.Add("@VIDP", SqlDbType.Int).Value         = z.Vidpom == 0 ? (object)DBNull.Value : z.Vidpom;
                command.Parameters.Add("@FRMMP", SqlDbType.Int).Value        = z.For_pom == 0 ? (object)DBNull.Value : z.For_pom;
                command.Parameters.Add("@LPU_1", SqlDbType.NVarChar).Value   = this.Lpu_1 ?? (object)DBNull.Value;
                command.Parameters.Add("@DET", SqlDbType.Int).Value          = this.Det == 0 ? (object)DBNull.Value : this.Det;
                command.Parameters.Add("@VNOV_M", SqlDbType.Int).Value       = z.Vnov_m == 0 ? (object)DBNull.Value : z.Vnov_m;
                command.Parameters.Add("@CODE_MES1", SqlDbType.NChar).Value  = this.Code_mes1 ?? (object)DBNull.Value;
                command.Parameters.Add("@CODE_MES2", SqlDbType.NChar).Value  = this.Code_mes2 ?? (object)DBNull.Value;
                command.Parameters.Add("@RSLT_D", SqlDbType.Int).Value       = z.Rslt_d == 0 ? (object)DBNull.Value : z.Rslt_d;
                command.Parameters.Add("@PRVS", SqlDbType.Int).Value         = this.Prvs == 0 ? (object)DBNull.Value : this.Prvs;
                command.Parameters.Add("@ED_COL", SqlDbType.Decimal).Value   = this.Ed_col == 0 ? (object)DBNull.Value : this.Ed_col;
                command.Parameters.Add("@OPLATA", SqlDbType.Int).Value       = z.Oplata == 0 ? (object)DBNull.Value : z.Oplata;
                command.Parameters.Add("@ID_PAC", SqlDbType.NVarChar).Value  = z.Pac.Id_pac ?? (object)DBNull.Value;
                command.Parameters.Add("@OT", SqlDbType.NVarChar).Value      = Convert.ToString(this.Podr) ?? (object)DBNull.Value;
                command.Parameters.Add("@G151", SqlDbType.Decimal).Value     = 1;
                command.Parameters.Add("@G141", SqlDbType.Decimal).Value     = this.Sumv == 0 ? (object)DBNull.Value : this.Sumv;
                command.Parameters.Add("@G161", SqlDbType.Decimal).Value     = this.Sumv == 0 ? (object)DBNull.Value : this.Sumv;
                command.Parameters.Add("@VBR", SqlDbType.Int).Value          = z.Vbr == 0 ? (object)DBNull.Value : z.Vbr;
                command.Parameters.Add("@UCHASTOK", SqlDbType.Int).Value     = this.Uchastok == 0 ? (object)DBNull.Value : this.Uchastok;
                command.Parameters.Add("@PUNKT", SqlDbType.Int).Value        = this.Punkt == 0 ? (object)DBNull.Value : this.Punkt;
                command.Parameters.Add("@TAL_D", SqlDbType.DateTime).Value   = this.Tal_d == DateTime.MinValue ? (object)DBNull.Value: this.Tal_d;
                command.Parameters.Add("@TAL_P", SqlDbType.DateTime).Value   = this.Tal_p == DateTime.MinValue ? (object)DBNull.Value : this.Tal_p;
                command.Parameters.Add("@DIRECT", SqlDbType.Int).Value       = z.P_otk == 0 ? (object)DBNull.Value : z.P_otk;
                command.Parameters.Add("@DELIVER", SqlDbType.Int).Value      = this.P_per == 0 ? (object)DBNull.Value : this.P_per;
                command.Parameters.Add("@PR_D_N", SqlDbType.Int).Value       = this.Ds1_dn == 0 ? (object)DBNull.Value : this.Ds1_dn;
                command.Parameters.Add("@INV", SqlDbType.Int).Value          = p.Inv == 0 ? (object)DBNull.Value : p.Inv;
                command.Parameters.Add("@MSE", SqlDbType.Int).Value          = p.Mse == 0 ? (object)DBNull.Value : p.Mse;
                command.Parameters.Add("@KSG_DK", SqlDbType.NVarChar).Value  = (object)DBNull.Value;
                command.Parameters.Add("@DS1_PR", SqlDbType.Decimal).Value   = this.Ds1_pr == 0 ? (object)DBNull.Value : this.Ds1_pr;
                command.Parameters.Add("@PR_NOV", SqlDbType.Bit).Value       = Convert.ToBoolean(this.Pr_nov);
                command.Parameters.Add("@PROFIL_K", SqlDbType.Decimal).Value = this.Profil_k == 0 ? (object)DBNull.Value : this.Profil_k;
                command.Parameters.Add("@TAL_NUM", SqlDbType.NVarChar).Value = this.Tal_num ?? (object)DBNull.Value;
                command.Parameters.Add("@KD", SqlDbType.Decimal).Value       = this.Kd == 0 ? (object)DBNull.Value : this.Kd;
                command.Parameters.Add("@DS1_DN", SqlDbType.Decimal).Value   = this.Ds1_dn == 0 ? (object)DBNull.Value : this.Ds1_dn;
                command.Parameters.Add("@Z_SL_ID", SqlDbType.Int).Value      = z.Z_sl_id == 0 ? (object)DBNull.Value : z.Z_sl_id;
                command.Parameters.Add("@DS_ONK", SqlDbType.Int).Value       = this.Ds_onk == 0 ? (object)DBNull.Value : this.Ds_onk;
                command.Parameters.Add("@C_ZAB", SqlDbType.Int).Value        = this.C_zab == 0 ? (object)DBNull.Value : this.C_zab;
                command.Parameters.Add("@REAB", SqlDbType.Int).Value         = this.Reab == 0 ? (object)DBNull.Value : this.Reab;

                slID         = Convert.ToInt64(((decimal)command.ExecuteScalar()));
                this.SluchID = slID;
                return(slID);
            }
            else
            {
                MessageBox.Show($"Случай {this.Idcase} \n уже имеет ID запрос не выполнен");
                slID = this.SluchID;
                return(slID);
            }
        }
Ejemplo n.º 2
0
        /// <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));
        }