internal void GetState() { TabPage tabPage = null; AssociativeEntity selectObject = null; foreach (var control in Controls) { if (control.GetType() == typeof(TabControl)) { var tabControl = control as TabControl; if (tabControl != null) { foreach (var subControl in tabControl.TabPages) { tabPage = subControl as TabPage; if (tabPage != null && (tabPage.ContainsFocus || tabPage.Visible)) { foreach (var subSubControl in tabPage.Controls) { if (subSubControl.GetType() == typeof(ListBox)) { var listBox = subSubControl as ListBox; if (listBox != null && listBox.SelectedItem != null && listBox.SelectedItem.GetType() == typeof(AssociativeEntity)) { selectObject = listBox.SelectedItem as AssociativeEntity; } break; } } break; } } } break; } } if (tabPage != null) { GeneratorController.Current.CurrentUnitLayout.RelationsBuilderTab = tabPage.Name; GeneratorController.Current.CurrentUnitLayout.RelationsBuilderTabHidden = false; } else { GeneratorController.Current.CurrentUnitLayout.RelationsBuilderTab = string.Empty; } if (selectObject != null) { GeneratorController.Current.CurrentUnitLayout.RelationsBuilderSelectedObject = selectObject.ObjectName; } else { GeneratorController.Current.CurrentUnitLayout.RelationsBuilderSelectedObject = string.Empty; } var propertyGrid = GetCurrentPropertyGrid(); GeneratorController.Current.CurrentUnitLayout.RelationsBuilderPropertySort = propertyGrid.PropertySort; if (propertyGrid.SelectedGridItem != null && propertyGrid.SelectedGridItem.PropertyDescriptor != null) { GeneratorController.Current.CurrentUnitLayout.RelationsBuilderSelectedGridItem = propertyGrid.SelectedGridItem.PropertyDescriptor.Name; } if (propertyGrid.PropertySort != PropertySort.Alphabetical) { GeneratorController.Current.CurrentUnitLayout.RelationsBuilderCollapsedCategories.Clear(); var root = propertyGrid.SelectedGridItem; if (root != null) { while (root.Parent != null) { root = root.Parent; } foreach (var item in root.GridItems) { var gridItem = item as GridItem; if (gridItem != null && !gridItem.Expanded) { GeneratorController.Current.CurrentUnitLayout.RelationsBuilderCollapsedCategories.Add( gridItem.Label); } } } } }
internal void SetAllPropertyGridSelectedObject(AssociativeEntity current) { SetPropertyGridSelectedObject(MainTabControl.TabPages[0], current); SetPropertyGridSelectedObject(MainTabControl.TabPages[1], current); SetPropertyGridSelectedObject(MainTabControl.TabPages[2], current); }
internal void Load(string filePath) { bool forceSave = false; IsLoading = true; LoadingTimer.Restart(); FileStream fs = null; try { Cursor.Current = Cursors.WaitCursor; var deserialized = false; var converted = false; while (!deserialized) { try { fs = File.Open(filePath, FileMode.Open); var xml = new XmlSerializer(typeof(CslaGeneratorUnit)); CurrentUnit = (CslaGeneratorUnit)xml.Deserialize(fs); if (VersionHelper.CurrentFileVersion != CurrentUnit.FileVersion) { if (fs != null) { fs.Close(); fs.Dispose(); } forceSave = VersionHelper.SolveVersionNumberIssues(filePath, null); converted = true; NewCslaUnit(); } else { deserialized = true; } } catch (InvalidOperationException exception) { if (fs != null) { fs.Close(); fs.Dispose(); } if (exception.InnerException == null || converted) { throw; } forceSave = VersionHelper.SolveVersionNumberIssues(filePath, exception); if (FixXmlSchemaErrors(filePath, exception)) { converted = true; NewCslaUnit(); } else { throw; } } } if (fs != null) { fs.Close(); fs.Dispose(); } if (forceSave) { Save(filePath); } CurrentUnit.FileVersion = VersionHelper.CurrentFileVersion; _currentUnit.ResetParent(); CurrentCslaObject = null; _currentAssociativeEntitiy = null; _currentFilePath = GetFilePath(filePath); ConnectionFactory.ConnectionString = _currentUnit.ConnectionString; // check if this is a valid connection, else let the user enter new connection info SqlConnection cn = null; try { cn = ConnectionFactory.NewConnection; cn.Open(); BuildSchemaTree(_currentUnit.ConnectionString); IsDBConnected = true; } catch //(SqlException e) { // call connect function which will allow user to enter new info Connect(); } finally { if (cn != null && cn.State == ConnectionState.Open) { cn.Close(); } if (cn != null) { cn.Dispose(); } } BindControls(); _currentUnit.CslaObjects.ListChanged += CslaObjects_ListChanged; if (_currentUnit.CslaObjects.Count > 0) { if (_mainForm.ProjectPanel.ListObjects.Items.Count > 0) { CurrentCslaObject = (CslaObjectInfo)_mainForm.ProjectPanel.ListObjects.Items[0]; } else { CurrentCslaObject = null; } if (_mainForm.DbSchemaPanel != null) { _mainForm.DbSchemaPanel.CurrentCslaObject = CurrentCslaObject; } } else { CurrentCslaObject = null; if (_mainForm.DbSchemaPanel != null) { _mainForm.DbSchemaPanel.CurrentCslaObject = null; } } _mainForm.ProjectPanel.ApplyFiltersPresenter(); _currentUnit.AssociativeEntities.ListChanged += AssociativeEntities_ListChanged; /*if (_currentUnit.AssociativeEntities.Count > 0) * { * _currentAssociativeEntitiy = _currentUnit.AssociativeEntities[0]; * } * else * { * _currentAssociativeEntitiy = null; * _frmGenerator.ObjectRelationsBuilder.PropertyGrid1.SelectedObject = null; * _frmGenerator.ObjectRelationsBuilder.PropertyGrid2.SelectedObject = null; * _frmGenerator.ObjectRelationsBuilder.PropertyGrid3.SelectedObject = null; * }*/ } catch (Exception e) { var message = filePath + Environment.NewLine + Environment.NewLine + e.Message; if (e.InnerException != null) { message += Environment.NewLine + e.InnerException.Message; } MessageBox.Show(_mainForm, message, "Loading File Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { Cursor.Current = Cursors.Default; if (fs != null) { fs.Close(); fs.Dispose(); } } LoadProjectLayout(filePath); CurrentCslaObject = (CslaObjectInfo)GetSelectedItem(); IsLoading = false; LoadingTimer.Stop(); }