コード例 #1
0
        private int GetDbUpdateNumber()
        {
            System.Data.DataTable dt = null;
            try
            {
                DbBase.DbConnection.Open();
                dt = DbBase.DbConnection.GetSchema("Tables");
            }
            finally
            {
                DbBase.DbConnection.Close();
            }

            bool PossuitdUpdate = false;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i]["TABLE_NAME"].ToString().ToUpper() == "TB_UPDATE")
                {
                    PossuitdUpdate = true;
                    break;
                }
            }

            if (!PossuitdUpdate)
            {
                DbBase.DbExecute("CREATE TABLE TB_UPDATE (UPDATE_NUMBER INTEGER);");
                DbBase.DbExecute("INSERT INTO TB_UPDATE (UPDATE_NUMBER) VALUES (0);");
            }

            return(cnv.ToInt(DbBase.DbGetValue("SELECT UPDATE_NUMBER FROM TB_UPDATE")));
        }
コード例 #2
0
ファイル: SimpleDataSource.cs プロジェクト: ricksam/Framework
        public void Insert <T>(T entity, DbTransaction Transaction = null)
        {
            lib.Class.Reflection r = new lib.Class.Reflection(entity);

            if (r.Properties.Length == 0)
            {
                return;
            }

            string db_fields = "";

            for (int i = 0; i < r.Properties.Length; i++)
            {
                KeyTypeAttributeState state = GetKeyTypeAttributeState(r.Properties[i]);
                bool IsDefaultValue         = r.IsDefaultValue(r.Properties[i]);

                if (state.IsQueryField || (IsDefaultValue && state.IsOmitIfIsNull))
                {
                    continue;
                }

                if (!state.IsPrimaryKey && !(state.IsForeignKey && IsDefaultValue))
                {
                    db_fields += (string.IsNullOrEmpty(db_fields) ? "" : ",") + r.Properties[i].Name;
                }
            }

            string db_values = "";

            for (int i = 0; i < r.Properties.Length; i++)
            {
                KeyTypeAttributeState state = GetKeyTypeAttributeState(r.Properties[i]);
                bool IsDefaultValue         = r.IsDefaultValue(r.Properties[i]);

                if (state.IsQueryField || (IsDefaultValue && state.IsOmitIfIsNull))
                {
                    continue;
                }

                if (!state.IsPrimaryKey && !(state.IsForeignKey && IsDefaultValue))
                {
                    db_values += (string.IsNullOrEmpty(db_values) ? "" : ",") + GetDbValue(r, r.Properties[i], false);
                }
            }

            string sql = string.Format("{0} INSERT INTO {1} ({2}) VALUES ({3});", DbBase.DbSetDateFormat, typeof(T).Name, db_fields, db_values);

            DbBase.DbExecute(sql, Transaction);
        }
コード例 #3
0
ファイル: SimpleDataSource.cs プロジェクト: ricksam/Framework
        public void Update <T>(T entity, T Conditions, DbTransaction Transaction = null)
        {
            lib.Class.Reflection r = new lib.Class.Reflection(entity);

            if (r.Properties.Length == 0)
            {
                return;
            }

            System.Reflection.PropertyInfo[] PropsCondition = null;

            if (Conditions != null)
            {
                PropsCondition = GetValidProperties(new lib.Class.Reflection(Conditions));
            }

            string db_fields_values = "";

            for (int i = 0; i < r.Properties.Length; i++)
            {
                KeyTypeAttributeState state = GetKeyTypeAttributeState(r.Properties[i]);
                bool IsDefaultValue         = r.IsDefaultValue(r.Properties[i]);

                if (state.IsQueryField || state.IsPrimaryKey || (IsDefaultValue && state.IsOmitIfIsNull))
                {
                    continue;
                }

                if (state.IsForeignKey && IsDefaultValue)
                {
                    db_fields_values += (string.IsNullOrEmpty(db_fields_values) ? "" : ",") + string.Format("{0}=NULL", r.Properties[i].Name);
                }
                else
                {
                    db_fields_values += (string.IsNullOrEmpty(db_fields_values) ? "" : ",") + string.Format("{0}={1}", r.Properties[i].Name, GetDbValue(r, r.Properties[i], false));
                }
            }

            DbBase.DbExecute(
                string.Format("{0} UPDATE {1} SET {2} {3}", DbBase.DbSetDateFormat, typeof(T).Name, db_fields_values, Condition(Conditions)),
                Transaction);
        }
コード例 #4
0
        public void Execute()
        {
            lib.Class.TextFile tf = new lib.Class.TextFile();
            tf.Open(lib.Class.enmOpenMode.Reading, FileName);
            string[] lines = tf.GetLines();
            tf.Close();

            #region Gera a lista de comandos
            List <ItemUpdate> itms = new List <ItemUpdate>();
            for (int i = 0; i < lines.Length; i++)
            {
                try
                {
                    if (string.IsNullOrEmpty(lines[i]))
                    {
                        continue;
                    }

                    string line = lines[i];

                    if (DbBase is lib.Entity.MySQL)
                    {
                        line = lines[i].ToUpper();
                    }

                    if (line.IndexOf("/*[UPDATE]") != -1)
                    {
                        int idx_ini = line.IndexOf("/*[UPDATE]") + 10;
                        int idx_end = line.IndexOf("*/");
                        itms.Add(new ItemUpdate(cnv.ToInt(line.Substring(idx_ini, idx_end - idx_ini))));
                    }
                    else
                    {
                        itms[itms.Count - 1].Script += line;
                    }
                }
                catch { continue; }
            }
            #endregion

            #region Executa atualização de Scripts
            int UpdateNumber = GetDbUpdateNumber();
            for (int i = 0; i < itms.Count; i++)
            {
                if (itms[i].Number > UpdateNumber)
                {
                    try
                    {
                        string[] cmds = itms[i].GetCommands();
                        for (int c = 0; c < cmds.Length; c++)
                        {
                            if (string.IsNullOrEmpty(cmds[c]))
                            {
                                continue;
                            }
                            DbBase.DbExecute(cmds[c]);
                        }
                    }
                    catch (Exception ex)
                    {
                        string mensagem = ex.Message;
                        mensagem = mensagem + "";
                    }

                    DbBase.DbExecute("UPDATE TB_UPDATE SET UPDATE_NUMBER = " + itms[i].Number);
                }
            }
            #endregion
        }
コード例 #5
0
ファイル: SimpleDataSource.cs プロジェクト: ricksam/Framework
 public void Remove <T>(T Conditions, DbTransaction Transaction = null)
 {
     DbBase.DbExecute(string.Format("{0} DELETE FROM {1} {2}", DbBase.DbSetDateFormat, typeof(T).Name, Condition(Conditions)), Transaction);
 }
コード例 #6
0
ファイル: SimpleDataSource.cs プロジェクト: ricksam/Framework
 public void RemoveAllData <T>(DbTransaction Transaction = null)
 {
     DbBase.DbExecute(string.Format("DELETE FROM {0}", typeof(T).Name), Transaction);
 }