moopoo.net
Fishing, technology and anything else

Highlighting row on form error with jQuery

May 18th, 2009 by Matt

When showing errors in web forms, I thought it would be useful to highlight the row where the error occurred so the user can visually see where they they need to make changes. jQuery is the ideal way to do this for me as I didn’t want to do it server side.

To begin I set a CSS class on the error messages that were displayed in the td with the form element. An error message could be in the form of

<span class=".valError">You have selected an invalid date.</span>

Now all we have to do in jQuery is find all elements which match the class, remove any classes that may be on any of the td tags, then add a class to the tr in which the error exists.

$(".valError").each(function() {
    // remove all classes from any td's of the below the parent row
    $(this).parent().parent().find("td").removeClass();
    // set the class on the tr
    $(this).parent().parent().addClass('ms-informationbar');
})

That’s it.

You could optionally set the class of the td rather than or as well as the tr. The following line would help you achieve this.

$(this).parent().parent().find("td").removeClass().addClass('myErrorClass');

Posted in jQuery | No Comments »

iPhone 3.0 beta restore error 1602 or 1604 solution

May 1st, 2009 by Matt

After downloading and trying to update 3.0 beta 4 and iTunes pre-release 8.2 to go with it, I was prompted with a nice error 1602 from iTunes and a pink screen on my iPhone. Trying again got me a lovely 1604 error instead.

You’ve never seen a man panic…

So, to get it working again here are the steps I took:

  1. Uninstall iTunes & QuickTime
  2. Backed up the iTunes folder in C:\Documents and Settings\[username]\Application Data\Apple Computer\, then deleted the original
  3. Rebooted the PC
  4. Re-install iTunes 8.2 pre-release
  5. Run the restore again from iTunes

Not sure how mandatory step 2 above is but I did it and it worked for me, plus I didn’t have anything in the iTunes folder that I needed to keep.

Posted in iPhone | No Comments »

CAML Querying using DateTime.

January 13th, 2009 by Matt

Caml queries on DateTime fields by default do not use the Time portion of the field. To overcome this use the attribute IncludeTimeValue=’TRUE’ in the value tag. For example:

<Value Type=’DateTime’ IncludeTimeValue=’TRUE’><Today /></Value>

Posted in SharePoint | No Comments »

SharePoint Web Part Properties

December 3rd, 2008 by Matt

When creating a WebPart inheriting from System.Web.UI.WebControls.WebParts.WebPart, use the following code to add a custom Integer property that will sit in it’s own Category when you modify the properties of the web part.

private const int _intMaxShiftsPerDay = 0;
private int IntMaxShiftsPerDay = _intMaxShiftsPerDay;
[Category("Custom Properties")]
[DefaultValue(_intMaxShiftsPerDay)]
[Personalizable(PersonalizationScope.Shared)]
[WebDisplayName("Maximum Shifts Allowed Per Day")]
[WebDescription("Type in the maximum allowed shifts per day for each person")]
[WebBrowsable(true)]
[XmlElement(ElementName = "intMaxShiftsPerDay")]
public int intMaxShiftsPerDay
{
    get
    {
        return IntMaxShiftsPerDay;
    }
    set
   {
        IntMaxShiftsPerDay = value;
    }
}

Posted in SharePoint | No Comments »

Deploy a sharepoint solution with stsadm

October 31st, 2008 by Matt

First off we need to add the solution to SharePoint

stsadm -o addsolution -filename c:\path-to\filename.wsp

Next, we deploy the solution to the site

stsadm -o deploysolution -name filename.wsp -url http://myurl -immediate Optionally if you use Code Access Security add the following to the above

-allowcaspoliciesand if you have assemblies that deploy to the GAC, add this line to the deploysolution statement above

-allowgacdeploymentThis will create a timer job, we then simply need to execute this job

stsadm -o execadmsvcjobs

Posted in SharePoint | No Comments »

Using the Rive Hooktyer

January 21st, 2008 by Matt

The Rive hooktyer is a great system for getting your hooklengths the perfect length every time, but it can be tricky to get going with, especially with the instruction supplied in French and the diagrams not particularly helpful. Well fear not, this guide will help you.

Firstly tie set the length bar on the tyer to the length you require. To speed up the process and reduce line wastage I tie as many loops on the line as I require enabling me to quickly cut off the line above the loop when I need to tie the next hook. Remember to leave enough extra line between each loop for tying.

 

Insert the brass pin through the hole and put the hook in with the shank at the bottom.

Attach the loop to the end of the tyer and and wrap the line around the far side of the pin and beginning whipping the line around the hook, making sure the the line comes off the front of the shank as you tie.

Whip down the shank for as many turns as are required then pass the line between the flat side of the brass pin and the bent pin.

Photograph of hook ready for the tag to be trimmed

Keeping the line under tension, remove the brass pin pulling through the line with it, again making sure you keep tension on as the line comes through the other side.

Moisten the knot and slowly pull from the top side to tighten the knot.

The finished hook

Job done. Once you have tighened the knot, trim the tag to size and the hooklength is the the perfect length.

After a bit of practice you should be able to tie many hooklengths in no time at all.

Posted in Fishing | 1 Comment »

Windows Live Writer

October 28th, 2007 by Matt

After seeing that the new WordPress 2.3.1 release had tagging support in for Windows Live Writer, I was curious as to what Live Writer actually was. Turns out it is a desktop application for authoring blog posts that can be published to a variety of different blogs, including WordPress.

I thought I’d download it and give it a go. So I’ve been using it for, well, since I started writing this post.

If you allow it, it will take a look at the theme you are using so you can author your posts and view them styles as they would appear on the blog. You can also view in a plain layout, view the html source, or preview the post how it’s going to look in you blog, as mentioned above.
Just on a side note about the HTML, Microsoft don’t tend to have a good history of creating HTML editors that actually put out good code. It seems they’re learning from their past mistakes, for now at least, the code produced here is pretty good.

Tags are added as Keywords in the properties box of a post as well as choosing the categories and other settings for the post.

Publishing is straight forward using the aptly titled Publish button on the toolbar. This will send the post off to your blog and publish it. You also have options for saving the draft locally or publishing the post as draft to your blog.

First impressions are good, I don’t totally see the reasons yet for having something like this, unless you have multiple blogs in which case it would save time logging into different blogs to post. I’m sure I’ll see other benefits after I’ve used it a while.

Posted in Technology | No Comments »

Importing CSV data into Oracle

October 25th, 2007 by Matt

Loading data into Oracle table requires the use of the sqlldr executable. To load data I create two files, one a CSV file containing the data to import and a control (.ctl) file containing the command information to pass to sqlldr.exe.

The Control File

load data
infile 'addresses.csv'
 
INTO TABLE myschema.mytable fields terminated BY "," 
         optionally enclosed BY '"'
(
    NAME
    ,TELEPHONE
    ,ADDRESS
    ,LAST_UPDT DATE 'dd-Mon-yyyy HH:MI:SS PM'
)

Notice that I’ve put a format on the date, I’ve had problems with dates if I don’t give the format for the date when importing. Save this file locally as addresses.ctl

The Data File

"Matt","3094785","55 My Street","25-Oct-07"
"Ricardo","354102","12 Easy Road","10-Mar-06"
........

Save this file as addresses.csv as declared in the control file. The file should be sve in the same directory as the control file.

To import the data, open a command prompt window and type the following:

c:\path\to\oracle\bin\sqlldr  username@oracleservername 
                        control=\path\to\addresses.ctl

That should import all the data into oracle. A relevant log file will be created as well as a bad file for rows that could not be imported. I tend to create a batch file to execute so I don’t have to remember the syntax for sqlldr.

If things go wrong

As stated above, I’ve had problems with date formatting before when importing. I’ve also come across issues with field terminations. By default CSV exports tend to be terminated by a comma (,) but I tend to use a semi colon (;) I’ve had less problems using this method.

Posted in Oracle | No Comments »

Exporting Crystal Reports from the web.

October 23rd, 2007 by Matt

Exporting Crystal Reports from a report displayed in the browser can be a pain, not least because it’s long winded, but also that I primarily use Firefox and the report rendering in anything other than IE is a joke.

For a while I have been trying to work out how I could export Crystal Reports in various formats such as Excel and PDF without having to render the report in the web browser first. Some of our customers wanted the data to put into their spreadsheet application so they could manipulate the data to their hearts content and I wanted to still use the power of Crystal Reports as it meant that the people who are good at writing the reports could do it and save me the work.

I’d seen it done in Crystal 8 but had not seen anything that pulled it all together in XI. I think I was looking a little too hard, the solution was in fact pretty straight forward.

The method employed is pretty similar to the post I made on displaying Crystal Reports in the browser, with only a couple of exceptions.

Firstly, you don’t need to employ the ReportViewer control as the report is not being rendered to the browser.

// Declare variables
private ReportDocument document1 = new ReportDocument();
private TableLogOnInfos infos1 = new TableLogOnInfos();
private TableLogOnInfo info2 = new TableLogOnInfo();
private ConnectionInfo info1 = new ConnectionInfo();
 
//  default export type
ExportFormatType expFormat = new ExportFormatType();
expFormat = ExportFormatType.PortableDocFormat;
 
// load the report
document1.Load(Request.PhysicalApplicationPath + “myReport.rpt);
 
// Add the parameters
document1.SetParameterValue(“param1″, “value1″);
document1.SetParameterValue(“param2″, “value2″);
 
//Set the login info for the database
info1.ServerName = ConfigurationSettings.AppSettings[“server_name”];
info1.DatabaseName = ConfigurationSettings.AppSettings[“database_name”];
info1.UserID = ConfigurationSettings.AppSettings[“user_id”];
info1.Password = ConfigurationSettings.AppSettings[“password”];
Tables tables1 = document1.Database.Tables;
 
//Apply login info to the report
foreach (CrystalDecisions.CrystalReports.Engine.Table table1 in tables1)
{
    info2 = table1.LogOnInfo;
    info2.ConnectionInfo = info1;
    table1.ApplyLogOnInfo(info2);
}
 
// Export the document
HttpResponse Response = HttpContext.Current.Response;
document1.ExportToHttpResponse(expFormat,Response,true,”Exported Report”);
document1.Close();

Posted in Web Development | No Comments »

Displaying Crystal Reports in a Web Browser

October 23rd, 2007 by Matt

Having tried for a while to find the right information for displaying Crystal Reports properly inside a web page using Crystal Report Viewer I finally managed to pull the information together into a solution that works; well for me anyway.

It’s worth mentioning that I don’t use the Crystal Reports extensions for Visual Studio, I have Crystal Server running on the box. I can’t see how this method wouldn’t work through the Visual Studio extensions.

Code Infront

Register the assembly in the top of your aspx page

<%@ Register TagPrefix="cr" Namespace="CrystalDecisions.Web" 
Assembly="CrystalDecisions.Web, Version=11.0.3300.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" %>

Place the control where you want it to appear in the page.

<cr:crystalreportviewer id="crReport1" runat="server" hasviewlist="False"
    hastogglegrouptreebutton="False" hassearchbutton="False"
    hasgotopagebutton="False" hasdrillupbutton="False" hascrystallogo="False"
    autodatabind="true" width="350px" displaygrouptree="False"
    height="50px" hyperlinktarget="_blank">

Code Behind

// declare the variables
protected CrystalReportViewer crReport1;
private ReportDocument document1 = new ReportDocument();
private TableLogOnInfos infos1 = new TableLogOnInfos();
private TableLogOnInfo info2 = new TableLogOnInfo();
private ConnectionInfo info1 = new ConnectionInfo();
 
// load the report
document1.Load(Request.PhysicalApplicationPath + "myReport.rpt");
 
// Add the parameters
document1.SetParameterValue("param1", "value1");
document1.SetParameterValue("param2", "value2");
 
//Set the login info for the database
info1.ServerName = ConfigurationSettings.AppSettings["server_name"];
info1.DatabaseName = ConfigurationSettings.AppSettings["database_name"];
info1.UserID = ConfigurationSettings.AppSettings["user_id"];
info1.Password = ConfigurationSettings.AppSettings["password"];
Tables tables1 = document1.Database.Tables;
 
//Apply login info to the report
foreach (CrystalDecisions.CrystalReports.Engine.Table table1 in tables1)
{
    info2 = table1.LogOnInfo;
    info2.ConnectionInfo = info1;
    table1.ApplyLogOnInfo(info2);
}
 
// Bind the report
crReport1.ReportSource = document1;
crReport1.DataBind();

You also need to remember to close the document after it has been rendered to free up memory. This should ideally be done in the Page_Unload method. See this post on MSDN for more information on why it should be placed in Page_Unload.

Posted in Web Development | No Comments »

« Previous Entries Next Entries »