|
Hello once again frends!
Right now im stuck doing a web form in which i have to compare 2 datagrids and/or 2 dates from a database depending on the problem.
now my questions are:
1. how do i compare 2 different dates with each other? i've tried
if (Convert.ToDateTime(ds.Tables[0].Rows[0][1].ToString()).Date >= Convert.ToDateTime(deductDate_1stMonth_End).Date)
{
drNewRow[0] = "S";
}
where ds = the dataset that i queried the dates to be compared from a database. somehow the dataset always return a "null" value in debug mode...i just dont get it.
2. how do i reference the results of datagrid1 in which if it is "null" or "" i place "NE" on the coresponding column of datagrid2? this one honestly i haven't tried yet though i was thinking instead of referencing datagrid1 i probably could go straight to my database query and return my desired result if it shows "null" or "NE". then again i could be wrong...
please oh wise gurus of codeproject could you please assist me in my dilema that i may learn from my mistakes and enhance my skils close to urs
thanx again for all your posts. its greatly appreciated!
Aim small, miss small...
|
|
|
|
|
DateTime.Compare
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
well that was short ...thanx!!
Aim small, miss small...
|
|
|
|
|
Somebody can help me how to use C#
to open tsk file or exact the tdywater.001
|
|
|
|
|
i am trying to do the folowing
<br />
FileStream fs = System.IO.File.Create("test.dat"); <br />
Image img;<br />
img = Image.FromFile( "image1.jpg" );<br />
img.Save(fs,ImageFormat.Jpeg);<br />
img.Dispose();<br />
<br />
long p2=fs.Position;<br />
img = Image.FromFile( "image2.jpg" );<br />
img.Save(fs,ImageFormat.Jpeg);<br />
img.Dispose(); <br />
<br />
fs.Position=0;
pictureBox1.Image=Bitmap.FromStream(fs);<br />
fs.Position=p2;
pictureBox1.Image=Bitmap.FromStream(fs);<br />
The result of this code is image1 get displayed in both pictureBox(1&2), even after i set the stream position to the start of image2. It appears that when the "Bitmap.FromStream(fs);" is invoked it rest the stream position to 0. To solve the problem I was thinking to load each image in a byte array, but then their is no method tha i know of to get a "bitmap" out of a jpeg byte array.
Any help would be apreciated.
thx
|
|
|
|
|
If you would like to use your code above, here is my two cents:
Create the following class in your project. It wraps a FileStream that allows you to override the seeking ability.
public class HardFileStream : FileStream
{
private bool hardPositionSet;
public HardFileStream( string path )
: base( path, FileMode.OpenOrCreate, FileAccess.ReadWrite ) {}
public bool HasHardPositionSet
{
get
{
return hardPositionSet;
}
}
public void SetHardPosition( long pos )
{
base.Position = pos;
hardPositionSet = true;
}
public void ReleaseHardPosition()
{
hardPositionSet = false;
}
public override long Position
{
get
{
return base.Position;
}
set
{
if( !hardPositionSet )
base.Position = value;
}
}
public override bool CanSeek
{
get
{
return !hardPositionSet;
}
}
public override long Seek( long offset, SeekOrigin origin )
{
if( !hardPositionSet )
{
return base.Seek( offset, origin );
}
return 0;
}
}
Now, change your code to the following:
HardFileStream fs = new HardFileStream( "test.dat" );
Image img;
img = Image.FromFile( "image1.jpg" );
img.Save(fs,ImageFormat.Jpeg);
img.Dispose();
long p2 = fs.Position;
img = Image.FromFile( "image2.jpg" );
img.Save( fs, ImageFormat.Jpeg );
img.Dispose();
fs.Position=0;
pictureBox1.Image = Image.FromStream(fs);
fs.SetHardPosition( p2 );
pictureBox2.Image = Image.FromStream(fs);
fs.ReleaseHardPosition();
And, that should do it. My test project compiles and shows the two separate images in the two picture boxes.
"we must lose precision to make significant
statements about complex systems."
-deKorvin on uncertainty
-- modified at 23:11 Monday 21st November, 2005
|
|
|
|
|
Really clever solution, that worked great!!!!!!!!!!
i have another question aroun the same idea now.
I have "byte[] buffer" with known size, it contain a JPEG image, how can i load the buffer in a GDI+ "Image" object. Can i attach a stream to the buffer and pass the stream to the "Image" object ?
--this just an idea that remember i read somewhere but don't know how to do it--.
thx
|
|
|
|
|
I got a simple HelloWorld.Exe that prints out helloworld
And I got another application that wants to process that exe file, store as a string and the reprint hello world, called "ReadHelloWorld.exe"
But I find that use the property from Process "UseShellExecute" when turned false, is that the Working directory I set to wont be used, so I can only execute HelloWorld.exe within ReadHelloWorld.exe.
Is there a way such that I can use the Process to store it as a string without resorting to using a shell to execute the command, store it as a text file, read its contents then removing the temporary text file?
Kuira
|
|
|
|
|
Kuira wrote: Is there a way such that I can use the Process to store it as a string without resorting to using a shell to execute the command, store it as a text file, read its contents then removing the temporary text file?
Yes. Basically you need how to learn to redirect the standard output. The following article and code will do exactly what you want and more:
Run other programs from your .NET code[^]
Hope it helps.
My articles and software tools
|
|
|
|
|
I have a Hashtable with following values:
[Key][Value]
[$0001][1]
[$0002][0]
[$0003][1]
[$0004][0]
[$0005][0]
[$0006][0]
[$0007][1]
[$0008][1]
[$0009][1]
[$0010][1]
Now I need all Keys with value "1". It is possible to extract them without a for loop?
My main problem is a recursion. This hashtable is used 4 times and I have to check each key. Hashtable contains ~800 entries, what means 800^4 possibilites. Big overhead.
Simple example:
[$0001][00]
[$0002][01]
[$0003][04]
[$0004][01]
[$0005][02]
Recursion - check element and its connectors
1. 0001 - my for loop checks all connectors -> Result: 0002 and 0004 (because Key is 01).
2. now check the connectors for connectors (we have 0002 and 0004)
3. 0002 has 0005(key = 02)
and so on .....
Is there a way for a fast progress in speed? Thanks for all tips.
|
|
|
|
|
Seraphin wrote: Now I need all Keys with value "1". It is possible to extract them without a for loop?
No. Use the values as keys into another hashtable where the values are arrays. I don't think .NET has multimaps.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi Chris,
Thanks for reply. Values are not unique, so it's a little bit hard to realize that.
The big problem is to check each key with all available keys (so keys^keys possibilities) to find connectors. Speed is really hard task.
|
|
|
|
|
I know values are not unique, that's why I said to store an array list against each key, so you have an array of values for each.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
OK, but I have still a problem with overhead.
Look at this link and look at those trees.
http://personal.vsnl.com/erwin/pruning.htm[^]
Level 1 Level 2 and so on.
My hashtable uses 4 levels and each node needs ALL nodes from the upper levels to check. Level 1 has 800 entries. Level 2 has 800x800 entries and so on, which makes me crazy.
|
|
|
|
|
Seraphin wrote: each node needs ALL nodes from the upper levels to check.
OK - in that case you probably want to look for a more optimised solution.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
You are right. I never had problems with algorithms and data structures, but this problems sets boundaries.
|
|
|
|
|
Seraphin wrote: Simple example:
[$0001][00]
[$0002][01]
[$0003][04]
[$0004][01]
[$0005][02]
Recursion - check element and its connectors
1. 0001 - my for loop checks all connectors -> Result: 0002 and 0004 (because Key is 01).
Just so I understand, you're starting with a value of (00)01 and asking which keys have this value? The result in this case being $0002 and $0004?
Seraphin wrote:
2. now check the connectors for connectors (we have 0002 and 0004)
3. 0002 has 0005(key = 02)
and so on .....
So having gotten the $0002 and $0004 keys, you are now interested in which keys have those two keys as values?
This suggestion may be exactly what Christian suggested, but I would switch things around and use the values as keys and the keys as values. Each key would have an array of values. It would look like this:
[00][$0001]
[01][$0002][$0004]
[04][$0003]
[02][$0005]
Asking the question again, which value(s) correspond to the 01 key? Answer: $0002 and $0004. Which value(s) correspond to the key 02? Answer: $0005 Which value(s) correspond to the key 04? Answer: $0003.
I'm a little confused on the differences in number formating, but I'm assuming that they are interchangable. At any rate, I'm probably missing something here, because this answer is too simple.
|
|
|
|
|
Hi Leslie,
Just so I understand, you're starting with a value of (00)01 and asking which keys have this value? The result in this case being $0002 and $0004?
Yes.
Christian suggestion leads into overhead within the recursion. It's impossible.
Try to make a recursion with 800 items, and you need about 10 min to loop through.
Yes, good idea ... but really time consuming (overhead)
The problem: Give me all connectors and subconnectors for current item. Lets draw better example:
$1 [0]
$2 [1]
$3 [1]
$4 [2]
Result:
a) $1 - $2 - $3 and
b) $1 - $3
for the first line
a) search connectors for $1 - found $2 and $3
then loop through founded subconnectors $2 and $3
$2 has $4 as connector
$3 has no further connectors
next element in main loop is §2
$2 - $4 .... $4 has no more connectors
|
|
|
|
|
Ok, I'm still mulling this over, but would it help if the values were sorted?
Say you have this:
$1 [0]
$2 [1]
$3 [2]
$4 [1]
$5 [2]
Then you sort them by values:
$1 [0]
$2 [1]
$4 [1]
$3 [2]
$5 [2]
What this buys you is that as soon as you encounter a value that doesn't equal the value you are currently searching with, you can stop the search for that value. And maybe even continue the search from that point for subconnectors.
Say you are searching with value [1]. You find the connectors $2 and $4. Then you encounter value [2]. You know at that point that you've found all of the connectors for [1].
However, did [1] have a connection to $2? Yes. So since you are already at [2], you can begin the search for $2's subconnectors from right where you are. Same goes for $4, which was also a connector for [1].
Does this help?
|
|
|
|
|
Thanks, looks better. Additionally I works with permutation now.
|
|
|
|
|
I have 10 Textboxes, textBox1 to textBox10
I have a string "naam" with contents textBox9. This 9 refers to the FOR-loop variable i
naam = "textBox" + Convert.ToString(i);
With the contents of de string-variable I would like to refer to the object with that name. I.e. textBox9.Text = ".....";
In this example I want to set de Text-property from textBox9 with the string naam
Problem: How can I refer to the name of the object textBox9 with the contents of the string naam?
Thanks
-- modified at 16:30 Sunday 20th November, 2005
|
|
|
|
|
if you just have 10 text box you can do it the long way with a switch case but it should work
ex:
<br />
switch(naam)<br />
{<br />
. case "textbox1":<br />
. TextBox1.Text="...";<br />
. break;<br />
. case "textbox2"<br />
.
}<br />
|
|
|
|
|
Let's say that you add textBox1 through textBox10 on your form. The TextBox.Name property has the string version of those stored if you use the visual form editor included in Visual Studio. So, to do what you want, if I understand your question properly, would be something like this:
int i = 9;
string naam = "textBox" + Convert.toString( i );
Control targetControl = null;
foreach( Control c in Controls )
{
if( c.Name == naam )
{
targetControl = c;
break;
}
}
if( targetControl != null )
{
}
"we must lose precision to make significant
statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
All right. Just what I meant. Works excellent. Thanks
|
|
|
|
|
My pleasure! Glad I could help you.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|