public static int getCurrent() { DatabaseManager manager; string where = null; Period pObj = null; List<Object> objects = null; int max = 1; int tmp = 0; manager = new DatabaseManager(); try { where = ""; objects = manager.select(typeof(Period),where); foreach (Object o in objects) { pObj = o as Period; tmp = Convert.ToInt32(pObj.period); if (tmp > max) { max = tmp; } } } finally { manager.release(); } return max + 1; }
/// <summary> /// Sucht nach einem Object in der Datenbank /// </summary> /// <param name="type">Typ des gesuchten objects</param> /// <param name="head">nummer des Kopfobjects</param> /// <returns>Das gesuchte Object</returns> public static PlanningObject search(Type type, string head) { DatabaseManager manager; string where; PlanningObject obj = null; List<Object> res; manager = new DatabaseManager(); try { where = "WHERE " + type.Name + " = \"" + head + "\""; res = manager.select(type, where); if (res != null && res.Count > 0) { obj = res[0] as PlanningObject; } } finally { manager.release(); } return obj; }
/// <summary> /// Erzeugt ein Object /// </summary> /// <param name="type">Type des Objects</param> /// <param name="head">Nummer des Objects</param> /// <returns>Das erzeugte Object</returns> public static PlanningObject create(Type type, string head) { DatabaseManager manager; PlanningObject obj = null; PropertyInfo[] props; manager = new DatabaseManager(); try { //Prüfen ob es die Objectposition bereits gibt obj = search(type, head); if (obj != null) { return null; } obj = Activator.CreateInstance(type) as PlanningObject; props = obj.GetType().GetProperties(); foreach (PropertyInfo p in props) { if (p.Name.Equals(type.Name, StringComparison.CurrentCultureIgnoreCase)) { p.SetValue(obj, head); break; } } manager.insert(obj); } finally { manager.release(); } return obj; }
/// <summary> /// Liefert alle Lagerplätze /// </summary> /// <returns></returns> public static List<Stock> getAll() { List<Stock> stock = null; List<Object> objects = null; DatabaseManager manager; manager = new DatabaseManager(); try { objects = manager.select(typeof(Stock), ""); stock = new List<Stock>(); foreach (Object o in objects) { stock.Add(o as Stock); } } finally { manager.release(); } return stock; }
internal static PlanningObject getHead(PlanningPosObject obj,Type headType) { PlanningObject head = null; DatabaseManager manager; string where; List<Object> res; Type type = obj.GetType(); PropertyInfo[] props = type.GetProperties(); string table = type.Name.Remove(type.Name.Length - 3); string value = null; manager = new DatabaseManager(); try { foreach (PropertyInfo p in props) { if (p.Name.Equals(table, StringComparison.CurrentCultureIgnoreCase)) { value = p.GetValue(obj).ToString(); } } where = "WHERE " + table + " = \"" + value + "\""; res = manager.select(headType, where); if (res != null && res.Count > 0) head = res[0] as PlanningObject; } finally { manager.release(); } return head; }
/// <summary> /// Speichert die änderungen an einer Objectposition in der Datenbank /// </summary> /// <param name="obj">Objectposition</param> public static void update(PlanningPosObject obj) { DatabaseManager manager; manager = new DatabaseManager(); try { manager.update(obj); } finally { manager.release(); } }
/// <summary> /// Sucht nach einem Object in der Datenbank /// </summary> /// <param name="type">Typ des gesuchten objects</param> /// <param name="sql">nummer des Kopfobjects</param> /// <returns>Das gesuchte Object</returns> public static List<PlanningPosObject> select(Type type, string sql) { DatabaseManager manager; List<Object> res; List<PlanningPosObject> obj = new List<PlanningPosObject>(); manager = new DatabaseManager(); try { res = manager.freeSelect(type, sql); foreach (Object o in res) { obj.Add(o as PlanningPosObject); } } finally { manager.release(); } return obj; }
/// <summary> /// Sucht alle Objectposition welche eine die gesuchte Pos beinhalten /// </summary> /// <param name="type">Typ des gesuchten objects</param> /// <param name="head">nummer des Kopfobjects</param> /// <returns></returns> public static List<PlanningPosObject> searchAllWithPos(Type type, string pos) { DatabaseManager manager; string where; List<Object> res; List<PlanningPosObject> obj = new List<PlanningPosObject>(); manager = new DatabaseManager(); try { where = "WHERE " + type.Name + " = \"" + pos + "\""; res = manager.select(type, where); foreach (Object o in res) { obj.Add(o as PlanningPosObject); } } finally { manager.release(); } return obj; }
/// <summary> /// Sucht nach Positionen mit abhäigkeiten /// </summary> /// <param name="type"></param> /// <param name="head"></param> /// <param name="pos"></param> /// <returns>Die gesuchte Position</returns> public static PlanningPosObject search(Type type, string head, string pos, string dependence) { DatabaseManager manager; string where; PlanningPosObject obj = null; List<Object> res; manager = new DatabaseManager(); try { where = "WHERE " + type.Name.Remove(type.Name.Length - 3) + " = \"" + head + "\"" + " AND " + type.Name + " = \"" + pos + "\"" + " AND dependence = \"" + dependence + "\""; res = manager.select(type, where); if (res != null && res.Count > 0) { obj = res[0] as PlanningPosObject; } } finally { manager.release(); } return obj; }
/// <summary> /// Sucht nach einem Object in der Datenbank /// </summary> /// <param name="type">Typ des gesuchten objects</param> /// <returns>Alle Objecte</returns> public static List<PlanningObject> searchAll(Type type) { DatabaseManager manager; string where; List<PlanningObject> obj = new List<PlanningObject>(); List<Object> res; manager = new DatabaseManager(); try { res = manager.select(type,null); foreach(Object o in res) { obj.Add(o as PlanningObject); } } finally { manager.release(); } return obj; }
/// <summary> /// Führt ein Datenbankupdate für das übergebene Object aus /// </summary> /// <param name="planningObject"></param> internal static void update(PlanningObject planningObject) { DatabaseManager manager; manager = new DatabaseManager(); try { manager.update(planningObject); } finally { manager.release(); } }