How can I add a dynamic key to an anonymous List such as the mydatetime below:
DateTime myDateTime = DateTime.Parse(datepickerval, ukCulture.DateTimeFormat);
var qid = (from p in db.Vw_INTERACTPEOPLE
select p
);
var AvilList = new List<object>();
var ddate = myDateTime.DayOfWeek.ToString().Substring(0, 3) + "Jul" + myDateTime.Day;
foreach (var q in qid)
{
AvilList.Add(
new
{// Availability
Name = q.Fullname,
here >>> ddate = "Some Test"
});
As adam says above there is no way to do this using Lists, however since the Slickgrid is expecting a Json return, I simply built the string in .net then returned it via the JavaScriptSerializer serializer, then in the code behind simply used eval to de-serialize back into an array.
Related
Since two days I'm on a problem and I can't solve it so I come here to ask some help...
I have that bit of dax that basically take the path of a hierarchical table (integers) and take the string names of the 2 first in the path.
the names I use:
'HIERARCHY' the hierarchical table with names, id, path, nbrItems, string
mytable / addedcolumn1/2 the new table used to emulate the for loop
DisplayPath =
var __Path =PATH(ParentChild[id], ParentChild[parent_id])
var __P1 = PATHITEM(__Path,1) var __P2 = PATHITEM(__Path,2)
var l1 = LOOKUPVALUE(ParentChild[Place],ParentChild[id],VALUE(__P1))
var l2a = LOOKUPVALUE(ParentChild[Place],ParentChild[id],VALUE(__P2))
var l2 = if(ISBLANK(l2a), "", " -> " & l2a)
return CONCATENATE(l1,l2)
My problem is... I don't know the number of indexes in my path, can go from 0 to I guess 15...
I've tried some things but can't figure out a solution.
First I added a new column called nbrItems which calculate the number of items in the list of the path.
The two columns:
Then I added that bit of code that emulates a for loop depending on the number of items in the path list, and I'd like in it to
get name of parameters
concatenate them in one string that I can return and get
string =
var n = 'HIERARCHY'[nbrItems]
var mytable = GENERATESERIES(1, n)
var addedcolumn1 = ADDCOLUMNS(mytable, "nom", /* missing part: get name */)
var addedcolumn2 = ADDCOLUMNS(addedcolumn1, "string", /* missing part: concatenate previous concatenated and new name */)
var mymax = MAXX(addedcolumn2, [Value])
RETURN MAXX(FILTER(addedcolumn2, [Value] = mymax), [string])
Full table:
Thanks for your help in advance!
Ok, so after some research and a lot of try and error... I've came up to a nice and simple solution:
The original problem was that I had a hierarchical table ,but with all data in the same table.
like so
What I did was, adding a new "parent" column with this dax:
parent =
var a = 'HIERARCHY'[id_parent]
var b = CALCULATE(MIN('HIERARCHY'[libelle]), FILTER(ALL('HIERARCHY'), 'HIERARCHY'[id_h] = a))
RETURN b
This gets the parent name from the id_parent (ref. screen).
then I could just use the path function, not on the id's but on the names... like so:
path = PATH('HIERARCHY'[libelle], 'HIERARCHY'[parent])
It made the problem easy because I didn't need to replace the id's by there names after this...
and finally to make it look nice, I used some substitution to remove the pipes:
formated_path = SUBSTITUTE('HIERARCHY'[path], "|", " -> ")
final result
A user can supply answers for up to 5 question, and each question has 3 columns in the database:
st_m1_id
st_m1_fam
st_m1_cip
st_m2_id
st_m2_fam
st_m2_cip
etc
When the form is submitted I get the IDs into an array and then loop over that and then query a different table to look up fam and cip.
aidms = listToArray(form['idms[]']);
for( i=1;i<=arrayLen(aidms);i++ ) {
qryData = invoke(dataCFC,'queryData', { smid = aidms[i]});
temp = invoke(userCFC,'updateUser',{
userid = session.userid,
st_m#i#_id = aidms[i],
st_m#i#_fam = qryData.fam,
etc......
});
};
How do I notate the dynamic query column names in the function so that when they are passed to updateUser the correct columns are referenced?
I have a query result same as below:
var ptns = from p in db.Patients
select p;
This query returns a list of patients, but I need to filter the result based on DoctorNameID. The DoctorNameID should be in list of doctors as below:
List<string> listofDoctors = usrtodrs.Split(',').ToList();
I have searched a lot but I don't know how to do this. I have tested this query which doesn't work:
var ptns1 = from d in listofDoctors
join p in ptns.ToList() on d equals p.DoctorNameID
select p;
And also this query:
var ptns1 = ptns.ToList()
.Where(a => listofDoctors.Equals(a.DoctorNameID))
.ToList();
Any help?
You can use Contains extension and get the desired result.
var ptns1 = ptns.Where(x => listofDoctors.Contains(x.DoctorNameID)).ToList();
Refer the C# Fiddle with sample data.
Please see I want list employee objects. So I have below two options.
List<Tuple<int, string, string, string>>
List<Employee>where Employee is class contains 4 properties.
My doubt is what should I use(tuple or list of employee object?
If it is List<Employee> then in which scenario I should use List<Tuple<int, string, ...>>.
You should not use tuples unless you are doing some sort of arithmetic operation where tuple would be an acceptable and widely understood method of supplying values. Tuples make it a maintenance nightmare for anyone who is not familiar with your process as you built it.
Edit: Think about the difference between seeing:
var employeeList = DAL.getEmployees();
var activeEmployees = employeeList.Where(employee => employee.IsActive);
vs
var employeeTuple = DAL.getEmployees();
var activeEmployees = employeeTuple.Where(employee => employee.Item3);
In the second example, I know THAT you created an active employee list, but I don't know HOW you did it.
That's rather obvious. If you already have the Employee class then using List<Employee> is straightforward:
List<Employee> list = new List<Employee>();
list.Add( e );
...
Employee e = list.Where( i => i.Name == "John" ).FirstOrDefault();
whereas using List<Tuple<...>> is at least cumbersome:
List<Tuple<....>> list = new List<Tuple<....>>();
list.Add( new Tuple<...>( e.Name, e.Surname, e.Whateverelse, e.YetAnother ) );
...
// retrieve the tuple
var tuple = list.Where( i => i.Item1 == "John" );
// make Employee out of it
Employee e = new Employee( e.Item1, e.Item2, e.Item3, e.Item4 );
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to strip out a url variable
I have url http://localhost/abc/detail.cfm?iId=1711471&countrysearch=3693&itemnumbersearch=&keywordsearch=&purl=%2FIGPCI%2Fthumbs%2Ecfm%3Fcountrysearch%3D3693%26itemnumbersearch%3D%26keywordsearch%3D%26x%3D78%26y%3D10&productid=1111&recordindex=1.
I want to search product details on clicking link called "next" each time i need to prepare new URL with new value of productid and recordindex.for example i have four product with respect to countryid="3693",
productid productname
1 p1
2 p2
3 p3
4 p4
when next click new URL prepare with productid=1 and recordindex=1,again click then URL is productid=2 and record id =2 and so on.
for getting URL i have used following code:
<cfset currentURL = "#CGI.SERVER_NAME#" & "#CGI.PATH_INFO#" & "#CGI.query_string#">
which give me the current url
then i prepare new url with below code:
<cfif queryString.recordset gt 0> <cfset recordindex=#recordindex#+1> <cfset newUrl=currentURL & '&productid=#queryString.poductid[recordindex]#&recordindex=#recordindex#' </cfif>
with this code that each time it's append url value with old with new one.
like:
http://localhost/abc/detail.cfm?iId=1711471&countrysearch=3693&itemnumbersearch=&keywordsearch=&purl=%2FIGPCI%2Fthumbs%2Ecfm%3Fcountrysearch%3D3693%26itemnumbersearch%3D%26keywordsearch%3D%26x%3D78%26y%3D10&productid=1111&recordindex=1&productid=2&recordindex=2
my question how to remove old &productid=1111&recordindex=1 in old URL.i tried with replace function but it replace when string are match,in my case every time product and recordindex values are change.how to remove old string using regular expression.please help me.
Thanks
You don't need regex for this. In fact, someone has already built a UDF for this.
QueryStringDeleteVar
Example:
<cfset currentURL = CGI.SERVER_NAME & CGI.PATH_INFO & queryStringDeleteVar("productid,recordindex")>
UDF code:
<cfscript>
/**
* Deletes a var from a query string.
* Idea for multiple args from Michael Stephenson (michael.stephenson#adtran.com)
*
* #param variable A variable, or a list of variables, to delete from the query string.
* #param qs Query string to modify. Defaults to CGI.QUERY_STRING.
* #return Returns a string.
* #author Nathan Dintenfass (michael.stephenson#adtran.comnathan#changemedia.com)
* #version 1.1, February 24, 2002
*/
function queryStringDeleteVar(variable){
//var to hold the final string
var string = "";
//vars for use in the loop, so we don't have to evaluate lists and arrays more than once
var ii = 1;
var thisVar = "";
var thisIndex = "";
var array = "";
//if there is a second argument, use that as the query string, otherwise default to cgi.query_string
var qs = cgi.query_string;
if(arrayLen(arguments) GT 1)
qs = arguments[2];
//put the query string into an array for easier looping
array = listToArray(qs,"&");
//now, loop over the array and rebuild the string
for(ii = 1; ii lte arrayLen(array); ii = ii + 1){
thisIndex = array[ii];
thisVar = listFirst(thisIndex,"=");
//if this is the var, edit it to the value, otherwise, just append
if(not listFind(variable,thisVar))
string = listAppend(string,thisIndex,"&");
}
//return the string
return string;
}
</cfscript>
Although, since you're looking to replace URL parameter values, QueryStringChangeVar would probably be more of what you want.
<cfscript>
/**
* Changes a var in a query string.
*
* #param name The name of the name/value pair you want to modify. (Required)
* #param value The new value for the name/value pair you want to modify. (Required)
* #param qs Query string to modify. Defaults to CGI.QUERY_STRING. (Optional)
* #return Returns a string.
* #author Nathan Dintenfass (nathan#changemedia.com)
* #version 2, September 5, 2002
*/
function QueryStringChangeVar(variable,value){
//var to hold the final string
var string = "";
//vars for use in the loop, so we don't have to evaluate lists and arrays more than once
var ii = 1;
var thisVar = "";
var thisIndex = "";
var array = "";
var changedIt = 0;
//if there is a third argument, use that as the query string, otherwise default to cgi.query_string
var qs = cgi.query_string;
if(arrayLen(arguments) GT 2)
qs = arguments[3];
//put the query string into an array for easier looping
array = listToArray(qs,"&");
//now, loop over the array and rebuild the string
for(ii = 1; ii lte arrayLen(array); ii = ii + 1){
thisIndex = array[ii];
thisVar = listFirst(thisIndex,"=");
//if this is the var, edit it to the value, otherwise, just append
if(thisVar is variable){
string = listAppend(string,thisVar & "=" & value,"&");
changedIt = 1;
}
else{
string = listAppend(string,thisIndex,"&");
}
}
//if it was not changed, add it!
if(NOT changedIt)
string = listAppend(string,variable & "=" & value,"&");
//return the string
return string;
}
</cfscript>