protected void buttonNewCategory_OnClick(object sender, EventArgs e) { if (String.IsNullOrEmpty(tbNewCategory.Text)) { Utils.displayStatus(ref labelStatusCategories, Color.Red, "Feltet 'Kategori navn' må fylles inn"); return; } try { Database.Interface.open(); Database.DeviceCategory category = new Database.DeviceCategory(tbNewCategory.Text, false); if (category.insert_with_ID_name(Guid.NewGuid(), tbNewCategory.Text)) { Utils.displayStatus(ref labelStatusCategories, Color.SeaGreen, "Enhets kategori '" + tbNewCategory.Text + "' opprettet"); } else { Utils.displayStatus(ref labelStatusCategories, Color.Red, "Oppretting av enhets kategori feilet"); } tbNewCategory.Text = ""; updateCategories(); } catch (Exception ex) { Utils.displayStatus(ref labelStatusCategories, Color.Red, ex.Message); } finally { Database.Interface.close(); } }
protected void gridDevicesED_OnSelectedIndexChanged(object sender, EventArgs e) { try { Database.Interface.open(); Database.Device device = new Database.Device(); if (!device.select_all_where_ID((Guid)gridDevicesED.SelectedDataKey.Value)) { Utils.displayStatus(ref labelStatusEdit, Color.Red, "Enhet ikke funnet"); return; } ddCategoriesEdit.SelectedValue = device.DeviceCategoryID.ToString(); ddTypesEdit.SelectedValue = device.DeviceTypeID.ToString(); ddAccountED.SelectedValue = device.AccountID.ToString(); tbSerialnumberED.Text = device.SerialNumber; ddStatusED.SelectedValue = device.Status; ddOwnershipED.SelectedValue = device.Ownership; tbCommentED.Text = device.Comment; if (device.ReceivedNew != DateTime.MinValue) { calReceivedNewED.SelectedDate = device.ReceivedNew; } gridDeviceHistory.DataSource = device.select_all_comments(); gridDeviceHistory.DataBind(); Database.DeviceCategory cat = new Database.DeviceCategory(); if (!cat.select_all_where_name("Detektor")) { Utils.displayStatus(ref labelStatusEdit, Color.Red, "Enhet 'Detektor' ikke funnet"); return; } if (ddCategoriesED.SelectedValue == cat.ID.ToString()) { ddCategoriesEdit.Enabled = false; ddTypesEdit.Enabled = false; } else { ddCategoriesEdit.Enabled = true; ddTypesEdit.Enabled = true; } panelDeviceED.Visible = true; } catch (Exception ex) { Utils.displayStatus(ref labelStatusEdit, Color.Red, ex.Message); } finally { Database.Interface.close(); } }
protected void gridCategories_OnDeleteCommand(object sender, GridViewDeleteEventArgs e) { try { Database.Interface.open(); Database.DeviceCategory deviceCategory = new Database.DeviceCategory(); if (!deviceCategory.select_all_where_ID((Guid)gridCategories.DataKeys[e.RowIndex].Values[0])) { Utils.displayStatus(ref labelStatusCategories, Color.Red, "Kategori ikke funnet"); return; } if (deviceCategory.Sticky) { Utils.displayStatus(ref labelStatusCategories, Color.Red, "Kategorien '" + deviceCategory.Name + "' kan ikke slettes"); e.Cancel = true; return; } else { // sjekk om det er typer tilordnet til denne kategorien List <Database.Device> deviceList = new List <Database.Device>(); if (Database.Device.select_all_where_categoryID(deviceCategory.ID, "vchSerialNumber", ref deviceList)) { Utils.displayStatus(ref labelStatusCategories, Color.Red, "Kategorien '" + deviceCategory.Name + "' har " + deviceList.Count.ToString() + " enheter i systemet. Slett disse først"); e.Cancel = true; return; } if (deviceCategory.delete_by_ID()) { Utils.displayStatus(ref labelStatusCategories, Color.SeaGreen, "Kategorien '" + deviceCategory.Name + "' slettet"); } else { Utils.displayStatus(ref labelStatusCategories, Color.Red, "Sletting av kategori feilet"); } } updateCategories(); } catch (Exception ex) { Utils.displayStatus(ref labelStatusCategories, Color.Red, ex.Message); } finally { Database.Interface.close(); } }
protected void gridCategories_OnUpdateCommand(object sender, GridViewUpdateEventArgs e) { TextBox tbEditName = (TextBox)gridCategories.Rows[e.RowIndex].Cells[0].Controls[0]; if (String.IsNullOrEmpty(tbEditName.Text)) { Utils.displayStatus(ref labelStatusCategories, Color.Red, "Feltet 'Kategori navn' må fylles inn"); return; } try { Database.Interface.open(); Database.DeviceCategory category = new Database.DeviceCategory(); if (!category.select_all_where_ID((Guid)gridCategories.DataKeys[e.RowIndex].Values[0])) { Utils.displayStatus(ref labelStatusCategories, Color.Red, "Kategori ikke funnet"); return; } category.Name = tbEditName.Text; category.update_all_by_ID(); gridCategories.EditIndex = -1; updateCategories(); Utils.displayStatus(ref labelStatusCategories, Color.SeaGreen, "Kategori '" + category.Name + "' oppdatert"); } catch (Exception ex) { Utils.displayStatus(ref labelStatusCategories, Color.Red, ex.Message); } finally { Database.Interface.close(); } }
protected void initializePage() { bool ringtestExists = false; bool hasStarted = false; try { Database.Interface.open(); Database.Configuration configuration = new Database.Configuration(); if (!configuration.select_all_where_name("Default")) { Utils.reportStatus(ref labelStatus, Color.Red, "Ringtest.initializePage: Configuration not found"); return; } Database.Ringtest ringtest = new Database.Ringtest(); if (ringtest.select_all_where_year(DateTime.Now.Year)) { ringtestExists = true; if (DateTime.Now >= ringtest.StartDate) { hasStarted = true; } if (hasStarted && ringtest.Finished) { multiViewRingtest.SetActiveView(viewFinished); return; } } Database.Account account = new Database.Account(); if (!account.select_all_where_ID(new Guid(hiddenAccountID.Value))) { Utils.reportStatus(ref labelStatus, Color.Red, "Ringtest.initializePage: Account not found"); return; } if (account.LastRegistrationYear != DateTime.Now.Year) { if (hasStarted) { // send info to admin multiViewRingtest.SetActiveView(viewSendMessage); labelSendMessage.Text = Lang.RingtestAlreadyStarted; } else { multiViewRingtest.SetActiveView(viewRegister); labelRegister.Text = Lang.RingtestAccountNotRegistered; } return; } if (hasStarted) { hiddenRingtestID.Value = ringtest.ID.ToString(); } else { multiViewRingtest.SetActiveView(viewNoInit); if (ringtestExists) { labelInit.Text = Lang.RingtestNotStarted + " " + ringtest.StartDate.ToShortDateString(); } else { labelInit.Text = Lang.RingtestDateNotDetermined; } return; } if (account.RingtestBoxID == Guid.Empty) { multiViewRingtest.SetActiveView(viewSendMessage); labelSendMessage.Text = Lang.RingtestAccountBoxNotAssigned; return; } hiddenRingtestBoxID.Value = account.RingtestBoxID.ToString(); Database.DeviceCategory category = new Database.DeviceCategory(); if (!category.select_all_where_name("Detektor")) { multiViewRingtest.SetActiveView(viewNoInit); labelInit.Text = Lang.DatabaseError; Utils.reportStatus(ref labelStatus, Color.Red, "Ringtest.initializePage: Category 'Detektor' not found"); return; } List <Database.Identifiers> idList = new List <Database.Identifiers>(); if (!Database.Device.select_identifiers_where_accountID_categoryID_status(account.ID, category.ID, "Ok", ref idList)) { multiViewRingtest.SetActiveView(viewNoInit); labelInit.Text = Lang.RingtestNoDetectors1 + " " + account.Name + Lang.RingtestNoDetectors2 + " " + configuration.RingtestAdminEmail + " " + Lang.RingtestNoDetectors3; return; } ddDetector.Items.Add(new ListItem("---", Guid.Empty.ToString())); foreach (Database.Identifiers ids in idList) { ddDetector.Items.Add(new ListItem(ids.Name, ids.ID.ToString())); } } catch (Exception ex) { Utils.reportStatus(ref labelStatus, Color.Red, "Ringtest.initializePage: " + ex.Message); } finally { Database.Interface.close(); } multiViewRingtest.SetActiveView(viewSelectDetector); }