Ejemplo n.º 1
0
        private bool executeTransaction(SQLiteDataObject oData, string sqlQuery)
        {
            var inTrans = false;

            try
            {
                inTrans = oData.BeginTransaction();
                if (!inTrans)
                {
                    return(false);
                }
                oData.ExecuteInTransaction(sqlQuery);
                oData.CommitTransaction();
                inTrans = false;
                return(true);
            }
            catch (Exception ex)
            {
                if (inTrans)
                {
                    oData.RollbackTransaction();
                }
                PNStatic.LogException(ex);
                return(false);
            }
        }
Ejemplo n.º 2
0
 internal static bool ExecuteTransactionForList(List<string> sqlList, string connectionString)
 {
     try
     {
         using (var oData = new SQLiteDataObject(connectionString))
         {
             if (oData.BeginTransaction())
             {
                 try
                 {
                     foreach (var s in sqlList)
                     {
                         oData.ExecuteInTransaction(s);
                     }
                     oData.CommitTransaction();
                 }
                 catch (Exception ex)
                 {
                     oData.RollbackTransaction();
                     PNStatic.LogException(ex);
                     return false;
                 }
             }
         }
         return true;
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
         return false;
     }
 }
Ejemplo n.º 3
0
 internal static bool ExecuteTransactionForStringBuilder(StringBuilder sb, string connectionString)
 {
     try
     {
         using (var oData = new SQLiteDataObject(connectionString))
         {
             if (oData.BeginTransaction())
             {
                 try
                 {
                     oData.ExecuteInTransaction(sb.ToString());
                     oData.CommitTransaction();
                 }
                 catch (Exception ex)
                 {
                     oData.RollbackTransaction();
                     PNStatic.LogException(ex);
                     return false;
                 }
             }
         }
         return true;
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
         return false;
     }
 }
Ejemplo n.º 4
0
        private bool exchangeGroups(SQLiteDataObject dataSrc, SQLiteDataObject dataDest, KeyValuePair <string, List <_FieldData> > tableData)
        {
            try
            {
                using (var t1 = dataSrc.FillDataTable("SELECT * FROM GROUPS"))
                {
                    using (var t2 = dataDest.FillDataTable("SELECT * FROM GROUPS"))
                    {
                        var t = t1.Clone();
                        IEnumerable <DataRow> rows1 = t1.AsEnumerable();
                        IEnumerable <DataRow> rows2 = t2.AsEnumerable();
                        foreach (var r1 in rows1)
                        {
                            var r2 = rows2.FirstOrDefault(r => (int)r["GROUP_ID"] == (int)r1["GROUP_ID"]);
                            if (r2 != null)
                            {
                                if (Convert.ToInt64(r1["UPD_DATE"]) >= Convert.ToInt64(r2["UPD_DATE"]))
                                {
                                    t.Rows.Add(r1.ItemArray);
                                }
                                else if (Convert.ToInt64(r2["UPD_DATE"]) > Convert.ToInt64(r1["UPD_DATE"]))
                                {
                                    t.Rows.Add(r2.ItemArray);
                                }
                            }
                            else
                            {
                                t.Rows.Add(r1.ItemArray);
                            }
                        }
                        foreach (var r2 in rows2)
                        {
                            if (rows1.All(r => (int)r["GROUP_ID"] != (int)r2["GROUP_ID"]))
                            {
                                t.Rows.Add(r2.ItemArray);
                            }
                        }

                        var sqlList = new List <string> {
                            "DELETE FROM GROUPS"
                        };
                        sqlList.AddRange(from DataRow r in t.Rows select createInsert(r, tableData));

                        var inTrans1 = false;
                        var inTrans2 = false;
                        try
                        {
                            inTrans1 = dataSrc.BeginTransaction();
                            inTrans2 = dataDest.BeginTransaction();
                            if (inTrans1 && inTrans2)
                            {
                                foreach (string s in sqlList)
                                {
                                    dataSrc.ExecuteInTransaction(s);
                                    dataDest.ExecuteInTransaction(s);
                                }
                                dataSrc.CommitTransaction();
                                inTrans1 = false;
                                dataDest.CommitTransaction();
                                inTrans2 = false;
                            }
                        }
                        catch (Exception ex)
                        {
                            if (inTrans1)
                            {
                                dataSrc.RollbackTransaction();
                            }
                            if (inTrans2)
                            {
                                dataDest.RollbackTransaction();
                            }
                            PNStatic.LogException(ex);
                            return(false);
                        }
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
                return(false);
            }
        }
Ejemplo n.º 5
0
        private bool exchangeGroups(SQLiteDataObject dataSrc, SQLiteDataObject dataDest, KeyValuePair<string, List<_FieldData>> tableData)
        {
            try
            {
                using (var t1 = dataSrc.FillDataTable("SELECT * FROM GROUPS"))
                {
                    using (var t2 = dataDest.FillDataTable("SELECT * FROM GROUPS"))
                    {
                        var t = t1.Clone();
                        IEnumerable<DataRow> rows1 = t1.AsEnumerable();
                        IEnumerable<DataRow> rows2 = t2.AsEnumerable();
                        foreach (var r1 in rows1)
                        {
                            var r2 = rows2.FirstOrDefault(r => (int)r["GROUP_ID"] == (int)r1["GROUP_ID"]);
                            if (r2 != null)
                            {
                                if (Convert.ToInt64(r1["UPD_DATE"]) >= Convert.ToInt64(r2["UPD_DATE"]))
                                {
                                    t.Rows.Add(r1.ItemArray);
                                }
                                else if (Convert.ToInt64(r2["UPD_DATE"]) > Convert.ToInt64(r1["UPD_DATE"]))
                                {
                                    t.Rows.Add(r2.ItemArray);
                                }
                            }
                            else
                            {
                                t.Rows.Add(r1.ItemArray);
                            }
                        }
                        foreach (var r2 in rows2)
                        {
                            if (rows1.All(r => (int)r["GROUP_ID"] != (int)r2["GROUP_ID"]))
                            {
                                t.Rows.Add(r2.ItemArray);
                            }
                        }

                        var sqlList = new List<string> { "DELETE FROM GROUPS" };
                        sqlList.AddRange(from DataRow r in t.Rows select createInsert(r, tableData));

                        var inTrans1 = false;
                        var inTrans2 = false;
                        try
                        {
                            inTrans1 = dataSrc.BeginTransaction();
                            inTrans2 = dataDest.BeginTransaction();
                            if (inTrans1 && inTrans2)
                            {
                                foreach (string s in sqlList)
                                {
                                    dataSrc.ExecuteInTransaction(s);
                                    dataDest.ExecuteInTransaction(s);
                                }
                                dataSrc.CommitTransaction();
                                inTrans1 = false;
                                dataDest.CommitTransaction();
                                inTrans2 = false;
                            }
                        }
                        catch (Exception ex)
                        {
                            if (inTrans1)
                            {
                                dataSrc.RollbackTransaction();
                            }
                            if (inTrans2)
                            {
                                dataDest.RollbackTransaction();
                            }
                            PNStatic.LogException(ex);
                            return false;
                        }
                    }
                }
                return true;
            }
            catch (Exception ex)
            {
                PNStatic.LogException(ex);
                return false;
            }
        }
Ejemplo n.º 6
0
 private bool executeTransaction(SQLiteDataObject oData, string sqlQuery)
 {
     var inTrans = false;
     try
     {
         inTrans = oData.BeginTransaction();
         if (!inTrans) return false;
         oData.ExecuteInTransaction(sqlQuery);
         oData.CommitTransaction();
         inTrans = false;
         return true;
     }
     catch (Exception ex)
     {
         if (inTrans)
         {
             oData.RollbackTransaction();
         }
         PNStatic.LogException(ex);
         return false;
     }
 }