private void Calc_pers(bool nieuw)
        {
            TaAdpt.Connection.ConnectionString  = Global.ConnectionString_fileserver;
            adapter.Connection.ConnectionString = Global.ConnectionString_fileserver;
            List <zeebregtsCs.RefItem> tmplst = new List <zeebregtsCs.RefItem>();
            ////////////////////
            int    pid    = _record_id;
            int    result = 0;
            string column = "";
            string table  = "";

            //zeebregtsCs.persoonsformdatasetTableAdapters.QueriesTableAdapter qtadapt = new zeebregtsCs.persoonsformdatasetTableAdapters.QueriesTableAdapter();
            zeebregtsCs.persoonsformdatasetTableAdapters.persoon_nr_locatiesTableAdapter locaties_adapt = new zeebregtsCs.persoonsformdatasetTableAdapters.persoon_nr_locatiesTableAdapter();
            locaties_adapt.Connection.ConnectionString = Global.ConnectionString_fileserver;
            zeebregtsCs.persoonsformdataset.persoon_nr_locatiesDataTable locaties_table = locaties_adapt.GetData();
            zeebregtsCs.persoonsformdatasetTableAdapters.var_pers_funct_countTableAdapter varcnttadapt = new zeebregtsCs.persoonsformdatasetTableAdapters.var_pers_funct_countTableAdapter();
            varcnttadapt.Connection.ConnectionString = Global.ConnectionString_fileserver;
            zeebregtsCs.persoonsformdataset.var_pers_funct_countDataTable varcntdt = varcnttadapt.GetData(pid);
            foreach (zeebregtsCs.persoonsformdataset.persoon_nr_locatiesRow row in locaties_table.Rows)
            {
                if (row.column == "persoon_nr")
                {
                    foreach (zeebregtsCs.persoonsformdataset.var_pers_funct_countRow dr in varcntdt.Rows)
                    {
                        tmplst.Add(new zeebregtsCs.RefItem {
                            funct_count = dr.aantal, funct_naam = dr.naam, functie_id = dr.functie_id, uit_var = true
                        });
                    }
                }
                else
                {
                    column = row.column.ToString();
                    table  = row.tabel.ToString();
                    result = (int)adapter.Check_del_pers(pid, column, table);

                    if (result > 0)
                    {
                        bool voegtoe = true;
                        foreach (zeebregtsCs.RefItem RI in tmplst)
                        {
                            if (RI.funct_naam == row.weergavenaam)
                            {
                                RI.funct_count += result;
                                RI.uit_var      = false;
                                RI.functie_id   = row.regel_nr;
                                voegtoe         = false;
                            }
                        }
                        if (voegtoe)
                        {
                            tmplst.Add(new zeebregtsCs.RefItem
                            {
                                funct_naam  = row.weergavenaam,
                                funct_count = result,
                                functie_id  = row.regel_nr,
                                uit_var     = false
                            });
                        }
                    }
                }
            }
            //qtadapt.Dispose();
            locaties_adapt.Dispose();
            locaties_table.Dispose();
            ///////////////////
            tmplst = tmplst.OrderByDescending(RefItem => RefItem.funct_count).ToList <zeebregtsCs.RefItem>();
            if (tmplst.Count == 1)
            {
                if (!nieuw)
                {
                    TaAdpt.del_agfl_funct(_record_id, 3);
                }
            }
            else if (tmplst.Count > 0)
            {
                if (nieuw)
                {
                    TaAdpt.new_agfl_funct(_record_id, 3, tmplst[0].functie_id, tmplst[0].uit_var);
                }
                else
                {
                    TaAdpt.update_agfl_funct(_record_id, 3, tmplst[0].functie_id, tmplst[0].uit_var);
                }
            }
        }
        private zeebregtsCs.RefItem convert_pers_nsave(database_tabellen.validator_set_1.persoon_voor_functRow prow)
        {
            List <zeebregtsCs.RefItem> tmplst = new List <zeebregtsCs.RefItem>();
            ////////////////////
            int    pid    = prow.persoon_nr;
            int    result = 0;
            string column = "";
            string table  = "";

            zeebregtsCs.persoonsformdatasetTableAdapters.persoonTableAdapter             qtadapt        = new zeebregtsCs.persoonsformdatasetTableAdapters.persoonTableAdapter();
            zeebregtsCs.persoonsformdatasetTableAdapters.persoon_nr_locatiesTableAdapter locaties_adapt = new zeebregtsCs.persoonsformdatasetTableAdapters.persoon_nr_locatiesTableAdapter();
            zeebregtsCs.persoonsformdataset.persoon_nr_locatiesDataTable locaties_table = locaties_adapt.GetData();
            zeebregtsCs.persoonsformdatasetTableAdapters.var_pers_funct_countTableAdapter varcnttadapt = new zeebregtsCs.persoonsformdatasetTableAdapters.var_pers_funct_countTableAdapter();
            zeebregtsCs.persoonsformdataset.var_pers_funct_countDataTable varcntdt = varcnttadapt.GetData(pid);
            foreach (zeebregtsCs.persoonsformdataset.persoon_nr_locatiesRow row in locaties_table.Rows)
            {
                if (row.column == "persoon_nr")
                {
                    foreach (zeebregtsCs.persoonsformdataset.var_pers_funct_countRow dr in varcntdt.Rows)
                    {
                        tmplst.Add(new zeebregtsCs.RefItem {
                            funct_count = dr.aantal, funct_naam = dr.naam, functie_id = dr.functie_id, uit_var = true
                        });
                    }
                }
                else
                {
                    column = row.column.ToString();
                    table  = row.tabel.ToString();
                    result = (int)qtadapt.Check_del_pers(pid, column, table);

                    if (result > 0)
                    {
                        bool voegtoe = true;
                        foreach (zeebregtsCs.RefItem RI in tmplst)
                        {
                            if (RI.funct_naam == row.weergavenaam)
                            {
                                RI.funct_count += result;
                                RI.uit_var      = false;
                                RI.functie_id   = row.regel_nr;
                                voegtoe         = false;
                            }
                        }
                        if (voegtoe)
                        {
                            tmplst.Add(new zeebregtsCs.RefItem
                            {
                                funct_naam  = row.weergavenaam,
                                funct_count = result,
                                functie_id  = row.regel_nr,
                                uit_var     = false
                            });
                        }
                    }
                }
            }
            qtadapt.Dispose();
            locaties_adapt.Dispose();
            locaties_table.Dispose();
            ///////////////////
            tmplst = tmplst.OrderByDescending(RefItem => RefItem.funct_count).ToList <zeebregtsCs.RefItem>();
            database_tabellen.validator_set_1TableAdapters.QueriesTableAdapter qta = new database_tabellen.validator_set_1TableAdapters.QueriesTableAdapter();

            if (tmplst.Count > 0)
            {
                qta.new_agfl_funct(prow.persoon_nr, 3, tmplst[0].functie_id, tmplst[0].uit_var);
                return(tmplst[0]);
            }
            else
            {
                return(null);
            }
        }