Exemplo n.º 1
0
 private void btnRegister_Click(object sender, EventArgs e)
 {
     try
     {
         var entity = this.cmbDynamicEntities.SelectedItem as DynamicEntityInfo;
         if (entity != null)
         {
             var unregistered = (from el in this._unregistered_entities
                                 where el.EntityName.Equals(entity.EntityName, StringComparison.InvariantCultureIgnoreCase)
                                 select el).FirstOrDefault();
             if (unregistered != null && unregistered.Fields.Count > 0)
             {
                 this.DataStore.RegisterEntity(entity);
                 this._unregistered_entities.Remove(unregistered);
                 if (DataStoreChanged != null)
                 {
                     DataStoreChanged.Invoke(this._DataStore, new EventArgs());
                 }
             }
         }
     }
     catch (Exception ex)
     {
         OpenNETCF.ORM.MainDemo.Logger.LogException(System.Reflection.MethodBase.GetCurrentMethod().Name, ex);
     }
     finally
     {
         RefreshUI();
     }
 }
 public void RefreshUI()
 {
     if (this.InvokeRequired)
     {
         this.BeginInvoke(new Action(RefreshUI));
     }
     else
     {
         try
         {
             CleanUI();
             if (this._DataStore != null)
             {
                 if (this._DataStore.StoreExists)
                 {
                     foreach (var entity in this._DataStore.GetEntities())
                     {
                         try
                         {
                             int iCount     = 0;
                             var entityNode = this.treeDBStructure.Nodes.Add(String.Format("{0} ({1}) - {2}", entity.EntityName, entity.Fields.Count, iCount));
                             entityNode.Tag = entity;
                             entityNode.Collapse();
                             if (!this._DataStore.TableExists(entity))
                             {
                                 entityNode.BackColor = Color.FromArgb(255, 255, 169, 71);
                             }
                             else
                             {
                                 iCount = this._DataStore.Count(entity.EntityType);
                             }
                             entityNode.Text = String.Format("{0} ({1}) - {2}", entity.EntityName, entity.Fields.Count, iCount);
                             foreach (var field in entity.Fields)
                             {
                                 var fieldNode = new TreeNode(String.Format("{0} ({1})", field.FieldName, field.DataType.ToSqlTypeString()));
                                 if (!this._DataStore.FieldExists(entity, field))
                                 {
                                     fieldNode.BackColor  = Color.FromArgb(255, 255, 169, 71);
                                     entityNode.BackColor = Color.FromArgb(255, 255, 169, 71);
                                 }
                                 entityNode.Nodes.Add(fieldNode);
                             }
                         }
                         catch (Exception ex)
                         {
                             OpenNETCF.ORM.MainDemo.Logger.LogException(System.Reflection.MethodBase.GetCurrentMethod().Name, ex);
                         }
                     }
                 }
                 else
                 {
                     throw new OpenNETCF.ORM.StoreNotFoundException();
                 }
                 if (DataStoreChanged != null)
                 {
                     DataStoreChanged.Invoke(this._DataStore, new EventArgs());
                 }
             }
         }
         catch (Exception ex)
         {
             OpenNETCF.ORM.MainDemo.Logger.LogException(System.Reflection.MethodBase.GetCurrentMethod().Name, ex);
         }
     }
 }