/// <summary> /// Load change log from a data row. /// </summary> /// <param name="dr">Data row containing the data to load.</param> /// <remarks></remarks> public ChangeLog(DataRow dr) { this.OwnerID = HString.SafeTrim(dr["owner_id"]); this.OwnerName = HString.SafeTrim(dr["owner_name"]); this.Type = HString.SafeTrim(dr["log_type"]); this.Timestamp = HDateTime.GetDateTime(dr["timestamp"]); }
/// <summary> /// Save current employee. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { // Set values. this.CurrentEmployee.FirstName = HString.SafeTrim(this.txtFirstName.Text); this.CurrentEmployee.LastName = HString.SafeTrim(this.txtLastName.Text); this.CurrentEmployee.Email = HString.SafeTrim(this.txtEmail.Text); this.CurrentEmployee.Phone = HString.SafeTrim(this.txtPhone.Text); this.CurrentEmployee.State = HString.SafeTrim(this.txtState.Text); this.CurrentEmployee.City = HString.SafeTrim(this.txtCity.Text); this.CurrentEmployee.Street = HString.SafeTrim(this.txtStreet.Text); this.CurrentEmployee.Zip = HString.SafeTrim(this.txtZip.Text); if (this.IsValidEmployee()) { // Save employee. this.CurrentEmployee.Commit(); this.divSuccess.Visible = true; this.divSuccess.InnerHtml = String.Format("<div>You have successfully {0} an employee.</div>", CurrentEmployee.ObjectState == ObjectState.ToBeInserted ? "added" : "updated"); if (this.CurrentEmployee.ObjectState == ObjectState.ToBeInserted) { // Allow for additional employees to be added. this.CurrentEmployee = new Employee(); this.ClearForm(); } } }
/// <summary> /// A state loaded from the database. /// </summary> /// <param name="dr">The data row to populate the State object.</param> public State(DataRow dr) { this.AnsiCode = HString.SafeTrim(dr["state_ansi_code"]); this.Name = HString.SafeTrim(dr["state_name"]); this.Capital = HString.SafeTrim(dr["state_capital"]); this.LargestCity = HString.SafeTrim(dr["state_largest_city"]); this.LargestMetro = HString.SafeTrim(dr["state_largest_metro"]); }
/// <summary> /// A user loaded from the database. /// </summary> /// <param name="dr">The data row to populate the User object.</param> public User(DataRow dr) { this.Guid = Guid.Parse(HString.SafeTrim(dr["user_master_guid"])); this.UserName = HString.SafeTrim(dr["user_name"]); this.UserPassword = HString.SafeTrim(dr["user_password"]); this.UserSalt = HString.SafeTrim(dr["user_salt"]); this.State = ObjectState.Unchanged; }
/// <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; }
/// <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; }
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); }
protected void btnSearch_Click(object sender, EventArgs e) { // Get search filter. String searchText = HString.SafeTrim(this.txtSearch.Text); BlobFilter filter = new BlobFilter() { IncludeBinaryData = false, Name = searchText }; // Search files by name. List <Blob> files = Blob.LoadCollection(filter); // Rebind results. this.BlobFileList = files; this.gvUploads.DataSource = this.BlobFileList; this.gvUploads.DataBind(); }
/// <summary> /// Delete the specified employee. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void lnkDelete_Click(object sender, EventArgs e) { LinkButton button = sender as LinkButton; Guid eid = Guid.Empty; Guid.TryParse(HString.SafeTrim(button.CommandArgument), out eid); if (eid != Guid.Empty) { Employee employee = Employee.Load(new EmployeeFilter() { Guid = eid }); if (employee != null) { employee.ObjectState = ObjectState.ToBeDeleted; employee.Commit(); } } }
/// <summary> /// An employee loaded from the database. /// </summary> /// <param name="dr">The data row to populate the Employee object.</param> public Employee(DataRow dr) { String employeeXml = HString.SafeTrim(dr["employee_xml"]); if (!String.IsNullOrEmpty(employeeXml)) { // NEW WAY Employee employee = HXml.DeserializeFromXml <Employee>(employeeXml); if (employee != null) { this.Guid = employee.Guid; this.FirstName = employee.FirstName; this.LastName = employee.LastName; this.Email = employee.Email; this.Phone = employee.Phone; this.State = employee.State; this.City = employee.City; this.Street = employee.Street; this.Zip = employee.Zip; this.ObjectState = ObjectState.Unchanged; } } else { // OLD WAY this.Guid = Guid.Parse(HString.SafeTrim(dr["employee_master_guid"])); this.FirstName = HString.SafeTrim(dr["employee_first_name"]); this.LastName = HString.SafeTrim(dr["employee_last_name"]); this.Email = HString.SafeTrim(dr["employee_email"]); this.Phone = HString.SafeTrim(dr["employee_phone"]); this.State = HString.SafeTrim(dr["employee_state"]); this.City = HString.SafeTrim(dr["employee_city"]); this.Street = HString.SafeTrim(dr["employee_street"]); this.Zip = HString.SafeTrim(dr["employee_zip"]); this.ObjectState = ObjectState.Unchanged; } this.UnchangedEmployee = this; }
/// <summary> /// Updates a user's username and/or password. /// </summary> /// <param name="user">User object to be committed to the database.</param> /// <param name="e">The item row being updated.</param> private void UpdateUser(User user, RepeaterCommandEventArgs e) { try { // Set username entered to check if we need to commit any changes. String newUsername = HString.SafeTrim(((TextBox)e.Item.FindControl("txtUserName")).Text); // If a new password is entered, update it. if (((TextBox)e.Item.FindControl("txtPassword")).Text.Length > 0) { // Generate a new salt and create a new password hash. user.UserSalt = HCryptography.BytesToHexString(HCryptography.GetRandomSalt(256)); user.UserPassword = HCryptography.GetHashString(HString.SafeTrim(((TextBox)e.Item.FindControl("txtPassword")).Text), user.UserSalt, 256); } // Check if the username has been modified and that it is unique in the database. if (!String.IsNullOrEmpty(newUsername) && this.ValidUsername(newUsername)) { // Get username from the corresponding textbox field on this data row. user.UserName = HString.SafeTrim(((TextBox)e.Item.FindControl("txtUserName")).Text); } // Update user credentials. user.Commit(); // Rebind data. this.SetUserTable(); // Toggle item row, regardless if we can update user or not. this.ToggleDataRow(e, true); } catch (Exception ex) { throw new Exception("Error: Unable to update user.", ex); } }
/// <summary> /// Search all employee fields by keyword. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSearch_Click(object sender, EventArgs e) { this.CurrentFilter.Keyword = HString.SafeTrim(this.txtKeyword.Text); }
/// <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); }