There has to be cleaner code

There has to be cleaner code

Word of warning....this is kind of a long post.

In the past, I've tried being abstract in order to understand concepts, but I don't think my true intentions come through my posts, so here's what I'm working on.

I've created a stateless form called frmTimeSheetDataEntry (see design below).

Time Sheet Data Entry

What happens is this: when the user updates the intEventID, it follows this procedural flowchart (see below).


Procedural Flow Chart

I CAN get the form to do this procedure, but it is spaghetti code (see below).

  1. //1. User Updates intDuration
    //2. Does Event Data Exist?
    if (count(frmEvent[intEventID == input.intEventID])  >  0)
    {
        //2-Yes
        //4.Does Time Sheet Data Exist?
        if (count(frmTimeSheet[intEventID == input.intEventID])  >  0)
        {
            //4-Yes
            //6. Get Time Sheet Data
            varTimeSheetData  =  frmTimeSheet  [intEventID == input.intEventID];
            //7. Populate & Lock Fields
            input.optTypeOfCharge = varTimeSheetData.optTypeOfCharge;
            input.dtmStartTime = varTimeSheetData.dtmStartTime;
            input.dtmEndTime = varTimeSheetData.dtmEndTime;
            input.intDuration = varTimeSheetData.intDuration;
            input.memInvoiceDetail = varTimeSheetData.memInvoiceDetail;
            input.memBillDetail = varTimeSheetData.memBillDetail;
            input.chkInvoice = varTimeSheetData.chkInvoice;
            input.chkPayroll = varTimeSheetData.chkPayroll;
            disable intEventID;
        }
        else
        {
            //4-No
            //5. Add Time Sheet Data Record
            varEventData  =  frmEvent  [intEventID == input.intEventID];
            insert into frmTimeSheet
            [
                Added_User = zoho.loginuser
                dtmEndTime = varEventData.dtmEndTime
                dtmStartTime = varEventData.dtmStartTime
                intDuration = ((varEventData.dtmEndTime - varEventData.dtmStartTime)  /  (1000  *  60  *  60))
                intEventID = input.intEventID
                optTypeOfCharge = "Interpreting"
            ]
            //6. Get Time Sheet Data
            varTimeSheetData  =  frmTimeSheet  [intEventID == input.intEventID];
            //7. Populate & Lock Fields
            input.optTypeOfCharge = varTimeSheetData.optTypeOfCharge;
            input.dtmStartTime = varTimeSheetData.dtmStartTime;
            input.dtmEndTime = varTimeSheetData.dtmEndTime;
            input.intDuration = varTimeSheetData.intDuration;
            input.memInvoiceDetail = varTimeSheetData.memInvoiceDetail;
            input.memBillDetail = varTimeSheetData.memBillDetail;
            input.chkInvoice = varTimeSheetData.chkInvoice;
            input.chkPayroll = varTimeSheetData.chkPayroll;
            disable intEventID;
        }
    }
    else
    {
        //2-No
        //3. Display Alert
        alert("Event ID #: " + input.intEventID + " does not exist.  Please try again.");
    }

























































I'm wondering if there is anyone out there...looking at you Gaev...that can help me learn how to use functions for much of this as there are blocks of code that I will need to use again.  Is the procedural flow chart the right way to think about this, or is there a different method of thinking about it.

Thanks.


Leo Saumure