|
Try a ProgressBar , and increment by each step
I are troll
|
|
|
|
|
I think you mean a progress bar - something to show the user haw far through you are? Rather than a track bar - something to let the user change numbers?
if so then:
FileInfo fi = new FileInfo(fileName);
ProgressBar pb = this.pbShowProgress;
pb.Maximum = (int)fi.Length;
string line;
while ((line = file.ReadLine()) != null)
{
pb.Value += line.Length;
}
You may want to add using(...) and / or try - catch to this.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
hi
i need to read XML data from an XML file into C#.i tried using XmlTextReader class but i am not getting all elements.
My XML file is as follows
<?xml version="1.0"?>
<Form1>
<button>username</button>
</Form1>
My code is as follows
XmlTextReader textReader = new XmlTextReader("C:\\books.xml");
textReader.Read();
while (textReader.Read())
{
textReader.MoveToElement();
Console.WriteLine("Attribute Count:" + textReader.Value.ToString());
}
in the above code i am not getting all the nodes and elements...(maybe due to whitespaces)
please give links to any code samples etc...is there any other method to read??
thanks in advance...
"Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"
|
|
|
|
|
|
hi there,
I have this text file
Enroll No,194,date2,30/4/2009,time2,0:3:38,Check Out
Enroll No,78,date2,30/4/2009,time2,0:3:43,Check Out
Enroll No,78,date1,30/4/2009,time1,9:44:47,Check In
Enroll No,107,date1,30/4/2009,time1,9:44:52,Check In
Enroll No,108,date1,30/4/2009,time1,9:57:39,Check In
Enroll No,106,date1,30/4/2009,time1,10:40:47,Check In
Enroll No,109,date1,30/4/2009,time1,15:23:30,Check In
Enroll No,107,date2,30/4/2009,time2,17:6:27,Check Out
Enroll No,194,date1,30/4/2009,time1,17:9:44,Check In
Enroll No,132,date1,30/4/2009,time1,17:32:19,Check In
Enroll No,106,date2,30/4/2009,time2,17:35:31,Check Out
Enroll No,78,date2,30/4/2009,time2,17:35:41,Check Out
Enroll No,132,date1,30/4/2009,time1,17:45:2,Check In
Enroll No,108,date2,30/4/2009,time2,18:33:18,Check Out
Enroll No,109,date2,30/4/2009,time2,22:30:18,Check Out
Enroll No,194,date2,1/5/2009,time2,0:4:18,Check Out
Enroll No,132,date2,1/5/2009,time2,0:4:29,Check Out
i'm using windows application c#.net 2005
i want to calculate the number of hours spend by each enroll no.
each employee should workk 7 hours daily and make 182 hours monthly.if the made more than 182 hours will be overtime,if he made less than 182 hours will be deduction.the employee can take 4 or 5 days off each month.
i want to calculate the number of hours he made between 2 dates as he may comes on 30/4/2009 at 8 o'clock pm and leaves 12:00 am that will be on 1/5/2009.
i also want to make a combobox which has enroll no's and the user choose his number then his working hours will be displayed according to his number.i don't know if that possible or not because i'm using this text file.
Best regards,
emmy
|
|
|
|
|
Which part of doing this whole thing are you having trouble with?
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
this is the part of teh code i wrote but i can't have anything for an output
i don't know where is the mistake to make it work
StreamReader reader = new StreamReader(@"C:\new.txt");
string line;
while (null != (line = reader.ReadLine()))
{
string[] split = line.Split(new char[] { ';' });
string bit = split[0];
if (bit == Convert.ToString(EnrollNo))
{
date1 = System.Convert.ToDateTime(split[1]);
TimeSpan ts = new TimeSpan();
date2 = Convert.ToDateTime("0:3:43");
ts = date2.Subtract(date1);
listBox1.Items.Add(ts.Days + " Days " + ts.Hours + " Hours " + ts.Seconds + " Seconds ");
break;
}
}
reader.Dispose();
|
|
|
|
|
emmy_232003 wrote: string[] split = line.Split(new char[] { ';' });
emmy_232003 wrote: Enroll No,194,date2,30/4/2009,time2,0:3:38,Check Out
Enroll No,78,date2,30/4/2009,time2,0:3:43,Check Out
Enroll No,78,date1,30/4/2009,time1,9:44:47,Check In
Problem number one: there is no ';' character in your sample file. Lots of ',' characters, though.
Problem number two: the date info is not in the second section, it is in the 4th.
Fix those, then see what happens.
[edit]left the damn "encode html tags" on again![/edit]
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
i changed it as you said but still same problem.
i think date1 should be date1 = System.Convert.ToDateTime(split[1]);
i have date1 & date2 if you misunderstand.
StreamReader reader = new StreamReader(@"C:\new.txt");
string line;
while (null != (line = reader.ReadLine()))
{
string[] split = line.Split(new char[] { ',' });
string bit = split[0];
if (bit == Convert.ToString(EnrollNo))
{
date1 = System.Convert.ToDateTime(split[4]);
//date2 = System.Convert.ToDateTime(split[2]);
TimeSpan ts = new TimeSpan();
date2 = Convert.ToDateTime("0:3:43");
ts = date2.Subtract(date1);
// time1 = split[2];
listBox1.Items.Add(ts.Days + " Days " + ts.Hours + " Hours " + ts.Seconds + " Seconds ");
break;
// DateTime dtDate1 = new DateTime(2009, 30, 4, 9,44,52);
// DateTime dtDate2 = new DateTime(2009, 30, 4, 17,6,27);
// TimeSpan dtDiff = dtDate2 - dtDate1;
// MessageBox.Show(dtDiff.ToString());
// If you want the result in No of days
// MessageBox.Show(dtDiff.Days.ToString());
// Total Minutes in the TimeSpanstring
// minutes = dtDiff.TotalMinutes;
// Total Hours in the TimeSpanstring
// int minutes = dtDiff.TotalHours;
}
}
reader.Dispose();
|
|
|
|
|
Noo, no, no, no.
"The 4th section" does not mean "split[4]" - zero based index, remember?
emmy_232003 wrote:
Enroll No,194,date2,30/4/2009,time2,0:3:38,Check Out
Enroll No,78,date2,30/4/2009,time2,0:3:43,Check Out
Enroll No,78,date1,30/4/2009,time1,9:44:47,Check In
On the first line,
string[] split = line.Split(new char[] { ',' });
gives:
split[0] = "Enroll No"
split[1] = "194"
split[2] = "date2"
and so forth.
If you aren't sure, write them out, or check with the debugger.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
you are right
i made this
string[] allLines = System.IO.File.ReadAllLines(@"C:\new.txt");
for (int m = 0; m < allLines.Length; m++)
{
string eachRow = allLines[m].ToString();
string[] rowaArray = eachRow.Split(',');
string enrollID = rowaArray[1].ToString();
date1 = DateTime.Now;
// DateTime time1 = System.Convert.ToDateTime(rowaArray[5].ToString());
date2 = System.Convert.ToDateTime(rowaArray[3].ToString());
// DateTime time2 = System.Convert.ToDateTime(rowaArray[5].ToString());
rowaArray[3].ToString(); // Date
// rowaArray[5].ToString(); // Time
// string Datez = rowaArray[3].ToString() + " " + rowaArray[5].ToString();
TimeSpan ts = new TimeSpan();
// ts = time2.Subtract(time1);
ts = date2.Subtract(date1);
listBox1.Items.Add(ts.Days + " Days " + ts.Hours + " Hours " + ts.Seconds + " Seconds ");
}
but still can't have output as when i add this code
string Datez = rowaArray[3].ToString() + " " + rowaArray[5].ToString();
tells me that Index was outside the bounds of the array.
when i highlight it i have this as o/p
-27 Days -12 Hours -55 Seconds
-27 Days -12 Hours -55 Seconds
-27 Days -12 Hours -55 Seconds
-27 Days -12 Hours -55 Seconds
-27 Days -12 Hours -55 Seconds
-27 Days -12 Hours -55 Seconds
-27 Days -12 Hours -55 Seconds
-27 Days -12 Hours -55 Seconds
-27 Days -12 Hours -55 Seconds
-27 Days -12 Hours -55 Seconds
-27 Days -12 Hours -55 Seconds
-27 Days -12 Hours -55 Seconds
-27 Days -12 Hours -55 Seconds
-27 Days -12 Hours -55 Seconds
-27 Days -12 Hours -55 Seconds
-26 Days -12 Hours -55 Seconds
-26 Days -12 Hours -55 Seconds
-26 Days -12 Hours -55 Seconds
-26 Days -12 Hours -55 Seconds
i think it's wrong right
|
|
|
|
|
First, a couple of things to make both our lives easier.
1) Before you paste a code fragment, there is a check box above the "Post message" button, labeled "Encode HTML tags when pasting". If this has a tick in it, the greater than and less than signs are replaced with & g t ; and & l t ; - untick it before you paste a code fragment.
2) Just above the line of smileys is "code block" - this encases your code fragment in <pre> and </pre> so that formatting is preserved.
Without:
DateTime date1;
DateTime date2;
string[] allLines = System.IO.File.ReadAllLines(@"C:\XXTemp\new.txt.txt");
foreach (string eachRow in allLines)
{
string[] rowaArray = eachRow.Split(',');
string enrollID = rowaArray[1];
date1 = DateTime.Now;
date2 = System.Convert.ToDateTime(rowaArray[3] + " " + rowaArray[5]);
TimeSpan ts = date1.Subtract(date2);
MessageBox.Show(ts.Days + " Days " + ts.Hours + " Hours " + ts.Seconds + " Seconds ");
}
With:
DateTime date1;
DateTime date2;
string[] allLines = System.IO.File.ReadAllLines(@"C:\XXTemp\new.txt.txt");
foreach (string eachRow in allLines)
{
string[] rowaArray = eachRow.Split(',');
string enrollID = rowaArray[1];
date1 = DateTime.Now;
date2 = System.Convert.ToDateTime(rowaArray[3] + " " + rowaArray[5]);
TimeSpan ts = date1.Subtract(date2);
MessageBox.Show(ts.Days + " Days " + ts.Hours + " Hours " + ts.Seconds + " Seconds ");
}
As you can see, I have changed yours a little - but not too much.
Try to use foreach, rather than a for loop - it is more readable and obvious.
You don't need all those .ToString() convertions: they are already strings!
What you call "highlighting" I assume means "making it go green"? If so, this is called commenting out - it turns the line from something the compiler will read into something only people will read.
Without the 'rowaArray[3] + " " + rowaArray[5]' bit, you are always ignoring the time. I don't know why the index was outside the bounds of the array, but it might be worth adding some error checking to ensure the data in your file is in the format you are expecting, or a duff line could cause that error.
You don't need the "new TimeSpan()" as you are throwing it away on the next line!
I suspect the answers are "wrong right" because your subtract was the wrong way round!
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
thanks for replying me..but
i tried it as you said and no output at all.
do you think i should subtract the time instead of date?.
|
|
|
|
|
Could this be because I output to a MessageBox, instead of a ListBox?
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
noo i already changed it
<pre>
DateTime date1;
DateTime date2;
string[] allLines = System.IO.File.ReadAllLines(@"C:\new.txt");
foreach (string eachRow in allLines)
{
string[] rowaArray = eachRow.Split(',');
string enrollID = rowaArray[1];
date1 = DateTime.Now;
date2 = System.Convert.ToDateTime(rowaArray[3] + " " + rowaArray[5]);
//time1=
TimeSpan ts = date1.Subtract(date2);
//MessageBox.Show(ts.Days + " Days " + ts.Hours + " Hours " + ts.Seconds + " Seconds ");
//string Datez = rowaArray[3].ToString() + " " + rowaArray[5].ToString();
//DateTime Dt = Convert.ToDateTime(date2);
// ts = DateTime.Now - Dt; //// Here Give you hours days. minutes.. whatever you want at between 2 dates.
listBox1.Items.Add(ts.Days + " Days " + ts.Hours + " Hours " + ts.Seconds + " Seconds ");
}
</pre>
|
|
|
|
|
Odd. I do in mine, even if I add a ListBox.
What do you get? Do you get something, then an exception?
Try putting the MessageBox.Show back, and see if that gives anything.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
I won't be ignoring you - gotta go to a meeting... back in a few hours.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
I'm back. Is it working now?
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
hi there,
i made this
<pre>
string[] allLines = System.IO.File.ReadAllLines(@"C:\new.txt");
foreach (string eachRow in allLines)
{
try
{
string[] rowaArray = eachRow.Split(',');
string enrollID = rowaArray[1];
DateTime date1 = DateTime.Now;
DateTime date2 = Convert.ToDateTime(rowaArray[3] + " " + rowaArray[5]);
TimeSpan dtDiff = date1 - date2;
listBox1.Items.Add(dtDiff.Days + " Days " + dtDiff.Hours + " Hours " + dtDiff.Seconds + " Seconds ");
}
catch
(IndexOutOfRangeException ex)
{ }
}
</pre>
i got this output
28 Days 9 Hours 13 Seconds
28 Days 9 Hours 8 Seconds
27 Days 23 Hours 4 Seconds
27 Days 23 Hours 59 Seconds
27 Days 23 Hours 12 Seconds
27 Days 23 Hours 4 Seconds
27 Days 18 Hours 21 Seconds
27 Days 16 Hours 24 Seconds
27 Days 16 Hours 7 Seconds
27 Days 16 Hours 32 Seconds
27 Days 16 Hours 20 Seconds
27 Days 16 Hours 10 Seconds
27 Days 15 Hours 49 Seconds
27 Days 15 Hours 33 Seconds
27 Days 11 Hours 33 Seconds
27 Days 9 Hours 33 Seconds
27 Days 9 Hours 22 Seconds
26 Days 23 Hours 20 Seconds
26 Days 23 Hours 14 Seconds
26 Days 23 Hours 8 Seconds
26 Days 23 Hours 27 Seconds
is this correct? as i feel it's alphabetical.
i want to also ask.if i made a combobox with all employees numbers(enroll no).what event i should use inorder when i select the enroll no.the required number of hours is displayed.
|
|
|
|
|
It's not alphabetical, it is in order of the lines in your file.
I suspect that what you now need to do is tie your enrol no to "check in" and "check out" from your file, and collect the data for display. That bit is over to you, as I do not have the time to do all your homework for you!
The event you are looking for is (predictably enough) "SelectedIndexChanged"
Good luck!
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
hi,
i tranced the o/p i have.the output i have isn't logic.
as it's subtract the date/time for today 28/5/2009 from for example:
Enroll No,78,date2,30/4/2009,time2,0:3:43,Check Out
the result is
No:78 Hours 14minutes2 Seconds 34
i should change this
DateTime date1 = DateTime.Now;
to refer to date1 from the file not for DateTime.Now;
but if date1=Convert.ToDateTime(rowaArray[3] + " " + rowaArray[5]); as they are same.
the result will be 0.
have you any idea to change this ?
|
|
|
|
|
Yes. But you will hav eto do the work - it's not that hard!
Look at the data in the file you showed earlier:
Enroll No,194,date2,30/4/2009,time2,0:3:38,Check Out
Enroll No,78,date2,30/4/2009,time2,0:3:43,Check Out
Enroll No,78,date1,30/4/2009,time1,9:44:47,Check In
Enroll No,107,date1,30/4/2009,time1,9:44:52,Check In
Enroll No,108,date1,30/4/2009,time1,9:57:39,Check In
Enroll No,106,date1,30/4/2009,time1,10:40:47,Check In
Enroll No,109,date1,30/4/2009,time1,15:23:30,Check In
Enroll No,107,date2,30/4/2009,time2,17:6:27,Check Out
Enroll No,194,date1,30/4/2009,time1,17:9:44,Check In
Enroll No,132,date1,30/4/2009,time1,17:32:19,Check In
Enroll No,106,date2,30/4/2009,time2,17:35:31,Check Out
Enroll No,78,date2,30/4/2009,time2,17:35:41,Check Out
Enroll No,132,date1,30/4/2009,time1,17:45:2,Check In
Enroll No,108,date2,30/4/2009,time2,18:33:18,Check Out
Enroll No,109,date2,30/4/2009,time2,22:30:18,Check Out
Enroll No,194,date2,1/5/2009,time2,0:4:18,Check Out
Enroll No,132,date2,1/5/2009,time2,0:4:29,Check Out
Each line is a record:
Number 194 Checked out on 30/4/2009 @ 0:3;38
Number 78 Checked out on 30/4/2009 @ 0:3:43
Number 78 Cheked in on 30/4/2009 @ 9:44:47
and so forth...
This means you have to match up the check in with the appropriate check out, and work out the time difference - I am sure this is what the exercise you were set says (and I have never seen the exercise...)
The data you need is not all on one line. Think about what you have been taught in the course so far: I am sure that the structures and loops etc. cover what you need.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
can you suggest me a good book as i'm still a beginner.i take long time to think what the right thing to put.
i was reading visual c# steop by step..but didn't finish it yet.
thanks,
|
|
|
|
|
I can't - there are so many of them, and for a complete beginner I really don't know - I came to C# from C++, and all the way back to assembler, so I started with knowledge you don't have and the books I used presummed that knowledge. Anything called step-by-step is probably a good starting point!
Don't think of it in C# terms: try to think "How would I do this if it was on a piece of paper?"
I would:
Call this "The List":
Enroll No,194,date2,30/4/2009,time2,0:3:38,Check Out
Enroll No,78,date2,30/4/2009,time2,0:3:43,Check Out
Enroll No,78,date1,30/4/2009,time1,9:44:47,Check In
Enroll No,107,date1,30/4/2009,time1,9:44:52,Check In
Enroll No,108,date1,30/4/2009,time1,9:57:39,Check In
Enroll No,106,date1,30/4/2009,time1,10:40:47,Check In
Enroll No,109,date1,30/4/2009,time1,15:23:30,Check In
Enroll No,107,date2,30/4/2009,time2,17:6:27,Check Out
Enroll No,194,date1,30/4/2009,time1,17:9:44,Check In
Enroll No,132,date1,30/4/2009,time1,17:32:19,Check In
Enroll No,106,date2,30/4/2009,time2,17:35:31,Check Out
Enroll No,78,date2,30/4/2009,time2,17:35:41,Check Out
Enroll No,132,date1,30/4/2009,time1,17:45:2,Check In
Enroll No,108,date2,30/4/2009,time2,18:33:18,Check Out
Enroll No,109,date2,30/4/2009,time2,22:30:18,Check Out
Enroll No,194,date2,1/5/2009,time2,0:4:18,Check Out
Enroll No,132,date2,1/5/2009,time2,0:4:29,Check Out
Get a blank sheet of paper, and a pen.
Look at the first line of the list, make a note of the Enroll number (194).
Beside this, I would write the date and time (30/4/2009 @ 0:3:38) and that this was a check out.
Look at the next line, and do the same. If the Enroll number is already on my piece of paper, then I would add the information to that, otherwise note it down separately.
Continue through the list doing all the lines.
I would then have:
Enroll No194 30/4/2009 @ 0: 3:38,Check Out
Enroll No194 30/4/2009 @ 17: 9:44,Check In
Enroll No194 1/5/2009 @ 0: 4:18,Check Out
Enroll No132 30/4/2009 @ 17:32:19,Check In
Enroll No132 30/4/2009 @ 17:45: 2,Check In
Enroll No132 1/5/2009 @ 0: 4:29,Check Out
Enroll No109 30/4/2009 @ 15:23:30,Check In
Enroll No109 30/4/2009 @ 22:30:18,Check Out
Enroll No108 30/4/2009 @ 9:57:39,Check In
Enroll No108 30/4/2009 @ 18:33:18,Check Out
Enroll No107 30/4/2009 @ 9:44:52,Check In
Enroll No107 30/4/2009 @ 17: 6:27,Check Out
Enroll No106 30/4/2009 @ 10:40:47,Check In
Enroll No106 30/4/2009 @ 17:35:31,Check Out
Enroll No 78 30/4/2009 @ 0: 3:43,Check Out
Enroll No 78 30/4/2009 @ 9:44:47,Check In
Enroll No 78 30/4/2009 @ 17:35:41,Check Out
Now it is easy to see that:
No194 Checked in on 30/4/2009 @ 17: 9:44 and out on 1/5/2009 @ 0: 4:18
so he/she was checked in for some 7 hours.
No132 Checked in on 30/4/2009 @ 17:45: 2 and out on 1/5/2009 @ 0: 4:29
so they were in for 6 1/4 hours or so.
All you have to do is translate that into the C# instructions you do know! I can't tell you what those instructions are because I don't know what instructions you do know - please, do not give me a list. Just have a try, it doesn't have to be good (or even work properly to start with) - you obviously know more than you think, since you are correctly using DateTime and TimeSpan structures already!
Post up what you come up with, and I'm sure we can get it working together.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
hi,
sorry to disturb you again.actually i think text file won't be the ideal solution for me.the data you see before is from a finger print device.i can grasp it easily from the machine.i already tried to insert it into database but from the text file by using bulk insert.the problem is i will make update to the txt.file everytime an employee checked out or in.
I'm thinking now to make a database and make update on it or trigger.
I want to as how to grasp the data from the machine and insert into the database directly?
i just need steps...
thanks alot,
emmy,
|
|
|
|
|