|
This is how it looks:
namespace Golf.Components
{
public class SkorekortDetailViewComponent : ViewComponent
{
public readonly GolfContext _db;
public SkorekortDetailViewComponent(GolfContext context)
{
_db = context;
}
public async Task<IViewComponentResult> InvokeAsync(int SkorekortID)
{
var items = await GetItemsAsync(SkorekortID);
return View(items);
}
private async Task<List<SkorekortDetailViewModel>> GetItemsAsync(int SkorekortID)
{
return (from s in _db.SkoreKort
from k in _db.Klub
from b in _db.Bane
where (s.SkorekortID == SkorekortID &&
s.BaneKlubID == k.KlubID &&
s.BaneID == b.BaneID)
select new {
s.SkorekortID,
k.DGUKlubNr,
s.SkoreDato,
s.SpillerHCP,
k.KlubNavn,
b.BaneNavn,
b.TeeNavn,
b.HerreDame,
b.BaneID,
k.KlubID
}).AsQueryable()
.Select(x => new SkorekortDetailViewModel {
SkorekortID = x.SkorekortID,
DGUKlubNr = x.DGUKlubNr,
SkoreDato = x.SkoreDato,
SpillerHCP = x.SpillerHCP,
KlubNavn = x.KlubNavn,
BaneNavn = x.BaneNavn,
TeeNavn = x.TeeNavn,
HerreDame = x.HerreDame,
SkoreListe = await GetSkorekortSkore(x.SkorekortID)
}).ToListAsync();
}
public async Task<List<SkorekortSkore>> GetSkorekortSkore(int SkorekortID)
{
return await (from s in _db.SkoreKortSkore
where s.SkorekortID == SkorekortID
select s).ToListAsync();
}
|
|
|
|
|
Try
return await (from s in _db.SkoreKort You're attempting to return an async operation without actually specifying that it's async.
This space for rent
|
|
|
|
|
It didn't change the error, it is still the same.
The error message suggest to add async in front of x => new SkorekortDetailViewModel as
}).AsQueryable()
.Select(async x => new SkorekortDetailViewModel {
SkorekortID = x.SkorekortID,
DGUKlubNr = x.DGUKlubNr,
SkoreDato = x.SkoreDato,
SpillerHCP = x.SpillerHCP,
KlubNavn = x.KlubNavn,
BaneNavn = x.BaneNavn,
TeeNavn = x.TeeNavn,
HerreDame = x.HerreDame,
SkoreListe = await GetSkorekortSkore(x.SkorekortID),
HulListe = await GetHuller(x.BaneID),
BaneListe = await GetBane(x.KlubID)
}).ToListAsync();
but that just shows all the linq as in error.
|
|
|
|
|
Were any parts actually working?
I would classify this as "unmaintainable"; and getting it to actually run would be bad karma.
You need to start with (working) "sub queries" that can be combined to arrive at the desired result; and where intermediate results can be checked / dumped if needed.
(Even the "SQL query plan optimizer" needs help sometimes).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
It works fine without the line "SkoreListe = await GetSkorekortSkore(x.SkorekortID)".
I'm not sure if it can work the way i thought it should work, so I have changed it to this instead which works:
private async Task<List<SkorekortDetailViewModel>> GetItemsAsync(int SkorekortID)
{
List<SkorekortDetailViewModel> skorekortdetail = await (from s in _db.SkoreKort
from k in _db.Klub
from b in _db.Bane
where (s.SkorekortID == SkorekortID &&
s.BaneKlubID == k.KlubID &&
s.BaneID == b.BaneID)
select new {
s.SkorekortID,
k.DGUKlubNr,
s.SkoreDato,
s.SpillerHCP,
k.KlubNavn,
b.BaneNavn,
b.TeeNavn,
b.HerreDame,
b.BaneID,
k.KlubID
}).AsQueryable()
.Select(x => new SkorekortDetailViewModel {
SkorekortID = x.SkorekortID,
DGUKlubNr = x.DGUKlubNr,
SkoreDato = x.SkoreDato,
SpillerHCP = x.SpillerHCP,
KlubNavn = x.KlubNavn,
BaneNavn = x.BaneNavn,
TeeNavn = x.TeeNavn,
HerreDame = x.HerreDame,
BaneID = x.BaneID,
KlubID = x.KlubID
}).ToListAsync();
foreach(var skorekort in skorekortdetail) {
skorekort.SkoreListe = await GetSkorekortSkoreAsync(skorekort.SkorekortID);
skorekort.HulListe = await GetHullerAsync(skorekort.BaneID);
skorekort.BaneListe = await GetBaneAsync(skorekort.KlubID);
}
return skorekortdetail;
}
|
|
|
|
|
hi
i need help to create temperature converter .
the user can write 10 value in Celsius using listbox.
then clicks converter button
and value of celsius in the listbox
converts to fahrenheit and to kelvin
then display results of fahrenheit and kelvin in two other listboxs
here is my initial code
|
|
|
|
|
what is working : so far i achieve to let user enter the value of celsius in the Celsiuslistbox for celsius by using add button
with code : celsiuslistbox.items.add(textbox.text)
//
Conversion from Celsius to Fahrenheit ,the program loops only one time
what is not working : conversion code can not go through data in the listbox and converts all values , rather it only converts the first value, then keep running
modified 22-Mar-18 0:57am.
|
|
|
|
|
Please post your code in the first post you made on this topic.
You need to create:
1. Methods to handle temperature conversion
2. a Method to convert a string, or a set of strings, to a floating point number(s) ... this method should handle potential bad data input
3. a user-interface for a user to enter multiple values
4. a user interface that lets the user specify whether input values are C or F
5. a Method, or Methods, to manage the ListBoxes: update them, etc.
We're here to help you, but, we are not going to write the code foe you.
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
I am using visual studio 2017
windows form. app(net.framework)
this my code
private void FjernBTN_Click(object sender, EventArgs e) // clear btn
{
textBox1.Text = "";
FahrenheitListBox.Items.Clear();
KelvinlistBox.Items.Clear();
Celsiuslistbox.Items.Clear();
}
private void KonverterBTN_Click(object sender, EventArgs e)// converter button code
{
Celsiuslistbox.Items.Add(textBox1);
double temp_Celsius; // temperature i celsius
double temp_Fahrenheit;// temperature i fahrenheit
int count;
for ( count = 0; count <10; count++)
{
temp_Celsius = Celsiuslistbox.Items.Add(textBox1.Text);
}
do
{
temp_Celsius = Celsiuslistbox.Items.Add(textBox1.Text);
} while ( count <=10);
temp_Fahrenheit = (9.0 / 5.0) * temp_Celsius + 32;
FahrenheitListBox.Items.Add(temp_Fahrenheit);
|
|
|
|
|
Please edit your original post, and update it, rather than post more.
And, what is the problem now . What works, what does not work ?
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
Quite a lot wrong with your code:
private void KonverterBTN_Click(object sender, EventArgs e)
{
Celsiuslistbox.Items.Add(textBox1);
double temp_Celsius;
double temp_Fahrenheit;
int count;
for ( count = 0; count <10; count++)
{
temp_Celsius = Celsiuslistbox.Items.Add(textBox1.Text);
}
do
{
temp_Celsius = Celsiuslistbox.Items.Add(textBox1.Text);
} while ( count <=10);
temp_Fahrenheit = (9.0 / 5.0) * temp_Celsius + 32;
FahrenheitListBox.Items.Add(temp_Fahrenheit);
|
|
|
|
|
If all the user does is enter "Celcius", then you can just make the F and K values "calculated columns" in a listbox / view / grid (Don't need "multiple listboxes").
More satisfying is creating a "temperature object" that can except a given value and scale and return a corresponding value in any other scale.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
I am building a database application which require some security with biometric prints. How to add the function to find records after scanning the print via the biometric machine?
|
|
|
|
|
Start with the biometric reader manufacturer's website: they will normally have sample code which demonstrates a basic "how to use it" app. Once you have that working, it should be fairly obvious what you need to do to get your app version working.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
In order to "find" something, you need "keys / data".
Find out what "data" is being captured (and stored) with the "biometric prints".
Find out if there are other data generation / collection options for the "biometric machine".
Document the old physical and old logical.
Then create your new logical and new physical models.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
I have an integerExponentiate() function that operates on two objects of like type, and relies only on the fact that the type implements the * operator and has an instance that represents the mathematical concept of a unit. I have several classes that meet those criteria, and would like it to be possible for integerExponentiate() to be called on instances of any of those classes. My first thought was to make integerExponentiate() a generic method that takes the unit and a delegate representing the multiplication operator as parameters, something like this:
delegate T multiplier<T>(T a, T b);
T integerExponentiate<T>(multiplier<T> m, T unit, T expBase, Integer exponent);
But I don't see a way to assign an operator to a delegate. Is there a way to do that directly, or do I have to wrap the operator in another function and use that? Or should I consider another approach entirely?
|
|
|
|
|
Solved it, I think: instead of cluttering up the classes in question with a do-nothing multiply() function, I can pass an anonymous function for the m parameter of integerExponentiate(). I hadn't used anonymous functions before.
|
|
|
|
|
See if this givs you some ideas:
public static class GenericMathExtensions
{
public static double? Exp<T>(this T tvalue, double topower)
where T :
struct,
IComparable,
IComparable<T>,
IConvertible,
IEquatable<T>,
IFormattable
{
if (typeof(T).IsNumeric())
{
try
{
return Math.Pow(Convert.ToDouble(tvalue), topower);
}
catch
{
}
}
return null;
}
public static bool IsNumeric(this Type type)
{
switch (Type.GetTypeCode(type))
{
case TypeCode.Byte:
case TypeCode.SByte:
case TypeCode.UInt16:
case TypeCode.UInt32:
case TypeCode.UInt64:
case TypeCode.Int16:
case TypeCode.Int32:
case TypeCode.Int64:
case TypeCode.Decimal:
case TypeCode.Double:
case TypeCode.Single:
return true;
case TypeCode.Object:
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))
{
return Nullable.GetUnderlyingType(type).IsNumeric();
}
return false;
default:
return false;
}
}
} Note: the Convert.ToDouble method can handle other types than those this code restricts the usage to.
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
Message Removed
modified 20-Mar-18 12:21pm.
|
|
|
|
|
i cant find a solution to create a chat application without the need to a server
all the project and idea i found are all based on a server and client
how can be done with just client in each pc and the clients are in the same local network so they need to discover each other IP and send the message to each other
|
|
|
|
|
The simple solution is to have an app that acts as both client and server.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
Do you know how to create an application which has a Server an a Client ?
In this case see my description - if not use Google to find some Examples and look how they work and try to understand the functionality.
|
|
|
|
|
Use the code you have found as a basis: start your app as a client, and look for an appropriate server. If you find one, connect to it and chat away.
If you don't, close the client, and open a server. The server then waits for another app to connect.
Or, start as a server, then open a client as well and search for other servers.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Additional to the answer of OriginalGriff :
The communication allways needs a Server (and could have one or more Clients).
So you could do the following :
You start your application as Client and try to connect a Server (I would use the synchronous methods here). If you don't get a response after a time (defined by you) there is no Server availible and perhaps your must be the Server (or you are not connected to a network ???) - so you switch to different methods (and tasks) in your application.
|
|
|
|
|