コード例 #1
0
        protected void Comment(DataAccess Dest, CopyContext Ctx, CopyDisplay CD)
        {
            DataTable T = Dest.CreateTableByName(table, "*");

            //Verifica quanti codici sono definiti e crea una stringa
            string comment = "";

            foreach (DataColumn C in T.Columns)
            {
                string extcode = GetExternalCodeForField(C.ColumnName);
                //esamina i campi  a  codifica esterna
                if (extcode != C.ColumnName)
                {
                    comment += "[" + C.ColumnName + " -> " + extcode + "] ";
                }

                if (myContext.IsDefined(extcode))
                {
                    if (extcode == C.ColumnName)
                    {
                        comment += "[" + extcode + " priv]";
                    }
                }
                else
                {
                    if (Ctx.IsDefined(extcode))
                    {
                        if (extcode == C.ColumnName)
                        {
                            comment += "[" + extcode + " ext]";
                        }
                    }
                    else
                    {
                        if (extcode != C.ColumnName)
                        {
                            comment += "\r\n\r\n>>>>>>>> E R R O R : " + extcode + " is not a defined translator <<<<<<<<<\r\n\r\n";
                        }
                    }
                }
            }
            foreach (string field in SkipFieldsWhenNull)
            {
                comment += "[Skips on " + field + " null] ";
            }
            if (comment != "")
            {
                comment = "Table " + table.ToUpper() + ":" + comment;
                CD.Comment(comment);
            }
        }
コード例 #2
0
        public virtual bool CopyTable(DataAccess Source, DataAccess Dest, CopyContext Ctx, CopyDisplay CD)
        {
            int count = 0;

            QueryHelper QHS = Dest.GetQueryHelper();

            try {
                DataTable Cols = Dest.SQLRunner("sp_columns " + table + ",'" + Dest.GetSys("userdb").ToString() + "'");
                if (Cols.Rows.Count == 0)
                {
                    Cols = Dest.SQLRunner("sp_columns " + table + ",'dbo'");
                }

                if (ClearDestAtStart)
                {
                    Dest.SQLRunner("DELETE FROM " + table);
                }

                if (dontCopy)
                {
                    CD.Comment("Table " + table + " skipped");
                    applied = true;
                    return(true);
                }

                if (skipIfNotEmpty)
                {
                    if (Dest.RUN_SELECT_COUNT(table, null, false) > 0)
                    {
                        CD.Comment("Table " + table + " skipped cause destination is not empty");
                        applied = true;
                        return(true);
                    }
                }

                Comment(Dest, Ctx, CD);
                int not_to_copy = 0;
                int nullskipped = 0;

                int nrows = Source.RUN_SELECT_COUNT(table, filter, false);
                CD.Start(filter == null? table: table + " where " + filter, "copy", nrows);

                string    insert = "INSERT INTO " + table + " VALUES(";//(
                string    s      = "";
                string    err;
                DataTable T   = Dest.CreateTableByName(table, "*");
                string    col = QueryCreator.ColumnNameList(T);


                DataAccess.DataRowReader DRR = new DataAccess.DataRowReader(Source, table, col, null, filter);
                foreach (DataRow row in DRR)
                {
                    CD.Update(1);
                    if (!IsToCopy(row))
                    {
                        not_to_copy++; continue;
                    }
                    if (SkipExtNulls(row, Ctx))
                    {
                        nullskipped++; continue;
                    }

                    Translate(Ctx, row);

                    if (skipduplicates)
                    {
                        int num = Dest.RUN_SELECT_COUNT(table, QHS.CmpKey(row), false);
                        if (num > 0)
                        {
                            continue;
                        }
                    }


                    count++;
                    string values = GetSQLDataValues(row, Cols);
                    s += insert + values;
                    if (count == 10)
                    {
                        Dest.SQLRunner(s, 0, out err);

                        if (err != null)
                        {
                            QueryCreator.ShowError(null, "Errore", err);
                            StreamWriter fsw = new StreamWriter("temp.sql", false, Encoding.Default);
                            fsw.Write(s.ToString());
                            fsw.Close();
                            MessageBox.Show("Errore durante la copia della tabella " + table + "\r\nLo script lanciato si trova nel file 'temp.sql'");
                            CD.Stop(false);
                            return(false);
                        }
                        s     = "";
                        count = 0;
                    }
                }
                if (s != "")
                {
                    Dest.SQLRunner(s, 0, out err);
                    count = 0;
                    if (err != null)
                    {
                        QueryCreator.ShowError(null, "Errore", err);
                        StreamWriter fsw = new StreamWriter("temp.sql", false, Encoding.Default);
                        fsw.Write(s.ToString());
                        fsw.Close();
                        MessageBox.Show("Errore durante la copia di " + table + "\r\nLo script lanciato si trova nel file 'temp.sql'");
                        CD.Stop(false);
                        return(false);
                    }

                    s = "";
                }
                CD.Stop(true);
                if (not_to_copy > 0 || nullskipped > 0)
                {
                    CD.Comment(">>Not to copy:" + not_to_copy.ToString() + "  NullSkipped:" + nullskipped.ToString());
                }
                applied = true;
                return(true);
            }
            catch (Exception E) {
                QueryCreator.ShowException(E);
                CD.Stop(false);
                return(false);
            }
        }
コード例 #3
0
        /// <summary>
        /// Copy all tables respecting dependencies
        /// </summary>
        /// <param name="CD"></param>
        /// <returns></returns>
        public bool CopyAll(CopyDisplay CD)
        {
            CD.Start("Copying");
            CD.Comment("Disable Triggers");
            Dest.CallSP("enable_disable_triggers",
                        new object[2] {
                Dest.GetSys("userdb").ToString(),
                'D'
            },
                        false,
                        500);



            List <string> FieldToLookup = new List <string>();

            foreach (Copyer C in AR)
            {
                foreach (string code in C.CodeDefined())
                {
                    FieldToLookup.Add(code);
                }
            }
            bool somethingcopied = true;
            Dictionary <string, translator> Trlist = new Dictionary <string, translator>();

            while (somethingcopied)
            {
                somethingcopied = false;
                foreach (Copyer C in AR)
                {
                    if (C.applied)
                    {
                        continue;
                    }
                    CopyContext Ctx = new CopyContext(Trlist);

                    //verifica le dipendenze di C
                    if (!C.CheckDependencies(Ctx, FieldToLookup))
                    {
                        continue;                                          //non può copiare ancora questa tabella, mancano dipendenze
                    }
                    C.MergePreTranslatorsTo(Ctx);

                    bool res = C.CopyTable(Source, Dest, Ctx, CD);

                    if (!res)
                    {
                        CD.Comment("Enable Triggers");
                        Dest.CallSP("enable_disable_triggers",
                                    new object[2] {
                            Dest.GetSys("userdb").ToString(),
                            'E'
                        },
                                    false,
                                    500);

                        MessageBox.Show("La copia della tabella " + C.table + " non è stata effettuata", "Errore");
                        return(false);
                    }
                    somethingcopied = true;
                    C.MergePostTranslatorsTo(Ctx);
                    if (!C.applied)
                    {
                        CD.Comment("\r\n>>>>>>>>>>>>>>>>>Table " + C.table + " did not set APPLIED flag <<<<<<<<<<<<<<<<<<<<<<<<\r\n");
                    }
                }
            }
            foreach (Copyer C in AR)
            {
                if (!C.applied)
                {
                    MessageBox.Show("La copia della tabella " + C.table + " non è stata effettuata per mancanza di dipendenze", "Errore");
                }
            }
            CD.Comment("Enable Triggers");
            Dest.CallSP("enable_disable_triggers",
                        new object[2] {
                Dest.GetSys("userdb").ToString(),
                'E'
            },
                        false,
                        500);

            return(true);
        }