another vbscript "cheat"

by Jesse 23. June 2008 13:08

I hate putting text boxes and labels on an aspx page.  It's stupid boring and that trigger in my brain says "There's GOT to be a faster way to do this" ...and now there is, I got sick of it so I made a vb script as such...

DIM fso, outputFile

const ForAppending = 8
dim LabelStart, TextBoxStart
LabelStart = "<asp:Label runat=" & chr(34) & "server" & chr(34) & " ID=" & chr(34) & "lbl"
TextBoxStart = "<asp:TextBox runat=" & chr(34) & "server" & chr(34) & " ID=" & chr(34) & "txt"

'variables we will need
dim controlName, labelText
dim keepAdding, intVal
keepAdding = True
Set fso = CreateObject("Scripting.FileSystemObject")
Set outputFile = fso.OpenTextFile("ControlGenerator.txt", ForAppending, True)
do while keepAdding

 controlName = InputBox("ControlName?")
 labelText = InputBox("Label Text?")

 outputFile.WriteLine(LabelStart & controlName & chr(34 & " Text=" & chr(34) & labelText & chr(34) & "/>")
 outputFile.WriteLine(TextBoxStart & controlName & chr(34) & "/><br />" )
 intVal = MsgBox("Add Another?", 4)
 if (intval = 7) then keepAdding = false
loop
outputFile.Close
wscript.echo("Complete")
 

Save that as a vbs file.  What will this do?

<asp:Label runat="server" ID="lblStreetName" Text="Street : "/>
<asp:TextBox runat="server" ID="txtStreetName"/><br />

Now to go pound out 40 or so controls like this....no, not joking.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Graduation

by Jesse 22. June 2008 17:43

Today I went to a graduation.  This wasn't any graduation but someone that use to work for me for a couple years.  He's older than me, has a family (two kids in high school) and never went to college before, although his wife has a masters so this was new to him.  He was going for all the right reasons.  He didn't like where he was nor where he was going so it was time to change it -- off to college he went.  The first couple classes in electronics, he brought in some questions from his homework (which I encouraged, I have a similar degree) so we used the whiteboard to draw out the whole thing and break it up so it's easy.  Each time we did so, at the end he'd shake his head "That's it?! Are you serious?" -- this was great, it let me know he was understanding how to make it simple.  To make it stick, I made a point to bridge what he was doing at the office with what he was learning so it was practical and useful in other places.  I also began to teach him how to ask exact questions to get the answer he wanted.  This went on almost daily as I was his manager/mentor.

Interestingly, he graduated exactly 5 years after I obtained my bachelors.  Same place, same time, just 5 years later.  It caused a moment of reflection of what I'd done in those 5 years and more importantly, I had a direct hand in someone's continuation of bettering himself.  It was a somewhat strange feeling watching him walk across the stage.  I'd guess it's the same feeling my parents had when I walked across that very stage -- I wasn't expecting that since I have no kids.  Strange as it was, it made me proud.

After his commencement, he told me he wants to talk -- thinking of the next step, "what's next".  I'm sure it'll be a great conversation because by now, he's fully outgrown his position where I use to manage.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Misc

DotNetPanel, how I love thee

by Jesse 17. June 2008 09:35

Recently we've been playing hot and loose with a couple webhosting companies.  I have my own here for rileytech, BUT its an uber account (resellers) so I host a number of other sites for people I know and trust.  As of late, I've been having to deal with some truly terrible interfaces for webhosting and no one is safe.  GoDaddy, NetworkSolutions, WebHosts4Life, I hate their interfaces but I must digress, I've been spoiled by DotNetPanel.

If you've never used DNP, you need to something fierce.  Since I came from the net admin side, I want everything even if I don't need it (because hey, I might ...someday).  I'd encourage you to check out their demo and insist whatever host you pick has DNP.  Yes, it's that good and better.  Just a quick search, I found that Integral Hosting has individual plans and runs DNP.

No, I don't own any type of share of DNP, nor do I know anyone that works there, nor getting anything for free from them (unless they'd like to!) -- I just happen to like stuff that works the way it should.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Sitefinity modules, the easier way!

by Jesse 16. June 2008 15:07

From my previous posts, I talked about creating a custom module that complies into a dll.  I've discovered that is THE hardest way possible to create a custom control.  The experience was good, but not exactly fun.

Luck would have it, they have a much stupid simpler way.  It's not as shareable, you have to add the files to each and evey site instead of just changing up the web.config.  So what?  There's a download they provide in their documentation that's kind of burried, but no sweat, you can get it here.  It's a full project and it takes a minute to unzip.

Before we get started, let me explain what this custom module does and what we're going to do to it.  The JobsModule consists of 4 user controls, your tried and true ascx files, that do various things, a couple classes, nothing intimidating.  One neat thing they did in this example was use an interface, "IJobsControlPanel", (app_code/jobsmodule.cs:142) to switch between two modes, "Category" and "Type", but in my examples I removed this for simplicity and the real module I was creating does not call for it.  Other files you need to note are all within the /Jobs folder.  Control panel and Toolbox are for the admin side, where the "JobList" and "JobListSummary" are for the user side. 

If you haven't went though the pain and agony of unzipping that file, do so now and let's take a look at the "JobsModule.cs" under the app code directory.  Line 28 begins the Nolics database init which later on, we won't need, but note where it is.  Under the properties region, lies the name/title/descript that will show up on the admin side.  On line 93/94, these are the files that will show up for the user side which will get more into later, just note that is where they are.  Next, take a look at line 112 and 121 as these are you admin controls.  Very easy to do.  Finally, there's the enum and interface for the other items they use for this module.  This is 95% of what it takes to make a module.

For this example, I am going to completely ignore the code behind for the user controls on the public facing side as they are unimportant.  Why?  Because user controls are user controls are user controls.  Make one, make 'em all, which is a very good thing!  Now, let's make a custom module, shall we?  Let's say we have a customer that wants a very very basic control that displays how many orders recieved today with the option to look at yesterday.  Our database table will look something like this...

TableName : Orders
Id  uniqueidentifier, not null, primary key
OrderDate datetime, not null
Quantity int, not null
DollarAmount money, not null
ItemOrdered nvarchar(1000), not null

Very simple, nothing fancy.  For the next step, I went away from the example just a bit and created a "CustomModules" folder under the App_Code directory along with a "DAL" folder with two folders within named "Generated" and "Extended".  See the image below for a bit of clarity. Now move "JobsModule.cs" into the CustomModule folder. Create yourself a folder in the root named "CustomControls" and a folder within it called "Orders" -- this is where the user controls will live.

At this point, if you've never touched subsonic, I would highly suggest jumping over there to brain up on how it works as I will not be covering that aspect.  Also, if you are unfamiliar with subsonic generating only certain tables, add the tag includeTableList="Orders" to your subsonic service.  For reference, this is a comma seperated list and will restrict subsonic to generating only those tables defined there.  Very handy since sitefinity has around 100 tables out of the box.  Generate this table and dump the files into App_Code/DAL/Generated.

Next, make a new class in App_Code/CustomModules and name it "OrdersModule.cs".  On the class declaration, inherit the WebModule from the Telerik namespace, implement the abstract class and change out the constructor from public to static as seen below.

Hop over to the JobsModule and copy the Methods region (override CreateControlPanel and Override CreateToolBoxControls), paste those into your OrdersModule -- don't worry about the string values yet, we'll get to those.  Also copy over the get in JobsModule:83-99 and paste that into the "Controls" override.  Finally, create a private variable of IList<Telerik.Web.IToolboxItems> (look to JobsModule:40 for example).

Now that's prepped, hop over to the CustomControl folder and create 3 user controls - "ControlPanel.ascx", "ToolboxPanel.ascx" and "OrderList.ascx".

ControlPanel needs to inherit the Telerik.IControlPanel and go ahead and give some string values, similar to this...

#region IControlPanel Members private readonly string status = "Orders";
private readonly string title = "Orders";

string IControlPanel.Status
{
     get { return status; }
}

string IControlPanel.Title
{
    
get { return title; }
}

#endregion

In the ToolboxPanel, inherit the Telerik.IControlPanelCommand and give values where necessary (Title for one).

Finally, for OrderList, we don't have to do anything yet.  If you feel like it, drop some text on the page just for rendering reasons.  Guess what? Most of the "behind the scenes" work is already done.  No really!

At this point, it should build and give you a custom module within your sitefinify project.  For the next post, I'll talk about how to wire up the subsonic stuff and even get at some data within sitefinity!

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

.Net | C# | Coding | Design

SQL Domain Error Occurred? Hu?

by Jesse 6. June 2008 15:57

Working with some good ole Sql today, get slapped in the face with this

Msg 3623, Level 16, State 1, Procedure FindLocations, Line 9
A domain error occurred.

Gah! Considering I copied this from an in-line sql statement, I figured I was golden, wrong.  So what's going on?  The procedure that did this is doing a little calculation to determine miles away based on a lat/long value lookup.  Where's the problem?  Lat/Long values can be negative and if you know anything about math, the square root of a negative number is (!) imaginary, something sql has NO CLUE how to handle (but matlab does!). 

So, to fix this problem, and since no results will ever be negative miles away (relativity?), I pulled the calculation result into the magical "ABS" (absolute) function to give me a positive number, no matter what.

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Tech | Weird | Sql

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

About the author

Like the description says, at my core, I'm a scientist and engineer.  I came from humble beginnings on a 486DX2 Packard Hell playing doom2 on IPX to in a small time retail shop and got into hardware (ISO layers FTW!) and it was all downhill from there.  I'm infinitely curious about almost everything and always wanting to know.

According to personality tests (real ones) I classify under "Rational" more specifically, a Fieldmarshal.  I think there's something to that.

Some of the stuff I'm currently into/researching...

Sitefinity

Ninject

Subsonic 

Currently working on ...
i did the hundred


and some extra stuff

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's, their brother, their dog, cat, ferret nor gold fish's view in anyway.  At all.  Ever.

© Copyright 2007-2009