/// <summary> /// Adds switch to layout dynamically. /// </summary> /// <param name="owner">The owner.</param> /// <param name="bmsListView">The main layout.</param> public void AddSwitchDeviceToLayout(Context owner, ListView bmsListView) { try { using (NmdMobileDBAdapter dbHelper = new NmdMobileDBAdapter(owner)) { dbHelper.OpenOrCreateDatabase(((SharedEnviroment)owner.ApplicationContext).ActionArgument); object obj = dbHelper.ExecuteScalar("SELECT Count(ID) FROM Device Where (IOType =1 OR (IOType=0 And Editable=0)) And CategoryID=" + ((SharedEnviroment)owner.ApplicationContext).ActionCode); if (obj != DBNull.Value) { int recCount = int.Parse(obj.ToString()); if (recCount == 0) { return; } } else { return; } using (SqliteDataReader reader = dbHelper.ExecuteReader("Select * From Device Where (IOType =1 OR (IOType=0 And Editable=0)) And CategoryID=" + ((SharedEnviroment)owner.ApplicationContext).ActionCode)) { while (reader.Read()) { BMSViewHolder swDevice = new BMSViewHolder { Text = reader["Name"].ToString(), Id = (int)reader["ID"], IsSwitch = true, }; swDevice.Enabled = (bool)reader["IOType"] && (NConvert.Int2Bool(GetAccessId(owner)) || HasAccess(owner, swDevice.Id)); swDevice.Checked = (!(reader["Value"] is DBNull) && (int)reader["Value"] != 0); if (swDevice.Enabled) { swDevice.CheckedChange += swDevice_Click; } itemList.Add(swDevice); } } } if (bmsListView.Adapter == null) { bmsListView.Adapter = new BMSViewHolderAdapter((Activity)owner, itemList); } else { ((BMSViewHolderAdapter)(bmsListView.Adapter)).NotifyDataSetChanged(); } } catch (Exception e) { ExceptionHandler.toastMsg(owner, e.Message); ExceptionHandler.logDActivity(e.ToString(), ((SharedEnviroment)owner.ApplicationContext).Logging, ((SharedEnviroment)owner.ApplicationContext).TAG); } }
/// <summary> /// Adds the sensor to layout. /// </summary> /// <param name="owner">The owner.</param> /// <param name="mainLayout">The main layout.</param> public async void AddEditableSensorToLayout(Context owner, ListView bmsListView) { try { using (NmdMobileDBAdapter dbHelper = new NmdMobileDBAdapter(owner)) { dbHelper.OpenOrCreateDatabase(((SharedEnviroment)owner.ApplicationContext).ActionArgument); object obj = dbHelper.ExecuteScalar("SELECT Count(ID) FROM Device Where IOType=0 And Editable=1 And CategoryID=" + ((SharedEnviroment)owner.ApplicationContext).ActionCode); if (obj != DBNull.Value) { int recCount = int.Parse(obj.ToString()); if (recCount == 0) { return; } } else { return; } using (SqliteDataReader reader = dbHelper.ExecuteReader("Select * From Device Where IOType=0 And Editable=1 And CategoryID=" + ((SharedEnviroment)owner.ApplicationContext).ActionCode)) { while (reader.Read()) { BMSViewHolder swDevice = new BMSViewHolder { Text = reader["Name"].ToString(), Id = (int)reader["ID"], IsSwitch = false }; swDevice.Click += btnEditableDevice_Click; itemList.Add(swDevice); } } } if (bmsListView.Adapter == null) { bmsListView.Adapter = new BMSViewHolderAdapter((Activity)owner, itemList); } else { ((BMSViewHolderAdapter)(bmsListView.Adapter)).NotifyDataSetChanged(); } } catch (Exception e) { ExceptionHandler.toastMsg(owner, e.Message); ExceptionHandler.logDActivity(e.ToString(), ((SharedEnviroment)owner.ApplicationContext).Logging, ((SharedEnviroment)owner.ApplicationContext).TAG); } }