private fn_show_lamp_control ( string username, byte password ) : IQueryable |
||
username | string | |
password | byte | |
Résultat | IQueryable |
/// <summary> /// Lampengruppen ein-/ausschalten /// </summary> /// <param name="username">Username</param> /// <param name="password">Passwort</param> /// <param name="groupId">Lampengruppen Id</param> /// <param name="onOff">Lampe ein/ Lampe aus</param> /// <returns>success -> ob erfolgreich oder nicht</returns> public static bool switchGroup(string username, string password, int groupId, bool onOff) { bool success = false; //Übergebenes Passwort hashen und in Var pwhash speichern für Übergabe an DB Byte[] pwhash = HelperClass.GetHash(password); using (itin18_aktEntities cont = new itin18_aktEntities()) { List<fn_show_lamp_control_Result> dbL = cont.fn_show_lamp_control(username, pwhash).ToList(); List<fn_show_lampgroups_Result> dbGr = cont.fn_show_lampgroups(username, pwhash).ToList(); string dbGroupName = ""; int HueLampId = 0; foreach (var item in dbGr) { if (item.id==groupId) { dbGroupName = item.roomgroupname; } } foreach (var item in dbL) { if (item.groupname==dbGroupName) { HueLampId = HueAccess.GetLampId(item.lampname); if (onOff==true) { cont.sp_lamp_on(username, pwhash, item.lamp_id); HelperClass.SetLampState(HueLampId, true); } else { cont.sp_lamp_off(username, pwhash, item.lamp_id); HelperClass.SetLampState(HueLampId, false); } } } } return success; }
/// <summary> /// Special 4 Bastl /// </summary> /// <param name="username">Username</param> /// <param name="password">Passwort</param> /// <returns>Liste des Datentyp's"fn_show_lamp_control_Result"</returns> public static List<fn_show_lamp_control_Result> GetLampControl(string username, string password) { Byte[] pwhash = HelperClass.GetHash(password); using (itin18_aktEntities cont = new itin18_aktEntities()) { List<fn_show_lamp_control_Result> tmp = new List<fn_show_lamp_control_Result>(); try { return cont.fn_show_lamp_control(username, pwhash).ToList(); } catch (Exception e) { //Fehlermeldung in die leere Liste hinzufügen, die FM wird als Lampenname eingetragen tmp.Add(new fn_show_lamp_control_Result { address = "", groupname = "", brightness = 0, status = true, lamp_id = 999, lampname = "Keine Datenbankverbindung" }); tmp.Add(new fn_show_lamp_control_Result { address = "", groupname = "", brightness = 0, status = true, lamp_id = 999, lampname = "No database connection" }); //tmp[0].groupname = "Keine Datenbankverbindung"; //tmp[1].groupname = "No database connection"; return tmp; } } }
/// <summary> /// PSP 2.1 /// Editieren eines Lampennamens anhand des alten Lampennamens /// </summary> /// <param name="username">Username</param> /// <param name="password">Passwort</param> /// <param name="lampNameOld">alter Lampenname</param> /// <param name="lampNameNew">neuer Lampenname</param> /// <returns>success -> ob erfolgreich oder nicht</returns> internal static bool editLampName(string username, string password, string lampNameOld, string lampNameNew) { //Übergebenes Passwort hashen und in Var pwhash speichern für Übergabe an DB Byte[] pwhash = HelperClass.GetHash(password); bool success = false; using (itin18_aktEntities cont = new itin18_aktEntities()) { List<fn_show_lamp_status_Result> dbLampStatus = null; List<fn_show_lamp_control_Result> dbLampsStatus = cont.fn_show_lamp_control(username, pwhash).ToList(); List<fn_show_lamp_control_Result> dbLampsStatusResult = new List<fn_show_lamp_control_Result>(); List<fn_show_lampgroups_Result> dbLampGroups = cont.fn_show_lampgroups(username, pwhash).ToList(); List<fn_show_lampgroup_status_Result> dbLampGroupStatus = null; List<fn_show_lamps_Result> dbLampsNew = null; //temporäre Variablen int? dbLampIdNew = 0; int? dblampId = 0; string dblampAdr = ""; string dbLampGroupName = ""; try { foreach (var item in dbLampsStatus) { // Suche des alten Namens zwecks Änderung if (item.lampname == lampNameOld) { dblampId = item.lamp_id; dblampAdr = item.address; dbLampStatus = cont.fn_show_lamp_status(username, pwhash, item.lamp_id).ToList(); dbLampsStatusResult.Add(item); dbLampGroupName = item.groupname; } } //Edit gibt es nicht in der DB, Lampe wird gelöscht und wieder neu angelegt cont.sp_delete_lamp(dblampId, username, pwhash); cont.sp_add_lamp(username, pwhash, dblampAdr, lampNameNew); dbLampsNew = cont.fn_show_lamps(username, pwhash).ToList(); foreach (var item in dbLampsNew) { if (item.name == lampNameNew) { dbLampIdNew = item.id; } } foreach (var outerItem in dbLampGroups) { dbLampGroupStatus = cont.fn_show_lampgroup_status(username, pwhash, outerItem.id).ToList(); foreach (var innerItem in dbLampGroupStatus) { if (innerItem.id == dblampId) { cont.sp_delete_lamp_from_roomgroup(username, pwhash, outerItem.id, dblampId); cont.sp_add_lamp_to_lampgroup(username, pwhash, outerItem.id, dbLampIdNew); } } } cont.sp_lamp_dimm(username, pwhash, dbLampIdNew, dbLampStatus[0].bright); if (dbLampStatus[0].status == true) { cont.sp_lamp_on(username, pwhash, dbLampIdNew); } else { cont.sp_lamp_off(username, pwhash, dbLampIdNew); } //Namen der Lampe in der HUE-Bridge ändern HelperClass.SetLampName(HueAccess.GetLampId(lampNameOld), lampNameNew); success = true; } catch (Exception e) { success = false; } } return success; }
/// <summary> /// Eine Liste welche zurechtgeschnitten ist für den LampControlController /// Gibt folgendes zurück: address, brightness, groupname, Lamp_id, lampname, status /// </summary> /// <param name="username">Username</param> /// <param name="password">Passwort</param> /// <returns>Liste des Datentyp's "fn_show_lamp_control_Result"</returns> public static List<fn_show_lamp_control_Result> GetAllLampsStatus(string username, string password) { //Übergebenes Passwort hashen und in Var pwhash speichern für Übergabe an DB Byte[] pwhash = HelperClass.GetHash(password); using (itin18_aktEntities cont = new itin18_aktEntities()) { List<fn_show_lamp_control_Result> tmp = new List<fn_show_lamp_control_Result>(); try { return cont.fn_show_lamp_control(username, pwhash).ToList(); } catch (Exception e) { //Fehlermeldung in die leere Liste hinzufügen, die FM wird als Lampenname eingetragen tmp.Add(new fn_show_lamp_control_Result { groupname = " ", address = " ", lampname = "Keine Datenbankverbindung" }); tmp.Add(new fn_show_lamp_control_Result { groupname = " ", address = " ", lampname = "No database connection" }); return tmp; } } }