/// <summary> /// Synchronizes metadata and data table /// [drops and/or inserts data columns in the view table] /// </summary> public void SynchronizeDataTable(View view, bool tryCompact = true) { try { if (isWebMode) { return; } Boolean noDataTable = dbDriver.TableExists(view.TableName) == false; if (noDataTable) { CreateDataTableForView(view, 1); } else { foreach (Page page in view.Pages) { DataTable fieldMetadataSync = view.GetMetadata().GetFieldMetadataSync(page.Id); DeleteUndefinedDataFields(page, fieldMetadataSync); } if (tryCompact) { try { dbDriver.CompactDatabase(); if (dbDriver.FullName.Contains("[MS Access]")) { string insertStatement = string.Format("insert into {0}([UniqueKey], [GlobalRecordId]) values (@UniqueKey, @GlobalRecordId)", view.TableName); Query insertQuery = dbDriver.CreateQuery(insertStatement); insertQuery.Parameters.Add(new QueryParameter("@UniqueKey", DbType.Int16, StartingId - 1)); insertQuery.Parameters.Add(new QueryParameter("@GlobalRecordId", DbType.String, "")); dbDriver.ExecuteNonQuery(insertQuery); string deleteStatement = string.Format("delete from {0} where UniqueKey={1} ", view.TableName, StartingId - 1); Query deleteQuery = dbDriver.CreateQuery(deleteStatement); dbDriver.ExecuteNonQuery(deleteQuery); } } catch { } } view.SetTableName(view.TableName); foreach (Page page in view.Pages) { SynchronizePageTable(page); } } } catch { } }
/// <summary> /// Constructor /// </summary> /// <param name="viewName">New <see cref="Epi.View"/> name.</param> /// <param name="isChildView">Is Related (child) view flag.</param> /// <returns>New project <see cref="Epi.View"/></returns> public View CreateView(string viewName, bool isChildView) { View newView = new View(this); newView.Name = viewName; newView.SetTableName(newView.Name); newView.IsRelatedView = isChildView; if (!Views.Contains(newView)) { Views.Add(newView); } Metadata.InsertView(newView); currentViewElement = newView.ViewElement; LoadViews(); return newView; }