/// <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> /// Validate certain fields of current employee. /// </summary> /// <returns></returns> private Boolean IsValidEmployee() { this.divError.InnerHtml = String.Empty; if (!(this.CurrentEmployee.FirstName.Length > 0)) { this.divError.InnerHtml += "<div>First Name is required.</div>"; } if (!(this.CurrentEmployee.LastName.Length > 0)) { this.divError.InnerHtml += "<div>Last Name is required.</div>"; } if (!(this.CurrentEmployee.Email.Length > 0)) { this.divError.InnerHtml += "<div>Email is required.</div>"; } else if (!HString.IsValidEmail(this.CurrentEmployee.Email)) { this.divError.InnerHtml += "<div>Email is invalid.</div>"; } if (!(this.CurrentEmployee.Phone.Length > 0)) { this.divError.InnerHtml += "<div>Phone is required.</div>"; } else if (!HString.IsValidPhoneNumber(this.CurrentEmployee.Phone)) { this.divError.InnerHtml += "<div>Phone is invalid.</div>"; } if (!(this.CurrentEmployee.State.Length > 0)) { this.divError.InnerHtml += "<div>State is required.</div>"; } if (!(this.CurrentEmployee.City.Length > 0)) { this.divError.InnerHtml += "<div>City is required.</div>"; } if (!(this.CurrentEmployee.Street.Length > 0)) { this.divError.InnerHtml += "<div>Street is required.</div>"; } if (!(this.CurrentEmployee.Zip.Length > 0)) { this.divError.InnerHtml += "<div>Zip is required.</div>"; } else if (!HString.IsValidZIPCode(this.CurrentEmployee.Zip)) { this.divError.InnerHtml += "<div>Zip is invalid.</div>"; } this.divError.Visible = true; return(!(this.divError.InnerHtml.Length > 0)); }
/// <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> /// 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 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> /// 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; }
/// <summary> /// Process contact node. /// </summary> /// <param name="contact">The contact node.</param> /// <returns>The contact information of employee.</returns> private String ProcessContact(XPathNavigator contact) { StringBuilder currentEmployee = new StringBuilder(); if (contact != null) { String phone = HString.CsvSafeTrim(HXml.SelectNodeValue(contact, "phone")); String email = HString.CsvSafeTrim(HXml.SelectNodeValue(contact, "email")); String address = this.ProcessAddress(contact.SelectSingleNode("address")); currentEmployee.AppendFormat("{0},{1},{2}", address, phone, email); } return(currentEmployee.ToString()); }
/// <summary> /// Process address node. /// </summary> /// <param name="address">The address node.</param> /// <returns>The address of employee.</returns> private String ProcessAddress(XPathNavigator address) { StringBuilder currentEmployee = new StringBuilder(); if (address != null) { String state = HString.CsvSafeTrim(HXml.SelectNodeValue(address, "state")); String city = HString.CsvSafeTrim(HXml.SelectNodeValue(address, "city")); String street = HString.CsvSafeTrim(HXml.SelectNodeValue(address, "street")); String zip = HString.CsvSafeTrim(HXml.SelectNodeValue(address, "zip")); currentEmployee.AppendFormat("{0},{1},{2},{3}", state, city, street, zip); } return(currentEmployee.ToString()); }
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> /// Create CSV for each employee. /// </summary> /// <param name="employee">The employee node.</param> /// <param name="transform">The CSV string.</param> private void TransformEmployee(XPathNavigator employee, ref StringBuilder transform) { StringBuilder currentEmployee = new StringBuilder(); String guid = Guid.NewGuid().ToString(); String id = HString.CsvSafeTrim(HXml.SelectNodeValue(employee, "id")); String firstName = HString.CsvSafeTrim(HXml.SelectNodeValue(employee, "first-name")); String lastName = HString.CsvSafeTrim(HXml.SelectNodeValue(employee, "last-name")); String title = HString.CsvSafeTrim(HXml.SelectNodeValue(employee, "title")); String dateOfBirth = HString.CsvSafeTrim(HXml.SelectNodeValue(employee, "date-of-birth")); String contact = this.ProcessContact(employee.SelectSingleNode("contact")); // Set CSV line for this employee. currentEmployee.AppendFormat("{0},{1},{2} {3},{4},{5},{6}", guid, id, firstName, lastName, title, dateOfBirth, contact); // Append to current transform data. transform.AppendLine(currentEmployee.ToString()); }
/// <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> /// 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); }
public OperationFailedException(string message) : base(HString.FormatAsText(message)) { }
public OperationFailedException(string message, Exception innerException) : base(HString.FormatAsText(message), innerException) { }
/// <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); }
protected void RenamedCore(object pDesktop, HString chName) => this.Notification.VirtualDesktopRenamed(this.Wrap(pDesktop), chName);
public static OperationFailedException Create(string messageFmt, params object[] parameters) { return(new OperationFailedException(HString.FormatAsText(messageFmt, parameters))); }
public void VirtualDesktopWallpaperChanged(IVirtualDesktop pDesktop, HString chPath) { this.WallpaperChangedCore(pDesktop, chPath); }
public void VirtualDesktopRenamed(IVirtualDesktop pDesktop, HString chName) { this.RenamedCore(pDesktop, chName); }
protected void WallpaperChangedCore(object pDesktop, HString chPath) => this.Notification.VirtualDesktopWallpaperChanged(this.Wrap(pDesktop), chPath);
/// <exception cref="ArgumentNullException" /> /// <exception cref="HAppFailureException" /> static void ThrowCommandParametersError(string messageFmt, params object[] parameters) { ThrowCommandParametersError(HString.FormatAsText(messageFmt, parameters)); }