ClosedXML report - format of input list - closedxml.report

The format for sending data to a closedXML template is a bit confusing to me.
In the Flat tables docs there's a sample for a template with header info and data from a list for the report, but I don't see where the list is connected to the template.
I have a similar scenario - header info for the top, data in a list for the report.
I've tried defining an object with all the data in it:
public class AllocationExportData
{
public List<AllocationExportItem> AllocationList { get; set; }
public string Host_custname { get; set; }
public string Host_custaddr { get; set; }
}
and setting up the template using those variables
But only the top two values are being found
I figure I'm naming something wrong, or setting up the object wrong.
Anyone?

Related

How can I store multiple images in a database with a Blazor application?

I have an application that shows a form to the users. The form is taken by the server and stored in a database where the information can be read on another page in the application. Part of the form takes an image, where the image is converted to a Base64 string and sent to Azure to be stored, and the URL to the image is stored in the database as a string. This all works fine. My trouble comes from trying to implement a feature where users can select multiple images.
I tried changing the string Image {get;set;} to a List<string> {get;set;} where the database would just store a list of the URLs where I could iterate through them in the application. This obviously did not work, as through some research, I learned that databases cannot store lists.
I am now wondering what I can do here. Is there a simpler way of doing this that I'm missing? What am I doing wrong?
I tried changing the string Image {get;set;} to a List
{get;set;} where the database would just store a list of the URLs
where I could iterate through them in the application. This obviously
did not work, as through some research, I learned that databases
cannot store lists.
You can try to use the following methods:
Add separator between the Image urls. Use string Image {get;set;} to store the image urls, the value like this: "image1url,image2url,etc" (use the , as the separator). You can consider using the String.Join Method.
Create a new Image table to store the Image information (contains ID, Name, Urls), then configure one-to-many relationship between the Main table and the Image model. In the Main model, use navigation property to add the Image. Code like this:
public class Main
{
public int Id { get; set; }
public string Name { get; set; }
public List<Image> Images { get; set; }
}
public class Image
{
public int Id { get; set; }
public string Name { get; set; }
public string Url { get; set; }
}
More detail information about the Entity relationship, see:
Relationships
Configuring One To Many Relationships in Entity Framework Core
Saving Related Data

Xamarin Forms Add List to SQL database

I have a problem. I created the following class:
public class KnownDevice
{
public int Id { get; set; }
public string Name { get; set; }
public string IP { get; set; }
public string MAC { get; set; }
public string Type { get; set; }
public List<TriangleRegistryObject> triangles { get; set; }
public List<HexagonRegistryObject> hexagons { get; set; }
}
Now, I want to create a Database on the mobile phone itself, so I use the following code to create the table:
database = DependencyService.Get<ISQLite>().GetConnection();
database.CreateTable<KnownDevice>();
But the code crashes on the second line with the error:
System.NotSupportedException: 'Don't know about
System.Collections.Generic.List`1
Now on the internet I found that it is not allowed to add a List to a database, but I need the data in that list, so I have no idea how I can fix this problem. The list can contain arround 25 rows!
Any idea how I can solve this problem?
List<TriangleRegistryObject> is not a valid type for a SQLite database value. Your type of List<TriangleRegistryObject> does not match any of the clrType == typeof(XXXX) statements, so you get that exception. You will need to rethink the class structure a little to be able to use SQLite-net like that.
For more details about the SQLite database, you could download the source file from the link for reference.
https://learn.microsoft.com/zh-cn/samples/xamarin/xamarin-forms-samples/todo/
If you want to use ou could use List, you could use SQLite-Net Extensions instead of SQLite.
You could refer to the link. The SQLite-Net Extensions library direct to specific relationships in database.
How can you store lists of objects in SQLite.net?

How can I serialize data to XML without .xsd schema?

I am writing an ASP.NET MVC (5) application in which I need to do some custom XML serialization. Before I go on, I should mention that I wasn't exactly sure if this question belongs here or on another forum. If this question would be better suited somewhere else, please let me know. I'll gladly move it.
Software overview:
I have a view that has a form for the user to fill out. When the user fills out the required fields and clicks the submit button, the information in the form should be serialized to XML (based on certain XML requirements), and posted to a URL. That's pretty simple for some, I'm sure. I have very little experience doing this sort of thing in ASP.NET MVC.
I don't possess the .xsd document that contains the XML schema. I have a document that contains the XML specifics (a Word document), but the actual .xsd document is not available to me. I am not sure how to serialize the data so that the XML turns out the way it is supposed to.
I have the following Model:
public class BookingRequest
{
public string billTo { get; set; }
public string bookingStatus { get; set; }
public string partNote { get; set; }
public int height { get; set; }
}
Note that this is an abbreviated version; there are WAY more fields in this class. Anyway, I need the height field to look like this when it is serialized to XML:
<HeightOf>15</HeightOf>
I also need all of the elements in the XML to adhere to this schema (where all of the fields in the form I mentioned fall under the <BookingRequest> tag):
<Data>
<Header>
<UserId/>
<Password/>
</Header>
<BookingRequest>
..
..
</BookingRequest>
</Data>
Can I do this without the schema?
Any help is greatly appreciated.
You don't need the xsd, as long as you know how is going to be the desired structure.
First, you need to decorate your class with the [Serializable] attribute. Then, you can use the attributes in System.Xml.Serialization namespace to control the result. For example, in case of height property, it can be achieve like this:
[Serializable]
public class BookingRequest
{
public string billTo { get; set; }
public string bookingStatus { get; set; }
public string partNote { get; set; }
[XmlElement(ElementName = "HeightOf")]
public int height { get; set; }
}
See this for further details:
https://learn.microsoft.com/en-us/dotnet/standard/serialization/controlling-xml-serialization-using-attributes

Dynamic Data Web Site, how to leave out columns?

I used VS 2012 to create a Dynamic Data Web Site using the standard built in template. Using EF I have added the database to the project that I want to use, and only selected the tables I saw fit for managing data through a web site. On the first page, you get the list of tables, when you click on one of those tables, it brings up a list of everything that's in that table(rows and columns). I'm very new to doing this type of thing and I'm wondering how I can make it so only certain COLUMNS appear. I want to do this because when you click on a table, if there are more columns than a few, they drag way off the right side of the browser. So basically I just want to display only columns that I think will be relevant. BTW, this project is in ASP.NET using EF for the data model. I still want these columns to be viewable when you click on the "Details" link for the row you want to see, I just want them to not show up in the list view. How can I do this, and what files do I need to modify?
You can leave out columns by using the [ScaffoldColumn(false)] data annotation attribute. I have a similar case where I do not want to include the CreatedBy, CreatedOn, UpdatedBy, and UpdatedOn columns. See the code sample to see how to exclude them.
using System;
using System.ComponentModel.DataAnnotations;
namespace S1000DDecision.Data
{
/// <summary>
/// Summary description for Category
/// </summary>
[ScaffoldTable(true)]
[MetadataType(typeof(CategoryMetadata))]
public partial class Category
{
}
public class CategoryMetadata
{
[ScaffoldColumn(false)]
public Object CreatedBy { get; set; }
[ScaffoldColumn(false)]
public Object CreatedOn { get; set; }
[ScaffoldColumn(false)]
public Object UpdatedBy { get; set; }
[ScaffoldColumn(false)]
public Object UpdatedOn { get; set; }
}
}

How to edit a SQL Server XML data field with asp.net Dynamic Data

I have a site based around asp.net 3.5's Dynamic Data feature. Everything's working great, but I would like to add a tagging feature via a column with an XML data type. I've made the column and added an appropriate schema, but it is showing up as read-only and the scaffold will not display or modify the field.
So, I have a few questions:
What do I need to do in order to enable my scaffold to see this xml column?
How would I go about editing the tags through the scaffold without directly editing all the xml?
Would I add logic to the getter/setter in the metadata?
Presumably I would need a custom fieldTemplate, would I add the xml parsing to it?
I hope this is helpful. As you mention, you would have to create a field template for your XML data. :
[MetadataType(typeof(DocumentMetadata))]
[DisplayName("Documents")]
public partial class Document {
[ScaffoldColumn(true)]
[Display(Name = "Some Xml")]
public string SomeXml
{
get
{
return "<note><to>Joe</to><from>Mary</from><heading>Reminder</heading><body>Hello World</body></note>"
}
}
}
public class DocumentMetadata
{
[ScaffoldColumn(false)]
public object Id { get; set; }
[Display(Name="Type")]
public object DocumentType { get; set; }
[UIHint("CustomXmlFieldTemplate")]
[Display(Name="Some XML")]
public object SomeXml { get; set; }
}

Resources