<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">function Database()
{
	this._tables = {};
    this._tables.lotoDetails = {};
}

Database.prototype.executeActions = function(actions)
{
    if (util.getType(actions) !== "array")
    {
        actions = [actions];
    }

    //perform the commands on the client side db tables
    for (var i in actions)
    {
        var action = actions[i]

        //Determine location of table working on
        var table;
        switch (action.table)
        {
            case "TmpB_TemplateBase":
                table = this._tables["Temp_Template"];
                break;
            default:
                if (typeof this._tables[action.table] === "undefined")
                {
                    this._tables[action.table] = [];
                }
                table = this._tables[action.table];
        }

        //Perform action on table
        if (action.operation === "D") //Delete
        {
            delete table[action.id];
        }
        else if (action.operation === "I")
        {
            var inserted = table[action.temporaryId] = action.fieldsAndValues;
        }
        else if (action.operation === "U")
        {
            //i need to both replace the id in tables if it changes and not overwrite
            for (var x in action.fieldsAndValues)
            {
                table[action.id][x] = action.fieldsAndValues[x];
            }

            var idField = this.getPrimaryKey(action.table);
            if (action.fieldsAndValues[idField] &amp;&amp; action.id !== action.fieldsAndValues[idField])
            {
                var inserted = table[action.fieldsAndValues[idField]] = table[action.id];
                delete table[action.id];
            }
        }

        //Link up new inserts to lotoDetails if necessary
        if (typeof inserted !== "undefined")
        {            
            switch (action.table)
            {
                case "Loto_Loto":
                    var lotoId = inserted.Loto_Id;

                    if (typeof this._tables.lotoDetails[lotoId] === "undefined")
                    {
                        this._tables.lotoDetails[lotoId] = {};
                    }
                    if (typeof this._tables.lotoDetails[lotoId][action.table] === "undefined")
                    {
                        this._tables.lotoDetails[lotoId][action.table] = {};
                    }

                    this._tables.lotoDetails[lotoId].Loto_Loto[lotoId] = inserted;
                    if (action.operation === "U") delete this._tables.lotoDetails[lotoId][action.table][action.id];
                    break;
                case "Hist_History":
                    var lotoId = inserted.Hist_Loto_Id;
                    
                    if (typeof this._tables.lotoDetails[lotoId] === "undefined")
                    {
                        this._tables.lotoDetails[lotoId] = {};
                    }
                    if (typeof this._tables.lotoDetails[lotoId][action.table] === "undefined")
                    {
                        this._tables.lotoDetails[lotoId][action.table] = {};
                    }                    
                    
                    this._tables.lotoDetails[lotoId].Hist_History[inserted.Hist_Id] = inserted;
                    if (action.operation === "U") delete this._tables.lotoDetails[lotoId][action.table][action.id];
                    break;
                case "LoID_LotoIsoDevice":
                    var lotoId = inserted.LoID_Loto_Id;
                    
                    if (typeof this._tables.lotoDetails[lotoId] === "undefined")
                    {
                        this._tables.lotoDetails[lotoId] = {};
                    }
                    if (typeof this._tables.lotoDetails[lotoId][action.table] === "undefined")
                    {
                        this._tables.lotoDetails[lotoId][action.table] = {};
                    }                    
                    
                    this._tables.lotoDetails[lotoId].LoID_LotoIsoDevice[inserted.LoID_Id] = inserted;
                    if (action.operation === "U") delete this._tables.lotoDetails[lotoId][action.table][action.id];
                    break;
                case "Modi_Modification":
                    var lotoId = inserted.Modi_Loto_Id;

                    if (typeof this._tables.lotoDetails[lotoId] === "undefined")
                    {
                        this._tables.lotoDetails[lotoId] = {};
                    }
                    if (typeof this._tables.lotoDetails[lotoId][action.table] === "undefined")
                    {
                        this._tables.lotoDetails[lotoId][action.table] = {};
                    }
                    
                    this._tables.lotoDetails[lotoId].Modi_Modification[inserted.Modi_Id] = inserted;
                    if (action.operation === "U") delete this._tables.lotoDetails[lotoId][action.table][action.id];
                    break;
                case "MoID_ModificationIsoDevice":
                    var modiId = inserted.MoID_Modi_Id;

                    if (typeof this._tables.lotoDetails[lotoId] === "undefined")
                    {
                        this._tables.lotoDetails[lotoId] = {};
                    }
                    if (typeof this._tables.lotoDetails[lotoId][action.table] === "undefined")
                    {
                        this._tables.lotoDetails[lotoId][action.table] = {};
                    }
                    
                    var lotoId = this._tables.Modi_Modification[modiId].Modi_Loto_Id;
                    this._tables.lotoDetails[lotoId].Modi_Modification[modiId].MoID_ModificationIsoDevice[inserted.MoID_Id] = inserted;
                    if (action.operation === "U") delete this._tables.lotoDetails[lotoId].Modi_Modification[modiId][action.table][action.id];
                    break;
                case "ReOO_ReportingOnOff":
                    var lotoId = inserted.ReOO_Loto_Id;

                    if (typeof this._tables.lotoDetails[lotoId] === "undefined")
                    {
                        this._tables.lotoDetails[lotoId] = {};
                    }
                    if (typeof this._tables.lotoDetails[lotoId][action.table] === "undefined")
                    {
                        this._tables.lotoDetails[lotoId][action.table] = {};
                    }
                    
                    this._tables.lotoDetails[lotoId].ReOO_ReportingOnOff[inserted.ReOO_Id] = inserted;
                    if (action.operation === "U") delete this._tables.lotoDetails[lotoId][action.table][action.id];
                    break;
            }
        }
    }
}

Database.prototype.get = function(table, id, field)
{
    var ret = this._tables;

    if (typeof ret[table] === "undefined")
    {
        return null;
    }
    else
    {
        var ret = ret[table];
    }

    if (id)
    {
        if (typeof ret[id] === "undefined")
        {
            return null;
        }
        else
        {
            ret = ret[id];
        }
    }

    if (field)
    {
        if (ret[field] === "undefined")
        {
            return false;
        }
        else
        {
            ret = ret[field];
        }
    }

    return ret;
}

Database.prototype.getRowWhereFieldEqualsVal = function(table, field, value)
{
    for (var i in this._tables[table])
    {
        if ($.trim(this._tables[table][i][field]) == $.trim(value))
        {
            return this._tables[table][i];
        }
    }
}

Database.prototype.getRowsWhereFieldEqualsVal = function(table, field, value)
{
    var ret = [];
    for (var i in this._tables[table])
    {
        if ($.trim(this._tables[table][i][field]) == $.trim(value))
        {
            ret.push(this._tables[table][i]);
        }
    }
    return ret;
}

//Used to set the entire row or table.  Will delete all existing row values
Database.prototype.set = function(table, id, fieldsAndValues)
{
    if (typeof this._tables[table] == "undefined")
    {
        this._tables[table] = {};
    }

    if (typeof id === "object")
    {
        fieldsAndValues = id;
        id = null;
    }

    if (id)
    {
        this._tables[table][id] = fieldsAndValues;
    }
    else
    {
        this._tables[table] = fieldsAndValues;
    }

}

//Used to update a rows individual fields without overwriting the entire row
Database.prototype.update = function(table, id, fieldsAndValues)
{
    for (var i in fieldsAndValues)
    {
        this._tables[table][id][i] = fieldsAndVales[i];
    }
}

Database.prototype.getPrimaryKey = function(table)
{
    //this is kind of a hack, but it works unless table naming schemes are changed
    return table.substring(0, 5) + "Id";
}</pre></body></html>