|
Okay thanks,
But why would DateTime TodayTest = DateTime.Now; produce the value "2006/09/11 12:00:00 PM" on my friend's computer but on mine it shows "11/09/2006". What could be the symptoms?
"Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
|
|
|
|
|
NarutoFan#1 wrote: But why would DateTime TodayTest = DateTime.Now; produce the value "2006/09/11 12:00:00 PM" on my friend's computer but on mine it shows "11/09/2006". What could be the symptoms?
DateTime , as I've already said, has no cultural bias. It has no display format. There are a few methods on DateTime that convert it into a culturally biased string. Most of these methods take the culture of the OS (i.e. what is in the control panel for how to display date and time information). The ToString() method on DateTime can be supplied with any format you like if you want to get specific. e.g. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
|
|
|
|
|
Naruto
You've asked the same question several times. I think you need to provide a little bit more information before we can help you.
Here's a few things to answer/think about:
What type of application is this? Is it WinForms or ASP.NET?
How are you attempting to print out the date? Have you printed out the DateTime.ToLongTimeString() to see if the time is there. BTW - you can't have a value of 14:00:00 PM;)
As I stated in an earlier answer to you, I suspect that your problem is the CurrentCulture. If you are using ASP.NET, then it is entirely possible that the problem is because the culture of the user that ASP.NET runs under is different to yours. To solve this, you can use a "clever" trick to sort this out.
In your Page_Load method, call the following routine:
public static void SetCulture(HttpRequest req)<br />
{<br />
if (req != null && req.UserLanguages != null && req.UserLanguages.Length > 0)<br />
{<br />
SetCulture((string)req.UserLanguages[0]);<br />
}<br />
}<br />
<br />
public static void SetCulture(string culture)<br />
{<br />
CultureInfo ci = new CultureInfo(culture);<br />
Thread.CurrentThread.CurrentCulture = ci;<br />
Thread.CurrentThread.CurrentUICulture = ci;<br />
}
If you call the first method, the user will get data presented to them in the culture that they have set up on their machine. So, somebody from France would probably get information back for the culture fr-FR. Now, calling the second method means that you can specify the culture explicitly, and the user will get information back in that culture, so the same French user would get back information with GB settings if you called SetCulture("en-GB");
Arthur Dent - "That would explain it. All my life I've had this strange feeling that there's something big and sinister going on in the world."
Slartibartfast - "No. That's perfectly normal paranoia. Everybody in the universe gets that."
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
No it's winforms. Thank you...i tried your previous example that you gave me...
CultureInfo culture = new CultureInfo("en-GB");<br />
<br />
DateTime dateTime = Convert.ToDateTime(_appDate+" "+startTime, culture);<br />
DateTime dateTime2 = Convert.ToDateTime(_appDate+" "+endTime, culture);
but this brought back the exact same date "11/09/2006" as when i tried just to
string _fromDateTime = _appDate+" "+startTime;<br />
string _endDateTime = _appDate+" "+endTime;<br />
FromTime = Convert.ToDateTime(_fromDateTime);<br />
ToTime = Convert.ToDateTime(_endDateTime);
but on my friends pc it brings back the value "2006/09/11 02:00:00 PM"
Sorry, in know i'm not explaing enough what my problem is but i'm not even sure what is wrong... its just when i try to compare to dates like in this example: if( _today>=vch.FromDate && _today <=vch.ToDate)
_today has the value of todays date... on my computer it is "11/09/2006" the value of vch.FromDate is "11/09/2006" and the value of vch.ToDate is "11/09/2006"... This if statement should return true... Am i right.
On my computer it returns false... ???? that is just one example... another one was yesterday's problem, but some how that sorted itself out... when the selected time "2006/09/11 02:00:00 PM" was writen into the database the the time would be inserted as AM but without the AM if that makes sense (like so: "2006/09/11 02:00:00.000)... Now it writes the time in the db correctly... "2006/09/11 14:00:00.000" Weird but true...
"Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
|
|
|
|
|
What is vch? Is it a calendar control or something? Could this be the source of your troubles?
Arthur Dent - "That would explain it. All my life I've had this strange feeling that there's something big and sinister going on in the world."
Slartibartfast - "No. That's perfectly normal paranoia. Everybody in the universe gets that."
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
the vch part is a class parameter. it is property in a class.
"Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
|
|
|
|
|
Naruto
Try the following wrapper class and test:
using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
<br />
namespace DateWrapper<br />
{<br />
public class WrappedDate<br />
{<br />
private DateTime? _dt = null;<br />
<br />
public WrappedDate()<br />
{<br />
}<br />
<br />
public WrappedDate(DateTime dt)<br />
{<br />
_dt = dt;<br />
}<br />
<br />
public WrappedDate(string dateOnly)<br />
: this(dateOnly, null)<br />
{<br />
}<br />
<br />
public WrappedDate(string date, string time)<br />
{<br />
if (string.IsNullOrEmpty(time))<br />
time = "00:00:00";<br />
if (!time.StartsWith(" "))<br />
time = " " + time;<br />
while (time.IndexOf(" ") > -1)<br />
{<br />
time = time.Replace(" ", " ");<br />
}<br />
try<br />
{<br />
_dt = Convert.ToDateTime(date + time);<br />
}<br />
catch (Exception ex)<br />
{<br />
_dt = null;<br />
}<br />
}<br />
<br />
public DateTime? Date<br />
{<br />
get { return _dt; }<br />
}<br />
<br />
}<br />
<br />
class Program<br />
{<br />
static void Main(string[] args)<br />
{<br />
WrappedDate start = new WrappedDate(DateTime.Now);<br />
WrappedDate dt = new WrappedDate("20/12/2006", "10:00:00");<br />
WrappedDate finish = new WrappedDate(DateTime.Now.AddHours(1));<br />
WrappedDate compare = new WrappedDate(DateTime.Now.AddMinutes(30));<br />
Console.WriteLine(dt.Date.ToString());<br />
<br />
if (compare.Date >= start.Date && compare.Date <= finish.Date)<br />
Console.WriteLine("Success");<br />
else<br />
Console.WriteLine("Failure");<br />
Console.ReadLine();<br />
}<br />
}<br />
}
Arthur Dent - "That would explain it. All my life I've had this strange feeling that there's something big and sinister going on in the world."
Slartibartfast - "No. That's perfectly normal paranoia. Everybody in the universe gets that."
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi Pete, i have great news...
The problem is only on my pc. As soon as i build and install onto another pc it works fine...
The variable shows me the wrong values in the debugger but somehow it contains the correct values and writes these correct values into the database.
The problem still eludes me, but for now it at least works on the client's computers.
Thank you for taking the time to help out...
Regards
Nico
"Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
|
|
|
|
|
That's great news.
I'll have a think about it some more, but it sounds as though the problem might have been with the debugger. As long as the info gets written properly, then that's all right.
Arthur Dent - "That would explain it. All my life I've had this strange feeling that there's something big and sinister going on in the world."
Slartibartfast - "No. That's perfectly normal paranoia. Everybody in the universe gets that."
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hello!
I have a panel with 2 buttons and it has to be possible for user, resize and change location (Drag&Drop) of buttons.
Do you have some tipps for me?
|
|
|
|
|
Have a look here:
http://www.codeproject.com/vb/net/RuntimeMovableControls.asp
Mark
|
|
|
|
|
Thank you for your answer.
The idea is nice, and I will take it, if I don't find a "standard" solution for C#..
Is there a standard solution for this problem?
|
|
|
|
|
Hi,
The background:
I have a class "Search" that has a collection in it. This collection is of type "criteria", where "criteria" is an abstract class. The reason being is that i have some concrete classes "IntCriteria", "StringCriteria", "BoolCritera" that i want stored in the collection and they all inherit from "criteria".
To the problem:
I bind "Search" to a property grid, it works fine and i can see/edit all the properties of search, but when i try i add an item to the collection of "criteria" i cant because it does not know what concrete classes to give me as the option to add (see here http://img242.imageshack.us/img242/5803/exampleko9.jpg to see what i want, this is to add columns to a data grid view). Is there a way i can tag "IntCriteria", "StringCriteria" and "BoolCritera" so that the property grid sees them as a type of "criteria".
if not then, is there anyway i can list "IntCriteria", "StringCriteria" or"BoolCritera" in the add new item screen.
Hope that made sense!!!
To Recreate the problem, make a windows application, create this file (i have put multiple classes in one file for ease)(its only example code, not my actual code!)
<br />
using System;<br />
<br />
using System.Collections.Generic;<br />
<br />
using System.Text;<br />
<br />
using System.Collections;<br />
<br />
namespace TestApp<br />
<br />
{<br />
<br />
public class Search<br />
<br />
{<br />
<br />
private string _A;<br />
<br />
private string _B;<br />
<br />
private CriteriaCollection _cc = new CriteriaCollection();<br />
<br />
public string A<br />
<br />
{<br />
<br />
get { return _A; }<br />
<br />
set { _A = value; }<br />
<br />
}<br />
<br />
public string B<br />
<br />
{<br />
<br />
get { return _B; }<br />
<br />
set { _B = value; }<br />
<br />
}<br />
<br />
public CriteriaCollection cc<br />
<br />
{<br />
<br />
get { return _cc; }<br />
<br />
set { _cc = value; }<br />
<br />
}<br />
<br />
public Search()<br />
<br />
{<br />
<br />
}<br />
<br />
}<br />
<br />
public class CriteriaCollection : CollectionBase<br />
<br />
{<br />
<br />
public CriteriaCollection()<br />
<br />
{<br />
<br />
}<br />
<br />
public void Add(Criteria C)<br />
<br />
{<br />
<br />
this.InnerList.Add(C);<br />
<br />
}<br />
<br />
public void Remove(Criteria element)<br />
<br />
{<br />
<br />
InnerList.Remove(element);<br />
<br />
}<br />
<br />
public Criteria this[int index]<br />
<br />
{<br />
<br />
get { return (Criteria)InnerList[index]; }<br />
<br />
}<br />
<br />
public void CopyTo(Criteria[] target, int index)<br />
<br />
{<br />
<br />
InnerList.CopyTo(target, index);<br />
<br />
}<br />
<br />
public int IndexOf(Criteria element)<br />
<br />
{<br />
<br />
return InnerList.IndexOf(element);<br />
<br />
}<br />
<br />
public bool Contains(Criteria element)<br />
<br />
{<br />
<br />
return InnerList.Contains(element);<br />
<br />
}<br />
<br />
public void Insert(int index, Criteria element)<br />
<br />
{<br />
<br />
InnerList.Insert(index, element);<br />
<br />
}<br />
<br />
}<br />
<br />
<br />
<br />
public abstract class Criteria<br />
<br />
{<br />
<br />
private string _C;<br />
<br />
private string _D;<br />
<br />
<br />
public string C<br />
<br />
{<br />
<br />
get<br />
<br />
{<br />
<br />
return _C;<br />
<br />
}<br />
<br />
set<br />
<br />
{<br />
<br />
_C = value;<br />
<br />
}<br />
<br />
}<br />
<br />
public string D<br />
<br />
{<br />
<br />
get<br />
<br />
{<br />
<br />
return _D;<br />
<br />
}<br />
<br />
set<br />
<br />
{<br />
<br />
_D = value;<br />
<br />
}<br />
<br />
}<br />
<br />
}<br />
<br />
<br />
public class IntCriteria : Criteria<br />
<br />
{<br />
<br />
public IntCriteria()<br />
<br />
{<br />
<br />
<br />
}<br />
<br />
public int DoSomeIntStuff()<br />
<br />
{<br />
<br />
return 0;<br />
<br />
}<br />
<br />
}<br />
<br />
<br />
<br />
<br />
public class StringCriteria : Criteria<br />
<br />
{<br />
<br />
public StringCriteria()<br />
<br />
{<br />
<br />
}<br />
<br />
public string DoSomeStringStuff()<br />
<br />
{<br />
<br />
return "Stuff done";<br />
<br />
}<br />
<br />
}<br />
<br />
<br />
public class BoolCriteria : Criteria<br />
<br />
{<br />
<br />
<br />
public BoolCriteria()<br />
<br />
{<br />
<br />
}<br />
<br />
public bool DoSomeBooleanStuff()<br />
<br />
{<br />
<br />
return true;<br />
<br />
}<br />
<br />
}<br />
<br />
}<br />
<br />
Then on a form add a property grid and add
<br />
private void Form1_Load(object sender, EventArgs e)<br />
<br />
{<br />
<br />
Search s = new Search();<br />
<br />
this.propertyGrid1.SelectedObject = s;<br />
<br />
}<br />
<br />
Run the form and try and add and item to cc in the property grid
TIA
Mark
|
|
|
|
|
Hi,
first create a class inheriting from CollectionEditor and override CreateNewItemTypes. The result should be an array of types which should be choosable.
Then add this attribute to your collection class:
[Editor(typeof(CriteriaCollectionEditor), typeof(System.Drawing.Design.UITypeEditor))]
public class CriteriaCollection : CollectionBase {
}
If you are lucky that's all you need to do .
Robert
|
|
|
|
|
WOW, nice 1, works a dream
Thanks, that has been the downfall of app and now its all working great.
I would have never worked that out by my self
Mark
|
|
|
|
|
I’m i bit stuck in my design.
It’s just that I not very familiar with XML programming in .NET.
Things is I’m creating a XMPP library in .NET. I have a working version dut I does not macth my demants.
What I want is a base xmpp element which it self extends some kind of XML element. This way I can easily set parameters en add sub element. But now the question, which element should I extend. I’ve tried XmlElement, but I don’t have a general XmlDocument in my project, nor can I. I could extend XmlDocument but this is overkill. I use the XmlTextReader to grab XML from the stream. I tried to extend XmlNode but I had no idea how to implement the abstract methods like name en such
Can any one point me in the write direction?
Tnx Remmelt
|
|
|
|
|
Hi
In my project i want to use an grid control which has abillity to add, edit, and remove rows
in the same manner what it do watch window in visual studio. In the beggining i suppose
what it can be achived throught ListView control, but unfortunately this control rather diffrent from my objective: one not have ability to add and remove rows in run-time and when i try to edit an column it is necessary what cell arlready have an value (at that this occur in creeper manner,
when i click by item which pretend to edit one responde only through an signifficant time).
Please advice me is exist an control which imitate VS Watch Window and where i can download one???
Or maiby some one already implement customization of ListView for similary purpose.
Thank.
|
|
|
|
|
hi all
i'm trying to access data from a datagrid. the datagrid contains the data of a datatable. how can i do it???
another problem is that i'm trying to show the contents of the datatable in a combo box.
the code i'm using is
if(results != null)<br />
{<br />
Databasecb.DataSource=results;<br />
}
the result is vey odd. instead of displaying the values in the datatable, the combo is filled with
System.Data.DataRowView
a multiple no of the times.
reply soon
|
|
|
|
|
to select data from datagrid try out
dataGrid1[row number,column number].ToString();
and to bind combo box try
Databasecb.DataSource=results.Table["table name"];
Databasecb.DisplayMeember="column name to display";
rahul
|
|
|
|
|
rahul
i tried doing what u sugested with the combo bue there is no option of results.Table["Table name"] so i tried Databasecb.DataSource=results.TableName;
however this gives me the following exception
Complex DataBinding accepts as a data source either an IList or an IlistSource
Saira
|
|
|
|
|
if Databasecb is datatable or dataview then try
Databasecb.DataSource=results;
Databasecb.DisplayMember="column name to display";
rahul
|
|
|
|
|
thanks rahul
u just solved the problem
Saira
|
|
|
|
|
My project requires to change Default Web Site of IIS to other name (example: medi) for browse http://medi instead of http://localhost. I don't know how to code in C#. Please give me a clue to solve.
Thanks.
|
|
|
|
|
Perhaps you can add the domain in the host file if you only want the name on your local machine.
If it is a network wide setting, you have to do it in your dns settings.
|
|
|
|
|
Hi,
Recently I have been working on creating an ActiveX DLL (for performing Image Scan using TWAIN and C#) which could be invoked using a Javascript call from an HTML page and the scanned image could be displayed within the page. I got most of the things but when I invoke the TWAIN driver, it displays the scanning control, I can perform New Scan multiple times within it but when I click at Accept nothing happens, the same code works perfectly when I invoke it from a Windows Form.
I trapped Windows Messages, it seems that when I do a call to the ActiveX from HTML it does not send any message back when I click Accept in the Scanning control.
The code for using TWAIN scanning using C# writtem by NETMaster was the guide for my current activity.
Help would be highly appreciated.
Regards,
|
|
|
|