Click here to Skip to main content
15,922,309 members
Home / Discussions / C#
   

C#

 
GeneralRe: dateTimePicker / smtp client Pin
OriginalGriff24-Oct-18 1:35
mveOriginalGriff24-Oct-18 1:35 
QuestionC# Socket TCP - Change the client class to send the file, and the server receives the file. Pin
Member 1181344422-Oct-18 6:13
Member 1181344422-Oct-18 6:13 
AnswerRe: C# Socket TCP - Change the client class to send the file, and the server receives the file. Pin
Afzaal Ahmad Zeeshan22-Oct-18 7:43
professionalAfzaal Ahmad Zeeshan22-Oct-18 7:43 
AnswerRe: C# Socket TCP - Change the client class to send the file, and the server receives the file. Pin
Richard MacCutchan22-Oct-18 21:37
mveRichard MacCutchan22-Oct-18 21:37 
QuestionCheque printing in winforms application using C# dotnet Pin
ccrenil20-Oct-18 1:43
ccrenil20-Oct-18 1:43 
AnswerRe: Cheque printing in winforms application using C# dotnet Pin
Afzaal Ahmad Zeeshan20-Oct-18 3:21
professionalAfzaal Ahmad Zeeshan20-Oct-18 3:21 
QuestionVery slow code in bar code reading Pin
Ali Alshihry19-Oct-18 14:57
Ali Alshihry19-Oct-18 14:57 
AnswerRe: Very slow code in bar code reading Pin
Dave Kreskowiak19-Oct-18 15:33
mveDave Kreskowiak19-Oct-18 15:33 
GeneralRe: Very slow code in bar code reading Pin
Ali Alshihry19-Oct-18 15:44
Ali Alshihry19-Oct-18 15:44 
GeneralRe: Very slow code in bar code reading Pin
Dave Kreskowiak19-Oct-18 15:58
mveDave Kreskowiak19-Oct-18 15:58 
Generalc# Identity Server 3: Set different Refresh Token Expiration for a specific user Pin
Member 1402363617-Oct-18 14:23
Member 1402363617-Oct-18 14:23 
QuestionApplication service with C#. Pin
Member 1401973516-Oct-18 20:55
Member 1401973516-Oct-18 20:55 
AnswerRe: Application service with C#. Pin
OriginalGriff16-Oct-18 21:16
mveOriginalGriff16-Oct-18 21:16 
GeneralRe: Application service with C#. Pin
Member 1401973516-Oct-18 22:09
Member 1401973516-Oct-18 22:09 
GeneralRe: Application service with C#. Pin
OriginalGriff16-Oct-18 22:13
mveOriginalGriff16-Oct-18 22:13 
GeneralRe: Application service with C#. Pin
Member 1401973516-Oct-18 22:46
Member 1401973516-Oct-18 22:46 
GeneralRe: Application service with C#. Pin
OriginalGriff16-Oct-18 23:02
mveOriginalGriff16-Oct-18 23:02 
GeneralRe: Application service with C#. Pin
Pete O'Hanlon16-Oct-18 23:59
mvePete O'Hanlon16-Oct-18 23:59 
AnswerRe: Application service with C#. Pin
#realJSOP22-Oct-18 9:03
professional#realJSOP22-Oct-18 9:03 
QuestionHow can I make my code modular? Pin
George Bradley16-Oct-18 12:43
George Bradley16-Oct-18 12:43 
AnswerRe: How can I make my code modular? Pin
V.16-Oct-18 18:44
professionalV.16-Oct-18 18:44 
GeneralRe: How can I make my code modular? Pin
henrydevid127-Oct-18 11:56
henrydevid127-Oct-18 11:56 
AnswerRe: How can I make my code modular? Pin
#realJSOP24-Oct-18 1:42
professional#realJSOP24-Oct-18 1:42 
0) Set the Tag property on each calc button to an appropriate (unique) integer index value, such as 1, 2, 3. etc

1) Set each calc button to use the same Click event handler

2) In the one-and-only Click event handler do something like this:

C#
private void Calc_Click(object sender,...)
{
    switch (Convert.ToInt32((Button)sender.Tag))
    {
        case 1 : MyCalcRoutine(1, txtTimeLimit1, txtEntryTime1, txtExitTime1); break;
        case 2 : MyCalcRoutine(2, txtTimeLimit2, txtEntryTime2, txtExitTime2); break;
        case 3 : MyCalcRoutine(3, txtTimeLimit3, txtEntryTime3, txtExitTime3); break;
    }
}


And finally, your generic calculation routine.

C#
private void MyCalcRoutine(int index, TextBox timeLimit, TextBox entryTime, TextBox exitTime)
{
    // I included the button index as the fist parameter in case you develop a need to do 
    // something that is button-specific in this method.

    string allotedTime = timeLimit.Text;
    string startTime   = entryTime.Text;
    string endTime     = exitTime;

    if (String.IsNullOrEmpty(allotedTime) || String.IsNullOrEmpty(startTime) || String.IsNullOrEmpty(endTime))
    {
        MessageBox.Show("Enter all time values");
    }
    else
    {
        TimeSpan alloted = TimeSpan.Parse(allotedTime);
        DateTime start = DateTime.Parse(startTime);
        DateTime end = DateTime.Parse(endTime);
        if (start > end)
        {
            end = end.AddDays(1);
        }
        TimeSpan duration = end.Subtract(start);

        //If the start time is greater than end that means the diff is above 12 hours
        //So subtracting the hours from a day to get the number of hours used 
        if (TimeSpan.Compare(alloted, duration) == -1)
        {
            overTime1++;
        }
        completeTime1++;
        lblOverTime1.Text = "" + overTime1;
        int percentage = (overTime1 * 100) / completeTime1;
        lblOverTimePercentage1.Text = "" + percentage;
        if (percentage > 50)
        {
            warnWarden();
        }
    }
}

".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

AnswerRe: How can I make my code modular? Pin
josda100026-Oct-18 18:29
josda100026-Oct-18 18:29 
GeneralRe: How can I make my code modular? Pin
josda100027-Oct-18 2:48
josda100027-Oct-18 2:48 

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.