<%@ language="javascript"%> <% /* $Revision$ $Id$ */ %> <% protectRequest.validateToken(); FCLTHeader.Requires() var urole = getFParamSafe("urole", ""); // Indien niet meegegeven, veronderstel dan frontend gebruik var inskenmerkdeelkey = getFParamInt("inskenmerkdeelkey", -1); var inskenmerkkey = getFParamInt("inskenmerkkey", -1); var insdeelkey = getFParamInt("insdeelkey", -1); var date = getFParamDate("date", null); //var save_new_value = getFParamInt("save_new_value", 0) == 1; authparams = user.checkAutorisation("WEB_INSMAN"); %>
<% FCLTHeader.Generate(); %>
<% if (date) { var new_value = getFParamInt('new_value', -1); // New or changed histories have a time of H24:MM = 00:00 var ora_date1 = date.beginToSQL(); var aant = getFParamInt("count", -1); if (aant <= 0) { if (inskenmerkdeelkey == -1) { // no history is present (no current value) sql = "INSERT INTO ins_kenmerkdeel " + " (ins_kenmerkdeel_waarde, ins_deel_key, ins_kenmerk_key, ins_kenmerkdeel_aanmaak)" + " VALUES " + " (" + new_value + "," + insdeelkey + "," + inskenmerkkey + "," + ora_date1 + ")"; Oracle.Execute(sql); } else { // one history (current value) is present (inskenmerkdeelkey) sql = " SELECT kd.ins_kenmerkdeel_key" + ", kd.ins_kenmerkdeel_aanmaak" + " FROM ins_kenmerkdeel kd" + " WHERE kd.ins_kenmerkdeel_key = " + inskenmerkdeelkey + " AND " + ora_date1 + " < kd.ins_kenmerkdeel_aanmaak"; oRs = Oracle.Execute(sql); if (!oRs.eof) { // date is before the only one history present sql = "INSERT INTO ins_kenmerkdeel " + " (ins_kenmerkdeel_waarde, ins_deel_key, ins_kenmerk_key, ins_kenmerkdeel_aanmaak, ins_kenmerkdeel_verwijder)" + " VALUES " + " (" + new_value + "," + insdeelkey + "," + inskenmerkkey + "," + ora_date1 + "," + new Date(oRs("ins_kenmerkdeel_aanmaak").value).beginToSQL() + ")"; Oracle.Execute(sql); } else { // date is after the only one history present // update the only one history present sql = "UPDATE ins_kenmerkdeel SET" + " ins_kenmerkdeel_verwijder = " + ora_date1 + " WHERE ins_kenmerkdeel_key = " + inskenmerkdeelkey; Oracle.Execute(sql); // insert new value sql = "INSERT INTO ins_kenmerkdeel " + " (ins_kenmerkdeel_waarde, ins_deel_key, ins_kenmerk_key, ins_kenmerkdeel_aanmaak)" + " VALUES " + " (" + new_value + "," + insdeelkey + "," + inskenmerkkey + "," + ora_date1 + ")"; Oracle.Execute(sql); } } %>
<% } else { // find ins_kenmerkdeel_key where the new date is between aanmaak date and verwijder date sql = "SELECT kd.ins_kenmerkdeel_key" + ", kd.ins_deel_key" + ", kd.ins_kenmerk_key" //+ ", ins_kenmerkdeel_aanmaak" + ", ins_kenmerkdeel_verwijder" + " FROM ins_kenmerkdeel kd" + " WHERE kd.ins_kenmerkdeel_verwijder IS NOT NULL" + " AND kd.ins_deel_key = " + insdeelkey + " AND " + ora_date1 + " BETWEEN kd.ins_kenmerkdeel_aanmaak" + " AND kd.ins_kenmerkdeel_verwijder"; oRs = Oracle.Execute(sql); if (!oRs.eof) { // did find ins_kenmerkdeel_key // update present one sql = "UPDATE ins_kenmerkdeel SET" + " ins_kenmerkdeel_verwijder = " + ora_date1 + " WHERE ins_kenmerkdeel_key = " + oRs("ins_kenmerkdeel_key").value; Oracle.Execute(sql); // insert new value sql = "INSERT INTO ins_kenmerkdeel " + " (ins_kenmerkdeel_waarde, ins_deel_key, ins_kenmerk_key, ins_kenmerkdeel_aanmaak, ins_kenmerkdeel_verwijder)" + " VALUES " + " (" + new_value + "," + oRs("ins_deel_key").value + "," + oRs("ins_kenmerk_key").value + "," + ora_date1 + "," + new Date(oRs("ins_kenmerkdeel_verwijder").value).beginToSQL() + ")"; Oracle.Execute(sql); %>
<% } else { // did not find ins_kenmerkdeel_key // date is before or after all history // is date before all history sql = "SELECT kd.ins_kenmerkdeel_key" + ", ins_kenmerkdeel_aanmaak" + " FROM ins_kenmerkdeel kd" + " WHERE kd.ins_kenmerkdeel_verwijder IS NOT NULL" + " AND kd.ins_deel_key = " + insdeelkey + " AND " + ora_date1 + " < kd.ins_kenmerkdeel_aanmaak" + " ORDER BY ins_kenmerkdeel_aanmaak ASC" oRs = Oracle.Execute(sql); if (!oRs.eof) { // date is before all history // insert new value sql = "INSERT INTO ins_kenmerkdeel" + " (ins_kenmerkdeel_waarde, ins_deel_key, ins_kenmerk_key, ins_kenmerkdeel_aanmaak, ins_kenmerkdeel_verwijder)" + " VALUES " + " (" + new_value + "," + insdeelkey + "," + inskenmerkkey + "," + ora_date1 + "," + new Date(oRs("ins_kenmerkdeel_aanmaak").value).beginToSQL() + ")"; Oracle.Execute(sql); %>
<% } else { // is date after all history sql = "SELECT kd.ins_kenmerkdeel_key" + " FROM ins_kenmerkdeel kd" + " WHERE kd.ins_kenmerkdeel_verwijder IS NOT NULL" + " AND kd.ins_deel_key = " + insdeelkey + " AND " + ora_date1 + " > kd.ins_kenmerkdeel_verwijder" + " ORDER BY kd.ins_kenmerkdeel_verwijder DESC" oRs = Oracle.Execute(sql); if (!oRs.eof) { // date is after all history // update last history sql = "UPDATE ins_kenmerkdeel SET" + " ins_kenmerkdeel_verwijder = " + ora_date1 + " WHERE ins_kenmerkdeel_key = " + inskenmerkdeelkey; Oracle.Execute(sql); // insert new value sql = "INSERT INTO ins_kenmerkdeel " + " (ins_kenmerkdeel_waarde, ins_deel_key, ins_kenmerk_key, ins_kenmerkdeel_aanmaak)" + " VALUES " + " (" + new_value + "," + insdeelkey + "," + inskenmerkkey + "," + ora_date1 + ")"; Oracle.Execute(sql); %>
<% } else { // error __Log("Internal strange error: could not insert new value?"); Response.Write("

" + L("lcl_internal_error") + "

"); Response.End(); } } } } } %>
<% ASPPAGE_END(); %>