protected void Page_Load(object sender, EventArgs e) { settingsMasterPage = (SettingsMasterPage)Page.Master; settingsMasterPage.InitializeMasterPageComponents(); int deviceId; Boolean isNumeric = int.TryParse(Request.QueryString["deviceId"], out deviceId); if (!isNumeric) { EmbedClientScript.ShowErrorMessage(this, "Os parâmetros passados para a página não estão em um formato válido.", true); return; } printingDeviceDAO = new PrintingDeviceDAO(settingsMasterPage.dataAccess.GetConnection()); List <Object> counterHistory = printingDeviceDAO.GetCounterHistory(deviceId); String[] columnNames = new String[] { "Contador", "Data" }; EditableList editableList = new EditableList(displayArea, columnNames, null); foreach (Object counter in counterHistory) { PageCounter pageCounter = (PageCounter)counter; String[] counterProperties = new String[] { pageCounter.counter.ToString(), String.Format("{0:dd/MM/yyyy HH:mm}", pageCounter.date) }; editableList.InsertItem(pageCounter.id, false, counterProperties); } editableList.DrawList(); }
public int RegisterDevices(List <PrintingDevice> deviceList) { if (deviceList == null) { return(0); } if (deviceList.Count == 0) { return(0); } StartDBAccess(); int rowCount = 0; PrintingDeviceDAO printingDeviceDAO = new PrintingDeviceDAO(dataAccess.GetConnection()); foreach (PrintingDevice printingDevice in deviceList) { printingDeviceDAO.SetPrintingDevice(printingDevice); rowCount++; } FinishDBAccess(); return(rowCount); }
protected void Page_Load(object sender, EventArgs e) { accountingMasterPage = (AccountingMasterPage)Page.Master; accountingMasterPage.InitializeMasterPageComponents(); if (!Authorization.AuthorizedAsAdministrator(Session)) { // Mostra aviso de falta de autorização ShowWarning(Authorization.GetWarning()); return; } // action: // null - Sem ação, apenas lista os dispositivos // 0 - Excluir dispositivo, lista os restantes int?action = null; int?deviceId = null; try { if (!String.IsNullOrEmpty(Request.QueryString["action"])) { action = int.Parse(Request.QueryString["action"]); } if (!String.IsNullOrEmpty(Request.QueryString["deviceId"])) { deviceId = int.Parse(Request.QueryString["deviceId"]); } } catch (System.FormatException) { // Remove todos os controles da página configurationArea.Controls.Clear(); controlArea.Controls.Clear(); // Mostra aviso de inconsistência nos parâmetros WarningMessage.Show(controlArea, ArgumentBuilder.GetWarning()); return; } Tenant tenant = (Tenant)Session["tenant"]; printingDeviceDAO = new PrintingDeviceDAO(accountingMasterPage.dataAccess.GetConnection()); if (deviceId != null) { switch (action) { case 0: printingDeviceDAO.RemovePrintingDevice(deviceId.Value); Response.Redirect("PageCounters.aspx"); // Limpa a QueryString para evitar erros break; default: break; } } List <Object> deviceList = printingDeviceDAO.GetAllPrintingDevices(tenant.id); String[] columnNames = new String[] { "Endereço IP", "Descrição", "Número de série", "Contador", "Atualizado Em" }; String viewScript = "window.open('PageCounterHistory.aspx?deviceId=' + {0}, 'Histórico do contador', 'width=540,height=600');"; String removeScript = "var confirmed = confirm('Deseja realmente excluir este dispositivo?'); if (confirmed) window.location='PageCounters.aspx?action=0&deviceId=' + {0};"; EditableListButton[] buttons = new EditableListButton[] { // Botões que devem aparecer para os items da lista new EditableListButton("Histórico", viewScript, ButtonTypeEnum.Edit), new EditableListButton("Excluir", removeScript, ButtonTypeEnum.Remove) }; EditableList editableList = new EditableList(configurationArea, columnNames, buttons); foreach (PrintingDevice device in deviceList) { String[] deviceProperties = new String[] { device.ipAddress, device.description, device.serialNumber, device.counter.ToString(), String.Format("{0:dd/MM/yyyy HH:mm}", device.lastUpdated) }; editableList.InsertItem(device.id, false, deviceProperties); } editableList.DrawList(); }