wp7 ObservableCollection population - windows-phone-7.1

I'm using the AMCharts control and I'm trying to follow the example however, I'm not sure how I get the data out of my historyItemCollection (fig 1) into an Observable collection (fig 2)?
Fig 1:
from item in App.ViewModel.historyItemCollection
where item.VehicleId == (Application.Current as App).vehicleId
select item;
Fig 2:
private ObservableCollection<TestDataItem> _data = new ObservableCollection<TestDataItem>()
{
new TestDataItem() { axis = "Mar", value=5},
new TestDataItem() { axis = "Apr", value=15.2},
new TestDataItem() { axis = "May", value=25},
new TestDataItem() { axis = "June", value=8.1},
};
In the historyitemcollection I have a date item that I would put in the axis value as well as a cost item that I would put in the value value (fig 2:)
How can I get my data into the observableCollection so I can use this chart control?

_data = new ObservableCollection<HistoryItem>
(
from item in App.ViewModel.historyItemCollection
where item.VehicleId == (Application.Current as App).vehicleId
select item;
)
or if at runtime
var historyItems =
from item in App.ViewModel.historyItemCollection
where item.VehicleId == (Application.Current as App).vehicleId
select item;
foreach (var item in historyItems)
_data.Add(item);

Related

Unable type values in input field RadioButtonGroup ComponentRenderer

Hi I am trying develop a feature something as below in the picture. When I am selecting option(Ex: Monthly) from left panel right side panel will automatically render the required components. When I select the option from the right side panel I want to type the required values in input box. When I click on input box I am not getting the focus to type. Facing same issue for Combobox as well. Attaching some code snippet as well.
radioGroup = new RadioButtonGroup<>();
radioGroup.addThemeVariants(RadioGroupVariant.LUMO_VERTICAL);
radioGroup.setItems("None", "Daily", "Weekly", "Monthly");
radioGroup.setValue("None");
VerticalLayout leftLayout = new VerticalLayout();
VerticalLayout rightLayout = new VerticalLayout();
radioGroup.addValueChangeListener(event -> {
if (event.getValue().equalsIgnoreCase("Monthly")) {
monthlyRadioGroup = new RadioButtonGroup<>();
monthlyRadioGroup.addThemeVariants(RadioGroupVariant.LUMO_VERTICAL);
monthlyRadioGroup.setItems("Day", "The");
monthlyRadioGroup.setValue("Day");
monthlyRadioGroup.setRenderer(new ComponentRenderer<>(item -> {
if ("Day".equals(item)) {
HorizontalLayout dayLayout = new HorizontalLayout();
IntegerField dayField = new IntegerField();
dayField.setValue(1);
dayField.focus();
dayField.setAutofocus(true);
dayField.setWidth("50px");
IntegerField monthField = new IntegerField();
monthField.setValue(1);
monthField.setWidth("50px");
dayLayout.add(new Label("Day"), dayField, new Label("of every"), monthField, new Label("month(s)"));
dayLayout.setAlignItems(Alignment.CENTER);
return dayLayout;
}else {
HorizontalLayout weekDayLayout = new HorizontalLayout();
ComboBox<String> weekNum = new ComboBox<String>();
weekNum.setItems("First", "Second", "Third", "Fourth", "Last");
weekNum.setValue("First");
weekNum.setWidth("100px");
ComboBox<String> day = new ComboBox<String>();
day.setItems("Day", "Weekday", "Weekend Day", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
day.setValue("Friday");
day.setWidth("120px");
IntegerField monthField = new IntegerField();
monthField.setValue(1);
monthField.setWidth("50px");
weekDayLayout.add(new Label("The"), weekNum, day, new Label("of every"), monthField,
new Label("month(s)"));
weekDayLayout.setAlignItems(Alignment.CENTER);
return weekDayLayout;
}
}));
rightLayout.add(monthlyRadioGroup);
}
});
It worked by adding below snippet in all the input fields
dayField.getElement().addEventListener("click", e -> dayField.focus());

Viewbag assign value for each iteration results in error

I am trying to dynamically set a value for each iteration of
int index = 0;
foreach (var item in model.ResponseRetest)
{
var result = _pointService.GetBuildings(item.ID).Select(x => new SelectListItem { Text = x, Value = x }).ToList();
ViewBag.Company[index] = result;
index++;
}
Even though result does have a value, I am getting the following error:
Message "Cannot perform runtime binding on a null reference"
Using ViewBag this way is not recommended as it creates overhead in unboxing the data with every iteration (in this case, Company). The error is likely happening on the first iteration because you're applying indexing on non-existent property Company.
List<List<datatype>> companyResults = new List<List<datatype>>();
foreach (var item in model.ResponseRetest)
{
var result = _pointService.GetBuildings(item.ID).Select(x => new SelectListItem { Text = x, Value = x }).ToList();
companyResults.Add(result);
}
ViewBag.Company = companyResults;

MVC - Linq to SQL JOINS

I have a controller that accepts a list of strings. THese strings essentially are IDs that a user selects on the view. I need to build the model based upon fields from to tables, hence the need for the join. The bellow code will not build as it claims the properties from the joined table do not exist. It only accepts table 1 values. Item.Well_No and Item.Well_Name throw the error. These are included in the "y" table that i joined to "x"..
[HttpPost]
public ActionResult buildSelectionTable(List<string> dta)
{
var a = from x in db._AGREEMENTS
join y in db.WELL_AGMT_XREF on x.AGMT_NUM equals y.AGMT_NUM
where dta.Contains(x.AGMT_NUM)
select x;
List<AgmtModel> model = new List<AgmtModel>();
foreach (var item in a)
{
model.Add(new AgmtModel { Agmt_Name = item.AGMT_NAME, Agmt_Num = item.AGMT_NUM, Agmt_Type = item.AGMT_TYPE_DESCR, Amnt_Status = item.AGMT_STAT_DESCR, Company = item.CO_NAME, DaysToExp = item.DaysToExp, Drs_Url = item.DRS_URL, Effective_Date = item.EFF_DT, Orig_Lessee = item.ORIG_LESSEE, Prop_Status = item.AGMT_PROP_STAT_DESCR, Expiration_Date = item.EXPR_DATE, Acreage = item.LGL_AREA, Extention_Expiration = item.EXTN_EXPR_DT, WellNo = item.WELL_NO, Well_Name = item.WELL_NAME });
}
return PartialView("_SelectionTable", model);
}
You are only selecting x in your query you need to also select y and reference it.
change select x to be select new { x, y}
and then
foreach (var item in a)
{
model.Add(new AgmtModel { Agmt_Name = item.y.AGMT_NAME, Agmt_Num = item.x.AGMT_NUM ... });
}
you need to insert .x or .y before you the field to determine the field names
alternatively you could actually put the constructor directly in the query
so instead of select x
select new AgmtModel { Agmt_Name = y.AGMT_NAME, etc...}
then you can just return PartialView("_SelectionTable", a.ToList())

How do i select a record in a grouped smartgwt listgrid?

I have site with a listgrid and a openlayers map with points. When i cklick on one of these, the application shall scroll and mark this record. This works with a standard listgrid, but with a grouped listgrid it does not work.
lg = new ListGrid();
lg.setWidth(330);
lg.setDataSource(ds1);
lg.setAutoFetchData(true);
lg.setSortField("KU_NAME");
lg.setGroupStartOpen(GroupStartOpen.ALL);
lg.setGroupByField("KU_NAME");
lg.setShowFilterEditor(true);
kuName = new ListGridField("KU_NAME", "Künstler Name",150);
// Standorte
ListGridField stdOrt = new ListGridField("STDORT_NR","Standort Nr.");
ListGridField oid = new ListGridField("OID","OID.");
lg.setFields(stdOrt,kuName,oid);
and the select:
String stdortOID = stdOrtOIDjso.toString();
ListGridRecord[] records = lg.getRecords();
int i;
for (i = 0; i < records.length; i++) {
if (records[i].getAttribute("OID").equalsIgnoreCase(stdortOID)){
break;
}
}
lg.deselectAllRecords();
lg.selectRecord(i);
lg.scrollToRow(lg.getRecordIndex(record));
the reason is that in the record is only the value of the group name and the other attributs are unavailable.
When grouping is enabled, all data are "transformed" into tree and listgrid itself contains data for groups so you have to look for your record in this tree. Replace last 3 lines with (modified) Vittorio Paternostro suggestion:
Tree tree = lg.getGroupTree();
if (tree != null) {
TreeNode node = tree.find("OID", stdortOID);
if (node != null) {
lg.selectSingleRecord(node);
lg.scrollToRow(getRecordIndex(node));
lg.markForRedraw();
}
}
Note: Instead of deselectAllRecords + selectRecord use simplified selectSingleRecord.
I had the same need and the following works fine for me. You can use getGroupTree() and search the desired property in it (column value) without worrying about grouping. Make sure you search for unique values (i.e. a unique key) to identify a precise node.
Tree tree = getGroupTree();
if (tree != null) {
TreeNode node = tree.find("property", "value");
if (node != null) {
selectSingleRecord(node);
scrollToRow(getRecordIndex(node));
markForRedraw();
}
}

Issue With Showing Distinct fields using Linq

var getAllProducts = _productService.GetAllProducts();
if (productstest.Count > 0)
{
model.idproduct.Add(new SelectListItem()
{
Value = "0",
Text = _localizationService.GetResource("Common.All")
});
foreach (var m in getAllProducts)
model.idproduct.Add(new SelectListItem()
{
Value = m.Id.ToString(),
**Text = m.Size.Distinct().ToString(),**
Selected = model.Pid == m.Id
});
}
public virtual IList<Product> GetAllProducts(bool showHidden = false)
{
var query = from p in _productRepository.Table
orderby p.Name
where (showHidden || p.Published) &&
!p.Deleted
select p;
var products = query.ToList();
return products;
}
The issue is even i tried to populate the select list with distinct size using: Text = m.Size.Distinct().ToString(), but it shows the duplicate for instance 100 products are of size 33 cm , the list will populate the dropdownlist in the view with 33cm occuring 100 times , I dont want to show 100 times , just want to show 1 time, Can any one assist me with this issue ?
Presumably you are only trying to show one product of each different size... if so initialising your getAllProducts variable like so will do the trick:
var getAllProducts = _productService.GetAllProducts().GroupBy(p => p.Size).Select(g => g.First());

Resources