public static void UpdateBillingPlanOptionsFromUI(PlaceHolder phPlans, BillingPlanOptions[] planOptions) { Type billingPlanOptionsType = typeof(BillingPlanOptions); PropertyInfo[] propertyInfoArray = billingPlanOptionsType.GetProperties(); foreach (var options in planOptions) { options.ContainsOptionWithEnabledCredits = false; } foreach (var propertyInfo in propertyInfoArray) { if (propertyInfo.PropertyType.IsGenericType && propertyInfo.PropertyType.GetGenericTypeDefinition() == typeof(BillingPlanOption<>)) { List<object> previousOptions = new List<object>(); foreach (var options in planOptions) { var option = propertyInfo.GetValue(options, null); string optionID = (string)option.GetType().GetField("ID").GetValue(option); object optionValue = option.GetType().GetField("Value").GetValue(option); Control control = FindControl(phPlans, optionID); if (control == null) throw new Exception("No Control with such ID!"); if (optionValue is Enum) { string val = ((DropDownList)control).SelectedItem.Value; optionValue = StringToEnum(optionValue.GetType(), val); } else if (optionValue is Boolean) { OptionAvailability availability = (OptionAvailability) Int32.Parse(((DropDownList)control).SelectedValue); optionValue = false; option.GetType().GetField("EnableCreditsPayment").SetValue(option, false); switch (availability) { case OptionAvailability.Allowed: optionValue = true; break; case OptionAvailability.NotAllowed: optionValue = false; break; case OptionAvailability.AllowedWithCredits: option.GetType().GetField("EnableCreditsPayment").SetValue(option, true); options.ContainsOptionWithEnabledCredits = true; break; } //optionValue = ((CheckBox)control).Checked; } else if (optionValue is String || optionValue is Int32 || optionValue is Double || optionValue is Decimal) { TextBox txtValue = (TextBox)control; if (optionValue is String) optionValue = txtValue.Text; else if (optionValue is Int32) { try { optionValue = Convert.ToInt32(txtValue.Text.Trim()); } catch (FormatException) { optionValue = 0; } } else if (optionValue is Double) { try { optionValue = Convert.ToDouble(txtValue.Text.Trim()); } catch (FormatException) { optionValue = 0.0; } } else if (optionValue is Decimal) { try { optionValue = Convert.ToDecimal(txtValue.Text.Trim()); } catch (FormatException) { optionValue = 0.0M; } } } else if (optionValue is string[]) { TextBox txtValues = (TextBox)control; optionValue = txtValues.Text.Split(','); } else if (optionValue is Hashtable) { TextBox txtValues = (TextBox)control; optionValue = StringToHashtable(txtValues.Text); } else if (optionValue is Color) { TextBox txtValue = (TextBox)control; optionValue = StringToColor(txtValue.Text); } else throw new Exception("Setting type not implemented!"); option.GetType().GetField("Value").SetValue(option, optionValue); bool allowCredits = (bool)option.GetType().GetField("AllowCredits").GetValue(option); if (allowCredits && !(optionValue is Boolean)) { CheckBox cbEnableCredits = FindControl(phPlans, optionID + "EnableCredits") as CheckBox; if (cbEnableCredits != null) { option.GetType().GetField("EnableCreditsPayment").SetValue(option, cbEnableCredits.Checked); if (cbEnableCredits.Checked) options.ContainsOptionWithEnabledCredits = true; } } if (allowCredits) { TextBox txtCredits = FindControl(phPlans, optionID + "Credits") as TextBox; if (txtCredits != null) { int credits; if (Int32.TryParse(txtCredits.Text.Trim(), out credits)) { option.GetType().GetField("Credits").SetValue(option, credits); } } } if (optionValue is Boolean) { if (!((bool)optionValue)) { previousOptions.Add(option); option.GetType().GetField("UpgradableToNextPlan").SetValue(option, false); } else { foreach (var previousOption in previousOptions) { previousOption.GetType().GetField("UpgradableToNextPlan").SetValue(previousOption, true); } previousOptions.Clear(); } } else if (optionValue is Int32) { previousOptions.Add(option); option.GetType().GetField("UpgradableToNextPlan").SetValue(option, false); bool enableCredits = (bool) option.GetType().GetField("EnableCreditsPayment").GetValue(option); foreach (var previousOption in previousOptions) { if (((BillingPlanOption<int>)previousOption).Value < (int)optionValue || enableCredits) previousOption.GetType().GetField("UpgradableToNextPlan").SetValue(previousOption, true); } } } } } }
public static void GenerateBillingPlanOptionsTable(PlaceHolder phPlans, BillingPlanOptions[] planOptions,Action executeAfterDelete, bool readOnly) { //PropertyData[] items = objectInstance == null ? // GetPropertiesData(SettingsClassType, NO_LANGUAGE) : GetPropertiesDataFromObject(objectInstance, NO_LANGUAGE); Table tblPlans = new Table(); tblPlans.CellPadding = 0; tblPlans.CellSpacing = 0; tblPlans.CssClass = "stable"; //PropertyData lastItem = null; int itemNum = 0; Type billingPlanOptionsType = typeof(BillingPlanOptions); PropertyInfo[] propertyInfoArray = billingPlanOptionsType.GetProperties(); foreach (var propertyInfo in propertyInfoArray) { if (propertyInfo.PropertyType.IsGenericType && propertyInfo.PropertyType.GetGenericTypeDefinition() == typeof(BillingPlanOption<>)) { #region Plan names if (itemNum == 0) { #region PlanInfo TableRow planNameRow = new TableRow(); TableCell planNameCell = new TableCell(); planNameRow.Cells.Add(planNameCell); planNameCell.Text = Lang.TransA("Plans"); planNameCell.CssClass = "table_header"; TableRow amountRow = new TableRow(); TableCell amountCell = new TableCell(); amountRow.Cells.Add(amountCell); amountCell.Text = Lang.TransA("<b>Amount</b>"); amountCell.CssClass = "slabel"; TableRow cycleRow = new TableRow(); TableCell cycleCell = new TableCell(); cycleRow.Cells.Add(cycleCell); cycleCell.Text = Lang.TransA("<b>Cycle</b>"); cycleCell.CssClass = "slabel"; TableRow cycleUnitRow = new TableRow(); TableCell cycleUnitCell = new TableCell(); cycleUnitRow.Cells.Add(cycleUnitCell); cycleUnitCell.Text = Lang.TransA("<b>CycleUnit</b>"); cycleUnitCell.CssClass = "slabel"; foreach (var options in planOptions) { planNameCell = new TableCell(); planNameCell.CssClass = "table_header"; amountCell = new TableCell(); cycleCell = new TableCell(); cycleUnitCell = new TableCell(); var option = propertyInfo.GetValue(options, null); int planID = (int)option.GetType().GetField("PlanID").GetValue(option); planNameRow.Cells.Add(planNameCell); amountRow.Cells.Add(amountCell); cycleRow.Cells.Add(cycleCell); cycleUnitRow.Cells.Add(cycleUnitCell); if (planID == -1) { planNameCell.Text = Lang.TransA("Non-Paying Members"); amountCell.Text = String.Empty; cycleCell.Text = String.Empty; cycleUnitCell.Text = String.Empty; } else { TextBox txtPlanName = new TextBox(); txtPlanName.ID = "PlanName" + planID; TextBox txtAmount = new TextBox(); txtAmount.ID = "Amount" + planID; TextBox txtCycle = new TextBox(); txtCycle.ID = "Cycle" + planID; DropDownList ddCycleUnits = new DropDownList(); ddCycleUnits.ID = "CycleUnits" + planID; ddCycleUnits.Items.Add(new ListItem(Lang.TransA(CycleUnits.Days.ToString()), ((int)CycleUnits.Days).ToString())); ddCycleUnits.Items.Add(new ListItem(Lang.TransA(CycleUnits.Weeks.ToString()), ((int)CycleUnits.Weeks).ToString())); ddCycleUnits.Items.Add(new ListItem(Lang.TransA(CycleUnits.Months.ToString()), ((int)CycleUnits.Months).ToString())); ddCycleUnits.Items.Add(new ListItem(Lang.TransA(CycleUnits.Years.ToString()), ((int)CycleUnits.Years).ToString())); var plan = BillingPlan.Fetch(planID); txtPlanName.Text = plan.Title; txtAmount.Text = plan.Amount.ToString(); txtCycle.Text = plan.Cycle.ToString(); ddCycleUnits.SelectedValue = ((int)plan.CycleUnit).ToString(); planNameCell.Controls.Add(txtPlanName); amountCell.Controls.Add(txtAmount); cycleCell.Controls.Add(txtCycle); cycleUnitCell.Controls.Add(ddCycleUnits); } } tblPlans.Rows.Add(planNameRow); tblPlans.Rows.Add(amountRow); tblPlans.Rows.Add(cycleRow); tblPlans.Rows.Add(cycleUnitRow); #endregion } //header.Text = item.ClassDesc; //headerRow.Cells.Add(header); //tblSettings.Rows.Add(headerRow); #endregion TableRow itemRow = new TableRow(); if (itemNum % 2 != 0) itemRow.CssClass = "even_row"; var firstOption = propertyInfo.GetValue(planOptions[0], null); TableCell descCell = new TableCell(); descCell.CssClass = "slabel"; descCell.Text = firstOption.GetType().GetField("PropertyDescription").GetValue(firstOption).ToString(); itemRow.Cells.Add(descCell); foreach (var options in planOptions) { var option = propertyInfo.GetValue(options, null); object optionValue = option.GetType().GetField("Value").GetValue(option); string optionID = (string) option.GetType().GetField("ID").GetValue(option); bool allowCredits = (bool)option.GetType().GetField("AllowCredits").GetValue(option); bool enableCreditsPayment = (bool)option.GetType().GetField("EnableCreditsPayment").GetValue(option); TableCell valueCell = new TableCell(); valueCell.CssClass = "svalue"; if (optionValue is Enum) { string[] fields = GetEnumElementsDescription((Enum)optionValue); Array values = Enum.GetValues(optionValue.GetType()); DropDownList dropEnums = new DropDownList(); dropEnums.ID = optionID; //dropEnums.Font.Name = "Arial"; //dropEnums.Font.Size = 9; for (int i = 0; i < fields.Length; ++i) { dropEnums.Items.Add(new ListItem(fields[i], values.GetValue(i).ToString())); } dropEnums.SelectedValue = optionValue.ToString(); valueCell.Controls.Add(dropEnums); } else if (optionValue is Boolean) { DropDownList ddValue = new DropDownList(); ddValue.ID = optionID; ddValue.Items.Add(new ListItem("Not Allowed".TranslateA(), ((int)OptionAvailability.NotAllowed).ToString())); ddValue.Items.Add(new ListItem("Allowed".TranslateA(), ((int)OptionAvailability.Allowed).ToString())); if (allowCredits) { ddValue.Items.Add(new ListItem("Allowed with credits".TranslateA(), ((int)OptionAvailability.AllowedWithCredits).ToString())); } if (enableCreditsPayment) { ddValue.SelectedValue = ((int)OptionAvailability.AllowedWithCredits).ToString(); } else if ((bool)optionValue) ddValue.SelectedValue = ((int)OptionAvailability.Allowed).ToString(); else ddValue.SelectedValue = ((int)OptionAvailability.NotAllowed).ToString(); valueCell.Controls.Add(ddValue); //CheckBox chkValue = new CheckBox(); //chkValue.ID = optionID; //chkValue.Checked = (bool)optionValue; //valueCell.Controls.Add(chkValue); } else if (optionValue is String || optionValue is Int32 || optionValue is Double || optionValue is Decimal) { TextBox txtValue = new TextBox(); txtValue.Columns = 4; txtValue.ID = optionID; txtValue.Text = optionValue.ToString(); //txtValue.Font.Name = "Arial"; //txtValue.Font.Size = 9; valueCell.Controls.Add(txtValue); } else if (optionValue is string[]) { TextBox txtValues = new TextBox(); txtValues.ID = optionID; txtValues.Text = StringArrayToCommaDelimitedString((string[])optionValue); //txtValues.Font.Name = "Arial"; //txtValues.Font.Size = 9; txtValues.TextMode = TextBoxMode.MultiLine; txtValues.Columns = 40; txtValues.Rows = 4; valueCell.Controls.Add(txtValues); } else if (optionValue is Hashtable) { TextBox txtValues = new TextBox(); txtValues.ID = optionID; txtValues.Text = HashtableToString((Hashtable)optionValue); //txtValues.Font.Name = "Arial"; //txtValues.Font.Size = 9; txtValues.TextMode = TextBoxMode.MultiLine; txtValues.Columns = 80; txtValues.Rows = 8; valueCell.Controls.Add(txtValues); } else if (optionValue is Color) { TextBox txtValue = new TextBox(); txtValue.ID = optionID; txtValue.Text = ColorToString((Color)optionValue, true); //txtValue.Font.Name = "Arial"; //txtValue.Font.Size = 9; valueCell.Controls.Add(txtValue); } else throw new Exception("Setting type not implemented!"); if (allowCredits && !(optionValue is Boolean)) { CheckBox cbEnableCredits = new CheckBox(); cbEnableCredits.ID = optionID + "EnableCredits"; cbEnableCredits.Checked = enableCreditsPayment; cbEnableCredits.Text = "Use credits".TranslateA(); valueCell.Controls.Add(cbEnableCredits); } if (allowCredits) { TextBox txtCredits = new TextBox(); int credits = (int)option.GetType().GetField("Credits").GetValue(option); txtCredits.Text = credits.ToString(); txtCredits.ID = optionID + "Credits"; txtCredits.Columns = 4; valueCell.Controls.Add(txtCredits); if (optionValue is Boolean) { var ddValue = valueCell.Controls[0] as DropDownList; ddValue.Attributes.Add("onchange", "$get('" + ddValue.ClientID + "').value == '" + (int)OptionAvailability.AllowedWithCredits + "' ? $get('" + txtCredits.ClientID + "').style.display = '' : $get('" + txtCredits.ClientID + "').style.display = 'none'"); if (!enableCreditsPayment) txtCredits.Style[HtmlTextWriterStyle.Display] = "none"; } } itemRow.Cells.Add(valueCell); } tblPlans.Rows.Add(itemRow); if (itemNum == propertyInfoArray.Length - 2) { TableRow footerRow = new TableRow(); TableCell footerCell = new TableCell(); footerRow.Cells.Add(footerCell); //footerCell.Text = Lang.TransA("Plans"); foreach (var options in planOptions) { footerCell = new TableCell(); var option = propertyInfo.GetValue(options, null); int planID = (int)option.GetType().GetField("PlanID").GetValue(option); footerRow.Cells.Add(footerCell); if (planID == -1) { //headerCell.Text = Lang.TransA("Non-Paying Members"); } else { Button button = new Button(); button.Enabled = !readOnly; button.ID = "btnDelete" + planID; button.Text = "Delete".TranslateA(); button.CommandName = "Delete"; button.CommandArgument = planID.ToString(); button.Command += new CommandEventHandler((s, e) => { if (e.CommandName == "Delete") { if (readOnly) return; BillingPlan.Delete(Int32.Parse((string)e.CommandArgument)); executeAfterDelete(); } }); //TextBox txtValue = new TextBox(); //txtValue.ID = "PlanName" + planID; //var plan = BillingPlan.Fetch(planID); //txtValue.Text = plan.Title; footerCell.Controls.Add(button); } } tblPlans.Rows.Add(footerRow); } //lastItem = item; ++itemNum; } } phPlans.Controls.Add(tblPlans); }
public void ProcessRequest(HttpContext context) { int width = Convert.ToInt32(context.Request.Params["width"]); int height = Convert.ToInt32(context.Request.Params["height"]); string cacheKey = "webcamUpload_" + context.Request.Params["guid"]; if (context.Cache.Get(cacheKey) != null) { Username = ((string)context.Cache.Get(cacheKey)).Split('|')[0]; string photoAlbumID = ((string)context.Cache.Get(cacheKey)).Split('|')[1]; if (photoAlbumID == "-1") PhotoAlbumID = null; else PhotoAlbumID = Convert.ToInt32(photoAlbumID); } if (Username != null) { User user = null; try { user = User.Load(Username); } catch (NotFoundException) { return; } Bitmap bmp = new Bitmap(width, height); Graphics graphics = Graphics.FromImage(bmp); SolidBrush brush = new SolidBrush(Color.White); graphics.FillRectangle(brush, 0, 0, width, height); for (int rows = 0; rows < height; rows++) { string parameters = context.Request.Params["px" + rows]; // convert the string into an array of n elements string[] crow = (parameters).Split(','); for (int cols = 0; cols < width; cols++) { string value = crow[cols]; if (value.Length > 0) { StringBuilder hex = new StringBuilder(value); while (hex.Length < 6) { hex.Insert(0, "0").Append(hex.ToString()); } int r = Int32.Parse(hex.ToString().Substring(0, 2), System.Globalization.NumberStyles.HexNumber); int g = Int32.Parse(hex.ToString().Substring(2, 2), System.Globalization.NumberStyles.HexNumber); int b = Int32.Parse(hex.ToString().Substring(4, 2), System.Globalization.NumberStyles.HexNumber); Color c = Color.FromArgb(r, g, b); bmp.SetPixel(cols, rows, c); } } } if (Config.Photos.DoWatermark && bmp.Width >= Config.Photos.MinWidthToWatermark && bmp.Height >= Config.Photos.MinHeightToWatermark) { Image watermark; if (context.Cache["Watermark_Image"] == null) { string filename = context.Server.MapPath("~/Images") + "/Watermark.png"; watermark = Image.FromFile(filename); context.Cache.Add("Watermark_Image", watermark, new CacheDependency(filename), Cache.NoAbsoluteExpiration, TimeSpan.FromHours(24), CacheItemPriority.NotRemovable, null); } else { watermark = (Image)context.Cache["Watermark_Image"]; } try { lock (watermark) { Photo.ApplyWatermark(bmp, watermark, Config.Photos.WatermarkTransparency, Config.Photos.WatermarkPosition); } } catch (Exception err) { Global.Logger.LogWarning("Unable to apply watermark", err); } } BillingPlanOptions billingPlanOptions = null; Subscription subscription = Subscription.FetchActiveSubscription(Username); if (subscription == null) billingPlanOptions = new BillingPlanOptions(); else { BillingPlan plan = BillingPlan.Fetch(subscription.PlanID); billingPlanOptions = plan.Options; } Photo photo = new Photo(); photo.Image = bmp; photo.ExplicitPhoto = false; photo.User = user; photo.PhotoAlbumID = PhotoAlbumID; photo.Name = String.Empty; photo.Description = String.Empty; if (Config.Photos.AutoApprovePhotos || billingPlanOptions.AutoApprovePhotos.Value || user.Level != null && user.Level.Restrictions.AutoApprovePhotos) { photo.Approved = true; } else { photo.Approved = false; } photo.Save(true); photo.Image.Dispose(); if (photo.Approved && !photo.PrivatePhoto) { #region Add NewFriendPhoto Event Event newEvent = new Event(photo.Username); newEvent.Type = Event.eType.NewFriendPhoto; NewFriendPhoto newFriendPhoto = new NewFriendPhoto(); newFriendPhoto.PhotoID = photo.Id; newEvent.DetailsXML = Misc.ToXml(newFriendPhoto); newEvent.Save(); string[] usernames = Classes.User.FetchMutuallyFriends(photo.Username); foreach (string friendUsername in usernames) { if (Config.Users.NewEventNotification) { string text = String.Format("Your friend {0} has uploaded a new photo".Translate(), "<b>" + photo.Username + "</b>"); string thumbnailUrl = ImageHandler.CreateImageUrl(photo.Id, 50, 50, false, true, true); Classes.User.SendOnlineEventNotification(photo.Username, friendUsername, text, thumbnailUrl, UrlRewrite.CreateShowUserPhotosUrl( photo.Username)); } } #endregion } } }
public static void GetBillingPlanOptionsData(BillingPlanOptions billingPlanOptions, int planID) { Type billingPlanOptionsType = billingPlanOptions.GetType(); PropertyInfo[] propertyInfoArray = billingPlanOptionsType.GetProperties(); foreach (var propertyInfo in propertyInfoArray) { if (propertyInfo.PropertyType.IsGenericType && propertyInfo.PropertyType.GetGenericTypeDefinition() == typeof(BillingPlanOption<>)) { object billingPlanOption = propertyInfo.GetValue(billingPlanOptions, null); string description = GetDescriptionAttribute(propertyInfo); billingPlanOption.GetType().GetField("PropertyDescription").SetValue(billingPlanOption, description); billingPlanOption.GetType().GetField("ID").SetValue(billingPlanOption, billingPlanOptionsType.FullName + propertyInfo.Name + planID); billingPlanOption.GetType().GetField("PlanID").SetValue(billingPlanOption, planID); bool allowCredits = GetAllowCreditsAttribute(propertyInfo); billingPlanOption.GetType().GetField("AllowCredits").SetValue(billingPlanOption, allowCredits); } } //return optionsData.ToArray(); }
public static void SetNonPayingMembersOptions(BillingPlanOptions options) { DBSettings.Set("Users_NonPayingMembersOptions", Classes.Misc.ToXml(options)); }