|
In my login form i have loaded role dropdown from database.
When user clicks on login button (while not selecting any role from dropdown.)
i have to retain same login page. but again roles dropdown is loading from database.
How can i avoid database hit another time in login page when validation fails in login page ?
Please help me.
kranthikumar2555@gmail.com
Kranthikumar
|
|
|
|
|
|
You have a valid SMS Gateway to send to, you have a valid SMS Gateway Domain id, and there is no reason for that Gateway to reject a message from the originating party based on their location or any other factor: correct ?
If your end-users have the Skype client, have you considered the Skype API's: [^].
« There is only one difference between a madman and me. The madman thinks he is sane. I know I am mad. » Salvador Dali
modified 23-Oct-14 13:18pm.
|
|
|
|
|
I found this class on a forum...
How do I use it - I can't seem to callthe Difference method in bold text?
I'm currently trying...
DateDiff dateDiff = new DateDiff();
dateDiff.Difference((DateTime)StartDate, (DateTime)EndDate); // Doesn't Work
Many thanks for any help.
public class DateDiff
{
private int _Years = 0;
private int _Months = 0;
private int _Weeks = 0;
private int _Days = 0;
private int _Hours = 0;
private int _Minutes = 0;
private int _Seconds = 0;
public int Years { get { return _Years; } }
public int Months { get { return _Months; } }
public int Weeks { get { return _Weeks; } }
public int Days { get { return _Days; } }
public int Hours { get { return _Hours; } }
public int Minutes { get { return _Minutes; } }
public int Seconds { get { return _Seconds; } }
public override string ToString()
{
return String.Format("{0} year{1}, {2} month{3}, {4} week{5}, {6} day{7}, {8} hour{9}, {10} minute{11}, {12} second{13}"
, Years, Years != 1 ? "s" : ""
, Months, Months != 1 ? "s" : ""
, Weeks, Weeks != 1 ? "s" : ""
, Days, Days != 1 ? "s" : ""
, Hours, Hours != 1 ? "s" : ""
, Minutes, Minutes != 1 ? "s" : ""
, Seconds, Seconds != 1 ? "s" : ""
);
}
static public DateDiff Difference(DateTime dt1, DateTime dt2)
{
if (dt1 > dt2)
{
DateTime dtTemp = dt1;
dt1 = dt2;
dt2 = dtTemp;
}
DateDiff dd = new DateDiff();
dd._Years = dt2.Year - dt1.Year;
if (dd._Years > 0)
{
if (dt2.Month < dt1.Month)
{
dd._Years--;
}
else if (dt2.Month == dt1.Month)
{
if (dt2.Day < dt1.Day)
{
dd._Years--;
}
else if (dt2.Day == dt1.Day)
{
if (dt2.Hour < dt1.Hour)
{
dd._Years--;
}
else if (dt2.Hour == dt1.Hour)
{
if (dt2.Minute < dt1.Minute)
{
dd._Years--;
}
else if (dt2.Minute == dt1.Minute)
{
if (dt2.Second < dt1.Second)
{
dd._Years--;
}
}
}
}
}
}
dd._Months = dt2.Month - dt1.Month;
if (dt2.Month < dt1.Month)
{
dd._Months = 12 - dt1.Month + dt2.Month;
}
if (dd._Months > 0)
{
if (dt2.Day < dt1.Day)
{
dd._Months--;
}
else if (dt2.Day == dt1.Day)
{
if (dt2.Hour < dt1.Hour)
{
dd._Months--;
}
else if (dt2.Hour == dt1.Hour)
{
if (dt2.Minute < dt1.Minute)
{
dd._Months--;
}
else if (dt2.Minute == dt1.Minute)
{
if (dt2.Second < dt1.Second)
{
dd._Months--;
}
}
}
}
}
dd._Days = dt2.Day - dt1.Day;
if (dt2.Day < dt1.Day)
{
dd._Days = DateTime.DaysInMonth(dt1.Year, dt1.Month) - dt1.Day + dt2.Day;
}
if (dd._Days > 0)
{
if (dt2.Hour < dt1.Hour)
{
dd._Days--;
}
else if (dt2.Hour == dt1.Hour)
{
if (dt2.Minute < dt1.Minute)
{
dd._Days--;
}
else if (dt2.Minute == dt1.Minute)
{
if (dt2.Second < dt1.Second)
{
dd._Days--;
}
}
}
}
dd._Weeks = dd._Days / 7;
dd._Days = dd._Days % 7;
dd._Hours = dt2.Hour - dt1.Hour;
if (dt2.Hour < dt1.Hour)
{
dd._Hours = 24 - dt1.Hour + dt2.Hour;
}
if (dd._Hours > 0)
{
if (dt2.Minute < dt1.Minute)
{
dd._Hours--;
}
else if (dt2.Minute == dt1.Minute)
{
if (dt2.Second < dt1.Second)
{
dd._Hours--;
}
}
}
dd._Minutes = dt2.Minute - dt1.Minute;
if (dt2.Minute < dt1.Minute)
{
dd._Minutes = 60 - dt1.Minute + dt2.Minute;
}
if (dd._Minutes > 0)
{
if (dt2.Second < dt1.Second)
{
dd._Minutes--;
}
}
dd._Seconds = dt2.Second - dt1.Second;
if (dt2.Second < dt1.Second)
{
dd._Seconds = 60 - dt1.Second + dt2.Second;
}
return dd;
}
}
|
|
|
|
|
Why not use the .NET DateTime Structure[^] which offers such features, and more? And. more importantly, it is fully documented and supported.
|
|
|
|
|
Try:
DateDiff diff = DateDiff.Difference(dt1, dt2);
But...You do realize there is a TimeSpan structure already in the .NET framework?
MSDN[^]
So you could just say:
TimeSpan diff = dt2 - dt1;
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Thanks for replying. I realize there is a TimeSpan but it's no use to me as it doesn't show Weeks or Years elapsed and I need them.
Your example worked (many thanks) - I hadn't noticed that the method was static...
|
|
|
|
|
|
Many thanks for the link - It doesn't quite go far enough for me though as I also need access to the hours and seconds (which the class I posted gives me - [I need to test it though]).
|
|
|
|
|
DateTime and TimeSpan give you everything you want, as I said in my earlier post. But you do have to read the documentation.
|
|
|
|
|
imho, the code you found is very poorly written, and to attempt to modify it is a waste of time.
CodeProject has a C# library for every possible DateTime calculation of exceptional quality by Jani Giannoudis, "Time Period Library:" [^].
« There is only one difference between a madman and me. The madman thinks he is sane. I know I am mad. » Salvador Dali
|
|
|
|
|
You might want to verify your requirements first before attempting something like this.
For example how many "days" exist between the following periods? How many "hours"?How many "days"? And does the answer change if the time zone does?
- July 7, 23:40 to July 8, 00:15
- Dec 31, 23:40 to Jan 1, 00:15
These are often business requirements and depends on what business needs are.
As another extreme example if one needs seven "business" days around December 25th then what impacts do holidays and weekends have on what the actual span is.
|
|
|
|
|
Hi,
I would like to ask what protocol is used for Teamviewr? and how can I make simple application similar to it?
Thanks,
Jassim
Technology News @ www.JassimRahma.com
|
|
|
|
|
You can find some details here[^], and I seriously doubt you could make a simple application like it. It's a very complicated piece of software (and it's certainly not written in C#).
|
|
|
|
|
Still not figured out how to use Google[^]?
|
|
|
|
|
Still not figured out how to use Google[^]?
Please read my question again..!
Technology News @ www.JassimRahma.com
|
|
|
|
|
|
The Protocol is not simple at all. If you want to do something similar take a look at VNC. If you want to connect clients through firewalls and routers search for hole punching or take a look at azure service bus.
|
|
|
|
|
Using this code. What am I doing wrong? This is my first Add-in and I'm still learning C#, so please forgive stupid mistakes. Thanks.
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.DocumentChange += new ApplicationEvents4_DocumentChangeEventHandler(Application_DocumentChange);
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
private void Application_DocumentChange()
{
this.Application.ActiveDocument.TrackRevisions = true;
int n = this.Application.ActiveDocument.Revisions.Count;
Word.Range[] change = new Word.Range[n];
for (int i = 0; i < n; i++)
{
change[i] = this.Application.ActiveDocument.Revisions[i].Range;
change[i].Select();
change[i].Copy();
string changed = Clipboard.GetText(TextDataFormat.Text);
MessageBox.Show(changed);
}
}
The event handler gets called even before the document is opened.. thats the problem.. Document change occurs when a documentis opened(old/new) right?
Error is in the line:
change[i] = this.Application.ActiveDocument.Revisions[i].Range;
modified 23-Oct-14 2:03am.
|
|
|
|
|
Where in the code does the error occur? I would think this error is rather self-explanatory.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
sorry for the incomplete description.. Please have a look at the modified question..
|
|
|
|
|
Seems like a simple check for ActiveDocument being open is in order here.
There's got to be some property to check to see if there is a document open. Experiment. Look around.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I get what you're saying but what I'm asking is that, why is the DocumentChange event being fired when there is no open document?
|
|
|
|
|
I doubt anyone would be able to tell you that. Software development is full of things like this. The best thing you can do is find a workaround, such as checking to see if there's a document open.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Thank you so this problem is not due to a bug in the code I have written right?
|
|
|
|