|
sorry sir..i did nt understand much..i use mssql... front end C#.net..want to check date and time using C#.net..nd no need of saving time...on time basis dates are saved..
plz help me..
|
|
|
|
|
For a start learn to write a sentence. Do NOT use txt speak otherwise you will be ignored.
Do you know what the DateTime [^]data type is. Take a look at the examples on that page.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
{
DateTime dt = dateTimePicker1.Value.Date.Add(dateTimePicker1.Value.TimeOfDay);
string m = dateTimePicker1.Value.ToString("hh:mm tt", CultureInfo.InvariantCulture);
DateTime dtcheck = Convert.ToDateTime(m);
string n = "2:00 PM";
string s ="4:00 PM";
TimeSpan end = new TimeSpan(2,0,0);
TimeSpan dtstrt = new TimeSpan (4,0,0);
string dat = dateTimePicker1.Value.ToString("dd-MM-yyyy",CultureInfo.InstalledUICulture);
if (dateTimePicker1.Value.Date == DateTime.Today)
{
bool silenceAlarm = TimeBetween(DateTime.Now, end, dtstrt);
}
}
bool TimeBetween(DateTime datetime, TimeSpan start, TimeSpan end)
{
TimeSpan now = datetime.TimeOfDay;
if (now >= start)
return true;
else if (now >= end)
return false;
else return true;
}
i use above code...
|
|
|
|
|
DateTime dt = dateTimePicker1.Value.Date.Add(dateTimePicker1.Value.TimeOfDay);
string m = dateTimePicker1.Value.ToString("hh:mm tt", CultureInfo.InvariantCulture);
DateTime dtcheck = Convert.ToDateTime(m);
Why on earth would you convert a DateTime to a String, just so you can convert it back to a DateTime? If the values are not already in DateTime form, then convert them into it as soon as possible. You can then do a simple comparison to ensure the later is actually later than the earlier one. Mycroft has already given you the link to the documentation, please study it.
|
|
|
|
|
The DateTime structure always includes a "date" and "time" component.
You can however effectively ignore the time by using the ".Date" property: e.g.
Console.WriteLine( DateTime.Now.Date );
... displays: 3/16/2016 12:00:00 AM
And this works:
if ( dt1.Date == d2.Date) {}
etc.
|
|
|
|
|
{
DateTime resultdate = new DateTime();
DateTime dt = dateTimePicker1.Value.Date.Add(dateTimePicker1.Value.TimeOfDay);
string dts = DateTime.Now.Date.ToString("MM/dd/yyyy");
string dte = DateTime.Now.Date.ToString("MM/dd/yyyy");
string st = dts+" 04:00:00 PM" .ToString();
string end = dte+" 02:00:00 PM".ToString();
DateTime start = Convert.ToDateTime(st);
DateTime stop = Convert.ToDateTime(end);
if (dt >= start || dt <= stop)
{
if (dt >= start)
{
resultdate = dateTimePicker1.Value.Date.Add(dateTimePicker1.Value.TimeOfDay).AddDays(1);
}
else
resultdate = dt;
}
this is the answer...
|
|
|
|
|
There are other possibilities.
Also, if you are going to use a "value" in more than one place, and it has to be the same, then you need to re-think how you handle "Now"...
It is possible for dts and dte to have different "Now" .Date values due to interrupts (e.g. around midnight); do this instead:
DateTime now = DateTime.Now.Date;
DateTime start = now.AddHours( 16 );
DateTime stop = now.AddHours( 14 );
|
|
|
|
|
I have a simple console application that allows users to keep adding an employee to an array until they answer no to a prompt asking them if they want to add more employees.
Below is my code but it is only showing the first employee and not the subsequent employees that were added.
class Program
{
static void Main(string[] args)
{
Employee[] employees = new Employee[5];
int employeeCount = 0;
bool addMoreEmployees = true;
String answer = string.Empty;
while(addMoreEmployees)
{
Employee emp = new Employee();
emp.AddEmployee();
if (employees[employeeCount] == null)
{
employees[employeeCount] = emp;
}
employeeCount++;
Console.WriteLine("Do you want to add more employees?");
answer = Console.ReadLine().ToUpper();
if (answer == "NO" || employeeCount > 5)
{
addMoreEmployees = false;
}
}
foreach (Employee employee in employees)
{
Console.WriteLine("firstname: {0} \n" +
"lastname: {1} \n" +
"department: {2} \n" +
"salary: {3}",
employee.FirstName,
employee.LastName,
employee.Department,
employee.Salary
);
Console.ReadLine();
}
}
}
public class Employee
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Department { get; set; }
public double Salary { get; set; }
public void AddEmployee()
{
Console.WriteLine("Enter employee's firstname.");
this.FirstName = Console.ReadLine();
Console.WriteLine("Enter employee's lastname.");
this.LastName = Console.ReadLine();
Console.WriteLine("Enter employee's department.");
this.Department = Console.ReadLine();
Console.WriteLine("Enter employee's salary.");
this.Salary = Convert.ToDouble(Console.ReadLine());
}
}
|
|
|
|
|
In your code, Console.ReadLine() is called withing the loop. So you will only see next employee when you hit enter key. Just take out that line of code from the loop and you will be fine.
Also place a null check in the foreach loop or else it will throw NullReference exception.
"You'd have to be a floating database guru clad in a white toga and ghandi level of sereneness to fix this goddamn clusterfuck.", BruceN[ ^]
|
|
|
|
|
Thanks for your reply that did the trick.
|
|
|
|
|
Use XDocument to load xm, show on gridview and textbox, then modify and save xml
|
|
|
|
|
Ummm...you might want to ask a question instead of just ordering people around.
|
|
|
|
|
Christian Torres M wrote: Use XDocument to load xm, show on gridview and textbox, then modify and save xml Use the virtually unlimited space available in a message to provide a detailed question that allows people to understand what kind of help is needed.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
I have a need to retrieve a list of attached USB HID devices and query their details to populate a list. .Net makes it easy to get a list of devices:
ManagementObjectCollection collection;
using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_PnPEntity Where PNPDeviceID like 'HID%'"))
{
collection = searcher.Get();
}
I can then iterate over the items in the collection and query the properties. Unfortunately the properties do not include the device friendly name e.g. "Big Image Inc Reader".
Is there a native .Net way to get properties such as the friendly name?
I have code that can do this in C++ using DeviceIOControl etc, and it might be that the best approach is to write a non managed C++ wrapper class and invoke it from C#. But native code woud be 'cleaner'.
|
|
|
|
|
since WMI doesnt provide what you wish, I think you're stuck with the 'wrapper class' or P/Invoke methodology - two things that may provide inspiration are :-
Simple HID Library - Home[^]
and
HIDSharp[^]
|
|
|
|
|
Thanks Garth, and sorry to reply so late. The HIDSharp may well be the answer although I have written most of a COM wrapper anyway.
|
|
|
|
|
This is how I get the friendly name of my USB serial devices.
The friendly name is in the caption of the management objects. I get them like this:
List<string> usbSerial = new List<string>();
List<ManagementObject> listObj = new List<ManagementObject>();
try
{
string query = "SELECT * FROM Win32_PnPEntity WHERE ConfigManagerErrorCode = 0";
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
listObj = searcher.Get().Cast<ManagementObject>().ToList();
searcher.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
usbSerial = new List<string>();
}
foreach (ManagementObject obj in listObj)
{
object captionObj = obj["Caption"];
if (captionObj != null)
{
string caption = captionObj.ToString();
if (caption.Contains("(COM"))
{
usbSerial.Add(caption);
}
}
}
usbDevices = usbSerial.Distinct().OrderBy(s => s).ToArray();
Hope this can help,
Groover
0200 A9 23
0202 8D 01 80
0205 00
|
|
|
|
|
I have a shared dll (model.dll) and two executables using it. In teh model library i have a property. In the one executable i would like to set [ReadOnlyAttribute(false)] for the property and in the other executable i would like to set [ReadOnlyAttribute(true)]. Using the conditional compilation settings in the respertive project properties does not do the trick. Does anybody have a suggestion for me?
|
|
|
|
|
Conditional compilation is just that: a compile time operation.
If you have two exes using the same DLL, then they will have the same attributes, because the compilation is only done once and the same assembly is being referenced. You can't use it to switch attribute settings at run time!
If you want two different attribute settings, then you need to build two separate DLL files - which kinda defeats the point of having it as a DLL in the first place!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
that's clear! Thanks for the reply.
Is there realy no smart alternative you can think of?
(I use the propertyGrid control)
|
|
|
|
|
A decorator, or a TypeConverter that returns a specific set of properties depending on the EntryAssembly.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
As you stated in your last reply to OriginalGriff that you want to use this for a PropertyGrid: Take a look at this article: PropertyGrid utilities[^] - I saw a similar question on another website where one of the answerers said he solved it with the code from that article.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Agreed with OriginalGriff and Sascha, but the big question I would ask is: why do you want this?
Best,
John
-- Log Wizard - a Log Viewer that is easy and fun to use!
|
|
|
|
|
the one executable is meant for configution, the other for execution. When executing the operator must not be able to change the properties, but he can observe them.
|
|
|
|
|
Out of the top of my head, I think you should
- create some sort of ConfigurationAPI class that resides in your dll
- you can even apply some credentials at construction (just throw if credentials aren't right)
- then the properties you want to configure can all be "internal set" - this way, in your ConfigurationAPI class you can configure away
Best,
John
-- Log Wizard - a Log Viewer that is easy and fun to use!
|
|
|
|