|
right now DateTime.Now.AddDays(365+30+1).ToString() returns 25-Oct-2010 1:11:42 on my system.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
The OP added a day when accessing the day, but not when accessing the month and year.
|
|
|
|
|
You're right of course.
And he shouldn't use multiple DateTime.Now calls anyway, it may fail around midnight.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
But he is only adding to the day variable:
string day = (DateTime.Now.AddDays(1).Day.ToString());
string month = (DateTime.Now.Month.ToString());
string year = (DateTime.Now.Year.ToString());
string date_nextDay = month + '/' + day + '/' + year;
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Ah... I saw the AddDays method and assumed that he would be using the returned DateTime instance so didn't look any more at the code.
Using three DateTime instances to create the string representations of a date's constituent parts is a WTF that I wasn't expecting!
|
|
|
|
|
DaveyM69 wrote: DateTime instances
WTF!
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
DaveyM69 wrote: I saw the AddDays method and assumed that he would be using the returned DateTime instance
So did I the first time I read it - just because thats the simple way to get it right
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Oh thankyou all 4 sharing your ideas.My problem is solved
thanks a lot
|
|
|
|
|
First, sorry my poor English.
goal: Modify and print an excel file that is being stored in a directory that is being observed.
Trouble: File Sharing.
Explain:
I have created a Windows service.This service contain a FileSystemWatcher Object who has got an "Created" delegate.
Code Constructor Service
Fsw = new FileSystemWatcher();
Fsw.Path = "c:\\DirListen";
Fsw.Filter = "*.xls";
Fsw.Created +=new FileSystemEventHandler(Fsw_Changed);
When the user save an excel file in "c:\\DirListen" the delegate is raised up and then I must modify the excel file and then print. The problem is that this file is being used by the SSOO (i Think) and I can't use it. I always get errors due to that delegate is raised up before the file has finished to save. I do not want to use timer objects, but with this problem... Please, any suggestion or solution?
Code Delegate
void Fsw_Changed(object sender, FileSystemEventArgs e)
{
try
{
Excel.Application oXL;
Excel._Workbook oWB;
Excel._Worksheet oSheet;
oXL = new Excel.Application();
oWB = oXL.Workbooks.Open(e.FullPath, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
object opc = Type.Missing;
oSheet = (Excel._Worksheet)oWB.Sheets.get_Item(2);
oSheet.Activate();
oSheet.Cells[1, 1] = "change";
oSheet.Cells[2, 4] = "another change";
oXL.Visible = true;
oSheet.PrintOut(1, 2, 1, false, "printer", true, false, Type.Missing);
FileStream fs2 = null;
StreamWriter sw2 = null;
oWB.Close(false, e.FullPath, Type.Missing);
oXL.Quit();
foreach (Process p in Process.GetProcessesByName("EXCEL"))
{
p.Kill();
}
}
catch (Exception ex)
{
FileStream fs = null;
StreamWriter sw = null;
fs = new FileStream("c:\\error.log", FileMode.CreateNew, FileAccess.Write);
sw = new StreamWriter(fs);
sw.WriteLine(ex.ToString());
}
}
Many Many Thanks.
regards
|
|
|
|
|
If I understand you correctly, you want to check if a file is in use. AFAIK, the .Net framework doesn't contain a class to do this. What about trying to open a file for exclusive read access, and catching the exception if it fails though?
File.Open(Path, FileMode.Open, FileAccess.ReadWrite, FileShare.None)
Source: here[^]
|
|
|
|
|
Hi,
yes FileSystemWatcher events fire when something changes about a file, which does not mean the file is ready for consumption. When you write a large file, you would get a Created event, and several Changed events. There is no event telling you the file operations have finished.
This basically means you need a delay; I would opt for a Created event handler with a retry loop containing a delay (say Thread.Sleep(100)) and your file operation; the retry loop should try say 10 times, then give up.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Many thanks,
end, It works. I have two possibilities.
1º Adding a Timer Object with an Elapsed delegated: When the delegate "change" that belongs to the FileSystemWatcher object is raised up, then I add the "e.fullname" to a global ListArray of String and reset the timer. Then when the timer is elapsed I consult the ListArray Object and work with entries (Names of Excel files). No problems about File Shared. Then do a clean ListArray object. I have not chosen this option. Not optimal.
2º Using an Thread.Sleep (xxx). Much faster and easier. I did not think about it. Many Thanks Luc Pattyn. I have chosen this option.
Thanks and regards
|
|
|
|
|
you're welcome.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Hi there,
I am working on projects which requires scanning data from scanner, format data,store selected data from scanned one to database. Any one with idea?
thanks
|
|
|
|
|
Dambod wrote: Any one with idea?
What is the problem then?
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Hi there,
I am working on projects which requires scanning data from scanner, format data,store selected data from scanned one to database. Any one with idea? I am looking for idea on how to read data from scanned one
|
|
|
|
|
Repeating the same useless statement does not change the fact the you've asked a VERY general question that isn't really answerable. Without further detail, like what you mean by "data" and how this data is supposed to be formatted, it's pretty impossible to answer your question.
|
|
|
|
|
Start by investigating the software that came with the scanner. Some of it can output into various formats e.g. Word, Excel etc. although I do not, personally, know of one that can do any DB formats.
If that is no joy then there are several 'form-reading' applications. Just google on open source form reader.
That should get you started.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
is that possible to
1. read data scanned based on some criteria,
2. put those data that meets the criteria to database?
3. if so, please some hint
thank u so much
|
|
|
|
|
As I said in my previous post, there is software (known as OCR software) that can scan data into, for example, Excel. If you can get the data into Excel, then it is relatively easy to filter it from there into a database. AFAIK you cannot scan selectively, it's either all or nothing.
As I also said there is a class of application that deals with producing forms that are filled in and then scanned. I believe these applications can use a database.
I gave you a search term for Google, and I suggest that you use that search term, read through the hits that you get until you find something that sounds likely and proceed from there.
There are enough hints in my two posts to give you a start. Try them out.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
You could buy something like TeleForm[^].
You create a template form that has alignment markers on it.
The software looks for the markers in the scanned image and uses them to locate the input fields specified when the template was created.
...cmk
The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.
- John Carmack
|
|
|
|
|
Hi!
I am creating an Excel Chart using C#. I have 2 series, and I would like one of them to have a seperate y axis on the right of the chart. Both axes should have different scales.
Excel 2003.
VS 2005.
I have a chart, and two series, but I can't see my second axis. It's like I never had one.
when creating my second series I do this:
elevationSeries.AxisGroup = XlAxisGroup.xlSecondary;
elevationSeries.Values = xlWorkSheet.get_Range ("C2", "C20");
elevationSeries.XValues = xlWorkSheet.getRange ("A2", "A20");
elevationSeries.Name = "Elevation";
Axis yAxis;
yAxis = (Excel.Axis)chartpage.Axes(Excel.XlAxisType.xlValues, Excel.XlAxisGroup.xlSecondary;
yAxis.HasTitle = true;
yAxis.AxisTitle.Text = "Elevation";
Thanks in advance.
|
|
|
|
|
I also encounter the same problem. But I think that the code here,
yAxis = (Excel.Axis)chartpage.Axes(Excel.XlAxisType.xlValues, Excel.XlAxisGroup.xlSecondary;
is only to retrieve the secondary axis unless you already set the secondary axis. Therefore there should be another function to enable the secondary axis. Do you solve the problem yet?
|
|
|
|
|
Hi i have an error in the Deserialize operation can you help me to solve it.
public class Employee
{
int id;
string name;
public int Id
{
get { return id; }
set { id = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
public void Show()
{
Console.WriteLine("Employee ID is " + Id);
Console.WriteLine("Employee name is " + Name);
}
}
static void Main(string[] args)
{
Employee[] emp = new Employee[3];
emp[0] = new Employee();
emp[0].Id = 10;
emp[0].Name = "x";
emp[1] = new Employee();
emp[1].Id = 20;
emp[1].Name = "y";
emp[2] = new Employee();
emp[2].Id = 30;
emp[2].Name = "x";
FileStream fs = new FileStream("123.txt", FileMode.Create);
XmlSerializer xs = new XmlSerializer(typeof(Employee[]));
xs.Serialize(fs, emp);
fs.Close();
}
static void Main(string[] args)
{
Employee[] emp = new Employee[3];
FileStream fs = new FileStream("123.txt", FileMode.Open);
XmlSerializer[] xs = new XmlSerializer[3];
for (int i = 0; i < emp.Length; i++)
{
xs[i] = new XmlSerializer(typeof(Employee));
emp[i] = new Employee();
emp[i] = (Employee)xs[i].Deserialize(fs);
emp[i].Show();
}
}
|
|
|
|
|
What is the error message ?
Probably you must use [Serializable] over the class Employee
[Serializable]
public class Employee
{
...
}
|
|
|
|