Advertisement
Guest User

DatabaseParameters

a guest
Nov 15th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.47 KB | None | 0 0
  1. public class DatabaseUploadCollectionParameters
  2.     {
  3.         public String Server { get; set; }
  4.         public String Database { get; set; }
  5.         public String UserID { get; set; }
  6.         public String Password { get; set; }
  7.         public List<SearchField> SearchFields { get; set; }
  8.         public List<FieldCollection> FieldCollections { get; set; }
  9.  
  10.         public DatabaseUploadCollectionParameters(String server, String database, String userID, String password)
  11.         {
  12.             Server = server;
  13.             Database = database;
  14.             UserID = userID;
  15.             Password = password;
  16.             SearchFields = new List<SearchField>();
  17.             FieldCollections = new List<FieldCollection>();
  18.         }
  19.  
  20.         public void AddTerm(SearchField searchTerm)
  21.         {
  22.             SearchFields.Add(searchTerm);
  23.         }
  24.  
  25.         public void AddTerms(List<SearchField> searchTerms)
  26.         {
  27.             SearchFields.AddRange(searchTerms);
  28.         }
  29.  
  30.         public void AddCollection(String name, List<object> fieldCollections)
  31.         {
  32.             if (fieldCollections != null)
  33.             {
  34.                 List<FieldCollection> Collections = getFieldCollection(fieldCollections);
  35.                 foreach (FieldCollection FC in Collections)
  36.                 {
  37.                     FC.Name = name;
  38.                 }
  39.                 FieldCollections.AddRange(Collections);
  40.             }
  41.         }
  42.  
  43.         public static List<FieldCollection> getFieldCollection(List<Object> ClassItems)
  44.         {
  45.             List<FieldCollection> objectInstances = new List<FieldCollection>();
  46.  
  47.             foreach (Object ClassItem in ClassItems)
  48.             {
  49.                 String ClassName = ClassItem.GetType().Name;
  50.                 List<Field> ObjectFields = new List<Field>();
  51.  
  52.                 var Properties = ClassItem.GetType().GetProperties();
  53.                 foreach (PropertyInfo FI in Properties)
  54.                 {
  55.                     String Name = FI.Name;
  56.                     String Type = FI.PropertyType.Name.ToString();
  57.                     String Value = null;
  58.                     if (FI.GetValue(ClassItem, null) != null)
  59.                         Value = FI.GetValue(ClassItem, null).ToString();
  60.  
  61.                     ObjectFields.Add(new Field(Name, Type, Value));
  62.                 }
  63.  
  64.                 objectInstances.Add(new FieldCollection(ClassName, ObjectFields));
  65.             }
  66.  
  67.             return objectInstances;
  68.         }
  69.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement