Click here to Skip to main content
15,896,118 members
Home / Discussions / C#
   

C#

 
GeneralRe: Sugestion needed for information - WM 6.0 Pin
hisen30-Nov-09 14:18
hisen30-Nov-09 14:18 
GeneralRe: Sugestion needed for information - WM 6.0 Pin
Maxdd 730-Nov-09 14:20
Maxdd 730-Nov-09 14:20 
GeneralRe: Sugestion needed for information - WM 6.0 Pin
hisen30-Nov-09 15:13
hisen30-Nov-09 15:13 
QuestionBind ListView from SQL query Pin
Maxdd 730-Nov-09 13:34
Maxdd 730-Nov-09 13:34 
QuestionBest WinForm approach to presenting XML file in a pretty manner? Pin
sherifffruitfly30-Nov-09 13:32
sherifffruitfly30-Nov-09 13:32 
AnswerRe: Best WinForm approach to presenting XML file in a pretty manner? Pin
PIEBALDconsult30-Nov-09 14:01
mvePIEBALDconsult30-Nov-09 14:01 
GeneralRe: Best WinForm approach to presenting XML file in a pretty manner? Pin
sherifffruitfly30-Nov-09 14:21
sherifffruitfly30-Nov-09 14:21 
QuestionWeird behaviour by DateTime.Substract Pin
Saksida Bojan30-Nov-09 11:48
Saksida Bojan30-Nov-09 11:48 
Hello, I do not know why it is happening, but sometimes DateTime.Substract returns either 0 or 1, while parameter have same values

public bool bCodeChange1; // Used to stop double check of NumericUpDown
public bool bCodeChange2; // Used to stop Double check for DateTimePicker

/// <summary>
/// Sets DateTime to have Time At: 00:00:00:00 (HH:MM:SS:mil)
/// </summary>
/// <param name="time"></param>
/// <returns></returns>
private DateTime RemoveTime(DateTime time)
{
    time = time.AddHours(-time.Hour);
    time = time.AddMilliseconds(-time.Millisecond);
    time = time.AddMinutes(-time.Minute);
    time = time.AddSeconds(-time.Second);
    return time;
}

private void dateTimePickerDateDeadLine_ValueChanged(object sender, EventArgs e)
{
    DateTime dtDateDeadLine = dateTimePickerDateDeadLine.Value;
    DateTime dtDateReciet = dateTimePickerDateReciet.Value;
    dtDateDeadLine = RemoveTime(dtDateDeadLine );
    dtDateReciet = RemoveTime(dtDateReciet );

    if (dtDateRecit >= dtDateDeadLine )
    {
        MessageBox.Show("DeadLine need to be at least one day ahead of Reciet", "Račun", MessageBoxButtons.OK);
        dateTimePickerDateDeadLine.Value = dtDateReciet.AddDays(1);
        return;
    }

    if (bCodeChange2)
    {
        bCodeChange2 = false;
        return;
    }
    bCodeChange1 = true;

// Here lies the problem
// dtDateDeadLine: {30.11.2009 0:00:00}
// dtDateReciet: {1.12.2009 0:00:00}

// All works whell, unless i select at date, with same dates.
// In Both cases (Normaly and not Normaly) below line, gets the same values(As Above), but sometimes it gives 2 or 1.
// It gives a One in normal whay, however it will return true if this statemnt executes: 'if (dtDateRecit >= dtDateDeadLine )'
    numericUpDownDaysTillDeadLine.Value = dtDateDeadLine.Subtract(dtDateReciet).Days + 1; 
}

private void numericUpDownDaysTillDeadLine_ValueChanged(object sender, EventArgs e)
{
    if (bCodeChange1)
    {
        bCodeChange1 = false;
        return;
    }
    bCodeChange2 = true;
    numericUpDownDaysTillDeadLine.Value = dateTimePickerDateReciet.Value.AddDays(Convert.ToDouble(numericUpDownDaysTillDeadLine.Value));
}


I am so puzzled. Thanks goes in Advance.

PS: If variables names missmatches, you do not need to point out, because i nearly translated variable names, so that you can understand.
AnswerRe: Weird behaviour by DateTime.Substract Pin
Richard MacCutchan30-Nov-09 12:27
mveRichard MacCutchan30-Nov-09 12:27 
AnswerRe: Weird behaviour by DateTime.Substract Pin
Luc Pattyn30-Nov-09 12:29
sitebuilderLuc Pattyn30-Nov-09 12:29 
GeneralRe: Weird behaviour by DateTime.Substract Pin
Saksida Bojan30-Nov-09 20:09
Saksida Bojan30-Nov-09 20:09 
GeneralRe: Weird behaviour by DateTime.Substract Pin
Luc Pattyn1-Dec-09 0:17
sitebuilderLuc Pattyn1-Dec-09 0:17 
QuestionNested if statements Pin
Wheels01230-Nov-09 10:05
Wheels01230-Nov-09 10:05 
AnswerRe: Nested if statements Pin
Saksida Bojan30-Nov-09 10:17
Saksida Bojan30-Nov-09 10:17 
GeneralRe: Nested if statements Pin
Luc Pattyn30-Nov-09 10:23
sitebuilderLuc Pattyn30-Nov-09 10:23 
AnswerRe: Nested if statements Pin
Luc Pattyn30-Nov-09 10:17
sitebuilderLuc Pattyn30-Nov-09 10:17 
GeneralRe: Nested if statements Pin
Wheels01230-Nov-09 10:30
Wheels01230-Nov-09 10:30 
AnswerRe: Nested if statements Pin
Ravi Bhavnani30-Nov-09 11:00
professionalRavi Bhavnani30-Nov-09 11:00 
GeneralRe: Nested if statements Pin
JollyMansArt30-Nov-09 11:20
JollyMansArt30-Nov-09 11:20 
GeneralRe: Nested if statements Pin
Luc Pattyn30-Nov-09 11:27
sitebuilderLuc Pattyn30-Nov-09 11:27 
GeneralRe: Nested if statements Pin
Wheels0121-Dec-09 1:26
Wheels0121-Dec-09 1:26 
QuestionsplitContainer control Pin
JollyMansArt30-Nov-09 10:01
JollyMansArt30-Nov-09 10:01 
AnswerRe: splitContainer control Pin
Luc Pattyn30-Nov-09 10:21
sitebuilderLuc Pattyn30-Nov-09 10:21 
QuestionRe: splitContainer control Pin
JollyMansArt30-Nov-09 11:19
JollyMansArt30-Nov-09 11:19 
AnswerRe: splitContainer control Pin
Luc Pattyn30-Nov-09 11:24
sitebuilderLuc Pattyn30-Nov-09 11:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.