示例#1
0
        public static int GetUniqueID(object Instance)
        {
            int ID = ((ReflectEntity)Instance).ID;

            if (ID > 0)
            {
                return(ID);
            }

            string Query  = "SELECT [ID] FROM [dbo].[" + EncryptTableName(Instance.GetType().Name) + "]";
            string Filter = "[IsDeleted] = 0";

            foreach (System.Reflection.PropertyInfo SystemAttribute in Instance.GetType().GetProperties().Where(x => Attribute.IsDefined(x, typeof(UniqueAtrribute))))
            {
                if (Attribute.IsDefined(SystemAttribute, typeof(RelationAttribute)))
                {
                    foreach (System.Reflection.PropertyInfo RelatedAttribute in SystemAttribute.PropertyType.GetProperties())
                    {
                        if (Attribute.IsDefined(RelatedAttribute, typeof(NoDataAttribute)) || Attribute.IsDefined(RelatedAttribute, typeof(NoRelationAttribute)) || Attribute.IsDefined(RelatedAttribute, typeof(RelationAttribute)))
                        {
                            continue;
                        }

                        else if (RelatedAttribute.PropertyType.Namespace.StartsWith("System") || RelatedAttribute.PropertyType.IsEnum)
                        {
                            if (RelatedAttribute.PropertyType.IsEnum || RelatedAttribute.GetValue(Instance, null) != null)
                            {
                                Filter += " AND [" + SystemAttribute.Name + "." + RelatedAttribute + "] = '" + (IsCryptable(RelatedAttribute) ? EncryptColumnValue(RelatedAttribute.GetValue(Instance, null).ToString()) : RelatedAttribute.GetValue(Instance, null)) + "'";
                            }
                        }
                    }
                }
                else if (SystemAttribute.PropertyType.Namespace.StartsWith("System") || SystemAttribute.PropertyType.IsEnum)
                {
                    if (SystemAttribute.PropertyType.IsEnum || SystemAttribute.GetValue(Instance, null) != null)
                    {
                        Filter += " AND [" + SystemAttribute.Name + "] = '" + (IsCryptable(SystemAttribute) ? EncryptColumnValue(SystemAttribute.GetValue(Instance, null).ToString()) : SystemAttribute.GetValue(Instance, null)) + "'";
                    }
                }
            }

            if (Filter != "")
            {
                Query += " WHERE " + Filter;
            }

            try
            {
                ID = Database.Executor.PrintQuery(Query);
            }
            catch (Exception)
            {
            }

            return(ID);
        }
示例#2
0
 public override int GetHashCode()
 {
     return(Id.GetHashCode() ^
            AssemblyId.GetHashCode() ^
            PluginId.GetHashCode() ^
            StepId.GetHashCode() ^
            Attributes.GetHashCode() ^
            Name.GetHashCode() ^
            RelatedAttribute.GetHashCode() ^
            EntityAlias.GetHashCode() ^
            ImageType.GetHashCode() ^
            MessagePropertyName.GetHashCode());
 }
示例#3
0
        public static int Save(object Instance)
        {
            int ID = ((ReflectEntity)Instance).ID;

            ((ReflectEntity)Instance).UpdatedOn = DateTime.Now;

            if (Instance.GetType().IsSubclassOf(typeof(ReflectEntity)))
            {
                if (((ReflectEntity)Instance).ID == 0)
                {
                    ((ReflectEntity)Instance).CreatedOn = DateTime.Now;
                    string Columns = "";
                    string Values  = "";

                    foreach (System.Reflection.PropertyInfo SystemAttribute in Instance.GetType().GetProperties())
                    {
                        if (Attribute.IsDefined(SystemAttribute, typeof(NoDataAttribute)))
                        {
                            continue;
                        }

                        if (SystemAttribute.Name != "ID")
                        {
                            if (Attribute.IsDefined(SystemAttribute, typeof(RelationAttribute)))
                            {
                                foreach (System.Reflection.PropertyInfo RelatedAttribute in SystemAttribute.PropertyType.GetProperties())
                                {
                                    if (Attribute.IsDefined(RelatedAttribute, typeof(NoDataAttribute)) || Attribute.IsDefined(RelatedAttribute, typeof(NoRelationAttribute)) || Attribute.IsDefined(RelatedAttribute, typeof(RelationAttribute)))
                                    {
                                        continue;
                                    }

                                    if (RelatedAttribute.PropertyType.Namespace.StartsWith("System") || RelatedAttribute.PropertyType.IsEnum)
                                    {
                                        if (Columns != "")
                                        {
                                            Columns += ", ";
                                        }

                                        Columns += "[" + EncryptColumnName(SystemAttribute.Name + "." + RelatedAttribute.Name) + "]";
                                    }
                                }
                            }
                            else if (SystemAttribute.PropertyType.Namespace.StartsWith("System") || SystemAttribute.PropertyType.IsEnum)
                            {
                                if (Columns != "")
                                {
                                    Columns += ", ";
                                }

                                Columns += "[" + EncryptColumnName(SystemAttribute.Name) + "]";
                            }

                            if (!SystemAttribute.PropertyType.IsEnum && SystemAttribute.GetValue(Instance, null) == null)
                            {
                                if (Values != "")
                                {
                                    Values += ", ";
                                }
                                Values += "NULL";
                            }
                            else
                            {
                                if (SystemAttribute.PropertyType == typeof(DateTime))
                                {
                                    if (Values != "")
                                    {
                                        Values += ", ";
                                    }

                                    if (Convert.ToDateTime(SystemAttribute.GetValue(Instance, null)) == DateTime.MinValue)
                                    {
                                        Values += "NULL";
                                    }
                                    else
                                    {
                                        Values += "'" + (IsCryptable(SystemAttribute) ? EncryptColumnValue(SystemAttribute.GetValue(Instance, null).ToString()) : new System.Data.SqlClient.SqlParameter("@var", SystemAttribute.GetValue(Instance, null))
                                        {
                                            SqlDbType = SqlDbType.SmallDateTime
                                        }.SqlValue.ToString()) + "'";
                                    }
                                }
                                else if (Attribute.IsDefined(SystemAttribute, typeof(RelationAttribute)))
                                {
                                    foreach (System.Reflection.PropertyInfo RelatedAttribute in SystemAttribute.PropertyType.GetProperties())
                                    {
                                        if (Attribute.IsDefined(RelatedAttribute, typeof(NoDataAttribute)) || Attribute.IsDefined(RelatedAttribute, typeof(NoRelationAttribute)) || Attribute.IsDefined(RelatedAttribute, typeof(RelationAttribute)))
                                        {
                                            continue;
                                        }

                                        else if (RelatedAttribute.PropertyType.Namespace.StartsWith("System") || RelatedAttribute.PropertyType.IsEnum)
                                        {
                                            if (Values != "")
                                            {
                                                Values += ", ";
                                            }

                                            if (RelatedAttribute.GetValue(Instance, null) == null)
                                            {
                                                Values += "[" + EncryptColumnName(SystemAttribute.Name + "." + RelatedAttribute.Name) + "] = NULL";
                                            }
                                            else
                                            {
                                                Values += "[" + EncryptColumnName(SystemAttribute.Name + "." + RelatedAttribute.Name) + "] = '" + (IsCryptable(RelatedAttribute) ? EncryptColumnValue(RelatedAttribute.GetValue(Instance, null).ToString()) : RelatedAttribute.GetValue(Instance, null)) + "'";
                                            }
                                        }
                                    }
                                }
                                else if (SystemAttribute.PropertyType.Namespace.StartsWith("System") || SystemAttribute.PropertyType.IsEnum)
                                {
                                    if (Values != "")
                                    {
                                        Values += ", ";
                                    }

                                    Values += "'" + (IsCryptable(SystemAttribute) ? EncryptColumnValue(SystemAttribute.GetValue(Instance, null).ToString()) : SystemAttribute.GetValue(Instance, null)) + "'";
                                }
                            }
                        }
                    }

                    string Query = "INSERT INTO [dbo].[" + EncryptTableName(Instance.GetType().Name) + "] (" + Columns + ") VALUES (" + Values + "); SELECT SCOPE_IDENTITY();";

                    ID = Database.Executor.PrintQuery(Query);
                }
                else
                {
                    string Values = "";

                    foreach (System.Reflection.PropertyInfo SystemAttribute in Instance.GetType().GetProperties())
                    {
                        if (Attribute.IsDefined(SystemAttribute, typeof(NoDataAttribute)))
                        {
                            continue;
                        }

                        if (SystemAttribute.Name != "ID")
                        {
                            if (Values != "")
                            {
                                Values += ", ";
                            }

                            if (SystemAttribute.PropertyType == typeof(DateTime))
                            {
                                if (Convert.ToDateTime(SystemAttribute.GetValue(Instance, null)) == DateTime.MinValue)
                                {
                                    Values += "[" + SystemAttribute.Name + "] = NULL";
                                }
                                else
                                {
                                    Values += "[" + SystemAttribute.Name + "] = '" + (IsCryptable(SystemAttribute) ? EncryptColumnValue(SystemAttribute.GetValue(Instance, null).ToString()) : new System.Data.SqlClient.SqlParameter("@var", SystemAttribute.GetValue(Instance, null))
                                    {
                                        SqlDbType = SqlDbType.SmallDateTime
                                    }.SqlValue.ToString()) + "'";
                                }
                            }
                            else if (Attribute.IsDefined(SystemAttribute, typeof(RelationAttribute)))
                            {
                                foreach (System.Reflection.PropertyInfo RelatedAttribute in SystemAttribute.PropertyType.GetProperties())
                                {
                                    if (Attribute.IsDefined(RelatedAttribute, typeof(NoDataAttribute)) || Attribute.IsDefined(RelatedAttribute, typeof(NoRelationAttribute)) || Attribute.IsDefined(RelatedAttribute, typeof(RelationAttribute)))
                                    {
                                        continue;
                                    }

                                    if (RelatedAttribute.PropertyType.Namespace.StartsWith("System") || RelatedAttribute.PropertyType.IsEnum)
                                    {
                                        if (!RelatedAttribute.PropertyType.IsEnum && RelatedAttribute.GetValue(Instance, null) == null)
                                        {
                                            Values += "[" + EncryptColumnName(SystemAttribute.Name + "." + RelatedAttribute.Name) + "]= NULL";
                                        }
                                        else
                                        {
                                            Values += "[" + EncryptColumnName(SystemAttribute.Name + "." + RelatedAttribute.Name) + "]= '" + (IsCryptable(RelatedAttribute) ? EncryptColumnValue(RelatedAttribute.GetValue(Instance, null).ToString()) : RelatedAttribute.GetValue(Instance, null)) + "'";
                                        }
                                    }
                                }
                            }
                            else if (SystemAttribute.PropertyType.Namespace.StartsWith("System") || SystemAttribute.PropertyType.IsEnum)
                            {
                                if (!SystemAttribute.PropertyType.IsEnum && SystemAttribute.GetValue(Instance, null) == null)
                                {
                                    Values += "[" + SystemAttribute.Name + "] = NULL";
                                }
                                else
                                {
                                    Values += "[" + SystemAttribute.Name + "] = '" + (IsCryptable(SystemAttribute) ? EncryptColumnValue(SystemAttribute.GetValue(Instance, null).ToString()) : SystemAttribute.GetValue(Instance, null)) + "'";
                                }
                            }
                        }
                    }

                    string Query = "UPDATE [dbo].[" + EncryptTableName(Instance.GetType().Name) + "] SET " + Values + " WHERE [ID] = '" + ((ReflectEntity)Instance).ID + "';";
                    Database.Executor.ExecuteQuery(Query);
                }
            }

            return(ID);
        }
示例#4
0
        public static List <object> ObjectsByDataSet(System.Type SystemType, DataSet Result)
        {
            if (Result.Tables.Count == 0)
            {
                return(new List <object>());
            }

            if (Result.Tables[0].Rows.Count == 0)
            {
                return(new List <object>());
            }

            List <object> ObjectList = new List <object>();

            foreach (System.Data.DataRow DataRow in Result.Tables[0].Rows)
            {
                object Instance = Activator.CreateInstance(SystemType);
                foreach (System.Reflection.PropertyInfo SystemAttribute in SystemType.GetProperties())
                {
                    if (Attribute.IsDefined(SystemAttribute, typeof(NoDataAttribute)))
                    {
                        continue;
                    }

                    try
                    {
                        if (SystemAttribute.PropertyType.IsEnum)
                        {
                            SystemAttribute.SetValue(Instance, Enum.Parse(SystemAttribute.PropertyType, (IsCryptable(SystemAttribute) ? DecryptColumnValue(DataRow[EncryptColumnName(SystemAttribute.Name)].ToString()) : DataRow[EncryptColumnName(SystemAttribute.Name)]).ToString(), true), null);
                        }
                        else if (SystemAttribute.PropertyType == typeof(Guid))
                        {
                            SystemAttribute.SetValue(Instance, Guid.Parse((IsCryptable(SystemAttribute) ? DecryptColumnValue(DataRow[EncryptColumnName(SystemAttribute.Name)].ToString()) : DataRow[EncryptColumnName(SystemAttribute.Name)]).ToString()), null);
                        }
                        else if (Attribute.IsDefined(SystemAttribute, typeof(RelationAttribute)))
                        {
                            object RelatedInstance = Activator.CreateInstance(SystemAttribute.PropertyType);

                            foreach (System.Reflection.PropertyInfo RelatedAttribute in SystemAttribute.PropertyType.GetProperties())
                            {
                                if (Attribute.IsDefined(RelatedAttribute, typeof(NoDataAttribute)) || Attribute.IsDefined(RelatedAttribute, typeof(RelationAttribute)) || Attribute.IsDefined(RelatedAttribute, typeof(NoRelationAttribute)))
                                {
                                    continue;
                                }

                                RelatedAttribute.SetValue(RelatedInstance, (IsCryptable(RelatedAttribute) ? DecryptColumnValue(DataRow[EncryptColumnName(SystemAttribute.Name + "." + RelatedAttribute.Name)].ToString()) : DataRow[EncryptColumnName(SystemAttribute.Name + "." + RelatedAttribute.Name)]), null);
                            }

                            SystemAttribute.SetValue(Instance, RelatedInstance);
                        }
                        else
                        {
                            SystemAttribute.SetValue(Instance, (IsCryptable(SystemAttribute) ? DecryptColumnValue(DataRow[EncryptColumnName(SystemAttribute.Name)].ToString()) : DataRow[EncryptColumnName(SystemAttribute.Name)]), null);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }

                ObjectList.Add(Instance);
            }

            return(ObjectList);
        }