public bool Import(string sUserID, string sTaskIDs, ref string sErr) { string sSQL = ""; dataAccess.acTransaction oTrans = new dataAccess.acTransaction(ref sErr); //we're doing this in a loop //why? because each row may have different import requirements //(overwrite, new version, etc.) //Now we are adding different import types not necessarily tied to task/proc. //for now we're still just doing it all here until there's a good reason to split it out if (sTaskIDs.Length > 0) { sSQL = "select task_id, task_code, task_name, import_mode from import_task" + " where user_id = '" + sUserID + "'" + " and task_id in (" + sTaskIDs + ")"; DataTable dt = new DataTable(); if (!dc.sqlGetDataTable(ref dt, sSQL, ref sErr)) { throw new Exception(sErr); } if (dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { string sTaskID = dr["task_id"].ToString(); string sNewTaskID = dr["task_id"].ToString(); string sTaskCode = dr["task_code"].ToString(); string sImportMode = dr["import_mode"].ToString(); string sOTID = ""; int iCount = 0; switch (sImportMode) { case "New": //just jam in the new row, IF there are no GUID conflicts. //~~~ NEW tasks get manipulated. //* MIGHT have their ID changed if there's a collision //* WILL have the original_task_id reset //* WILL have the version reset to 1.000 //* WILL be loaded as 'Development' status //* WILL be the default version //check ID oTrans.Command.CommandText = "select count(*) from task" + " where task_id = '" + sTaskID + "'"; if (!oTrans.ExecGetSingleInteger(ref iCount, ref sErr)) { throw new Exception("Unable to check for GUID conflicts.<br />" + sErr); } //if there's a GUID conflict then just generate a new guid for this task. if (iCount > 0) { sNewTaskID = ui.NewGUID(); } //check the steps to see if there are any GUID conflicts //and repair them if necessary if (!ReIDSteps(ref oTrans, sUserID, sTaskID, ref sErr)) { throw new Exception("Unable to issue new Step GUIDs.<br />" + sErr); } //insert the manipulated TASK oTrans.Command.CommandText = "insert into task" + " (task_id, original_task_id, version," + " task_name, task_code, task_desc, task_status," + " use_connector_system, default_version," + " concurrent_instances, queue_depth, parameter_xml, created_dt)" + " select" + " '" + sNewTaskID + "', '" + sNewTaskID + "', 1.000," + " task_name, task_code, task_desc, 'Development'," + " use_connector_system, 1," + " concurrent_instances, queue_depth, parameter_xml, created_dt" + " from import_task" + " where user_id = '" + sUserID + "'" + " and task_id = '" + sTaskID + "'"; if (!oTrans.ExecUpdate(ref sErr)) { throw new Exception(sErr); } ui.WriteObjectAddLog(Globals.acObjectTypes.Task, sNewTaskID, dr["task_code"].ToString() + " - " + dr["task_name"].ToString(), "New - Created via Import"); break; case "New Version": //if it's a new version, we need to make sure the "original_task_id" //is correct in the target database. //(no guarantee the original_id in the source db is correct.) //just jam in the new row, IF there are no GUID conflicts. //~~~ NEW VERSION tasks get manipulated. //* MIGHT have their ID changed if there's a collision //* MIGHT have the original_task_id reset (to match the target) //* WILL have the version reset to the user selection //* WILL be loaded as 'Development' status //* WILL NOT be the default version //check ID oTrans.Command.CommandText = "select count(*) from task" + " where task_id = '" + sTaskID + "'"; if (!oTrans.ExecGetSingleInteger(ref iCount, ref sErr)) { throw new Exception("Unable to check for GUID conflicts.<br />" + sErr); } //if there's a GUID conflict then just generate a new guid for this task. //and re-id the steps if (iCount > 0) { sNewTaskID = ui.NewGUID(); } //check the steps to see if there are any GUID conflicts //and repair them if necessary if (!ReIDSteps(ref oTrans, sUserID, sTaskID, ref sErr)) { throw new Exception("Unable to issue new Step GUIDs.<br />" + sErr); } //NOW, we need to make sure this task is connected to it's family //we do this by ensuring the original_task_id matches. //BUT, we got here by assuming the task_code was the key. //so... find the original_task_id for this task_code oTrans.Command.CommandText = "select original_task_id" + " from task where task_code = '" + sTaskCode + "' limit 1"; if (!oTrans.ExecGetSingleString(ref sOTID, ref sErr)) { throw new Exception("Unable to get original task ID for [" + sTaskCode + "].<br />" + sErr); } //insert the manipulated TASK oTrans.Command.CommandText = "insert into task" + " (task_id, original_task_id, version," + " task_name, task_code, task_desc, task_status," + " use_connector_system, default_version," + " concurrent_instances, queue_depth, parameter_xml, created_dt)" + " select" + " '" + sNewTaskID + "', '" + sOTID + "', version," + " task_name, task_code, task_desc, 'Development'," + " use_connector_system, 0," + " concurrent_instances, queue_depth, parameter_xml, created_dt" + " from import_task" + " where user_id = '" + sUserID + "'" + " and task_id = '" + sTaskID + "'"; if (!oTrans.ExecUpdate(ref sErr)) { throw new Exception(sErr); } ui.WriteObjectAddLog(Globals.acObjectTypes.Task, sNewTaskID, dr["task_code"].ToString() + " - " + dr["task_name"].ToString(), "New Version - Created via Import"); break; /* * Note: I stopped here because I'm not convinced that "Overwrite" is a safe or useful * feature. * * So, we'll come back to it if needed. * * Be aware, this was pseudocode... it never worked, was just placeholder stuff and ideas. */ //case "Overwrite": // //stomp it, but make sure to set the task_id/original_task_id // //to match in the target db. // //just because the code matches doesn't mean the ID's do. // //we can just UPDATE the task row // //DON'T FORGET to DELETE the existing steps and codeblocks // //we need to make sure the "original_task_id" // //is correct in the target database. // //(no guarantee the original_id in the source db is correct.) // //~~~ OVERWRITE tasks get manipulated. // //* MIGHT have their ID changed to match the code/version being imported // //* MIGHT have the original_task_id reset (to match the target) // //* WILL have the version reset to the user selection // //* WILL be loaded as 'Development' status // //* MIGHT be the default version (not gonna update that value) // //NOW, we need to make sure this task is connected to it's family // //we do this by ensuring the original_task_id matches. // //BUT, we got here by assuming the task_code was the key. // //so... find the task AND original_task_id for this task_code // oTrans.Command.CommandText = "select top 1 task_id" + // " from task where task_code = '" + sTaskCode + "'"; // if (!oTrans.ExecGetSingleString(ref sNewTaskID, ref sErr)) // throw new Exception("Unable to get task ID for [" + sTaskCode + "].<br />" + sErr); // oTrans.Command.CommandText = "select top 1 original_task_id" + // " from task where task_code = '" + sTaskCode + "'"; // if (!oTrans.ExecGetSingleString(ref sOTID, ref sErr)) // throw new Exception("Unable to get original task ID for [" + sTaskCode + "].<br />" + sErr); // //get a datareader on the import_task row // sSQL = "select task_desc, manual_or_digital, use_connector_system," + // " concurrent_instances, queue_depth, parameter_xml, created_dt" + // " from import_task" + // " where user_id = '" + sUserID + "'" + // " and task_id = '" + sTaskID + "'"; // OdbcDataReader drTaskRow = null; // if (!dc.sqlGetDataReader(ref drTaskRow, sSQL, ref sErr)) return false; // if (drTaskRow.HasRows) // { // //insert the manipulated TASK // //THIS WAS NEVER TESTED // oTrans.Command.CommandText = "update task" + // " set task_desc = ''," + // " manual_or_digital = ''," + // " use_connector_system = ''," + // " concurrent_instances = ''," + // " queue_depth = ''," + // " parameter_xml = ''," + // " created_dt = ''" + // " select" + // " '" + sNewTaskID + "', '" + sOTID + "', version," + // " task_name, task_code, task_desc, 'Development', manual_or_digital," + // " use_connector_system, 0," + // " concurrent_instances, queue_depth, parameter_xml, created_dt" + // " from import_task" + // " where user_id = '" + sUserID + "'" + // " and task_id = '" + sTaskID + "'"; // if (!oTrans.ExecUpdate(ref sErr)) // throw new Exception(sErr); // } // ui.WriteObjectAddLog(Globals.acObjectTypes.Task, sNewTaskID, dr["task_code"].ToString() + " - " + dr["task_name"].ToString(), "Overwritten by Import"); // break; default: break; } //CODEBLOCKS AND STEPS can be done here... they are just inserted // (because they were manipulated already if needed) //CODEBLOCKS oTrans.Command.CommandText = "insert into task_codeblock" + " (task_id, codeblock_name)" + " select" + " '" + sNewTaskID + "', codeblock_name" + " from import_task_codeblock" + " where user_id = '" + sUserID + "'" + " and task_id = '" + sTaskID + "'"; if (!oTrans.ExecUpdate(ref sErr)) { throw new Exception(sErr); } //STEPS oTrans.Command.CommandText = "insert into task_step" + " (step_id, task_id, codeblock_name, step_order, commented," + " locked, function_name, function_xml, step_desc, output_parse_type," + " output_row_delimiter, output_column_delimiter, variable_xml)" + " select" + " step_id, '" + sNewTaskID + "', codeblock_name, step_order, commented," + " locked, function_name, function_xml, step_desc, output_parse_type," + " output_row_delimiter, output_column_delimiter, variable_xml" + " from import_task_step" + " where user_id = '" + sUserID + "'" + " and task_id = '" + sTaskID + "'"; if (!oTrans.ExecUpdate(ref sErr)) { throw new Exception(sErr); } } } else { sErr = "No Task import items were found."; oTrans.RollBack(); return(false); } //whack those rows from the import table. //why? their disposition has now changed, and we don't wanna accidentally reload them. //or add confusion to the user. oTrans.Command.CommandText = "delete from import_task where user_id = '" + sUserID + "' and task_id in (" + sTaskIDs + ")"; if (!oTrans.ExecUpdate(ref sErr)) { throw new Exception(sErr); } oTrans.Command.CommandText = "delete from import_task_codeblock where user_id = '" + sUserID + "' and task_id in (" + sTaskIDs + ")"; if (!oTrans.ExecUpdate(ref sErr)) { throw new Exception(sErr); } oTrans.Command.CommandText = "delete from import_task_step where user_id = '" + sUserID + "' and task_id in (" + sTaskIDs + ")"; if (!oTrans.ExecUpdate(ref sErr)) { throw new Exception(sErr); } } //all done with everything... close it out oTrans.Commit(); return(true); }
public bool Import(string sUserID, string sTaskIDs, ref string sErr) { string sSQL = ""; dataAccess.acTransaction oTrans = new dataAccess.acTransaction(ref sErr); //we're doing this in a loop //why? because each row may have different import requirements //(overwrite, new version, etc.) //Now we are adding different import types not necessarily tied to task/proc. //for now we're still just doing it all here until there's a good reason to split it out if (sTaskIDs.Length > 0) { sSQL = "select task_id, task_code, task_name, import_mode from import_task" + " where user_id = '" + sUserID + "'" + " and task_id in (" + sTaskIDs + ")"; DataTable dt = new DataTable(); if (!dc.sqlGetDataTable(ref dt, sSQL, ref sErr)) throw new Exception(sErr); if (dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { string sTaskID = dr["task_id"].ToString(); string sNewTaskID = dr["task_id"].ToString(); string sTaskCode = dr["task_code"].ToString(); string sImportMode = dr["import_mode"].ToString(); string sOTID = ""; int iCount = 0; switch (sImportMode) { case "New": //just jam in the new row, IF there are no GUID conflicts. //~~~ NEW tasks get manipulated. //* MIGHT have their ID changed if there's a collision //* WILL have the original_task_id reset //* WILL have the version reset to 1.000 //* WILL be loaded as 'Development' status //* WILL be the default version //check ID oTrans.Command.CommandText = "select count(*) from task" + " where task_id = '" + sTaskID + "'"; if (!oTrans.ExecGetSingleInteger(ref iCount, ref sErr)) throw new Exception("Unable to check for GUID conflicts.<br />" + sErr); //if there's a GUID conflict then just generate a new guid for this task. if (iCount > 0) { sNewTaskID = ui.NewGUID(); } //check the steps to see if there are any GUID conflicts //and repair them if necessary if (!ReIDSteps(ref oTrans, sUserID, sTaskID, ref sErr)) throw new Exception("Unable to issue new Step GUIDs.<br />" + sErr); //insert the manipulated TASK oTrans.Command.CommandText = "insert into task" + " (task_id, original_task_id, version," + " task_name, task_code, task_desc, task_status," + " use_connector_system, default_version," + " concurrent_instances, queue_depth, parameter_xml, created_dt)" + " select" + " '" + sNewTaskID + "', '" + sNewTaskID + "', 1.000," + " task_name, task_code, task_desc, 'Development'," + " use_connector_system, 1," + " concurrent_instances, queue_depth, parameter_xml, created_dt" + " from import_task" + " where user_id = '" + sUserID + "'" + " and task_id = '" + sTaskID + "'"; if (!oTrans.ExecUpdate(ref sErr)) throw new Exception(sErr); ui.WriteObjectAddLog(Globals.acObjectTypes.Task, sNewTaskID, dr["task_code"].ToString() + " - " + dr["task_name"].ToString(), "New - Created via Import"); break; case "New Version": //if it's a new version, we need to make sure the "original_task_id" //is correct in the target database. //(no guarantee the original_id in the source db is correct.) //just jam in the new row, IF there are no GUID conflicts. //~~~ NEW VERSION tasks get manipulated. //* MIGHT have their ID changed if there's a collision //* MIGHT have the original_task_id reset (to match the target) //* WILL have the version reset to the user selection //* WILL be loaded as 'Development' status //* WILL NOT be the default version //check ID oTrans.Command.CommandText = "select count(*) from task" + " where task_id = '" + sTaskID + "'"; if (!oTrans.ExecGetSingleInteger(ref iCount, ref sErr)) throw new Exception("Unable to check for GUID conflicts.<br />" + sErr); //if there's a GUID conflict then just generate a new guid for this task. //and re-id the steps if (iCount > 0) sNewTaskID = ui.NewGUID(); //check the steps to see if there are any GUID conflicts //and repair them if necessary if (!ReIDSteps(ref oTrans, sUserID, sTaskID, ref sErr)) throw new Exception("Unable to issue new Step GUIDs.<br />" + sErr); //NOW, we need to make sure this task is connected to it's family //we do this by ensuring the original_task_id matches. //BUT, we got here by assuming the task_code was the key. //so... find the original_task_id for this task_code oTrans.Command.CommandText = "select original_task_id" + " from task where task_code = '" + sTaskCode + "' limit 1"; if (!oTrans.ExecGetSingleString(ref sOTID, ref sErr)) throw new Exception("Unable to get original task ID for [" + sTaskCode + "].<br />" + sErr); //insert the manipulated TASK oTrans.Command.CommandText = "insert into task" + " (task_id, original_task_id, version," + " task_name, task_code, task_desc, task_status," + " use_connector_system, default_version," + " concurrent_instances, queue_depth, parameter_xml, created_dt)" + " select" + " '" + sNewTaskID + "', '" + sOTID + "', version," + " task_name, task_code, task_desc, 'Development'," + " use_connector_system, 0," + " concurrent_instances, queue_depth, parameter_xml, created_dt" + " from import_task" + " where user_id = '" + sUserID + "'" + " and task_id = '" + sTaskID + "'"; if (!oTrans.ExecUpdate(ref sErr)) throw new Exception(sErr); ui.WriteObjectAddLog(Globals.acObjectTypes.Task, sNewTaskID, dr["task_code"].ToString() + " - " + dr["task_name"].ToString(), "New Version - Created via Import"); break; /* Note: I stopped here because I'm not convinced that "Overwrite" is a safe or useful feature. So, we'll come back to it if needed. Be aware, this was pseudocode... it never worked, was just placeholder stuff and ideas. */ //case "Overwrite": // //stomp it, but make sure to set the task_id/original_task_id // //to match in the target db. // //just because the code matches doesn't mean the ID's do. // //we can just UPDATE the task row // //DON'T FORGET to DELETE the existing steps and codeblocks // //we need to make sure the "original_task_id" // //is correct in the target database. // //(no guarantee the original_id in the source db is correct.) // //~~~ OVERWRITE tasks get manipulated. // //* MIGHT have their ID changed to match the code/version being imported // //* MIGHT have the original_task_id reset (to match the target) // //* WILL have the version reset to the user selection // //* WILL be loaded as 'Development' status // //* MIGHT be the default version (not gonna update that value) // //NOW, we need to make sure this task is connected to it's family // //we do this by ensuring the original_task_id matches. // //BUT, we got here by assuming the task_code was the key. // //so... find the task AND original_task_id for this task_code // oTrans.Command.CommandText = "select top 1 task_id" + // " from task where task_code = '" + sTaskCode + "'"; // if (!oTrans.ExecGetSingleString(ref sNewTaskID, ref sErr)) // throw new Exception("Unable to get task ID for [" + sTaskCode + "].<br />" + sErr); // oTrans.Command.CommandText = "select top 1 original_task_id" + // " from task where task_code = '" + sTaskCode + "'"; // if (!oTrans.ExecGetSingleString(ref sOTID, ref sErr)) // throw new Exception("Unable to get original task ID for [" + sTaskCode + "].<br />" + sErr); // //get a datareader on the import_task row // sSQL = "select task_desc, manual_or_digital, use_connector_system," + // " concurrent_instances, queue_depth, parameter_xml, created_dt" + // " from import_task" + // " where user_id = '" + sUserID + "'" + // " and task_id = '" + sTaskID + "'"; // OdbcDataReader drTaskRow = null; // if (!dc.sqlGetDataReader(ref drTaskRow, sSQL, ref sErr)) return false; // if (drTaskRow.HasRows) // { // //insert the manipulated TASK // //THIS WAS NEVER TESTED // oTrans.Command.CommandText = "update task" + // " set task_desc = ''," + // " manual_or_digital = ''," + // " use_connector_system = ''," + // " concurrent_instances = ''," + // " queue_depth = ''," + // " parameter_xml = ''," + // " created_dt = ''" + // " select" + // " '" + sNewTaskID + "', '" + sOTID + "', version," + // " task_name, task_code, task_desc, 'Development', manual_or_digital," + // " use_connector_system, 0," + // " concurrent_instances, queue_depth, parameter_xml, created_dt" + // " from import_task" + // " where user_id = '" + sUserID + "'" + // " and task_id = '" + sTaskID + "'"; // if (!oTrans.ExecUpdate(ref sErr)) // throw new Exception(sErr); // } // ui.WriteObjectAddLog(Globals.acObjectTypes.Task, sNewTaskID, dr["task_code"].ToString() + " - " + dr["task_name"].ToString(), "Overwritten by Import"); // break; default: break; } //CODEBLOCKS AND STEPS can be done here... they are just inserted // (because they were manipulated already if needed) //CODEBLOCKS oTrans.Command.CommandText = "insert into task_codeblock" + " (task_id, codeblock_name)" + " select" + " '" + sNewTaskID + "', codeblock_name" + " from import_task_codeblock" + " where user_id = '" + sUserID + "'" + " and task_id = '" + sTaskID + "'"; if (!oTrans.ExecUpdate(ref sErr)) throw new Exception(sErr); //STEPS oTrans.Command.CommandText = "insert into task_step" + " (step_id, task_id, codeblock_name, step_order, commented," + " locked, function_name, function_xml, step_desc, output_parse_type," + " output_row_delimiter, output_column_delimiter, variable_xml)" + " select" + " step_id, '" + sNewTaskID + "', codeblock_name, step_order, commented," + " locked, function_name, function_xml, step_desc, output_parse_type," + " output_row_delimiter, output_column_delimiter, variable_xml" + " from import_task_step" + " where user_id = '" + sUserID + "'" + " and task_id = '" + sTaskID + "'"; if (!oTrans.ExecUpdate(ref sErr)) throw new Exception(sErr); } } else { sErr = "No Task import items were found."; oTrans.RollBack(); return false; } //whack those rows from the import table. //why? their disposition has now changed, and we don't wanna accidentally reload them. //or add confusion to the user. oTrans.Command.CommandText = "delete from import_task where user_id = '" + sUserID + "' and task_id in (" + sTaskIDs + ")"; if (!oTrans.ExecUpdate(ref sErr)) throw new Exception(sErr); oTrans.Command.CommandText = "delete from import_task_codeblock where user_id = '" + sUserID + "' and task_id in (" + sTaskIDs + ")"; if (!oTrans.ExecUpdate(ref sErr)) throw new Exception(sErr); oTrans.Command.CommandText = "delete from import_task_step where user_id = '" + sUserID + "' and task_id in (" + sTaskIDs + ")"; if (!oTrans.ExecUpdate(ref sErr)) throw new Exception(sErr); } //all done with everything... close it out oTrans.Commit(); return true; }