|
Linq Method Would probably be the best as I have to write it out to a field.
I'll put together some code and see what you think?
|
|
|
|
|
Sounds good!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Im trying to do something like this:
var complexQuery = from e in orgContext.CreateQuery("Eval")
join c in orgContext.CreateQuery("Contract")
on e["contractid"] equals c["contractnameid"]
I want to do a Count of the complexQuery and whatever the count is I want to add this to a variable so I can write this out to a field.
|
|
|
|
|
Um...you do realize that a Collection has a Count method?[^]
So to get all the elements in your total sequence:
var complexQuery = from e in orgContext.CreateQuery("Eval")
join c in orgContext.CreateQuery("Contract")
on e["contractid"] equals c["contractnameid"];
int count = complexQuery.Count();
If you are trying to get the count of elements with matching ids (i.e. a collection of counts) then just Group the linq query and select the count of each group.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Thanks for your help Ill try this.
|
|
|
|
|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
It sounds to me like you're looking at having a Dictionary of Dictionaries like this:
private Dictionary<string, Dictionary<string, ClassRepresentingOtherItems>> dictionary = new Dictionary<string, Dictionary<string, ClassRepresentingOtherItems>>();
public void Add(string id, string fieldValue, ClassRepresentingOtherItems items)
{
if (!dictionary.ContainsKey(id))
{
Dictionary<string, ClassRepresentingOtherItems> childDictionary = new Dictionary<string, ClassRepresentingOtherItems>();
dictionary.Add(id, childDictionary);
}
dictionary[id].Values.Add(fieldValue, items);
} This allows you to associate many fields with the same ID.
|
|
|
|
|
I have no code written yet as I'm just looking for ideas.
I am just reading the values in a field in records in a database table.
There are multiple records with the value H1 and I want to get each value C1 in each record with ID H1. And then I would count the number of occurences of C1 from the records with ID H1.
I am looking how to do this using C#
|
|
|
|
|
macca24 wrote: I don't want to do this in SQL.
Why not?
If the set is small, like say less than 100,000 than a query each time is likely to be best.
If the set is large, like 10 billion, then dragging all of the records across the wire probably isn't a good idea. Which suggests you basic assumption of a solution is wrong and again SQL would probably be better for a real solution.
|
|
|
|
|
It is only for a very small number of records around 50-100.
|
|
|
|
|
Then as I suggested - do the query.
|
|
|
|
|
I have to create PDF file in c#. The constrain is that I should not use assemblies (Ex. pdfSharp, itextSharp). The PDF file should be created by using StreamWriter class. If anyone knows the answer, please help me.
|
|
|
|
|
This is not a trivial project in any way - that's why you get libraries such as pdfSharp.
So if you can't use them, then you will have to write your own, or use a PDF printer driver (google will find you those)
Writing your own is a big job - so start here: https://en.wikipedia.org/wiki/Portable_Document_Format[^] and set aside probably a few months to get it right. I'd recommend installing a number of PDF readers to check it with as you go along - you can't rely on just one to have not made the same mistakes you probably will!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Who gave you this constraint? What does the problem say, exactly? The reason I ask this is that writing a PDF is a complex task based on an understanding of the PDF file format which is huge. Even if you choose to target an early version of the format, it's still a big thing you need to create.
|
|
|
|
|
Member 11585846 wrote: The constrain is that I should not use assemblies (Ex. pdfSharp, itextSharp)
Why not? This sounds like homework ...
"I've seen more information on a frickin' sticky note!" - Dave Kreskowiak
|
|
|
|
|
I have created PDF without using those libraries. I have finished it in 5 days.... Thanks for your comments.
|
|
|
|
|
i have seen many artical only to upload a image...
or by using database.
|
|
|
|
|
And how is that different from what you want to do?
The source of the data should be pretty much irrelevant here...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I found example here: http://forums.codeguru.com/showthread.php?182234-serial-ports-C[^] for serial communication on C# using PInvoke calls.
One question I have is that DCB structure they use here:
[StructLayout(LayoutKind.Sequential)]
public struct DCB {
public int DCBlength; public int BaudRate;
public uint flags;
public ushort wReserved; public ushort XonLim; public ushort XoffLim; public byte ByteSize; public byte Parity; public byte StopBits; public char XonChar; public char XoffChar; public char ErrorChar; public char EofChar; public char EvtChar; public ushort wReserved1; }
You can see they have commented out the `CTS`, `DSR`, `RTS`, `DTR` and `XON/XOFF` out flow control parameters. But I need to be able to set these parameters. How do I modify this structure such that I can use these parameters also? Should I just uncomment the commented fields?
PS. Also, does the implementation I linked look reasonable to you?
|
|
|
|
|
No, you don't uncomment them - they are bit fields - which mean s that each of the "names" refers to a single bit within the flags element: fBinary is bit 0, fParity is bit 1, and so on.
If you uncomment them, you will get totally the wrong structure size.
C# doesn't have bit fields - so you need to define const values for each bit value and set it on and off using the C# &, |, and ~ bitwise operators.
Is there a good reason for not using the C# SerialPort implementation instead?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Can you please show me a sample how I would use that structure in C# so that I can set DSR, DTR, RTS, CTS and Xon/Xoff parameters to true or false?
PS thing is I have C++ implementation of serial communication and need to translate to C#. C#'s SerialPort doesn't allow to fine tune as many parameters as C++ does, e.g., see here: http://stackoverflow.com/questions/32859276/rewrite-serial-port-communicationf-rom-c-to-c-sharp[^]. What is the way I should approach it you think?
I will appreciate if you can show me how to use that DCB in C# so that I can set all (DSR, DTR, RTS, CTS and Xon/Xoff) parameters.
|
|
|
|
|
You are kidding, right?
Use the C# bitwise operators:
private const int Bit2 = 4;
...
int myFlags = 0;
myFlags |= Bit2; // Set bit 2.
myFlags &= ~Bit2; // Clear bit 2.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Why am I kidding ?
how do I know which bits in the new C# structure:
[StructLayout(LayoutKind.Sequential)]
public struct DCB {
public int DCBlength; public int BaudRate;
public uint flags;
public ushort wReserved; public ushort XonLim; public ushort XoffLim; public byte ByteSize; public byte Parity; public byte StopBits; public char XonChar; public char XoffChar; public char ErrorChar; public char EofChar; public char EvtChar; public ushort wReserved1; }
correspond to parameters like CTS, DSR, RTS, DTR, Xon/Xoff from the original structure?
PS. Do you think I should give a try maybe to SerialPort and if doesn't work revert to this PInvoke implementation?
|
|
|
|
|
If I were you, I'd look for an implementation such as this[^].
|
|
|
|
|
Try the version of this structure from pinvoke.net, which provides properties to get and set the individual bits:
http://pinvoke.net/default.aspx/Structures/DCB.html[^]
The SerialPort class[^] would be a better choice for .NET code. It gives you friendly properties for all of the settings from the DCB struct.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
modified 30-Sep-15 8:42am.
|
|
|
|