protected void Page_Load(object sender, EventArgs e) { if (HttpContext.Current.User.Identity.IsAuthenticated) { menuNavigation.Items[0].Text = Resources.Localization.Logout; menuNavigation.Items[0].NavigateUrl = "~/Logout.aspx"; try { string accName = (string)Session["AccountName"]; if (String.IsNullOrEmpty(accName)) { Database.Interface.open(); Database.Account account = new Database.Account(); MembershipUser user = Membership.GetUser(); account.select_all_where_ID((Guid)user.ProviderUserKey); Session["AccountName"] = account.Name; accName = account.Name; } labelProfile.Text = Resources.Localization.Account + ": " + accName; } catch (Exception ex) { Database.Interface.close(); } } else { menuNavigation.Items[0].Text = Resources.Localization.Login; menuNavigation.Items[0].NavigateUrl = "~/Login.aspx"; menuNavigation.Visible = false; return; } // Get page name from relative path string thisPage = Page.AppRelativeVirtualPath; int slashPos = thisPage.LastIndexOf("/"); string pageName = "~" + thisPage.Substring(slashPos, thisPage.Length - slashPos); // Select menu item with matching NavigateUrl property foreach (MenuItem parentMenu in menuNavigation.Items) { if (parentMenu.NavigateUrl.ToUpper() == pageName.ToUpper()) { parentMenu.Selected = true; } } }
protected void buttonRegister_OnClick(object sender, EventArgs e) { try { if (ddRegister.Items.Count <= 0) { Utils.displayStatus(ref labelStatusRegister, Color.Red, Lang.You_need_min_one_contact_before_register); return; } if (ddRegister.SelectedValue == Guid.Empty.ToString()) { Utils.displayStatus(ref labelStatusRegister, Color.Red, Lang.You_need_to_select_a_contact_before_register); return; } Database.Interface.open(); Database.Account account = new Database.Account(); if (!account.select_all_where_ID(new Guid(hiddenAccountID.Value))) { Utils.reportStatus(ref labelStatusRegister, Color.Red, "Ringtest.buttonRegister_OnClick: account.select_all_where_ID failed"); return; } if (!account.update_Int_by_ID("intLastRegistrationYear", DateTime.Now.Year)) { Utils.reportStatus(ref labelStatusRegister, Color.Red, "Ringtest.buttonRegister_OnClick: account.update_Int_by_ID failed"); return; } if (!account.update_String_by_ID("vchRingtestContact", ddRegister.SelectedItem.Text)) { Utils.reportStatus(ref labelStatusRegister, Color.Red, "Ringtest.buttonRegister_OnClick: account.update_String_by_ID failed"); return; } } catch (Exception ex) { Utils.reportStatus(ref labelStatusRegister, Color.Red, "Ringtest.buttonRegister_OnClick: " + ex.Message); } finally { Database.Interface.close(); } initializePage(); }
protected void buttonAccountRegisterE_OnClick(object sender, EventArgs e) { if (ddUsers.SelectedValue == Guid.Empty.ToString()) { Utils.displayStatus(ref labelStatusEdit, Color.Red, "Du må velge en konto først"); return; } try { Database.Interface.open(); Database.Ringtest ringtest = new Database.Ringtest(); if (ringtest.select_all_where_year(DateTime.Now.Year)) { if (ringtest.Finished) { Utils.displayStatus(ref labelStatusEdit, Color.Red, "Ringtesten for " + DateTime.Now.Year.ToString() + " er avsluttet"); return; } } Database.Account account = new Database.Account(); account.select_all_where_ID(new Guid(ddUsers.SelectedValue)); if (account.update_Int_by_ID("intLastRegistrationYear", DateTime.Now.Year)) { Utils.displayStatus(ref labelStatusEdit, Color.SeaGreen, "Konto '" + account.Name + "' etter-registrert"); tbLastRegistrationE.Text = DateTime.Now.Year.ToString(); } else { Utils.displayStatus(ref labelStatusEdit, Color.Red, "Etter-registrering av konto feilet"); } } catch (Exception ex) { Utils.displayStatus(ref labelStatusEdit, Color.Red, ex.Message); } finally { Database.Interface.close(); } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { try { MembershipUser User = Membership.GetUser(HttpContext.Current.User.Identity.Name); object UserGUID = User.ProviderUserKey; dataSourceActors.SelectParameters.Add("accountID", UserGUID.ToString()); Database.Interface.open(); Database.Account account = new Database.Account(); if (!account.select_all_where_ID((Guid)UserGUID)) { Utils.reportStatus(ref labelStatus, Color.Red, Lang.Account_for_user + " '" + HttpContext.Current.User.Identity.Name + "' " + Lang.not_found); return; } tbUserNameE.Text = HttpContext.Current.User.Identity.Name; tbNameE.Text = account.Name; hiddenName.Value = tbNameE.Text; tbContactE.Text = account.Contact; tbAddressE.Text = account.Address; //tbPostboxE.Text = account.Postbox; tbPostalE.Text = account.Postal; tbEmailE.Text = account.Email; tbPhoneE.Text = account.Phone; tbMobileE.Text = account.Mobile; tbFaxE.Text = account.Fax; tbWebsiteE.Text = account.Website; } catch (Exception ex) { Utils.reportStatus(ref labelStatus, Color.Red, "Account.Page_Load: " + ex.Message); } finally { Database.Interface.close(); } } }
protected void buttonAccountUnregisterE_OnClick(object sender, EventArgs e) { if (ddUsers.SelectedValue == Guid.Empty.ToString()) { Utils.displayStatus(ref labelStatusEdit, Color.Red, "Du må velge en konto først"); return; } try { Database.Interface.open(); Database.Account account = new Database.Account(); account.select_all_where_ID(new Guid(ddUsers.SelectedValue)); Database.Ringtest ringtest = new Database.Ringtest(); if (ringtest.select_all_where_year(DateTime.Now.Year)) { Database.RingtestReport.delete_where_AccountID_and_Year(account.ID, ringtest.ID); } account.RingtestBoxID = Guid.Empty; account.select_LastYear_from_RingtestReport(); if (!account.update_all_by_ID()) { Utils.displayStatus(ref labelStatusEdit, Color.Red, "buttonAccountUnregisterE_OnClick: Oppdatering av konto feilet"); return; } tbLastRegistrationE.Text = account.LastRegistrationYear.ToString(); Utils.displayStatus(ref labelStatusEdit, Color.SeaGreen, "Konto '" + account.Name + "' avregistrert fra årets ringtest"); } catch (Exception ex) { Utils.displayStatus(ref labelStatusEdit, Color.Red, ex.Message); } finally { Database.Interface.close(); } }
protected void ddUsers_OnSelectedIndexChanged(object sender, EventArgs e) { if (ddUsers.SelectedValue == Guid.Empty.ToString()) { clearAllUpdateFields(); return; } try { Database.Interface.open(); Database.Account account = new Database.Account(); account.select_all_where_ID(new Guid(ddUsers.SelectedValue)); tbNameE.Text = account.Name; lblAccountID.Text = account.ID.ToString().ToUpper(); tbContactE.Text = account.Contact; tbAddressE.Text = account.Address; tbPostalE.Text = account.Postal; tbEmailE.Text = account.Email; tbPhoneE.Text = account.Phone; tbMobileE.Text = account.Mobile; tbFaxE.Text = account.Fax; tbWebsiteE.Text = account.Website; cbActiveE.Checked = account.Active; tbCommentE.Text = account.Comment; tbLastRegistrationE.Text = account.LastRegistrationYear.ToString(); tbRingtestCountE.Text = account.RingtestCount.ToString(); Membership.ApplicationName = "/Lorakon"; MembershipUser user = Membership.GetUser(account.ID); tbUserNameE.Text = user.UserName; hiddenName.Value = tbNameE.Text; Membership.ApplicationName = "/LorakonAdmin"; } catch (Exception ex) { Utils.displayStatus(ref labelStatusEdit, Color.Red, ex.Message); } finally { Database.Interface.close(); } }
protected void login_OnLoggingIn(object sender, LoginCancelEventArgs e) { Database.Account account = new Database.Account(); try { MembershipUser User = Membership.GetUser(login.UserName); if (User == null) { return; } object UserGUID = User.ProviderUserKey; Database.Interface.open(); if (!account.select_all_where_ID((Guid)UserGUID)) { Utils.reportStatus(ref labelStatus, Color.Red, "Login:login_OnLoggingIn: " + Lang.Account_for_user + " '" + login.UserName + "' " + Lang.not_found); return; } if (!account.Active) { Utils.displayStatus(ref labelStatus, Color.SeaGreen, Lang.Account_for_user + " '" + login.UserName + "' " + Lang.is_not_active); e.Cancel = true; } } catch (Exception ex) { Utils.reportStatus(ref labelStatus, Color.Red, ex.Message); } finally { Database.Interface.close(); } }
protected void buttonAccountE_OnClick(object sender, EventArgs e) { if (String.IsNullOrEmpty(tbNameE.Text) || String.IsNullOrEmpty(tbAddressE.Text) || String.IsNullOrEmpty(tbPostalE.Text) || String.IsNullOrEmpty(tbEmailE.Text)) { Utils.displayStatus(ref labelStatus, Color.Red, Lang.Account_update_failed + ". " + Lang.MissingInformation); return; } if (!Utils.isValidEmail(tbEmailE.Text)) { Utils.displayStatus(ref labelStatus, Color.Red, Lang.Email_invalid_address); return; } try { MembershipUser User = Membership.GetUser(HttpContext.Current.User.Identity.Name); object UserGUID = User.ProviderUserKey; Database.Interface.open(); if (tbNameE.Text.ToLower() != hiddenName.Value.ToLower()) { if (Database.Account.accountNameExists(tbNameE.Text)) { Utils.displayStatus(ref labelStatus, Color.Red, Lang.The_name + " '" + tbNameE.Text + "' " + Lang.already_exists); return; } } Database.Account account = new Database.Account(); if (!account.select_all_where_ID((Guid)UserGUID)) { Utils.reportStatus(ref labelStatus, Color.Red, "Account.buttonAccountE_OnClick: " + Lang.Account + " '" + HttpContext.Current.User.Identity.Name + "' " + Lang.not_found); return; } account.Name = tbNameE.Text; account.Contact = tbContactE.Text; account.Address = tbAddressE.Text; account.Postbox = "Field not active"; account.Postal = tbPostalE.Text; account.Email = tbEmailE.Text; account.Phone = tbPhoneE.Text; account.Mobile = tbMobileE.Text; account.Fax = tbFaxE.Text; account.Website = tbWebsiteE.Text; if (account.update_all_by_ID()) { hiddenName.Value = tbNameE.Text; Utils.displayStatus(ref labelStatus, Color.SeaGreen, Lang.Account_update + " " + Lang.success); } else { Utils.reportStatus(ref labelStatus, Color.Red, "Account.buttonAccountE_OnClick: " + Lang.Account_update + " '" + HttpContext.Current.User.Identity.Name + "' " + Lang.failed); } } catch (Exception ex) { Utils.reportStatus(ref labelStatus, Color.Red, "Account.buttonAccountE_OnClick: " + ex.Message); } finally { Database.Interface.close(); } }
protected void buttonAccountE_OnClick(object sender, EventArgs e) { if (ddUsers.SelectedValue == Guid.Empty.ToString()) { Utils.displayStatus(ref labelStatusEdit, Color.Red, "Du må velge en konto først"); return; } if (String.IsNullOrEmpty(tbUserNameE.Text) || String.IsNullOrEmpty(tbEmailE.Text) || String.IsNullOrEmpty(tbNameE.Text) || String.IsNullOrEmpty(tbAddressE.Text) || String.IsNullOrEmpty(tbPostalE.Text)) { Utils.displayStatus(ref labelStatusEdit, Color.Red, "Mangler informasjon"); return; } try { Database.Interface.open(); // Sjekk at konto ikke er oppmeldt til ringtest eller kurs hvis active er false if (!cbActiveE.Checked) { Database.Interface.command.Parameters.Clear(); Database.Interface.command.CommandText = @" SELECT COUNT(Contact.ID) FROM Contact, Course, Contact_Course WHERE Course.bitCompleted = 0 AND Contact.AccountID = @accountID AND Contact.ID = Contact_Course.ContactID AND Course.ID = Contact_Course.CourseID"; Database.Interface.command.CommandType = CommandType.Text; Database.Interface.command.Parameters.AddWithValue("@accountID", new Guid(ddUsers.SelectedValue)); int count = (int)Database.Interface.command.ExecuteScalar(); if (count > 0) { Utils.displayStatus(ref labelStatusEdit, Color.Red, "Kan ikke sette konto til deaktivert. Kontoen er oppmeldt til en eller flere kurs"); return; } Database.Interface.command.Parameters.Clear(); Database.Interface.command.CommandText = @" SELECT COUNT(RingtestReport.ID) FROM RingtestReport WHERE RingtestReport.bitApproved = 0 AND RingtestReport.AccountID = @accountID"; Database.Interface.command.CommandType = CommandType.Text; Database.Interface.command.Parameters.AddWithValue("@accountID", new Guid(ddUsers.SelectedValue)); count = (int)Database.Interface.command.ExecuteScalar(); if (count > 0) { Utils.displayStatus(ref labelStatusEdit, Color.Red, "Kan ikke sette konto til deaktivert. Kontoen har en eller flere uferdige ringtest rapporter"); return; } Database.Interface.command.Parameters.Clear(); } if (tbNameE.Text.ToLower() != hiddenName.Value.ToLower()) { if (Database.Account.accountNameExists(tbNameE.Text)) { Utils.displayStatus(ref labelStatusEdit, Color.Red, "Navnet " + tbNameE.Text + " finnes allerede"); return; } } Database.Account account = new Database.Account(); account.select_all_where_ID(new Guid(ddUsers.SelectedValue)); account.Name = tbNameE.Text; account.Contact = tbContactE.Text; account.Address = tbAddressE.Text; account.Postbox = "Field not active"; account.Postal = tbPostalE.Text; account.Email = tbEmailE.Text; account.Phone = tbPhoneE.Text; account.Mobile = tbMobileE.Text; account.Fax = tbFaxE.Text; account.Website = tbWebsiteE.Text; account.Active = cbActiveE.Checked; account.Comment = tbCommentE.Text; //account.LastRegistrationYear = Convert.ToInt32(tbLastRegistrationE.Text); //account.RingtestCount = Convert.ToInt32(tbRingtestCountE.Text); if (account.update_all_by_ID()) { Utils.displayStatus(ref labelStatusEdit, Color.SeaGreen, "Konto '" + account.Name + "' oppdatert"); hiddenName.Value = tbNameE.Text; } else { Utils.displayStatus(ref labelStatusEdit, Color.Red, "Oppdatering av konto feilet"); } } catch (Exception ex) { Utils.displayStatus(ref labelStatusEdit, 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); }
protected void buttonSendMessage_OnClick(object sender, EventArgs e) { if (ConfigurationManager.AppSettings["UseEmail"] != "yes") { Utils.displayStatus(ref labelStatusMessage, Color.Red, "Sending av epost er deaktivert"); return; } if (String.IsNullOrEmpty(tbMessage.Text)) { Utils.displayStatus(ref labelStatusMessage, Color.Red, Lang.Missing_fields); return; } try { Database.Interface.open(); Database.Configuration configuration = new Database.Configuration(); if (!configuration.select_all_where_name("Default")) { Utils.displayStatus(ref labelStatusMessage, Color.Red, Lang.Configuration + " " + Lang.not_found); return; } Database.Account account = new Database.Account(); if (!account.select_all_where_ID(new Guid(hiddenAccountID.Value))) { Utils.reportStatus(ref labelStatusMessage, Color.Red, "Ringtest.buttonSendMessage_OnClick: account.select_all_where_ID failed"); return; } if (!String.IsNullOrEmpty(ConfigurationManager.AppSettings["MailServer"]) && !String.IsNullOrEmpty(ConfigurationManager.AppSettings["MailServerPort"])) { string mailTitle = "Forespørsel fra LORAKON konto " + account.Name + "(" + account.Email + ")"; string mailBody = tbMessage.Text; MailMessage mail = new MailMessage(); mail.To.Add(configuration.RingtestAdminEmail); mail.From = new MailAddress(configuration.RingtestAdminEmail); mail.BodyEncoding = System.Text.Encoding.Default; mail.IsBodyHtml = true; mail.Subject = mailTitle; mail.Body = mailBody; SmtpClient smtp = new SmtpClient(ConfigurationManager.AppSettings["MailServer"], Convert.ToInt32(ConfigurationManager.AppSettings["MailServerPort"])); smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.Send(mail); Utils.displayStatus(ref labelStatusMessage, Color.SeaGreen, Lang.Message_sent); } else { Utils.displayStatus(ref labelStatusMessage, Color.Red, Lang.Email_no_server); } tbMessage.Text = ""; } catch (Exception ex) { Utils.displayStatus(ref labelStatusMessage, Color.Red, "Ringtest.buttonSendMessage_OnClick: " + ex.Message); } finally { Database.Interface.close(); } }