private static CBE.SubmoduleCollection ConvertDataTableToCollection(DataTable dt) { try { CBE.SubmoduleCollection submodules = new CBE.SubmoduleCollection(); for (int i = 0; i < dt.Rows.Count; i++) { CBE.SubmoduleCBE submodule = new CBE.SubmoduleCBE(); if (dt.Rows[i]["SUBMODULE_ID"] != DBNull.Value) { submodule.SubModuleId = Convert.ToInt32(dt.Rows[i]["SUBMODULE_ID"]); } if (dt.Rows[i]["MODULE_ID"] != DBNull.Value) { submodule.ModuleId = Convert.ToInt32(dt.Rows[i]["MODULE_ID"]); } if (dt.Rows[i]["SUBMODULE_NAME"] != DBNull.Value) { submodule.SubModuleName = Convert.ToString(dt.Rows[i]["SUBMODULE_NAME"]); } if (dt.Rows[i]["IS_GUI_VISIBLE"] != DBNull.Value) { submodule.IsGuiVisible = Convert.ToInt32(dt.Rows[i]["IS_GUI_VISIBLE"]); } if (dt.Rows[i]["SUBMODULE_URL"] != DBNull.Value) { submodule.SubmoduleUrl = Convert.ToString(dt.Rows[i]["SUBMODULE_URL"]); } if (dt.Rows[i]["ICON"] != DBNull.Value) { submodule.Icon = Convert.ToString(dt.Rows[i]["ICON"]); } submodules.Add(submodule); } return(submodules); } catch (Exception ex) { throw ex; } }
/// <summary> /// Get next value for the primary key /// </summary> /// <returns></returns> private static int GetNextValue() { //next value will be 1 if there is no row in the datatable. int nextValue = 1; try { //Get object collection CBE.SubmoduleCollection objs = GetAll(); //Get all objects Id int[] sortedObjsId = new int[objs.Count]; for (int i = 0; i < objs.Count; i++) { sortedObjsId[i] = objs[i].ModuleId; } //Sort the object id Array.Sort(sortedObjsId); for (int j = 0; j < sortedObjsId.Length; j++) { if (j + 1 < sortedObjsId.Length) { if (sortedObjsId[j] + 1 < sortedObjsId[j + 1]) { nextValue = sortedObjsId[j] + 1; break; } } else { nextValue = sortedObjsId[sortedObjsId.Length - 1] + 1; } } } catch (Exception ex) { throw ex; } return(nextValue); }
public static CBE.SubmoduleCollection GetAll() { CBE.SubmoduleCollection submodules = new CBE.SubmoduleCollection(); try { //Stored procedure must have cur_out parameter. //There is no need to add ref cursor for oracle in code. string spName = Constants.oraclePackagePrefix + "SubModule_GetAll"; DbCommand command = VaaaN.MLFF.Libraries.CommonLibrary.DBA.DBAccessor.GetStoredProcCommand(spName); submodules = ConvertDataTableToCollection(VaaaN.MLFF.Libraries.CommonLibrary.DBA.DBAccessor.LoadDataSet(command, tableName).Tables[tableName]); } catch (Exception ex) { throw ex; } return(submodules); }
public static CBE.SubmoduleCBE GetSubModuleById(CBE.SubmoduleCBE submodule) { try { CBE.SubmoduleCollection submodules = new CBE.SubmoduleCollection(); string spName = Constants.oraclePackagePrefix + "SubModule_GetById"; DbCommand command = VaaaN.MLFF.Libraries.CommonLibrary.DBA.DBAccessor.GetStoredProcCommand(spName); command.Parameters.Add(VaaaN.MLFF.Libraries.CommonLibrary.DBA.DBAccessor.CreateDbParameter(ref command, "p_submodule_id", DbType.Int32, submodule.SubModuleId, ParameterDirection.Input)); submodules = ConvertDataTableToCollection(VaaaN.MLFF.Libraries.CommonLibrary.DBA.DBAccessor.LoadDataSet(command, tableName).Tables[tableName]); return(submodules[0]); } catch (Exception ex) { throw ex; } }
public static VaaaN.MLFF.Libraries.CommonLibrary.CBE.SubmoduleCollection GetByModuleId(int moduleId) { CBE.SubmoduleCollection Submodules = new CBE.SubmoduleCollection(); try { string spName = Constants.oraclePackagePrefix + "SUBMODULE_GETBYMODULEID"; DbCommand command = VaaaN.MLFF.Libraries.CommonLibrary.DBA.DBAccessor.GetStoredProcCommand(spName); command.Parameters.Add(VaaaN.MLFF.Libraries.CommonLibrary.DBA.DBAccessor.CreateDbParameter(ref command, "p_module_id", DbType.Int32, moduleId, ParameterDirection.Input)); DataSet ds = VaaaN.MLFF.Libraries.CommonLibrary.DBA.DBAccessor.LoadDataSet(command, tableName); DataTable dt = ds.Tables[tableName]; Submodules = ConvertDataTableToCollection(dt); } catch (Exception ex) { throw ex; } return(Submodules); }