Show three datatable horizontal in stimul report - report

I am using stimulsoft report, and I want to show three datatable next to each other, but when I add a table to page it fixes the whole width of page and the next table goes to the bottom. What should I do?

it depend on what you want to do if you have 3 independent datatable you can use 3 panel in your report but if they are related datatables you should make a class like this
public class MainDatatable
{
public List<Detail> DataTableList1 { get; set; }
public List<Detail> DataTableList2 { get; set; }
public List<Detail> DataTableList3 { get; set; }
}
public class Detail
{
public int Id { get; set; }
public string Name { get; set; }
public string value { get; set; }
}
and in your report you should make your business Object Category MainDatatable with 3 child business object and put one DataBind set the DatSource on MainDatatable , after that put 3 subreport on databind , in each page of subreport's put Databind and set The data source and master component each of them should be parent data bind

Related

ASP.NET Razor - How to create a POST form for List of objects?

I need to create a POST form to add new objects to database. I have to create a Razor page where I can add new lesson form on click of a button. And after it on click of another button all the lessons should be added to DB context. I still don't know how to do it so I want you to help me
public class Course
{
public Guid Id { get; set; }
public string Category { get; set; }
public string Title{ get; set; }
public List<Lesson> Lessons { get; set; } = new List<Lesson>();
}
public class Lesson
{
public Guid Id { get; set; }
public string Title { get; set; }
public string Text { get; set; }
}
Here is some image of what I mean:
DB has a Course table and a Lesson table. Please tell me how I can create a page to create new 'Course' with dynamic amount of 'Lessons'
Please try with this in your controller method you need to pass from the page.
public ActionResult PostMethod(Course course, FormCollection formCollection)
{
string title = course.Title; // Title value
string category = course.Category; // Category value
//add course into database
if (course.Lessons != null && course.Lessons.Count > 0)
{
foreach (var item in course.Lessons)
{
//add Lessons into database
}
}
}
Please note in this example you are going to perform many operations in databases
you have to manage transaction as well for this.
Using Transactions or SaveChanges(false) and AcceptAllChanges()?

Conditionally validate collection/list item properties based on parent model value

I have the following view models
public class Step4ViewModel {
[Required(ErrorMessage="Yes/No Required")]
public bool? HaveVehicles { get; set; }
public List<Vehicle> Vehicles { get; set; }
public Step4ViewModel() {
this.Vehicles = new List<Vehicle>();
}
}
public class Vehicle {
public string Index { get; set; }
[DisplayName("Registration/Vin")]
[Required(ErrorMessage="Registration Required")]
[ValidVehicleRegistrationNumber(ErrorMessage = "Invalid Id Number")]
public string Registration { get; set; }
[Required(ErrorMessage="Make Required")]
public string Make { get; set; }
[Required(ErrorMessage="Model Required")]
public string Model { get; set; }
[Required(ErrorMessage="Year")]
public string Year { get; set; }
public Vehicle()
{
this.Index = Guid.NewGuid().ToString();
}
}
The validation works just fine. The problem is that it always works. I only want the validation to fire on vehicles in the collection when the user has indicated that they have vehicles. If HaveVehicles equals false I do not want the validation to fire.
Normally for this sort of validation I would build a custom validator in which I would only return validation errors if HaveVehicles is true. I am unable to do this here because HaveVehicles resides in a parent model which is inaccesible from the within the vehicle object.
One approach I've though of that may work is using a partial view to add/remove the collection from the DOM as null collections aren't validated. If the user selects yes ajax loads a partial view which contains a for loop that iterates over each vehicle and calls another partial view to display it.
Is there a better approach to do this or is something similar to the above my only option?

Nested TreeGrid ExtJs

I need to know if's possible to create a nested treegrid, where each level contains its own set of columns.
Something like if I create a grid wich display this 2 classes:
public class Class
{
public int Id { get; set; }
public string ClassName { get; set; }
public string Teacher { get; set; }
}
public class Students
{
public int Id { get; set; }
public string StudentName { get; set; }
public DateTime Birthday { get; set; }
public int IdClass { get; set; }
}
That when i display the grid there's a node of Class that show the class informations and when it expand, show the students informations
Yes, it is kind of possible (the columns will be the same for both types). You have two solutions:
map all .net properties from both classes to a single Model in ExtJs and then render them in ExtJS (eventually showing data from both entities in the same columns: you decide how to combine data).
Map all the relevant data from .net to a single field in ExtJS and render a single column.
Also you need a scheme to make all your nodes distinct (eg. the class with ID 1 in .net has the ID c1 in ExtJS and Student with ID1 in .net has the ID s1 in ExtJS). Also it should be clear that a single URl will be provide both the list of classes and the students for a class.

asp.net MVC 4 - Many to Many data not updating - Updating Entity Framework with ViewModel Edit View

asp.net mvc 4, Entity Framework 5, SQL Server 2012 Express
I have a Place model:
public virtual int PlaceID { get; set; }
public virtual ICollection<Tag> Tags { get; set; }
public virtual string Name { get; set; }
and a related Tag model:
public virtual int TagID { get; set; }
public virtual string Name { get; set; }
public virtual string NamePlural { get; set; }
public virtual ICollection<Place> Places { get; set; }
many to many relationship.
There is a view with the following ViewModel associated. In it I can edit place details - and edit what tags are associated with the place (for example, the place might have a 'restaurant' tag and a 'bar' tag - and perhaps I want to add a 'cafe' tag, and remove 'restaurant' tag).
PlacesWithTagsViewModel:
public Place place { get; set; }
public ICollection<Tag> SelectedTags { get; set; }
When the view does an httpost back to controller - I update tags like this:
place.Tags = SelectedTags
db.Entry(ptvm.place).State = EntityState.Modified;
db.SaveChanges();
However, place properties update (eg Name) - but Tags always stay the same.
How can I update tags?
Avoid db.Entry(ptvm.place).State = EntityState.Modified; as it causes conflicts with no updation.
You must use UpdateModel(table object, "model");
Full Example is as belows :
[HttpPost]
public ActionResult PlaceTag(PlacesWithTagsViewModel model)
{
if (ModelState.IsValid)
{
tag tagtest = GetTagById(model.tagid);
tag.name= model.tag.name;
tag.nameplural = model.tag.nameplural;
UpdateModel(tag, "model");
db.SaveChanges();
return RedirectToAction("Index", "Dashboard", new { id = 5 });
}
}
The advantage of UpdateModel is that you have to mention only those fields which you update avoiding those which remain static. In this way you can update your related data with Viewmodel in Edit View.

asp.net MVC ViewModel construction

I'm tying myself in knots - and thought it best to take a big step back, and back to basics.
I understand I should be using a ViewModel, so that is what I'm trying to contruct.
My demo app will have 4 sections (4 different parts of a form to complete):
Get Date/Number of days from user
Use that data to query the database, and return a list of qualifying records - each of these will have a unique ID of TypeID - and for each of these, they should also have 2 dynamic DropDownLists associated with them (so that whatever is selected in ListBox3 for each of the lists, corresponds to the TypeID3 (and whatever ID that has)
user will then be able to select Extras, again from a drop down list populated dynamically
users Name/Add/Tel will be collected
My "View" of what the ViewModel needs to look like/hold is:
I beleive my viewModel should look something like this:
public class SearchViewModel
{
public DateTime Date{ get; set; }
public int Days { get; set; }
public IQueryable<TypeID> TypeIDs { get; set; }
public IQueryable<LB1Item> LB1Items { get; set; }
public IQueryable<LB2Item> LB2Items { get; set; }
public IQueryable<Extras> Extras { get; set; }
public string Name { get; set; }
public string Add { get; set; }
public string Tel { get; set; }
public string email { get; set; }
}
First of all - is this how you would construct a ViewModel for what I've described above? I'm not certain of the DropDown Boxes, as for each form, there could be 1, 2, 3....10, 11, 12 for each TypeID retrieved - based on the Date selected.
Each of the drop down boxes for LB1Item and LB2Item - need to have their selected values stored against the TypeID for each line also.
This is what I think the class should look like for 1 drop down:
public class LB1Item
{
public String TypeName { get; set; }
public long TypeID { get; set; }
public int NumSelected { get; set; }
public int TypeCount { get; set; }
public IEnumerable<SelectListItem> CarsAvail
{
get
{
return new SelectList(
Enumerable.Range(0, TypeCount+1)
.OrderBy(typecount => typecount)
.Select(typecount => new SelectListItem
{
Value = typecount.ToString(),
Text = typecount.ToString()
}
), "Value", "Text");
}
}
}
Does that look ok also? Or am I overcomplicating what I'm trying to achieve?
I'd also like, after POSTing back the data after each stage (1, 2, 3, 4) to be actively populating the ViewModel with the selected values - and passing it back down to the view, so that I can retrieve it for the next Step.
What I want to end up with is something like this:
Date: 01/09/2012
Days: 4
{ List:
TypeID: 3059 ListBox1: 2 ListBox2: 8748,
TypeID: 2167 ListBox1: 7 ListBox2: 2378,
TypeID: 4983 ListBox1: 4 ListBox2: 5873
}
{List:
ExtraID: 4324,
ExtraID: 3878,
ExtraID: 4872,
ExtraID: 7698,
ExtraID: 2873
}
Name: Mark
Add: My town
Tel: 0912378
Email: me#me.com
Thanks for any help/pointers/samples...
Mark
For this type of solution I would separate out each section you want to render as individual views and use Ajax calls using Jquery ajax method. I would also use KnockoutJS to handle the views in your client. So you will essentially have two ViewModels, one in JavaScript in the client and one in MVC for returning the pieces you need as JSON for the Ajax calls from the client. Section 1 of your view is entered by the user into the client so you do not need it on the Controller side. Section 1 is basically the data used to query for Section 2. No need to make your collections IQueryable either since you will not being querying the lists that are returned. Your ViewModel on the Controller side might look something like this:
public class Section2
{
public List<TypeID> TypeIDs { get; set; }
public List<LB1Item> LB1Items { get; set; }
public List<LB2Item> LB2Items { get; set; }
}
public class Section3
{
public List<Extras> Extras { get; set; }
}
public class Section4
{
public string Name { get; set; }
public string Add { get; set; }
public string Tel { get; set; }
public string email { get; set; }
}
So the steps that would be taken are that when an event is thrown that the date and days have been entered by the user an Ajax call is made back to a controller with entered data and days to query for the information that will populate Section 2. The controller returns the Section2 ViewModel as JSON and it is rendered in the HTML using Knockout. Then when the user selects from the lists in Section 2 an event is thrown to query the controller again to return the information needed to populate Section 3, and the cycle is repeated.
There is an excellent example on using Knockout to do exactly what you are trying to do here.

Resources