4 Replies - 271 Views - Last Post: 15 May 2019 - 10:12 AM Rate Topic: -----

#1 DarenR   User is offline

  • D.I.C Lover

Reputation: 617
  • View blog
  • Posts: 4,113
  • Joined: 12-January 10

in a quandary on how to proceed with a weird check

Posted 14 May 2019 - 11:47 AM

ok so this app i am making has the ability to add items and downtime which calculates the total minutes used in a hour

if the entries are greater than the hour then dont allow save --- this is done
it also checks to see if additional items being added will go over the hour -- this is done


the quandry

how can i code it so that if the hour is a different hour it will allow more input?

i tried storing the hour as a session variable and then checking current hour against that however it still runs the check for previous time entered instead of allowing items to be entered.


 Protected Sub saveHourBtn_onclick(sender As Object, e As EventArgs)

        txtProducedPounds.CssClass ="textboxStyle3"
        Dim msg As String =""
        _saveErrorMSG = ""

        if txtProducedPounds.Text = "" Then
            _saveErrorMSG = "Please fill in the Produced Tons"
            txtProducedPounds.CssClass = "textboxStyleError3"
            else
                Dim _newTime as Integer =  DateTime.Now.TimeofDay.Hours
                if Session("priorTime") < _newTime

                    ShowNextHourlyID()

                End If
               msg = CheckForExceedingMinutes()
            if msg <> "" Then
                
                _saveErrorMSG = lblHourError.Text &  "<br/>" & msg
                UpdateServerTime()
                clearFields()
                Else 

                
                   

                    saveHourlyTransaction()
                    clearFields()
                  
            End If
             
        End If
      
    End Sub


 Protected function CheckForExceedingMinutes()
       
        Dim _accountedMinutes as Decimal = 0.00
        Dim msg as String = ""
        Dim preSaveCheck As SaveData = new SaveData()
        Dim _PoundsAndDowntime As decimal = 0.00
        Dim _shiftID As Integer = convert.ToInt32(txtHourlyShiftID.text)
        Dim _ProductID as integer = ddlProduct.SelectedValue
        Dim _Trans_Date as DateTime = datetime.Now.Date.ToShortDateString()
        Dim _TransStartTime as String = ""
        Dim _PoundsPerHour as decimal = convert.ToDecimal(txtProducedPounds.text)
        Dim _plantId as Integer =Session("PlantID")
        Dim _HourlyAccountedMinutes as new LoadUnEditData
        Dim _previousavedItemMinutes As Decimal=0.00
        Dim _addedTotalMinutes As Decimal = 0.00
        Dim _hourlyID as Integer = convert.ToInt32(txtHourlyID.Text)

        For Each x As Control In reasonsTable.Controls
          
            If TypeOf x Is TableRow Then 
                for each tc as TableCell In x.Controls
                    for each con in tc.Controls
                        if TypeOf con Is TextBox
                            if con.text =""
                                msg = "Please enter minutes before proceeding"
                            else
                                 _accountedMinutes += Convert.ToDecimal(con.text)
                            end if
                        End If
                    Next
                Next
            End If
        Next

        if _accountedMinutes > 60
            _accountedMinutes = _accountedMinutes - 60
            msg = "The Reason minutes exceed 60 minutes by " & _accountedMinutes & " minutes"

        End If
        _PoundsAndDowntime = preSaveCheck.CheckSpentMinutesBeforeSaveHour(_shiftID,_plantId ,_ProductID,_PoundsPerHour, _accountedMinutes)
        
        if _PoundsAndDowntime > 60
            msg = "The Total minutes is or exceeds 60 minutes"
       
        '    msg = "You have reached 60 minutes of use in this hour"
        End If

        
        _previousavedItemMinutes = convert.ToDecimal(_HourlyAccountedMinutes.LoadHourlyProductAccountedMinutes(_shiftID).ToString())
        if _previousavedItemMinutes >= 60
            msg = "The Total minutes is or exceeds 60 minutes"
        End If
        _addedTotalMinutes = _PoundsAndDowntime + _previousavedItemMinutes

        if _addedTotalMinutes > 60

            msg = "The Total minutes is or exceeds 60 minutes"
        End If

        return msg
    End function



any thoughts on how i can have it allow saving if the hour isnt the same? im sure it is something simple i am over looking

Is This A Good Question/Topic? 0
  • +

Replies To: in a quandary on how to proceed with a weird check

#2 Sheepings   User is offline

  • D.I.C Lover
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,260
  • Joined: 05-December 13

Re: in a quandary on how to proceed with a weird check

Posted 14 May 2019 - 02:09 PM

Your question is unclear, and lacks information and clarity regarding which hour. You have a function and a method. Where does your problem reside? Where and What section of code is not doing what you want it to? Which section do you want to change?

At a glance, you should keep your functions tight and minimal, and perhaps make use of passing parameters to it? Most of the declarations in your function are interacting with your UI, so why not create a separate class for those objects declared within?

If this is a web project (which it appears to be), I suggest you track when the user session starts and then create a timer from that time counting down one hour. If the session interacts with a DB, include a timestamp of when the session started.

If you can be a bit clearer, I can try be a bit more precise and provide an example.
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6798
  • View blog
  • Posts: 28,102
  • Joined: 12-December 12

Re: in a quandary on how to proceed with a weird check

Posted 15 May 2019 - 12:50 AM

I agree that clarification is required, including what application type this is.

I glanced through your code and notice that there is a lot of manipulation of integers, decimals and strings. If you are performing time calculations then you should be working largely with DateTime, TimeSpan, and methods of these objects.
Was This Post Helpful? 0
  • +
  • -

#4 DarenR   User is offline

  • D.I.C Lover

Reputation: 617
  • View blog
  • Posts: 4,113
  • Joined: 12-January 10

Re: in a quandary on how to proceed with a weird check

Posted 15 May 2019 - 07:59 AM

i have done it in sql and i am directly passing the time to a function to determine if the time is good or not

as for the manipulation it is because the client doesnt know sql and they want to be able to see times in en 12 hour format with am/pm in the field which can only be varchar
Was This Post Helpful? 0
  • +
  • -

#5 Sheepings   User is offline

  • D.I.C Lover
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,260
  • Joined: 05-December 13

Re: in a quandary on how to proceed with a weird check

Posted 15 May 2019 - 10:12 AM

You could and should do some cleaning up first. Since you skipped my post, there isn't much more to say...

You do know tons are not measured in pounds?
if txtProducedPounds.Text = "" Then
08
           _saveErrorMSG = "Please fill in the Produced Tons"

There are 2000 pounds in a ton. :/ So what happens when they type in an amount in tons? That'll be an angry customer whom gets their delivery.

Also, if you have saved the session time, then you need to store it somewhere external to the database. As there is no point querying the database each time to extract the session start time. Once you have this value, you can compare the date times of the session to that of the executed countdown while using conditional operators. Seem simple and straight forward.

Is that pounds per weight or pounds per hour?

I ask because its very unclear when reading your database topic https://www.dreaminc...ost__p__2397820

The above looks like a typo?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1