示例#1
0
        private void Save()
        {
            Contact contact       = BLL.CurrentContact;
            bool    showSmsCols   = BLL.Mandator.SmsNotifications;
            bool    showEmailCols = BLL.Mandator.OnNewEventNotifyContacts ||
                                    BLL.Mandator.OnEditEventNotifyContacts ||
                                    BLL.Mandator.OnNewSubscriptionNotifyContacts ||
                                    BLL.Mandator.OnEditSubscriptionNotifyContacts ||
                                    BLL.Mandator.OnDeleteSubscriptionNotifyContacts;

            string emailBefore = contact.Email;

            try
            {
                contact.Name           = Name.Text;
                contact.Email          = Email.Text;
                contact.MobilePhone    = MobilePhone.Text;
                contact.LiftMgmtSmsOn  = LiftMgmtSmsOn.Checked;
                contact.EventMgmtSmsOn = EventMgmtSmsOn.Checked;

                foreach (EventCategory category in BLL.ListEventCategories())
                {
                    ContactSetting setting          = EventSiteBL.GetContactSetting(contact, category);
                    Hashtable      categoryControls = (Hashtable)ViewState[String.Format("ES_CategoryControls_{0}", category.EventCategoryId)];

                    //check if contactsettings have changed --> if not changed set id to 0 to ignore saving this item
                    bool   notifByEmail = false, notifBySms = false, notifSubscr = false;
                    NInt32 autoNotifSubscr = new NInt32(0, true);
                    if (showEmailCols)
                    {
                        notifByEmail = EvaluateCheckBox(Request.Form[(string)categoryControls[String.Format("chkNotifyByEmail_{0}", category.EventCategoryId)]]);
                    }
                    if (showSmsCols)
                    {
                        notifBySms      = EvaluateCheckBox(Request.Form[(string)categoryControls[String.Format("chkNotifyBySms_{0}", category.EventCategoryId)]]);
                        notifSubscr     = EvaluateCheckBox(Request.Form[(string)categoryControls[String.Format("chkSmsNotifSubscription_{0}", category.EventCategoryId)]]);
                        autoNotifSubscr = EvaluateNInt32TextBox(Request.Form[(string)categoryControls[String.Format("tbAutoNotifSubscription_{0}", category.EventCategoryId)]]);
                    }

                    if (showEmailCols && setting.NotifyByEmail != notifByEmail ||
                        showSmsCols && (setting.NotifyBySms != notifBySms ||
                                        setting.SmsNotifSubscriptionsOn != notifSubscr ||
                                        setting.AutoNotifSubscription.IsNull != autoNotifSubscr.IsNull ||
                                        !setting.AutoNotifSubscription.IsNull && setting.AutoNotifSubscription != autoNotifSubscr))
                    {
                        if (showEmailCols)
                        {
                            setting.NotifyByEmail = notifByEmail;
                        }
                        if (showSmsCols)
                        {
                            setting.NotifyBySms             = notifBySms;
                            setting.SmsNotifSubscriptionsOn = notifSubscr;
                            setting.AutoNotifSubscription   = autoNotifSubscr;
                        }
                    }
                    else
                    {
                        setting.ContactSettingId = 0;
                    }
                    //set NotifyBySms in any case, for validation if mobilephone is empty
                    setting.NotifyBySms = notifBySms;
                }
            }
            catch (EventSiteException ex)
            {
                RegisterStartupScriptIfNeeded("invalContactData", ex.JavaScriptAlertString);
                BLL.RenewCurrentContact();
                FillFieldValues();
                return;
            }

            BLL.EditContact(contact);
            BLL.SaveContactSettings(contact);

            if (!contact.Email.Equals(emailBefore))
            {
                //current contact's email has changed --> signout after update
                string signoutScript = string.Format(pbHelpers.JavaScriptString, @"
	alert('Da die eigene Email-Adresse geändert wurde, musst Du dich neu anmelden.');
	document.getElementById('"     + LogoutButton.ClientID + @"').click();
");
                RegisterStartupScriptIfNeeded("signoutScript", signoutScript);

                return;
            }
            else
            {
                RegisterStartupScriptIfNeeded("saveSuccess", String.Format(playboater.gallery.commons.Helpers.JavaScriptAlertString, "Einstellungen erfolgreich gespeichert."));
                BLL.RenewCurrentContact();
            }

            FillFieldValues();
        }
        private void Default_PreRender(object sender, EventArgs e)
        {
            #region Features
            string featureAssembly;
            string featureAssemblyClassName;
            if (IsCategoryFilterOn && CurrentEventCategory.FeatureAssembly != null)
            {
                featureAssembly          = CurrentEventCategory.FeatureAssembly;
                featureAssemblyClassName = CurrentEventCategory.FeatureAssemblyClassName;
            }
            else
            {
                featureAssembly          = BLL.Mandator.FeatureAssembly;
                featureAssemblyClassName = BLL.Mandator.FeatureAssemblyClassName;
            }
            if (featureAssembly != null)
            {
                try
                {
                    Assembly a       = Assembly.LoadFrom(featureAssembly);
                    IFeature feature = (IFeature)a.CreateInstance(featureAssemblyClassName);
                    //					IFeature feature = (IFeature)a.CreateInstance(BLL.Mandator.FeatureAssemblyClassName, false, BindingFlags.CreateInstance, null, new object[]{Request}, null, null);

                    feature.AddContent(pnlFeature, Request);
                }
                catch (Exception ex)
                {
                    Helpers.TrySendErrorMail(ex);

                    Label lbl = new Label();
                    lbl.Text  = "Beim Versuch das FeatureAssembly auszuführen ist folgender Fehler aufgetreten: ";
                    lbl.Text += ex.ToString();
                    pnlFeature.Controls.Clear();
                    pnlFeature.Controls.Add(lbl);
                }
            }
            #endregion

            EventCategories.Attributes.Add("onchange", String.Format("document.getElementById('{0}').checked = false;document.getElementById('{0}').click();", chkCategoryFilterOn.ClientID));
            EventCategoryFilterPopup.PopupText    = IsCategoryFilterOn ? "Filter deaktivieren" : "Nach Kategorie filtern";
            EventCategoryFilterPopup.PopupIconSrc = IsCategoryFilterOn ? "images\\icons\\filter_on.gif" : "images\\icons\\filter_off.gif";

            if (BLL.Mandator.UseSubscriptions)
            {
                dgrSubscriptions.DataBind();
//				events.DataBind();

                pnlAddSubscription.Visible  = !BLL.IsReader();
                AddSubscriptionCell.Visible = !BLL.IsReader();
                if (!pnlAddContact.Visible)
                {
                    pnlSubscriptions.Visible = true;
                }
                notifSubscription.Visible = true;

//				string styleBlock = @"
//<style type=""text/css"">
//<!--
//#pnlEventContainer > #pnlEvent
//{
//	 width: 10%;
//}
//
//#eventList
//{
//	vertical-align: bottom;
//}
//#eventChooser > #eventList
//{
//	vertical-align: baseline;
//}
//-->
//</style>";
//				if(!IsClientScriptBlockRegistered("StyleHack"))
//					RegisterClientScriptBlock("StyleHack", styleBlock);
                pnlEvent.Style["FLOAT"]               = "left";
                pnlEvent.Style["MARGIN-BOTTOM"]       = "auto";
                pnlEventDetails.Style["MARGIN-RIGHT"] = "auto";

                string clientScript = string.Format(pbHelpers.JavaScriptString, @"
				fResetEventDetailSize();
				
				/*Überwachung von Veränderung der Fenstergrösse initialisieren*/
				window.onresize = fResetEventDetailSize;
");
                RegisterStartupScriptIfNeeded("EventDetailHandling", clientScript);

                if (IsOldEvent)
                {
                    pnlAddSubscription.Visible = false;
                    subscriptionStates.Enabled = false;
                    email.Enabled              = false;
                    email.BackColor            = Color.FromKnownColor(KnownColor.LightGray);
                    subscriptionTime.Enabled   = false;
                    subscriptionTime.BackColor = Color.FromKnownColor(KnownColor.LightGray);
//					maxNotifications.Enabled = false;
//					maxNotifications.BackColor = Color.FromKnownColor(KnownColor.LightGray);
                    txtComment.Enabled                  = false;
                    txtComment.BackColor                = Color.FromKnownColor(KnownColor.LightGray);
                    AddSubscription.Enabled             = false;
                    dgrSubscriptions.Columns[1].Visible = false;
                    dgrSubscriptions.Columns[9].Visible = false;
                }
                else
                {
                    subscriptionStates.Enabled = true;
                    email.Enabled              = true;
                    email.BackColor            = Color.White;
                    subscriptionTime.Enabled   = true;
                    subscriptionTime.BackColor = Color.White;
//					maxNotifications.Enabled = true;
//					maxNotifications.BackColor = Color.White;
                    txtComment.Enabled                  = true;
                    txtComment.BackColor                = Color.White;
                    AddSubscription.Enabled             = true;
                    dgrSubscriptions.Columns[1].Visible = true;
                    dgrSubscriptions.Columns[9].Visible = true;
                }

                dgrSubscriptions.Columns[9].Visible = BLL.Mandator.IsLiftManagementEnabled && dgrSubscriptions.Columns[9].Visible;
            }
            else
            {
//				string styleBlock = @"
//<style type=""text/css"">
//<!--
//#eventDetails
//{
//	width: 100%;
//}
//
//TABLE#pnlEventDetails DIV
//{
//	 width: auto;
//}
//
//#eventList
//{
//	vertical-align: bottom;
//}
//					#eventChooser > #eventList
//					{
//	vertical-align: baseline;
//}
//-->
//</style>";
//				if(!IsClientScriptBlockRegistered("StyleHack"))
//					RegisterClientScriptBlock("StyleHack", styleBlock);

                pnlAddSubscription.Visible  = false;
                AddSubscriptionCell.Visible = false;
                pnlSubscriptions.Visible    = false;
                notifSubscription.Visible   = false;

                pnlEvent.Style["FLOAT"]               = "none";
                pnlEvent.Style["MARGIN-BOTTOM"]       = "20px";
                pnlEventDetails.Style["MARGIN-RIGHT"] = "5px";
            }

            string titleAdd;
            if (CurrentEvent == null)
            {
                titleAdd = "Kein(e) " + BLL.Mandator.EventName + " ausgewählt";
                lblSubscriptions.Text    = "Es ist kein Anlass ausgewählt.";
                dgrSubscriptions.Visible = false;
                legendDiv.Visible        = false;
            }
            else
            {
                titleAdd = CurrentEvent.EventTitle;
                lblSubscriptions.Text    = "Zur Zeit sind für diesen Anlass folgende Einträge vorhanden:";
                dgrSubscriptions.Visible = true;
                legendDiv.Visible        = BLL.Mandator.IsLiftManagementEnabled;
            }
            Page.Title          = BLL.Mandator.SiteTitle + " - " + titleAdd;
            pageTitle.InnerText = BLL.Mandator.SiteTitle + " - " + titleAdd;
            helptext.Text       = BLL.Mandator.HelpText;

            if (pnlAddSubscription.Visible)
            {
                string previousValue = null;
                if (IsPostBack)
                {
                    previousValue = subscriptionStates.SelectedValue;
                }

                subscriptionStates.DataSource = BLL.ListSubscriptionStates(CurrentEvent.EventCategory);
                subscriptionStates.DataBind();
                if (!IsPostBack && subscriptionStates.Items.Count > 0)
                {
                    subscriptionStates.Items[0].Selected = true;
                }
                else if (IsPostBack && subscriptionStates.Items.Count > 0)
                {
                    //try to set previous value
                    try
                    {
                        subscriptionStates.SelectedValue = previousValue;
                    }
                    catch
                    {
                        subscriptionStates.Items[0].Selected = true;
                    }
                }

                subscriptionMailContainer.Visible = BLL.IsAdministrator() || BLL.IsManager();
            }

            if (BLL.IsReader())
            {
                chkNotifSubscription.Visible     = false;
                txtNumSmsNotifications.Visible   = false;
                numSmsNotificationsLabel.Visible = false;

                lblNofifSubscriptionDisabled.Text    = "Da du nur Leserechte besitzt, kannst<br>du diese Option nicht nutzen.";
                lblNofifSubscriptionDisabled.Visible = true;
            }
            else
            {
                if (CurrentEvent != null && EventSiteBL.GetContactSetting(BLL.CurrentContact, CurrentEvent.EventCategory).SmsNotifSubscriptionsOn)
                {
                    chkNotifSubscription.Visible     = true;
                    txtNumSmsNotifications.Visible   = true;
                    numSmsNotificationsLabel.Visible = true;

                    lblNofifSubscriptionDisabled.Visible = false;

                    SetNotifSubscriptionFields();

                    string notifSubscriptionChangeScript = string.Format(@"
<SCRIPT type=""text/javascript"" language=""javascript"">
	
	function UpdateNotifSubscriptionChange()
	{{
		var nofifSubscriptionElem;
		var maxNotificationsElem;
		nofifSubscriptionElem = document.getElementById('{0}'); 
		maxNotificationsElem = document.getElementById('{1}'); 

		document.getElementById('{4}').style.backgroundColor = 'yellow'; 

		var notifSubscriptionOn;
		var maxNotifications;
		notifSubscriptionOn = nofifSubscriptionElem.checked;

		if(notifSubscriptionOn)
		{{
			maxNotifications = maxNotificationsElem.value;
		}}
		else
		{{
			maxNotificationsElem.value = '';
			maxNotifications = '';
		}}
		//alert(notifSubscriptionOn);
		//alert(maxNotifications);

		//ajax postback to update notifSubscription
		EventSiteBL.UpdateNotifSubscription('{2}', {3}, notifSubscriptionOn, maxNotifications, UpdateNotifSubscription_CallBack);
	}}

	function UpdateNotifSubscription_CallBack(response)
	{{
		if (response.error != null)
		{{
			alert(response.error.description + '\nDie Einstellung konnte nicht gespeichert werden!');
		}}
		else
		{{
			document.getElementById('{4}').style.backgroundColor = '#eeeeee'; 
		}}
	}}
</SCRIPT>
",
                                                                         chkNotifSubscription.ClientID,
                                                                         txtNumSmsNotifications.ClientID,
                                                                         BLL.Mandator.MandatorId,
                                                                         CurrentEvent == null ? "" : CurrentEvent.EventId.ToString(),
                                                                         notifSubscription.ClientID);
                    RegisterStartupScriptIfNeeded("notifSubscriptionChangeScript", notifSubscriptionChangeScript);
                    chkNotifSubscription.Attributes.Add("onclick", "UpdateNotifSubscriptionChange();");
                    txtNumSmsNotifications.Attributes.Add("onchange", "UpdateNotifSubscriptionChange();");
                    txtNumSmsNotifications.Attributes.Add("onkeyup", "UpdateNotifSubscriptionChange();");
                }
                else if (CurrentEvent != null)
                {
                    chkNotifSubscription.Visible     = false;
                    txtNumSmsNotifications.Visible   = false;
                    numSmsNotificationsLabel.Visible = false;

                    if (BLL.Mandator.UseEventCategories)
                    {
                        lblNofifSubscriptionDisabled.Text = "Du hast die Abonnierungsfunktion auf dieser<br>Kategorie zur Zeit ausgeschaltet";
                    }
                    else
                    {
                        lblNofifSubscriptionDisabled.Text = "Du hast die Abonnierungsfunktion<br>zur Zeit ausgeschaltet";
                    }
                    lblNofifSubscriptionDisabled.Visible = true;
                }
                else
                {
                    chkNotifSubscription.Checked     = false;
                    txtNumSmsNotifications.Text      = string.Empty;
                    chkNotifSubscription.Visible     = false;
                    txtNumSmsNotifications.Visible   = false;
                    numSmsNotificationsLabel.Visible = false;

                    lblNofifSubscriptionDisabled.Text    = "Momentan ist kein Anlass ausgewählt";
                    lblNofifSubscriptionDisabled.Visible = true;
                }
            }

            events.Visible    = !BLL.Mandator.ShowEventsAsList;
            eventList.Visible = BLL.Mandator.ShowEventsAsList;

            EventDetails_EventUrlLabel.Visible       = BLL.Mandator.UseEventUrl;
            EventDetails_EventUrlControl.Visible     = BLL.Mandator.UseEventUrl;
            EventDetails_MinMaxSubscriptions.Visible = BLL.Mandator.UseMinMaxSubscriptions;
            EventDetails_EventCategory.Visible       = BLL.Mandator.UseEventCategories;
            EventCategoryFilterPopup.Visible         = BLL.Mandator.UseEventCategories;
        }