コード例 #1
0
        /// <summary>
        /// Check all conditions necessary to do the copy. Does not write to db
        /// </summary>
        /// <param name="CD"></param>
        /// <returns></returns>
        public virtual bool CheckAll(CopyDisplay CD)
        {
            CD.Start("Checking");
            bool          status_ok = true;
            List <string> CC        = new List <string>();

            foreach (Copyer C in AR)
            {
                if (CC.Contains(C.table))
                {
                    MessageBox.Show("Errore di programmazione: il Copyer di " + C.table + " è stato aggiunto due volte", "Errore");
                    continue;
                }
                CC.Add(C.table);
                CD.Start(C.table, "check", 1);
                if (C.CheckPreconditions(Source, Dest) == false)
                {
                    CD.Stop(false);
                    status_ok = false;
                }
                else
                {
                    CD.Stop(true);
                }
            }
            return(status_ok);
        }
コード例 #2
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);
            }
        }
コード例 #3
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);
            }
        }
コード例 #4
0
 public override bool CopyTable(DataAccess Source, DataAccess Dest, CopyContext Ctx, CopyDisplay CD)
 {
     if (DontCopy)
     {
         applied = true;
         return(true);
     }
     return(base.CopyTable(Source, Dest, Ctx, CD));
 }
コード例 #5
0
        public override bool CopyTable(DataAccess Source, DataAccess Dest, CopyContext Ctx, CopyDisplay CD)
        {
            applied = false;
            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'");
                }
                Comment(Dest, Ctx, CD);


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



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


                DataAccess.DataRowReader DRR = new DataAccess.DataRowReader(Source, "surplus", col, null, filter);

                foreach (DataRow row in DRR)
                {
                    CD.Update(1);
                    if (!IsToCopy(row))
                    {
                        continue;                  // copia quelle che NON sono da inserire
                    }
                    Translate(Ctx, row);

                    string    delete = "";
                    DataTable T2     = Dest.RUN_SELECT("surplus", "*", null, QHS.CmpEq("ayear", row["ayear"]), null, false);

                    if (T2.Rows.Count > 0)
                    {
                        DataRow RR = T2.Rows[0];
                        foreach (DataColumn CR in T2.Columns)
                        {
                            string field = CR.ColumnName;
                            if (CR.DataType == typeof(decimal))
                            {
                                if (RR[field] == DBNull.Value)
                                {
                                    continue;
                                }
                                if (row[field] == DBNull.Value)
                                {
                                    row[field] = RR[field];
                                }
                                else
                                {
                                    row[field] = CfgFn.GetNoNullDecimal(row[field]) + CfgFn.GetNoNullDecimal(RR[field]);
                                }
                            }
                        }
                        delete = "delete from surplus where " + QHS.CmpEq("ayear", row["ayear"]) + "\n\r";
                    }
                    row["locked"] = "S";
                    count++;
                    string values = GetSQLDataValues(row, Cols);
                    s += delete + insert + values;
                    if (count == 1)    //è necessario farlo una riga alla volta
                    {
                        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);
                applied = true;
                return(true);
            }
            catch (Exception E) {
                QueryCreator.ShowException(E);
                CD.Stop(false);
                return(false);
            }
        }
コード例 #6
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);
        }