protected BasePanel(IVisualBootstrapper visualBootstrapper, IVisualCollection children) : base(visualBootstrapper) { _children = children is VisualCollection good ? good : new VisualCollection(children); }
// Returns a FieldDefinition object given a collection and a field name. Does not work for collection fields or entity fields public static FieldDefinition GetFieldDefinition(this IVisualCollection collection, string FieldName) { var entityType = (IEntityType)collection.Details.GetModel().ElementType; bool isNullable = false; FieldDefinition fd = null; foreach (IEntityPropertyDefinition p in entityType.Properties) { //Ignore hidden fields and computed field if (p.Attributes.Where(a => a.Class.Name == "Computed").FirstOrDefault() == null) { if (!(p.PropertyType is ISequenceType)) { //ignore collections and entities if (p.Name == FieldName) { fd = new FieldDefinition(); fd.Name = p.Name; fd.DisplayName = p.Name; fd.TypeName = GetPropertyType(p.PropertyType, ref isNullable); fd.IsNullable = isNullable; if (fd.TypeName == "Entity") { fd.EntityType = (IEntityType)p.PropertyType; } break; // TODO: might not be correct. Was : Exit For } } } } return(fd); }
private UniformStackPanel(//IDataBinding<T>? binding, IVisualBootstrapper visualBootstrapper, IVisualCollection children) //: base(binding, visualBootstrapper, children, new SequentialUniformRenderer(children)) : base(visualBootstrapper, children, new SequentialUniformRenderer(children)) { }
public SequentialUniformRenderer(IVisualCollection visuals, Boolean isWrapContent = false) : base(visuals, isWrapContent) { _maxHeight = _maxWidth = 0; _lastOrientation = Orientations.Vertical; }
public ColumnRenderer(IVisualCollection visuals, Dictionary <Int32, Double> rowHeights) : base(visuals) { _rowHeights = rowHeights; RowHeights = new Dictionary <Int32, Double>(); }
public ModalWindow(IVisualCollection visualCollection, string dialogName, string entityName = "") { _collection = visualCollection; _dialogName = dialogName; _entityName = ((entityName != "") ? entityName : _collection.Details.GetModel().ElementType.Name); _screen = _collection.Screen; }
public SequentialRenderer(IVisualCollection visuals, Boolean isWrapContent = false) { _measureLock = new Object(); _currentlyRendering = new List <IVisualElement>(); _visuals = visuals; _isWrapContent = isWrapContent; ElementsRendered = new Dictionary <IVisualElement, ValueRenderRectangle>(); }
//protected BaseSequentialPanel(IDataBinding<T>? binding, // IVisualBootstrapper visualBootstrapper) // : this(binding, visualBootstrapper, new VisualCollection()) //{ //} //protected BaseSequentialPanel(IDataBinding<T>? binding, // IVisualBootstrapper visualBootstrapper, // IVisualCollection children, // ISequentialRenderer? renderer = null) // : base(binding, visualBootstrapper, children) //{ // _renderer = EnsureRenderer(renderer); // VerticalAlignment = VerticalAlignments.Default; // HorizontalAlignment = HorizontalAlignments.Default; //} protected BaseSequentialPanel(IVisualBootstrapper templateResolver, IVisualCollection children, ISequentialRenderer?renderer = null) //: this(null, templateResolver, children, renderer) : base(templateResolver, children) { _renderer = EnsureRenderer(renderer); VerticalAlignment = VerticalAlignments.Default; HorizontalAlignment = HorizontalAlignments.Default; }
// exports collection to a new workbook starting at cell A1 on the first worksheet public static dynamic Export(IVisualCollection collection) { dynamic result = null; try { ExcelHelper excel = new ExcelHelper(); excel.CreateWorkbook(); List <string> columnNames = new List <string>(); if (collection.Count > 0) { // get column properties IEnumerable <IEntityProperty> columnProperties = collection.OfType <IEntityObject>().First().Details.Properties.All(); int columnCounter = 1; int rowCounter = 1; // add columns names to the list foreach (IEntityProperty entityProperty in columnProperties) { columnNames.Add(entityProperty.Name); // add column headers to Excel workbook excel.Cells(rowCounter, columnCounter, entityProperty.DisplayName); columnCounter += 1; } // add values on the row following the headers rowCounter = 2; // iterate the collection and extract values by column name foreach (IEntityObject entityObj in collection) { for (int i = 0; i <= columnNames.Count - 1; i++) { excel.Cells(rowCounter, i + 1, LightSwitchHelper.GetValue(entityObj, columnNames[i])); } rowCounter += 1; } } excel.ShowWorkbook(); result = excel.Workbook; } catch (Exception ex) { throw ex; } return(result); }
public static bool ValidData(string value, int row, ColumnMapping mapping, IVisualCollection collection, Dictionary <string, IEntityObject> navProperties, List <string> errorList) { bool bValid = false; IEntityType targetEntityType = mapping.TableField.EntityType; //Need to grab the entity set and check number of results we get IApplicationDefinition appModel = collection.Screen.Details.Application.Details.GetModel(); IEntityContainerDefinition entityContainerDefinition = (from ecd in appModel.GlobalItems.OfType <IEntityContainerDefinition>() where ecd.EntitySets.Any(es => object.ReferenceEquals(es.EntityType, targetEntityType)) select ecd).FirstOrDefault(); if (entityContainerDefinition == null) { throw new Exception("Could not find an entity container representing the entity type: " + targetEntityType.Name); } IEntitySetDefinition entitySetDefinition = (from es in entityContainerDefinition.EntitySets where object.ReferenceEquals(es.EntityType, targetEntityType) select es).First(); var dataService = (IDataService)collection.Screen.Details.DataWorkspace.Details.Properties[entityContainerDefinition.Name].Value; var entitySet = (IEntitySet)dataService.Details.Properties[entitySetDefinition.Name].Value; var dsQuery = entitySet.GetQuery(); //Search for the matching entity for the relationship IEnumerable<IEntityObject> var results = SearchEntityMethodInfo().MakeGenericMethod(dsQuery.ElementType).Invoke(null, new object[] { dsQuery, value, targetEntityType }) as IEnumerable <IEntityObject>; int searchCount = results.Count(); if (searchCount == 0) { bValid = false; errorList.Add(String.Format("Column:{0} Row:{1} Cannot find a matching '{2}' for '{3}'", mapping.OfficeColumn, row, mapping.TableField.DisplayName, value)); } else if (searchCount > 1) { bValid = true; errorList.Add(String.Format("Column:{0} Row:{1} Multiple matching '{2}' for '{3}'. Will select first match.", mapping.OfficeColumn, row, mapping.TableField.DisplayName, value)); navProperties[String.Format("{0}_{1}", mapping.TableField.Name, value)] = results.FirstOrDefault(); } else { bValid = true; navProperties[String.Format("{0}_{1}", mapping.TableField.Name, value)] = results.FirstOrDefault(); } return(bValid); }
// exports a collection to a workbook starting at the specified location public static dynamic Export(IVisualCollection collection, string Workbook, string Worksheet, string Range, List <string> ColumnNames) { List <ColumnMapping> mappings = new List <ColumnMapping>(); ColumnMapping map = default(ColumnMapping); foreach (string name in ColumnNames) { map = new ColumnMapping("", name); map.TableField.DisplayName = name; mappings.Add(map); } return(Export(collection, Workbook, Worksheet, Range, mappings)); }
// Imports a range from workbook chosen by end-user. Assumes table starts at cell A1 on the first worksheet. public static void Import(IVisualCollection collection) { _collection = collection; Dispatchers.Main.BeginInvoke(() => { OpenFileDialog dialog = new OpenFileDialog(); dialog.Multiselect = false; dialog.Filter = "Excel Documents(*.xls;*.xlsx;*.csv)|*.xls;*.xlsx;*.csv|All files (*.*)|*.*"; if (dialog.ShowDialog() == true) { FileInfo f = dialog.File; try { ExcelHelper excel = new ExcelHelper(); excel.OpenWorkbook(f.FullName); _excelDocRange = excel.UsedRange(1, 1); excel.Dispose(); List <FieldDefinition> tablePropertyChoices = GetTablePropertyChoices(); _columnMappings = new List <ColumnMapping>(); Int32 numColumns = _excelDocRange.GetLength(1); for (var i = 0; i <= numColumns - 1; i++) { _columnMappings.Add(new ColumnMapping(_excelDocRange[0, i], tablePropertyChoices)); } ColumnMapper columnMapperContent = new ColumnMapper(); columnMapperContent.OfficeColumn.Text = "Excel Column"; ScreenChildWindow columnMapperWindow = new ScreenChildWindow(); columnMapperContent.DataContext = _columnMappings; columnMapperWindow.Closed += OnMappingDialogClosed; //set parent to current screen IServiceProxy sdkProxy = VsExportProviderService.GetExportedValue <IServiceProxy>(); columnMapperWindow.Owner = (Control)sdkProxy.ScreenViewService.GetScreenView(_collection.Screen).RootUI; columnMapperWindow.Show(_collection.Screen, columnMapperContent); } catch (SecurityException ex) { collection.Screen.Details.Dispatcher.BeginInvoke(() => { _collection.Screen.ShowMessageBox("Error: Silverlight Security error. Could not load Excel document. Make sure the document is in your 'Documents' directory."); }); } catch (COMException comEx) { _collection.Screen.Details.Dispatcher.BeginInvoke(() => { _collection.Screen.ShowMessageBox("Error: Could not open this file. It may not be a valid Excel document."); }); } } }); }
// Create HTML table based on IVisualCollection public static string HtmlExport(IVisualCollection collection) { List <string> columnNames = new List <string>(); string sBody = ""; if (collection.Count > 0) { // opening an html tag and creating a table //Body = "<html>" //sBody = sBody + "</br></br>" //sBody = sBody + "<body style=""font-family: Arial, Helvetica, sans-serif;"" >" sBody = "<table border=\"1\">"; // get column properties IEnumerable <IEntityProperty> columnProperties = collection.OfType <IEntityObject>().First().Details.Properties.All(); // add columns names to the list // row begins sBody = sBody + "<tr>"; foreach (IEntityProperty entityProperty in columnProperties) { columnNames.Add(entityProperty.Name); sBody = sBody + "<td>"; sBody = sBody + " " + entityProperty.DisplayName; sBody = sBody + "</td>"; } // row ends sBody = sBody + "</tr>"; // iterate the collection and extract values by column name foreach (IEntityObject entityObj in collection) { sBody = sBody + "<tr>"; for (int i = 0; i <= columnNames.Count - 1; i++) { sBody = sBody + "<td>"; sBody = sBody + LightSwitchHelper.GetValue(entityObj, columnNames[i]); sBody = sBody + "</td>"; } sBody = sBody + "</tr>"; } // closing the tags sBody = sBody + "</table>"; //sBody = sBody + "</body>" //sBody = sBody + "</html>" } return(sBody); }
// Imports a range starting at the location specified by workbook, worksheet, and range. // Workbook should be the full path to the workbook. public static void Import(IVisualCollection collection, string Workbook, string Worksheet, string Range) { _collection = collection; Dispatchers.Main.BeginInvoke(() => { ExcelHelper xlProxy = new ExcelHelper(); dynamic wb = null; dynamic ws = null; dynamic rg = null; wb = xlProxy.Excel.Workbooks.Open(Workbook); if ((wb != null)) { ws = wb.Worksheets(Worksheet); if ((ws != null)) { rg = ws.Range(Range); _excelDocRange = ConvertToArray(rg); List <FieldDefinition> tablePropertyChoices = GetTablePropertyChoices(); _columnMappings = new List <ColumnMapping>(); Int32 numColumns = _excelDocRange.GetLength(1); for (var i = 0; i <= numColumns - 1; i++) { _columnMappings.Add(new ColumnMapping(_excelDocRange[0, i], tablePropertyChoices)); } ColumnMapper columnMapperContent = new ColumnMapper(); columnMapperContent.OfficeColumn.Text = "Excel Column"; ScreenChildWindow columnMapperWindow = new ScreenChildWindow(); columnMapperContent.DataContext = _columnMappings; columnMapperWindow.Closed += OnMappingDialogClosed; //set parent to current screen IServiceProxy sdkProxy = VsExportProviderService.GetExportedValue <IServiceProxy>(); columnMapperWindow.Owner = (Control)sdkProxy.ScreenViewService.GetScreenView(_collection.Screen).RootUI; columnMapperWindow.Show(_collection.Screen, columnMapperContent); } } rg = null; ws = null; wb.Close(false); wb = null; xlProxy.Dispose(); }); }
// Create HTML table based on IVisualCollection public static string HtmlExport(IVisualCollection Collection, List <string> ColumnNames) { string sBody = ""; if (Collection.Count > 0) { // opening an html tag and creating a table //sBody = "<html>" //sBody = sBody + "</br></br>" //sBody = sBody + "<body style=""font-family: Arial, Helvetica, sans-serif;"" >" sBody = "<table border=\"1\">"; string sColumnName = null; // add columns names to the list // row begins sBody = sBody + "<tr>"; foreach (string sColumnName_loopVariable in ColumnNames) { sColumnName = sColumnName_loopVariable; sBody = sBody + "<td>"; sBody = sBody + " " + sColumnName; sBody = sBody + "</td>"; } // row ends sBody = sBody + "</tr>"; // iterate the collection and extract values by column name foreach (IEntityObject entityObj in Collection) { sBody = sBody + "<tr>"; for (int i = 0; i <= ColumnNames.Count - 1; i++) { sBody = sBody + "<td>"; sBody = sBody + LightSwitchHelper.GetValue(entityObj, ColumnNames[i]); sBody = sBody + "</td>"; } sBody = sBody + "</tr>"; } // closing the tags sBody = sBody + "</table>"; //sBody = sBody + "</body>" //sBody = sBody + "</html>" } return(sBody); }
private static void TriggerCanExecute(IVisualCollection visualCollection) { //this will make sure that the CanExecute method is triggered in a potential button for doing something //with the selection result. //not elegant, but no other option... var currentItem = visualCollection.SelectedItem; var collection = visualCollection as IEnumerable <IEntityObject>; if (!visualCollection.SelectedItem.Equals(collection.Last())) { visualCollection.SelectedItem = collection.Last(); } else { visualCollection.SelectedItem = collection.First(); } visualCollection.SelectedItem = currentItem; }
public static dynamic CreateEmail(string Address, string Subject, IVisualCollection Items) { try { string sBody = null; sBody = HtmlExport(Items); if (GetOutlook()) { dynamic mail = outlook.CreateItem(olMailItem); var _with3 = mail; // checking if it contains an html tags if (sBody.ToLower().Contains("<html>")) { _with3.BodyFormat = olFormatHTML; _with3.HTMLBody = sBody; } else { _with3.BodyFormat = olFormatPlain; _with3.Body = sBody; } _with3.Recipients.Add(Address); _with3.Subject = Subject; _with3.Display(); // Returning the dynamic return(mail); } } catch (Exception ex) { throw new InvalidOperationException("Failed to create email.", ex); } return(null); }
// Imports a range starting at the location specified by workbook, worksheet, and range. // Workbook should be the full path to the workbook. public static void Import(IVisualCollection collection, string Workbook, string Worksheet, string Range, List <ColumnMapping> ColumnMapping) { _collection = collection; _columnMappings = ColumnMapping; // Ensure that we have the correct and complete field definition. foreach (OfficeSharp.ColumnMapping map in _columnMappings) { map.TableField = collection.GetFieldDefinition(map.TableField.Name); } Dispatchers.Main.BeginInvoke(() => { ExcelHelper xlProxy = new ExcelHelper(); dynamic wb = null; dynamic ws = null; dynamic rg = null; wb = xlProxy.Excel.Workbooks.Open(Workbook); if ((wb != null)) { ws = wb.Worksheets(Worksheet); if ((ws != null)) { rg = ws.Range(Range); _excelDocRange = ConvertToArray(rg); ValidateData(); } } rg = null; ws = null; wb.Close(false); wb = null; xlProxy.Dispose(); }); }
// Exports an IVisualCollection to a table in either the active (UseActiveDocument = True) or a new document (UseActiveDocument = False) public static dynamic Export(IVisualCollection collection, bool UseActiveDocument) { dynamic doc = null; WordHelper wordProxy = new WordHelper(); bool bUseActiveDocument = false; dynamic rg = null; // if Word is active then use it if (wordProxy.GetWord()) { // obtain a reference to the selection range if (UseActiveDocument) { rg = wordProxy.Word.Selection.Range; bUseActiveDocument = true; } else { wordProxy.CreateDocument(); } } else { wordProxy.CreateWord(); wordProxy.CreateDocument(); } List<string> columnNames = new List<string>(); if (collection.Count > 0) { // get column properties IEnumerable<IEntityProperty> columnProperties = collection.OfType<IEntityObject>().First().Details.Properties.All(); int columnCounter = 1; int rowCounter = 1; // add table dynamic oTable = null; if (bUseActiveDocument) { oTable = wordProxy.AddTable(collection.Count + 1, columnProperties.Count(), rg); } else { oTable = wordProxy.AddTable(collection.Count + 1, columnProperties.Count()); } // add columns names to the list foreach (IEntityProperty entityProperty in columnProperties) { columnNames.Add(entityProperty.Name); // add column headers to table wordProxy.SetTableCell(oTable, 1, columnCounter, entityProperty.DisplayName); columnCounter += 1; } // add values on the row following the headers rowCounter = 2; // iterate the collection and extract values by column name foreach (IEntityObject entityObj in collection) { for (int i = 0; i <= columnNames.Count - 1; i++) { wordProxy.SetTableCell(oTable, rowCounter, i + 1, LightSwitchHelper.GetValue(entityObj, columnNames[i])); } rowCounter += 1; } } doc = wordProxy.Document; wordProxy.ShowDocument(); return doc; }
// Exports an IVisualCollection to a table in given Document. BookmarkName is the name of the bookmark associated // with the table. public static dynamic Export(dynamic Document, string BookmarkName, int StartRow, bool BuildColumnHeadings, IVisualCollection collection, List<ColumnMapping> ColumnNames) { if (collection.Count > 0) { // get column properties int columnCounter = 1; int rowCounter = StartRow; // validate that the Documnet argument is expected type of Word.Document if (!IsWordDocumentObject(Document)) { throw new System.ArgumentException("'Document' is not the expected type of dynamic. Expected dynamic should be a Word.Document dynamic.", "Document"); } // validate the BookmarkName argument if (!IsValidBookmark(Document, BookmarkName)) { throw new System.ArgumentException("'BookmarkName' was not found in 'Document'", "BookmarkName"); } // validate that the bookmark is part of a table if (Document.Bookmarks(BookmarkName).Range.Tables.Count == 0) { throw new System.ArgumentException("No table was found at the bookmark", "BookmarkName"); } // add table dynamic oTable = null; oTable = Document.Bookmarks(BookmarkName).Range.Tables(1); // validate the StartRow argument if (StartRow > oTable.Rows.Count) { throw new System.ArgumentException("'StartRow' is greater then the number of rows in the table", "StartRow"); } // add columns names to the list foreach (ColumnMapping map in ColumnNames) { if (columnCounter > oTable.Columns.Count) { oTable.Columns.Add(); } if (BuildColumnHeadings) { if (map.TableField.DisplayName.Length > 0) { oTable.Cell(rowCounter, columnCounter).Range.Text = map.TableField.DisplayName; } else { oTable.Cell(rowCounter, columnCounter).Range.Text = map.TableField.Name; } } columnCounter += 1; } // add values on the row following the headers if (BuildColumnHeadings) { rowCounter += 1; } // iterate the collection and extract values by column name foreach (IEntityObject entityObj in collection) { for (int i = 0; i <= ColumnNames.Count - 1; i++) { if (rowCounter > oTable.Rows.Count) { oTable.Rows.Add(); } try { oTable.Cell(rowCounter, i + 1).Range.Text = LightSwitchHelper.GetValue(entityObj, ColumnNames[i].TableField.Name); } catch (Exception ex) { throw ex; } } rowCounter += 1; } } else { // No items in the collection } return Document; }
// Exports a collection to a table in given Document. BookmarkName is the name of the bookmark associated // with the table. public static dynamic Export(dynamic Document, string BookmarkName, int StartRow, bool BuildColumnHeadings, IVisualCollection collection, List<string> ColumnNames) { List<ColumnMapping> mappings = new List<ColumnMapping>(); ColumnMapping map = default(ColumnMapping); FieldDefinition fd = default(FieldDefinition); foreach (string name in ColumnNames) { fd = collection.GetFieldDefinition(name); map = new ColumnMapping("", name); if (fd == null) { map.TableField.DisplayName = name; } else { map.TableField = fd; } mappings.Add(map); } return Export(Document, BookmarkName, StartRow, BuildColumnHeadings, collection, mappings); }
// Exports a collection to a table in given Document. BookmarkName is the name of the bookmark associated // with the table. public static dynamic Export(string DocumentPath, string BookmarkName, int StartRow, bool BuildColumnHeadings, IVisualCollection collection, List<ColumnMapping> ColumnNames) { dynamic functionReturnValue = null; dynamic doc = null; WordHelper wordProxy = new WordHelper(); // if Word is active then use it if (!wordProxy.GetWord()) { if (!wordProxy.CreateWord()) { throw new System.Exception("Could not start Microsoft Word."); } } wordProxy.OpenDocument(DocumentPath); doc = wordProxy.Document; functionReturnValue = Export(doc, BookmarkName, StartRow, BuildColumnHeadings, collection, ColumnNames); wordProxy.ShowDocument(); return functionReturnValue; }
// Exports a collection to a table in given Document. BookmarkName is the name of the bookmark associated // with the table. public static dynamic Export(string DocumentPath, string BookmarkName, int StartRow, bool BuildColumnHeadings, IVisualCollection collection, List<string> ColumnNames) { dynamic functionReturnValue = null; List<ColumnMapping> mappings = new List<ColumnMapping>(); ColumnMapping map = default(ColumnMapping); dynamic doc = null; WordHelper wordProxy = new WordHelper(); FieldDefinition fd = default(FieldDefinition); // if Word is active then use it if (!wordProxy.GetWord()) { if (!wordProxy.CreateWord()) { throw new System.Exception("Could not start Microsoft Word."); } } wordProxy.OpenDocument(DocumentPath); doc = wordProxy.Document; foreach (string name in ColumnNames) { fd = collection.GetFieldDefinition(name); map = new ColumnMapping("", name); if (fd == null) { map.TableField.DisplayName = name; } else { map.TableField = fd; } mappings.Add(map); } functionReturnValue = Export(doc, BookmarkName, StartRow, BuildColumnHeadings, collection, mappings); wordProxy.ShowDocument(); return functionReturnValue; }
// exports a collection to a workbook starting at the specified location public static dynamic Export(IVisualCollection collection, string Workbook, string Worksheet, string Range) { ExcelHelper xlProxy = new ExcelHelper(); dynamic wb = null; dynamic ws = null; dynamic rg = null; dynamic result = null; try { wb = xlProxy.Excel.Workbooks.Open(Workbook); if ((wb != null)) { ws = wb.Worksheets(Worksheet); if ((ws != null)) { rg = ws.Range(Range); List <string> columnNames = new List <string>(); if (collection.Count > 0) { // get column properties IEnumerable <IEntityProperty> columnProperties = collection.OfType <IEntityObject>().First().Details.Properties.All(); int columnCounter = 0; int rowCounter = 0; // add columns names to the list foreach (IEntityProperty entityProperty in columnProperties) { columnNames.Add(entityProperty.Name); rg.Offset(rowCounter, columnCounter).Value = entityProperty.DisplayName; columnCounter += 1; } // add values on the row following the headers rowCounter = 1; // iterate the collection and extract values by column name foreach (IEntityObject entityObj in collection) { for (int i = 0; i <= columnNames.Count - 1; i++) { rg.Offset(rowCounter, i).Value = LightSwitchHelper.GetValue(entityObj, columnNames[i]); } rowCounter += 1; } } result = wb; xlProxy.ShowWorkbook(); } } } catch (System.Runtime.InteropServices.COMException comException) { result = null; xlProxy.Quit(); switch (comException.ErrorCode) { case -2147352565: // Bad worksheet name throw new System.ArgumentException("Unknown worksheet", "Worksheet"); case -2146827284: // Bad path parameter or invalid range reference if (comException.InnerException == null) { throw new System.ArgumentException("Invalid range reference", "Range"); } else { throw new System.ArgumentException("Can't open Excel workbook", comException.InnerException); } default: throw comException; } } return(result); }
// Exports a collection to a table in a Word document located at DocumentPath. BookmarkName is the name of the bookmark associated // with the table. public static dynamic Export(string DocumentPath, string BookmarkName, int StartRow, bool BuildColumnHeadings, IVisualCollection collection) { dynamic doc = null; dynamic word = null; dynamic result = null; try { word = GetWord(); if ((word != null)) { doc = GetDocument(word, DocumentPath); if ((doc != null)) { result = Export(doc, BookmarkName, StartRow, BuildColumnHeadings, collection); word.Visible = true; } else { throw new System.Exception("Could not open the document '" + DocumentPath + "'."); } } else { throw new System.Exception("Could not obtain a reference to Microsoft Word."); } } catch (Exception ex) { throw ex; } return(result); }
// Exports an IVisualCollection to a table in given Document. BookmarkName is the name of the bookmark associated // with the table. public static dynamic Export(dynamic Document, string BookmarkName, int StartRow, bool BuildColumnHeadings, IVisualCollection collection, List <ColumnMapping> ColumnNames) { if (collection.Count > 0) { // get column properties int columnCounter = 1; int rowCounter = StartRow; // validate that the Documnet argument is expected type of Word.Document if (!IsWordDocumentObject(Document)) { throw new System.ArgumentException("'Document' is not the expected type of dynamic. Expected dynamic should be a Word.Document dynamic.", "Document"); } // validate the BookmarkName argument if (!IsValidBookmark(Document, BookmarkName)) { throw new System.ArgumentException("'BookmarkName' was not found in 'Document'", "BookmarkName"); } // validate that the bookmark is part of a table if (Document.Bookmarks(BookmarkName).Range.Tables.Count == 0) { throw new System.ArgumentException("No table was found at the bookmark", "BookmarkName"); } // add table dynamic oTable = null; oTable = Document.Bookmarks(BookmarkName).Range.Tables(1); // validate the StartRow argument if (StartRow > oTable.Rows.Count) { throw new System.ArgumentException("'StartRow' is greater then the number of rows in the table", "StartRow"); } // add columns names to the list foreach (ColumnMapping map in ColumnNames) { if (columnCounter > oTable.Columns.Count) { oTable.Columns.Add(); } if (BuildColumnHeadings) { if (map.TableField.DisplayName.Length > 0) { oTable.Cell(rowCounter, columnCounter).Range.Text = map.TableField.DisplayName; } else { oTable.Cell(rowCounter, columnCounter).Range.Text = map.TableField.Name; } } columnCounter += 1; } // add values on the row following the headers if (BuildColumnHeadings) { rowCounter += 1; } // iterate the collection and extract values by column name foreach (IEntityObject entityObj in collection) { for (int i = 0; i <= ColumnNames.Count - 1; i++) { if (rowCounter > oTable.Rows.Count) { oTable.Rows.Add(); } try { oTable.Cell(rowCounter, i + 1).Range.Text = LightSwitchHelper.GetValue(entityObj, ColumnNames[i].TableField.Name); } catch (Exception ex) { throw ex; } } rowCounter += 1; } } else { // No items in the collection } return(Document); }
// Create HTML table based on IVisualCollection public static string HtmlExport(IVisualCollection collection) { List<string> columnNames = new List<string>(); string sBody = ""; if (collection.Count > 0) { // opening an html tag and creating a table //Body = "<html>" //sBody = sBody + "</br></br>" //sBody = sBody + "<body style=""font-family: Arial, Helvetica, sans-serif;"" >" sBody = "<table border=\"1\">"; // get column properties IEnumerable<IEntityProperty> columnProperties = collection.OfType<IEntityObject>().First().Details.Properties.All(); // add columns names to the list // row begins sBody = sBody + "<tr>"; foreach (IEntityProperty entityProperty in columnProperties) { columnNames.Add(entityProperty.Name); sBody = sBody + "<td>"; sBody = sBody + " " + entityProperty.DisplayName; sBody = sBody + "</td>"; } // row ends sBody = sBody + "</tr>"; // iterate the collection and extract values by column name foreach (IEntityObject entityObj in collection) { sBody = sBody + "<tr>"; for (int i = 0; i <= columnNames.Count - 1; i++) { sBody = sBody + "<td>"; sBody = sBody + LightSwitchHelper.GetValue(entityObj, columnNames[i]); sBody = sBody + "</td>"; } sBody = sBody + "</tr>"; } // closing the tags sBody = sBody + "</table>"; //sBody = sBody + "</body>" //sBody = sBody + "</html>" } return sBody; }
// Create HTML table based on IVisualCollection public static string HtmlExport(IVisualCollection Collection, List<string> ColumnNames) { string sBody = ""; if (Collection.Count > 0) { // opening an html tag and creating a table //sBody = "<html>" //sBody = sBody + "</br></br>" //sBody = sBody + "<body style=""font-family: Arial, Helvetica, sans-serif;"" >" sBody = "<table border=\"1\">"; string sColumnName = null; // add columns names to the list // row begins sBody = sBody + "<tr>"; foreach (string sColumnName_loopVariable in ColumnNames) { sColumnName = sColumnName_loopVariable; sBody = sBody + "<td>"; sBody = sBody + " " + sColumnName; sBody = sBody + "</td>"; } // row ends sBody = sBody + "</tr>"; // iterate the collection and extract values by column name foreach (IEntityObject entityObj in Collection) { sBody = sBody + "<tr>"; for (int i = 0; i <= ColumnNames.Count - 1; i++) { sBody = sBody + "<td>"; sBody = sBody + LightSwitchHelper.GetValue(entityObj, ColumnNames[i]); sBody = sBody + "</td>"; } sBody = sBody + "</tr>"; } // closing the tags sBody = sBody + "</table>"; //sBody = sBody + "</body>" //sBody = sBody + "</html>" } return sBody; }
public static dynamic CreateEmail(string Address, string Subject, IVisualCollection Items) { try { string sBody = null; sBody = HtmlExport(Items); if (GetOutlook()) { dynamic mail = outlook.CreateItem(olMailItem); var _with3 = mail; // checking if it contains an html tags if (sBody.ToLower().Contains("<html>")) { _with3.BodyFormat = olFormatHTML; _with3.HTMLBody = sBody; } else { _with3.BodyFormat = olFormatPlain; _with3.Body = sBody; } _with3.Recipients.Add(Address); _with3.Subject = Subject; _with3.Display(); // Returning the dynamic return mail; } } catch (Exception ex) { throw new InvalidOperationException("Failed to create email.", ex); } return null; }
public VisualCollection(IVisualCollection collection) : this(collection.GetFromEachChild(c => c)) { }
private WrapPanel(IVisualBootstrapper visualBootstrapper, IVisualCollection children) : base(visualBootstrapper, children, new SequentialUniformRenderer(children)) { }
// Exports an IVisualCollection to a table in either the active (UseActiveDocument = True) or a new document (UseActiveDocument = False) public static dynamic Export(IVisualCollection collection, bool UseActiveDocument) { dynamic doc = null; WordHelper wordProxy = new WordHelper(); bool bUseActiveDocument = false; dynamic rg = null; // if Word is active then use it if (wordProxy.GetWord()) { // obtain a reference to the selection range if (UseActiveDocument) { rg = wordProxy.Word.Selection.Range; bUseActiveDocument = true; } else { wordProxy.CreateDocument(); } } else { wordProxy.CreateWord(); wordProxy.CreateDocument(); } List <string> columnNames = new List <string>(); if (collection.Count > 0) { // get column properties IEnumerable <IEntityProperty> columnProperties = collection.OfType <IEntityObject>().First().Details.Properties.All(); int columnCounter = 1; int rowCounter = 1; // add table dynamic oTable = null; if (bUseActiveDocument) { oTable = wordProxy.AddTable(collection.Count + 1, columnProperties.Count(), rg); } else { oTable = wordProxy.AddTable(collection.Count + 1, columnProperties.Count()); } // add columns names to the list foreach (IEntityProperty entityProperty in columnProperties) { columnNames.Add(entityProperty.Name); // add column headers to table wordProxy.SetTableCell(oTable, 1, columnCounter, entityProperty.DisplayName); columnCounter += 1; } // add values on the row following the headers rowCounter = 2; // iterate the collection and extract values by column name foreach (IEntityObject entityObj in collection) { for (int i = 0; i <= columnNames.Count - 1; i++) { wordProxy.SetTableCell(oTable, rowCounter, i + 1, LightSwitchHelper.GetValue(entityObj, columnNames[i])); } rowCounter += 1; } } doc = wordProxy.Document; wordProxy.ShowDocument(); return(doc); }
// Exports a collection to a table in given Document. BookmarkName is the name of the bookmark associated // with the table. public static dynamic Export(string DocumentPath, string BookmarkName, int StartRow, bool BuildColumnHeadings, IVisualCollection collection, List <ColumnMapping> ColumnNames) { dynamic functionReturnValue = null; dynamic doc = null; WordHelper wordProxy = new WordHelper(); // if Word is active then use it if (!wordProxy.GetWord()) { if (!wordProxy.CreateWord()) { throw new System.Exception("Could not start Microsoft Word."); } } wordProxy.OpenDocument(DocumentPath); doc = wordProxy.Document; functionReturnValue = Export(doc, BookmarkName, StartRow, BuildColumnHeadings, collection, ColumnNames); wordProxy.ShowDocument(); return(functionReturnValue); }
// Exports a collection to a table in given Document. BookmarkName is the name of the bookmark associated // with the table. public static dynamic Export(string DocumentPath, string BookmarkName, int StartRow, bool BuildColumnHeadings, IVisualCollection collection, List <string> ColumnNames) { dynamic functionReturnValue = null; List <ColumnMapping> mappings = new List <ColumnMapping>(); ColumnMapping map = default(ColumnMapping); dynamic doc = null; WordHelper wordProxy = new WordHelper(); FieldDefinition fd = default(FieldDefinition); // if Word is active then use it if (!wordProxy.GetWord()) { if (!wordProxy.CreateWord()) { throw new System.Exception("Could not start Microsoft Word."); } } wordProxy.OpenDocument(DocumentPath); doc = wordProxy.Document; foreach (string name in ColumnNames) { fd = collection.GetFieldDefinition(name); map = new ColumnMapping("", name); if (fd == null) { map.TableField.DisplayName = name; } else { map.TableField = fd; } mappings.Add(map); } functionReturnValue = Export(doc, BookmarkName, StartRow, BuildColumnHeadings, collection, mappings); wordProxy.ShowDocument(); return(functionReturnValue); }
// Exports a collection to a table in given Document. BookmarkName is the name of the bookmark associated // with the table. public static dynamic Export(dynamic Document, string BookmarkName, int StartRow, bool BuildColumnHeadings, IVisualCollection collection, List <string> ColumnNames) { List <ColumnMapping> mappings = new List <ColumnMapping>(); ColumnMapping map = default(ColumnMapping); FieldDefinition fd = default(FieldDefinition); foreach (string name in ColumnNames) { fd = collection.GetFieldDefinition(name); map = new ColumnMapping("", name); if (fd == null) { map.TableField.DisplayName = name; } else { map.TableField = fd; } mappings.Add(map); } return(Export(Document, BookmarkName, StartRow, BuildColumnHeadings, collection, mappings)); }
public static bool ValidData(string value, int row, ColumnMapping mapping, IVisualCollection collection, Dictionary<string, IEntityObject> navProperties, List<string> errorList) { bool bValid = false; IEntityType targetEntityType = mapping.TableField.EntityType; //Need to grab the entity set and check number of results we get IApplicationDefinition appModel = collection.Screen.Details.Application.Details.GetModel(); IEntityContainerDefinition entityContainerDefinition = (from ecd in appModel.GlobalItems.OfType<IEntityContainerDefinition>() where ecd.EntitySets.Any(es => object.ReferenceEquals(es.EntityType, targetEntityType)) select ecd).FirstOrDefault(); if (entityContainerDefinition == null) throw new Exception("Could not find an entity container representing the entity type: " + targetEntityType.Name); IEntitySetDefinition entitySetDefinition = (from es in entityContainerDefinition.EntitySets where object.ReferenceEquals(es.EntityType, targetEntityType) select es).First(); var dataService = (IDataService)collection.Screen.Details.DataWorkspace.Details.Properties[entityContainerDefinition.Name].Value; var entitySet = (IEntitySet)dataService.Details.Properties[entitySetDefinition.Name].Value; var dsQuery = entitySet.GetQuery(); //Search for the matching entity for the relationship IEnumerable<IEntityObject> var results = SearchEntityMethodInfo().MakeGenericMethod(dsQuery.ElementType).Invoke(null, new object[] { dsQuery, value, targetEntityType }) as IEnumerable<IEntityObject>; int searchCount = results.Count(); if (searchCount == 0) { bValid = false; errorList.Add(String.Format("Column:{0} Row:{1} Cannot find a matching '{2}' for '{3}'", mapping.OfficeColumn, row, mapping.TableField.DisplayName, value)); } else if (searchCount > 1) { bValid = true; errorList.Add(String.Format("Column:{0} Row:{1} Multiple matching '{2}' for '{3}'. Will select first match.", mapping.OfficeColumn, row, mapping.TableField.DisplayName, value)); navProperties[String.Format("{0}_{1}", mapping.TableField.Name, value)] = results.FirstOrDefault(); } else { bValid = true; navProperties[String.Format("{0}_{1}", mapping.TableField.Name, value)] = results.FirstOrDefault(); } return bValid; }
// Exports a collection to a table in a Word document located at DocumentPath. BookmarkName is the name of the bookmark associated // with the table. public static dynamic Export(string DocumentPath, string BookmarkName, int StartRow, bool BuildColumnHeadings, IVisualCollection collection) { dynamic doc = null; dynamic word = null; dynamic result = null; try { word = GetWord(); if ((word != null)) { doc = GetDocument(word, DocumentPath); if ((doc != null)) { result = Export(doc, BookmarkName, StartRow, BuildColumnHeadings, collection); word.Visible = true; } else { throw new System.Exception("Could not open the document '" + DocumentPath + "'."); } } else { throw new System.Exception("Could not obtain a reference to Microsoft Word."); } } catch (Exception ex) { throw ex; } return result; }