/// <summary> /// Delete a blob. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void gvUploads_RowDeleting(object sender, GridViewDeleteEventArgs e) { Int32?blobId = HNumeric.GetNullableInteger(this.gvUploads.DataKeys[e.RowIndex].Value); if (blobId != null) { try { // Delete blob from database with the specified binary ID. Blob blob = new Blob() { ID = blobId.Value, State = ObjectState.ToBeDeleted }; blob.Commit(); // Update grid data source. this.BlobFileList.RemoveAll(x => x.ID.Equals(blobId.Value)); this.SortGridView(); } catch (Exception ex) { throw new Exception("Error: Failed to delete blob.", ex); } } }
/// <summary> /// A blob created from a file uploaded by a client. /// </summary> /// <param name="file">A file uploaded by a client.</param> public Blob(HttpPostedFile file) { this.Name = HString.SafeTrim(Path.GetFileName(file.FileName)); this.BinaryData = HBinary.GetBytes(file.InputStream); this.Size = HNumeric.GetSafeInteger(file.ContentLength); this.MimeType = HString.SafeTrim(file.ContentType); this.State = ObjectState.ToBeInserted; }
/// <summary> /// Load a change log item from a data row. /// </summary> /// <param name="dr">Data row containing the data to load.</param> /// <remarks></remarks> public ChangeLogItem(DataRow dr) : base(dr) { this.ID = HNumeric.GetSafeInteger(dr["change_log_master_id"]); this.PropertyName = HString.SafeTrim(dr["property_name"]); this.PreviousValue = HString.SafeTrim(dr["prev_value"]); this.NewValue = HString.SafeTrim(dr["new_value"]); this.State = ObjectState.Unchanged; }
protected void btnSubmit_Click(object sender, EventArgs e) { // Get the month the page should display. DateTime displayMonth = HDateTime.GetDateTime(HNumeric.GetSafeInteger(this.ddlYear.SelectedValue), HNumeric.GetSafeInteger(this.ddlMonth.SelectedValue), 1); // Set UI to indicate what month is being displayed. this.SetControls(displayMonth); // Output html to page. this.LoadCalendar(displayMonth); }
/// <summary> /// A blob loaded from the database. /// </summary> /// <param name="dr">The data row to populate the Blob object.</param> /// <param name="IncludeBinaryData">Flag that determines whether to load the binary data or not.</param> public Blob(DataRow dr, Boolean IncludeBinaryData) { this.ID = HNumeric.GetSafeInteger(dr["binary_id"]); if (IncludeBinaryData) { this.BinaryData = (Byte[])dr["binary_data"]; } this.Name = HString.SafeTrim(dr["binary_name"]); this.MimeType = HString.SafeTrim(dr["binary_mime_type"]); this.Size = HNumeric.GetSafeInteger(dr["binary_size"]); this.State = ObjectState.Unchanged; }
/// <summary> /// Modify what data gets binded. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void gvUploads_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { // This is the current row being binded. GridViewRow gridRow = e.Row as GridViewRow; if (gridRow.Cells.Count >= 3) { // Modify file size value to something friendlier. TableCell fileSize = gridRow.Cells[2]; fileSize.Text = HBinary.GetBytesReadable(HNumeric.GetSafeInteger(fileSize.Text)); } } }
public void ProcessRequest(HttpContext context) { // Possible query strings to transform an image Int32? width = HNumeric.GetNullableInteger(context.Request.QueryString["width"]); Int32? height = HNumeric.GetNullableInteger(context.Request.QueryString["height"]); Decimal?scale = HNumeric.GetNullableDecimal(context.Request.QueryString["scale"]); Decimal?scalew = HNumeric.GetNullableDecimal(context.Request.QueryString["scalew"]); Decimal?scaleh = HNumeric.GetNullableDecimal(context.Request.QueryString["scaleh"]); Int32? pad = HNumeric.GetNullableInteger(context.Request.QueryString["pad"]); Int32? x1 = HNumeric.GetNullableInteger(context.Request.QueryString["x1"]); Int32? y1 = HNumeric.GetNullableInteger(context.Request.QueryString["y1"]); Int32? x2 = HNumeric.GetNullableInteger(context.Request.QueryString["x2"]); Int32? y2 = HNumeric.GetNullableInteger(context.Request.QueryString["y2"]); String cropx = HString.SafeTrim(context.Request.QueryString["x"]); String cropy = HString.SafeTrim(context.Request.QueryString["y"]); Boolean square = HBoolean.ToBooleanFromYN(HString.SafeTrim(context.Request.QueryString["square"])); // Grab image from database--just set one for testing Bitmap image = (Bitmap)System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath("image.gif")); Byte[] imageBytes; /* 1. Resize image */ imageBytes = HImage.RedrawImage(HImage.GetBytesFromBitmap(image), width, height); /* 2. Scale the resized image */ imageBytes = HImage.RedrawImageScaleByRatio(imageBytes, scalew, scaleh, scale, square); /* 3. Crop the scaled image */ if (!String.IsNullOrEmpty(cropx) || !String.IsNullOrEmpty(cropy)) { imageBytes = HImage.RedrawImageSafeCropByGrid(imageBytes, cropx, cropy); } else { imageBytes = HImage.RedrawImageSafeCropByCoordinates(imageBytes, x1, y1, x2, y2); } /* 4. Add padding to image */ if (pad > 0) { imageBytes = HImage.RedrawImageWithPad(imageBytes, pad); } context.Response.Clear(); context.Response.ContentType = "image/" + HImage.GetImageFormat(image).ToString(); context.Response.BinaryWrite(imageBytes); }
public void ProcessRequest(HttpContext context) { Int32?id = HNumeric.GetNullableInteger(context.Request.QueryString["id"]); if (id != null) { BlobFilter filter = new BlobFilter() { ID = id.Value, IncludeBinaryData = true }; Blob file = Blob.Load(filter); if (file != null) { context.Response.Clear(); context.Response.ContentType = file.MimeType; context.Response.AddHeader("content-disposition", "attachment; filename=" + file.Name); context.Response.BinaryWrite(file.BinaryData.ToArray()); } } context.Response.End(); }
/// <summary> /// Determine that the form is valid by checking each input. /// </summary> /// <returns></returns> private Boolean IsValidForm() { Boolean valid = true; // Validate e-mail input. if (HString.IsValidEmail(this.txtEmail.Text.Trim())) { this.AddResultControl(this.inputEmail, this.txtEmail.Text.Trim(), true); } else { this.AddResultControl(this.inputEmail, this.txtEmail.Text.Trim(), false); valid = false; } // Validate password input. if (HString.IsValidPassword(this.txtPassword.Text.Trim())) { this.AddResultControl(this.inputPassword, this.txtPassword.Text.Trim(), true); } else { this.AddResultControl(this.inputPassword, this.txtPassword.Text.Trim(), false); valid = false; } // Validate phone number input. if (HString.IsValidPhoneNumber(this.txtTelephoneNo.Text.Trim())) { this.AddResultControl(this.inputTelephoneNo, this.txtTelephoneNo.Text.Trim(), true); } else { this.AddResultControl(this.inputTelephoneNo, this.txtTelephoneNo.Text.Trim(), false); valid = false; } // Validate URL input. if (HString.IsValidURL(this.txtWebsite.Text.Trim())) { this.AddResultControl(this.inputWebsite, this.txtWebsite.Text.Trim(), true); } else { this.AddResultControl(this.inputWebsite, this.txtWebsite.Text.Trim(), false); valid = false; } // Validate ZIP code input. if (HString.IsValidZIPCode(this.txtZipCode.Text.Trim())) { this.AddResultControl(this.inputZipCode, this.txtZipCode.Text.Trim(), true); } else { this.AddResultControl(this.inputZipCode, this.txtZipCode.Text.Trim(), false); valid = false; } // Validate date input. if (HDateTime.IsValidDate(this.txtDate.Text.Trim(), "M/d/yyyy", "MM/dd/yyyy")) { this.AddResultControl(this.inputDate, this.txtDate.Text.Trim(), true); } else { this.AddResultControl(this.inputDate, this.txtDate.Text.Trim(), false); valid = false; } // Validate DOB input. if (HDateTime.IsValidDateOfBirth(this.txtDOB.Text.Trim(), "M/d/yyyy", "MM/dd/yyyy")) { this.AddResultControl(this.inputDOB, this.txtDOB.Text.Trim(), true); } else { this.AddResultControl(this.inputDOB, this.txtDOB.Text.Trim(), false); valid = false; } // Validate military time input. if (HDateTime.IsValidMilitaryTime(this.txtTimeMilitary.Text.Trim())) { this.AddResultControl(this.inputTimeMilitary, this.txtTimeMilitary.Text.Trim(), true); } else { this.AddResultControl(this.inputTimeMilitary, this.txtTimeMilitary.Text.Trim(), false); valid = false; } // Validate standard time input. if (HDateTime.IsValidStandardTime(this.txtTimeStandard.Text.Trim())) { this.AddResultControl(this.inputTimeStandard, this.txtTimeStandard.Text.Trim(), true); } else { this.AddResultControl(this.inputTimeStandard, this.txtTimeStandard.Text.Trim(), false); valid = false; } // Validate number input. if (HNumeric.GetNullableInteger(this.txtNumber.Text.Trim()) != null) { this.AddResultControl(this.inputNumber, this.txtNumber.Text.Trim(), true); } else { this.AddResultControl(this.inputNumber, this.txtNumber.Text.Trim(), false); valid = false; } // Validate currency input. if (HNumeric.GetNullableCurrency(this.txtCurrency.Text.Trim(), CultureInfo.GetCultureInfo("en-US")) != null) { this.AddResultControl(this.inputCurrency, this.txtCurrency.Text.Trim(), true); } else { this.AddResultControl(this.inputCurrency, this.txtCurrency.Text.Trim(), false); valid = false; } return(valid); }
/// <summary> /// Get any differences between the old and new property values. /// </summary> /// <param name="prevValue">Prevous property value.</param> /// <param name="newValue">New property value.</param> /// <param name="ObjectState">The state of the object.</param> /// <param name="ObjectType">The type of the object.</param> /// <param name="propertyInfo">The property being evaluated.</param> /// <returns></returns> private ChangeLogItem GetChangeLogItem(Object prevValue, Object newValue, ObjectState ObjectState, Type ObjectType, PropertyInfo propertyInfo) { ChangeLogItem lItem = new ChangeLogItem(); lItem.OwnerID = this.OwnerID; lItem.OwnerName = ObjectType.Name; lItem.PropertyName = propertyInfo.Name; lItem.Type = ObjectState.ToString().Replace("ToBe", String.Empty); // Get rid of future tense from state name. if (Object.ReferenceEquals(propertyInfo.PropertyType, typeof(String))) { // COMPARE STRINGS String logPrevious = HString.SafeTrim(prevValue); String logNew = HString.SafeTrim(newValue); if (!logNew.Equals(logPrevious)) { lItem.PreviousValue = logPrevious; lItem.NewValue = logNew; return(lItem); } } else if (Object.ReferenceEquals(propertyInfo.PropertyType, typeof(Int32))) { // COMPARE INTEGERS Int32 logPrevious = HNumeric.GetSafeInteger(prevValue); Int32 logNew = HNumeric.GetSafeInteger(newValue); if (!logNew.Equals(logPrevious)) { lItem.PreviousValue = logPrevious.ToString(); lItem.NewValue = logNew.ToString(); return(lItem); } } else if (Object.ReferenceEquals(propertyInfo.PropertyType, typeof(Decimal))) { // COMPARE DECIMALS Decimal logPrevious = HNumeric.GetSafeDecimal(prevValue); Decimal logNew = HNumeric.GetSafeDecimal(newValue); if (!logNew.Equals(logPrevious)) { lItem.PreviousValue = logPrevious.ToString(); lItem.NewValue = logNew.ToString(); return(lItem); } } else if (Object.ReferenceEquals(propertyInfo.PropertyType, typeof(DateTime))) { // COMPARE DATETIMES DateTime logPrevious = HDateTime.GetDateTime(prevValue); DateTime logNew = HDateTime.GetDateTime(newValue); if (!logNew.Equals(logPrevious)) { lItem.PreviousValue = logPrevious.ToString(); lItem.NewValue = logNew.ToString(); return(lItem); } } else if (propertyInfo.PropertyType.IsEnum) { // COMPARE ENUMS Int32 logPrevious = Convert.ToInt32(prevValue); Int32 logNew = Convert.ToInt32(newValue); if (!logNew.Equals(logPrevious)) { lItem.PreviousValue = logPrevious.ToString(); lItem.NewValue = logNew.ToString(); return(lItem); } } return(null); }