예제 #1
0
        private bool lFile(DataSet ds)
        {
            bool            result = false;
            string          strMes = "";
            OleDbConnection conn;

            ADODB.Connection adodbCon = new ADODB.Connection();
            adodbCon.ConnectionString = connString;
            ADOX.Catalog cat = new ADOX.Catalog();
            ADOX.Table   tab;
            DAO.DBEngine dbEngine = new DAO.DBEngine();

            try
            {
                //внесение данных
                txtLog.AppendLine("Внесение данных");
                Application.DoEvents();
                string postFix = "";
                if (rbTypeTo.Checked)
                {
                    postFix = "rokb";
                }
                DAO.Database  db = dbEngine.OpenDatabase(pathToDb);
                DAO.Recordset rs = db.OpenRecordset($"ZGLV{postFix}");
                foreach (DataRow dr in ds.Tables["ZGLV"].Rows)
                {
                    rs.AddNew();
                    rs.Fields["H"].Value = "L";
                    foreach (DataColumn dc in ds.Tables["ZGLV"].Columns)
                    {
                        rs.Fields[dc.ColumnName].Value = dr[dc.ColumnName].ToString();
                    }
                    rs.Update();
                }
                rs.Close();
                //
                //PERS
                //
                if (ds.Tables.Contains("PERS"))
                {
                    txtLog.AppendLine("Таблица PERS");
                    Application.DoEvents();
                    System.Threading.Thread.Sleep(10000);
                    pb.Minimum = 0;
                    pb.Maximum = ds.Tables["PERS"].Rows.Count;
                    pb.Value   = 0;
                    Application.DoEvents();
                    rs = db.OpenRecordset($"PERS{postFix}");
                    int counter = 0;
                    foreach (DataRow drSchet in ds.Tables["PERS"].Rows)
                    {
                        pb.Value = counter++;
                        Application.DoEvents();
                        rs.AddNew();
                        rs.Fields["PLAT"].Value = _PLAT;
                        foreach (DataColumn dc in ds.Tables["PERS"].Columns)
                        {
                            rs.Fields[dc.ColumnName].Value = drSchet[dc.ColumnName].ToString();
                        }
                        rs.Update();
                    }
                    rs.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                txtLog.AppendLine(ex.Message);
            }
            finally
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(dbEngine);
                dbEngine = null;
            }
            cat = null;
            return(result);
        }
예제 #2
0
        private bool hFile(DataSet ds)
        {
            bool            result = false;
            string          strMes = "";
            OleDbConnection conn;

            ADODB.Connection adodbCon = new ADODB.Connection();
            adodbCon.ConnectionString = connString;
            ADOX.Catalog cat = new ADOX.Catalog();
            ADOX.Table   tab;
            //int SLUCH_ID = 0;
            DAO.DBEngine dbEngine = new DAO.DBEngine();
            try
            {
                string postFix = "";
                if (rbTypeTo.Checked)
                {
                    postFix = "rokb";
                }
                txtLog.AppendLine("Внесение данных");
                Application.DoEvents();
                //внесение данных
                string _CODE = "", _NSCHET = "", _N_ZAP = "", _IDCASE = "", _USL_TIP = "2";
                txtLog.AppendLine("Таблица ZGLV");
                Application.DoEvents();
                DAO.Database  db = dbEngine.OpenDatabase(pathToDb);
                DAO.Recordset rs = db.OpenRecordset($"ZGLV{postFix}");
                foreach (DataRow dr in ds.Tables["ZGLV"].Rows)
                {
                    rs.AddNew();
                    rs.Fields["H"].Value = "H";
                    foreach (DataColumn dc in ds.Tables["ZGLV"].Columns)
                    {
                        rs.Fields[dc.ColumnName].Value = dr[dc.ColumnName].ToString();
                    }
                    rs.Update();
                }
                rs.Close();
                //
                //SCHET
                //
                txtLog.AppendLine("Таблица SCHET");
                Application.DoEvents();
                rs = db.OpenRecordset($"SCHET{postFix}");
                DataRow drSchet = ds.Tables["SCHET"].Rows[0];
                _CODE   = drSchet["CODE"].ToString();
                _NSCHET = drSchet["NSCHET"].ToString();
                rs.AddNew();
                foreach (DataColumn dc in ds.Tables["SCHET"].Columns)
                {
                    rs.Fields[dc.ColumnName].Value = drSchet[dc.ColumnName].ToString();
                }
                rs.Update();
                rs.Close();
                //
                //ZAP
                //
                txtLog.AppendLine("Таблица ZAP");
                Application.DoEvents();
                pb.Minimum = 0;
                pb.Maximum = ds.Tables["ZAP"].Rows.Count;
                pb.Value   = 0;
                int counter = 0;
                rs = db.OpenRecordset($"ZAP{postFix}");
                foreach (DataRow dr in ds.Tables["ZAP"].Rows)
                {
                    pb.Value = counter++;
                    Application.DoEvents();
                    rs.AddNew();
                    _N_ZAP = dr["N_ZAP"].ToString();
                    int ZAP_Id = int.Parse(dr["ZAP_Id"].ToString());
                    rs.Fields["CODE"].Value   = _CODE;
                    rs.Fields["PLAT"].Value   = _PLAT;
                    rs.Fields["NSCHET"].Value = _NSCHET;
                    foreach (DataColumn dc in ds.Tables["ZAP"].Columns)
                    {
                        rs.Fields[dc.ColumnName].Value = dr[dc.ColumnName].ToString();
                    }
                    rs.Update();
                    //
                    //PACIENT
                    //
                    DAO.Recordset rsPacient = db.OpenRecordset($"PACIENT{postFix}");
                    if (ds.Tables.Contains("PACIENT"))
                    {
                        List <DataRow> pacList = ds.Tables["PACIENT"].AsEnumerable().Where(m => m.Field <Int32>("ZAP_Id") == ZAP_Id).ToList <DataRow>();
                        foreach (DataRow drPac in pacList)
                        {
                            rsPacient.AddNew();
                            rsPacient.Fields["N_ZAP"].Value = _N_ZAP;
                            rsPacient.Fields["PLAT"].Value  = _PLAT;
                            foreach (DataColumn dc in ds.Tables["PACIENT"].Columns)
                            {
                                rsPacient.Fields[dc.ColumnName].Value = drPac[dc.Ordinal].ToString();
                            }
                            rsPacient.Update();
                        }
                        rsPacient.Close();
                    }
                    //
                    //SLUCH
                    //
                    if (!ds.Tables.Contains("SLUCH"))
                    {
                        continue;
                    }
                    DAO.Recordset  rsSLUCH   = db.OpenRecordset($"SLUCH{postFix}");
                    List <DataRow> sluchList = ds.Tables["SLUCH"].AsEnumerable().Where(m => m.Field <Int32>("ZAP_Id") == ZAP_Id).ToList <DataRow>();
                    foreach (DataRow drSluch in sluchList)
                    {
                        _IDCASE = drSluch[ds.Tables["SLUCH"].Columns["IDCASE"].Ordinal].ToString();
                        //SLUCH_ID = int.Parse(drSluch["SLUCH_Id"].ToString());
                        //if (SLUCH_ID == 1098)
                        //{
                        //    int zz = 0;
                        //}
                        int SLUCH_Id = int.Parse(drSluch[ds.Tables["SLUCH"].Columns["SLUCH_Id"].Ordinal].ToString());
                        rsSLUCH.AddNew();
                        rsSLUCH.Fields["N_ZAP"].Value = _N_ZAP;
                        rsSLUCH.Fields["PLAT"].Value  = _PLAT;
                        foreach (DataColumn dc in ds.Tables["SLUCH"].Columns)
                        {
                            rsSLUCH.Fields[dc.ColumnName].Value = drSluch[dc.Ordinal].ToString();
                        }
                        rsSLUCH.Update();
                        //
                        //HMP
                        //
                        if (ds.Tables.Contains("HMP"))
                        {
                            DAO.Recordset  rsHMP   = db.OpenRecordset($"HMP{postFix}");
                            List <DataRow> hmpList = ds.Tables["HMP"].AsEnumerable().Where(m => m.Field <Int32>("SLUCH_Id") == SLUCH_Id).ToList <DataRow>();
                            if (hmpList != null && hmpList.Count > 0)
                            {
                                foreach (DataRow drHMP in hmpList)
                                {
                                    rsHMP.AddNew();
                                    rsHMP.Fields["IDCASE"].Value = _IDCASE;
                                    foreach (DataColumn dc in ds.Tables["HMP"].Columns)
                                    {
                                        rsHMP.Fields[dc.ColumnName].Value = drHMP[dc.Ordinal].ToString();
                                    }
                                    rsHMP.Update();
                                }
                            }
                            rsHMP.Close();
                        }
                        //
                        //NAPR_FROM
                        //
                        if (ds.Tables.Contains("NAPR_FROM"))
                        {
                            DAO.Recordset  rsNaprFrom   = db.OpenRecordset($"NAPR_FROM{postFix}");
                            List <DataRow> naprFromList = ds.Tables["NAPR_FROM"].AsEnumerable().Where(m => m.Field <Int32>("SLUCH_Id") == SLUCH_Id).ToList <DataRow>();
                            if (naprFromList != null && naprFromList.Count > 0)
                            {
                                foreach (DataRow drNaprFrom in naprFromList)
                                {
                                    rsNaprFrom.AddNew();
                                    rsNaprFrom.Fields["IDCASE"].Value = _IDCASE;
                                    foreach (DataColumn dc in ds.Tables["NAPR_FROM"].Columns)
                                    {
                                        rsNaprFrom.Fields[dc.ColumnName].Value = drNaprFrom[dc.Ordinal].ToString();
                                    }
                                    rsNaprFrom.Update();
                                }
                            }
                            rsNaprFrom.Close();
                        }
                        //
                        //CONS
                        //
                        if (ds.Tables.Contains("CONS"))
                        {
                            DAO.Recordset  rsCons   = db.OpenRecordset($"CONS{postFix}");
                            List <DataRow> consList = ds.Tables["CONS"].AsEnumerable().Where(m => m.Field <Int32>("SLUCH_Id") == SLUCH_Id).ToList <DataRow>();
                            if (consList != null && consList.Count > 0)
                            {
                                foreach (DataRow drCons in consList)
                                {
                                    rsCons.AddNew();
                                    rsCons.Fields["IDCASE"].Value = _IDCASE;
                                    foreach (DataColumn dc in ds.Tables["CONS"].Columns)
                                    {
                                        rsCons.Fields[dc.ColumnName].Value = drCons[dc.Ordinal].ToString();
                                    }
                                    rsCons.Update();
                                }
                            }
                            rsCons.Close();
                        }
                        //
                        //ONK_SL
                        //
                        if (ds.Tables.Contains("ONK_SL"))
                        {
                            DAO.Recordset  rsOnkSl   = db.OpenRecordset($"ONK_SL{postFix}");
                            List <DataRow> onkSlList = ds.Tables["ONK_SL"].AsEnumerable().Where(m => m.Field <Int32>("SLUCH_Id") == SLUCH_Id).ToList <DataRow>();
                            if (onkSlList != null && onkSlList.Count > 0)
                            {
                                foreach (DataRow drOnkSl in onkSlList)
                                {
                                    int OnkSl_Id = int.Parse(drOnkSl[ds.Tables["ONK_SL"].Columns["ONK_SL_Id"].Ordinal].ToString());
                                    rsOnkSl.AddNew();
                                    rsOnkSl.Fields["IDCASE"].Value = _IDCASE;
                                    foreach (DataColumn dc in ds.Tables["ONK_SL"].Columns)
                                    {
                                        rsOnkSl.Fields[dc.ColumnName].Value = drOnkSl[dc.Ordinal].ToString();
                                    }
                                    rsOnkSl.Update();
                                    //
                                    //B_DIAG
                                    //
                                    if (ds.Tables.Contains("B_DIAG"))
                                    {
                                        DAO.Recordset  rsBDiag   = db.OpenRecordset($"B_DIAG{postFix}");
                                        List <DataRow> bDiagList = ds.Tables["B_DIAG"].AsEnumerable().Where(m => m.Field <Int32>("ONK_SL_Id") == OnkSl_Id).ToList <DataRow>();
                                        if (bDiagList != null && bDiagList.Count > 0)
                                        {
                                            foreach (DataRow drBDiag in bDiagList)
                                            {
                                                rsBDiag.AddNew();
                                                rsBDiag.Fields["IDCASE"].Value = _IDCASE;
                                                foreach (DataColumn dc in ds.Tables["B_DIAG"].Columns)
                                                {
                                                    rsBDiag.Fields[dc.ColumnName].Value = drBDiag[dc.Ordinal].ToString();
                                                }
                                                rsBDiag.Update();
                                            }
                                        }
                                        rsBDiag.Close();
                                    }
                                    //
                                    //ONK_USL
                                    //
                                    if (ds.Tables.Contains("ONK_USL"))
                                    {
                                        DAO.Recordset  rsOnkUsl   = db.OpenRecordset($"ONK_USL{postFix}");
                                        List <DataRow> onkUslList = ds.Tables["ONK_USL"].AsEnumerable().Where(m => m.Field <Int32>("ONK_SL_Id") == OnkSl_Id).ToList <DataRow>();
                                        if (onkUslList != null && onkUslList.Count > 0)
                                        {
                                            foreach (DataRow drOnkUsl in onkUslList)
                                            {
                                                rsOnkUsl.AddNew();
                                                rsOnkUsl.Fields["IDCASE"].Value = _IDCASE;
                                                int ONK_USL_Id = int.Parse(drOnkUsl["ONK_USL_Id"].ToString());
                                                foreach (DataColumn dc in ds.Tables["ONK_USL"].Columns)
                                                {
                                                    rsOnkUsl.Fields[dc.ColumnName].Value = drOnkUsl[dc.Ordinal].ToString();
                                                }
                                                rsOnkUsl.Update();
                                                //
                                                //LEK_PR
                                                //
                                                if (ds.Tables.Contains("LEK_PR"))
                                                {
                                                    DAO.Recordset  rsLekPr   = db.OpenRecordset($"LEK_PR{postFix}");
                                                    List <DataRow> lekPrList = ds.Tables["LEK_PR"].AsEnumerable().Where(m => m.Field <Int32>("ONK_USL_Id") == ONK_USL_Id).ToList <DataRow>();
                                                    if (lekPrList != null && lekPrList.Count > 0)
                                                    {
                                                        foreach (DataRow drLekPr in lekPrList)
                                                        {
                                                            int            LEK_PR_Id   = int.Parse(drLekPr["LEK_PR_Id"].ToString());
                                                            List <DataRow> dateInjList = ds.Tables["DATE_INJ"].AsEnumerable().Where(m => m.Field <Int32>("LEK_PR_Id") == LEK_PR_Id).ToList <DataRow>();
                                                            if (dateInjList != null && dateInjList.Count > 0)
                                                            {
                                                                foreach (DataRow drDateInj in dateInjList)
                                                                {
                                                                    rsLekPr.AddNew();
                                                                    foreach (DataColumn dc in ds.Tables["LEK_PR"].Columns)
                                                                    {
                                                                        rsLekPr.Fields[dc.ColumnName].Value = drLekPr[dc.Ordinal].ToString();
                                                                    }
                                                                    rsLekPr.Fields["IDCASE"].Value   = _IDCASE;
                                                                    rsLekPr.Fields["USL_TIP"].Value  = "2";
                                                                    rsLekPr.Fields["DATE_INJ"].Value = drDateInj["DATE_INJ_Text"].ToString();
                                                                    rsLekPr.Update();
                                                                }
                                                            }
                                                            else
                                                            {
                                                                rsLekPr.AddNew();
                                                                rsLekPr.Fields["IDCASE"].Value  = _IDCASE;
                                                                rsLekPr.Fields["USL_TIP"].Value = "2";
                                                                rsLekPr.Update();
                                                            }
                                                        }
                                                    }
                                                    rsLekPr.Close();
                                                }
                                            }
                                        }
                                        rsOnkUsl.Close();
                                    }
                                }
                            }
                            rsOnkSl.Close();
                        }
                        //
                        //USL
                        //
                        if (ds.Tables.Contains("USL"))
                        {
                            DAO.Recordset  rsUSL   = db.OpenRecordset($"USL{postFix}");
                            List <DataRow> uslList = ds.Tables["USL"].AsEnumerable().Where(m => m.Field <Int32>("SLUCH_Id") == SLUCH_Id).ToList <DataRow>();
                            if (uslList != null && uslList.Count > 0)
                            {
                                foreach (DataRow drUSL in uslList)
                                {
                                    int USL_Id = int.Parse(drUSL["USL_Id"].ToString());
                                    rsUSL.AddNew();
                                    rsUSL.Fields["IDCASE"].Value = _IDCASE;
                                    rsUSL.Fields["N_ZAP"].Value  = _N_ZAP;
                                    rsUSL.Fields["PLAT"].Value   = _PLAT;
                                    foreach (DataColumn dc in ds.Tables["USL"].Columns)
                                    {
                                        rsUSL.Fields[dc.ColumnName].Value = drUSL[dc.Ordinal].ToString();
                                    }
                                    rsUSL.Update();
                                    //
                                    //SL_KOEF
                                    //
                                    if (ds.Tables.Contains("SL_KOEF"))
                                    {
                                        DAO.Recordset  rsSlKoef   = db.OpenRecordset($"SL_KOEF{postFix}");
                                        List <DataRow> slKoefList = ds.Tables["SL_KOEF"].AsEnumerable().Where(m => m.Field <Int32>("USL_Id") == USL_Id).ToList <DataRow>();
                                        if (slKoefList != null && slKoefList.Count > 0)
                                        {
                                            foreach (DataRow drSlKoef in slKoefList)
                                            {
                                                rsSlKoef.AddNew();
                                                rsSlKoef.Fields["IDCASE"].Value = _IDCASE;
                                                foreach (DataColumn dc in ds.Tables["SL_KOEF"].Columns)
                                                {
                                                    rsSlKoef.Fields[dc.ColumnName].Value = drSlKoef[dc.Ordinal].ToString();
                                                }
                                                rsSlKoef.Update();
                                            }
                                        }
                                        rsSlKoef.Close();
                                    }
                                    //
                                    //SL_KOEF
                                    //
                                    if (ds.Tables.Contains("KSG_KPG"))
                                    {
                                        DAO.Recordset  rsKSGKPG = db.OpenRecordset($"KSG_KPG{postFix}");
                                        List <DataRow> KSGKPG   = ds.Tables["KSG_KPG"].AsEnumerable().Where(m => m.Field <Int32>("USL_Id") == USL_Id).ToList <DataRow>();
                                        if (KSGKPG != null && KSGKPG.Count > 0)
                                        {
                                            foreach (DataRow drKSGKPG in KSGKPG)
                                            {
                                                rsKSGKPG.AddNew();
                                                rsKSGKPG.Fields["IDCASE"].Value = _IDCASE;
                                                foreach (DataColumn dc in ds.Tables["KSG_KPG"].Columns)
                                                {
                                                    rsKSGKPG.Fields[dc.ColumnName].Value = drKSGKPG[dc.Ordinal].ToString();
                                                }
                                                rsKSGKPG.Update();
                                            }
                                        }
                                        rsKSGKPG.Close();
                                    }
                                }
                            }
                            rsUSL.Close();
                        }
                    }
                    rsSLUCH.Close();
                }
                rs.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                txtLog.AppendLine(ex.Message);
            }
            finally
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(dbEngine);
                dbEngine = null;
            }

            cat = null;
            return(result);
        }