Associate the chart and table in devextreme - mongodb

I want to associate the table and chart in devextreme. I want to filter the chart also filter the table. can you help me?

You can achieve this by using filter option of related datasource
function chartFilter(ChartInstance, ChartKey, KeyValue, ReloadChartsFunc) {
/*
ChartInstance = Instance of devExtreme Chart
ChartKey = filter by ChartKey Field
KeyValue = value of ChartKey
ReloadChartsFunc = Callback function to execute once filter the ds
*/
var searchOperator = "<>";
if (KeyValue != "")
searchOperator = psChart.option("quickSearchOption");
var ds = ChartInstance.getDataSource();
ds.filter(ChartKey, searchOperator, KeyValue);
ds.load().done(function (result) {
if (ReloadChartsFunc != undefined && result[0] != undefined && result[0] != null) {
ReloadChartsFunc(result[0])
}
});
}
You can do whatever you want to modify the above code according to your need.

Related

Why does this query always return ALL records?

I'm using WCF RIA in a Lightswitch project to create some query results. This query brings back all results regardless. I cannot make it filter the records based on the parameter passed (string Town).
public IQueryable<Enquiries> TestQuery(string Town)
{
List<Enquiries> riaenqs = new List<Enquiries>();
var enqs = this.Context.ClientEnquiries
.Include("Client")
.Include("Client.Town")
.OrderBy(enq => enq.Id);
if (Town != null)
{
enqs.Where(enq => enq.Client.Town.TownName == Town);
}
foreach (ClientEnquiry item in enqs.ToList())
{
Enquiries enq = new Enquiries();
enq.Id = item.Id;
enq.ClientName = item.Client.FirstName + " " + item.Client.Surname;
enq.Town = item.Client.Town != null ? item.Client.Town.TownName : null;
riaenqs.Add(enq);
}
return riaenqs.AsQueryable();
}
During debugging I can see that the Town is correctly populated and I can see that the query is built accordingly if Town is not null. However, when I hit the foreach statement where the linq to ef query is executed I always get all the results. I just cannot figure out where I'm slipping up.
The LINQ methods like the Where do not modify the collection/expression but always returning a new one.
So you need to reassign the result of the Where to your original variable enqs:
if (Town != null)
{
enqs = enqs.Where(enq => enq.Client.Town.TownName == Town);
}

Open XML word content controls

Here is my code trying to get the content controls with the tag "company"
using (WordprocessingDocument template = WordprocessingDocument.Open("d:/dev/ProposalTemplate1.dotx", true))
{
MainDocumentPart mainPart = template.MainDocumentPart;
SdtBlock block = mainPart.Document.Body.Descendants<SdtBlock>().Where(r => r.SdtProperties.GetFirstChild<Tag>().Val == "TEST").Single();
Text t = block.Descendants<Text>().Single();
t.Text = "COMPANY_NAME";
}
I got the error "Object reference not set to an instance of an object" because of the query line but I don't know why...
This works well when I create a simple template with just one content controls but not when using a bigger word template
Any idea ?
EDIT
I try doing it without .Single() but still not working
MainDocumentPart mainPart = template.MainDocumentPart;
var blocks = mainPart.Document.Body.Descendants<SdtBlock>().Where(r => r.SdtProperties.GetFirstChild<Tag>().Val == "Company");
foreach (SdtBlock block in blocks)
{
Text t = block.Descendants<Text>().Single();
t.Text = "COMPANY1";
}
EDIT 2
I change the Text.Single()
The problem is still there "Object reference not set to an instance of an object" on the SdtBlock block = ... line
MainDocumentPart mainPart = template.MainDocumentPart;
var blocks = mainPart.Document.Body.Descendants<SdtBlock>().Where(r => r.SdtProperties.GetFirstChild<Tag>().Val == "Company");
foreach (SdtBlock block in blocks)
{
var t = block.Descendants<Text>();
foreach (Text text in t)
{
text.Text = "COMPANY1";
}
}
Not all SdtBlock elements have child Tag elements. You are assuming one exists and attempting to access the Val property but are getting a null reference exception in doing so.
You can fix it by checking for null within the Where predicate:
var blocks = mainPart.Document.Body.Descendants<SdtBlock>().Where(r =>
{
var tag = r.SdtProperties.GetFirstChild<Tag>();
return tag != null && tag.Val == "Company";
});
As per the comments there is more information about the issues you originally had with using Single in my answer here.
Try this:
foreach( SdtBlock sdt in sdtList )
{
if( sdt.SdtProperties != null )
{
Tag tag = sdt.SdtProperties.GetFirstChild<Tag>();
if( tag!= null )
{
if( tag.Val.Value == "Company" )
{
if( sdt.InnerText != string.Empty )
{
//Do something
}
}
}
}
}
Accepted solution returns no results on my query either. So i come up with this solution;
var doc = document.MainDocumentPart.Document;
List<Tag> sdtSubTable = doc.Body.Descendants<Tag>().Where(r =>
{
return r != null && r.Val.Value.Contains("Company");
}).ToList();

View Criteria not returning row

I'm new to ADF BC and I'm trying to save a record in the DB.
If the record already exists, I'll update the fields if not I'll create a new row.
I'm using the same View Criteria in other methods and it works, but not in this method. Here's my code:
public String saveRecord() {
boolean isNewRow = false;
String merchId = generateIds(); //returns the correct Id, I've checked
DCIteratorBinding dc = (DCIteratorBinding)evaluteEL("#{bindings.GaeInitialSetup1Iterator}");
ViewObject vo = dc.getViewObject();
ViewCriteriaManager vcm = vo.getViewCriteriaManager();
vo.setNamedWhereClauseParam("merchId", merchId);
vcm.applyViewCriteria(vo.getViewCriteriaManager().getViewCriteria("GaeInitialSetupVOCriteria"));
vo.executeQuery();
Row rowSelected = vo.next(); //it's always null even if the record exists
if (rowSelected == null) { // null == null - leads to error when trying to insert the same Id twice
isNewRow = true;
rowSelected = vo.createRow();
rowSelected.setAttribute("MerchId", merchId);
rowSelected.setAttribute("MerchLevel", merchLevelCalc(merchId));
rowSelected.setAttribute("ParentId", parentIdCalc(merchId));
}
rowSelected.setAttribute("IpssDefault", validateIPSSDefault());
rowSelected.setAttribute("IpssBase", validateIPSSBase());
rowSelected.setAttribute("LimMinMdqPct", validateLIM_MIN_MDQ_PCT());
rowSelected.setAttribute("LimMinMdqPctNewSku", validateLIM_MIN_MDQ_PCT_NEW_SKU());
rowSelected.setAttribute("DifMdqPctMin", validateDIF_MDQ_PCT_MIN());
rowSelected.setAttribute("VarMinMdqChg", validateVAR_MIN_MDQ_CHG());
rowSelected.setAttribute("LimMinRotDays", validateLIM_MIN_ROT_DAYS());
rowSelected.setAttribute("LimMaxRotDays", validateLIM_MAX_ROT_DAYS());
rowSelected.setAttribute("DaysNewSku", validateDAYS_NEW_SKU());
rowSelected.setAttribute("IncrS1", validateINCR_S1());
rowSelected.setAttribute("IncrS2", validateINCR_S2());
rowSelected.setAttribute("IncrS3", validateINCR_S3());
rowSelected.setAttribute("IncrS4", validateINCR_S4());
rowSelected.setAttribute("ReplSuspComb", validateREPL_SUSP_COMB());
rowSelected.setAttribute("VarPctMinStkRot", validateVAR_PCT_MIN_STK_ROT());
rowSelected.setAttribute("AbcgA", validateABCG_A());
rowSelected.setAttribute("AbcgB", validateABCG_B());
rowSelected.setAttribute("AbcgC", validateABCG_C());
rowSelected.setAttribute("AbcgD", validateABCG_D());
rowSelected.setAttribute("AbcgE", validateABCG_E());
rowSelected.setAttribute("AbcgF", validateABCG_F());
rowSelected.setAttribute("AbcgG", validateABCG_G());
if (isNewRow) {
vo.insertRow(rowSelected);
}
DCBindingContainer bindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
OperationBinding operationBinding = (OperationBinding)bindings.getOperationBinding("Execute");
operationBinding.execute();
OperationBinding operationBinding2 = (OperationBinding)bindings.getOperationBinding("Commit");
operationBinding2.execute();
return null;
}
What am I missing?
Your code seems perfectly right, could you try making the below mentioned changes?
vo.executeQuery();
if (vo.hasNext()) {
Row rowSelected = vo.next();
//write rest of your logic here
}
This will not have null == null check and is the best practice.
I've fixed the problem.
I removed the line: Row rowSelected = vo.next();
And I've added: Row rowSelected = vo.first();

declare variable to store linq entity for conditional statements

I am trying to look up record using if I have the key then use Find if not use Where
private ApplicationDbContext db = new ApplicationDbContext();
public bool DeactivatePrice(int priceId = 0, string sponsorUserName = "")
{
var prices = db.BeveragePrices;
// if we have an id then find
if (priceId != 0)
{
prices = prices.Find(priceId);
}
else
{
prices = prices.Where(b => b.UserCreated == sponsorUserName);
}
if (prices != null)
{
// do something
}
return true;
I get the following error for
prices = prices.Find(priceId);
Cannot convert app.Model.BeveragePrices from system.data.entity.dbset
I am copying the pattern from this answer but something must be different.
Seems you forgot to put a predicate inside the Find function call. Also you need to do ToList on the collection. The second option is a lot more efficient. The first one gets the whole collection before selection.
Another note commented by #Alla is that the find returns a single element. So I assume another declaration had been made for 'price' in the first option I state down here.
price = prices.ToList.Find(b => b.PriceId == priceId);
Or
prices = prices.Select(b => b.PriceId == priceId);
I assume the field name is PriceId.

The 'ArrayIndex' LINQ expression node type is not supported by LINQ to Entities - using interface & ReportViewer

a quick question really.
I'm struggling to implement Linq2Entities statement that could take more than one value for a particular "field". I'm passing a number of strings to the getClientsProjected() I can easily compare single value. But I've got on my page multiple dropdown and out of that I get string separated with coma I then later use to split it to string[] e.g. __ACCOUNT_SITE = "1234,5678" (see the code below) I've tried for/foreach/contains none of which worked...
public IQueryable<ClientViewModel> getClientsProjected(string __ACCOUNT_SITE, string __ACCOUNT)
{
var projectedClients = from c in getClosedSRs()
select new ClientViewModel
{
_ACCOUNT_ID_CSR = c.ACCOUNT_ID_CSR,
_ACCOUNT = c.ACCOUNT,
_ACCOUNT_FAMILY = c.ACCOUNT_FAMILY,
...
...
_ACCOUNT_SITE = c.ACCOUNT_SITE
};
if (String.IsNullOrEmpty(__ACCOUNT) != true && __ACCOUNT != "ALL")
{
//this works fine as an __ACCOUNT is of a single value
projectedClients = projectedClients.Where(c => c._ACCOUNT == __ACCOUNT);
}
if (String.IsNullOrEmpty(__ACCOUNT_SITE) != true && __ACCOUNT_SITE != "ALL")
{
String[] splitSites = __ACCOUNT_SITE.Split(',');
//????????????????????????????????????????????????
}
return projectedClients;
}
Now, to most of you this will make complete sense. I've read many articles but did not find a proper answer. I however can't use Linq2SQL as already built my entire site using L2E, interface and ReportViewer.
Any workaround?
If you are trying to filter projectedClients based on the values in splitSites, then use:
if (String.IsNullOrEmpty(__ACCOUNT_SITE) != true && __ACCOUNT_SITE != "ALL")
{
String[] splitSites = __ACCOUNT_SITE.Split(',');
projectedClients = projectedClients.Where(x => splitSites.Contains(x._ACCOUNT);
}