Wednesday, September 1, 2010

SQL - User Defined Table Types

So a very interesting feature in SQL Server 2008 is user-defined table types. This is basically a custom variable type. Similary to a typedef in C. You can create user-defined table type as so...


create type CustomerUdt as table
(
Id int,
CustomerName nvarchar(50),
PostalCode nvarchar(50)
)


and then utilize that in a stored procedure like so...


create procedure InsertCustomerInfo
(
@CustomerInfoTvp as CustomerUdt readonly
)
as
insert into [Customers]
select * from @CustomerInfoTvp


this will do a bulk insertion for you... very nice!

the schema that you setup in the user-defined table type has to be the same as [Customers] in the example above.

This works best in the case where you are make multiple calls to the database for each row of data to separate tables. You can combine user-defined table types in one stored procedure like so...


create procedure InsertNewOrder
(
@OrderTvp as OrderUdt readonly,
@OrderDetailTvp as OrderDetailsUdt readonly
)
insert into [Orders]
select * from @OrderTvp
insert into [OrderDetails]
select * from @OrderDetailTvp


That makes one call to the database. Easy peasy.

iPhone Development - Day 11 Review

I have resumed my studies utilizing the Apple documentation. Whoever thought that documentation from the creators would be so easy to understand and read? It might also because I have attempted to read three books now on the subject with little help, but the documentation clears up some techniques and concepts. We'll see how this goes ... great a separate attempt at this stupid project, of course I am excited to learn mobile development, but damn, is it this hard for real?

Friday, August 27, 2010

iPhone Development - Day 7 Review

Another book bites the dust. Code doesn't fit, words, words, words, anyone ever heard of video teaching?

Wednesday, August 25, 2010

iPhone Development - Day 5 Review

I got through another two chapters. Starting to get muddy around here. I went to use the provided code for the book, and I can't because the code is in iPhone 3 SDK, which is not supported under the newest Xcode version...great. So the only thing I can do with the code is copy and paste it in to mine and see if there's works with my code, and go from there. Not so happy with that. There is only one book out there so far that I have found that uses iOS 4. That is iPhone and iPad Development for Absolute Beginners from APRESS.

I have reached some errors in my last two projects that I have done through the book. Both errors are not in my code, so I have yet to find a way to work through those errors.

Thursday, August 19, 2010

iPhone Development - Day 2 Review

So here we are with Day 2 complete. Once again, Deitel did not fail, well, almost. I had a little complication with understanding delegates. However... voila! ... I checked out this website and got a great understand by comparing the code that Deitel had to this, and the explanation that this blog provided was nothing less than understandable.

I am still taking the positive attitude that it is possible for me to be an iPhone developer! This book is providing me with much more understanding and better tutorials as to what I am doing. It is also providing great examples to build off of for later projects.

Once again, the book that I am using is iPhone for Programmers: An-App Driven Approach.

Tuesday, August 17, 2010

iPhone Development - Day 1 Review

Hooray!

For the first time in my iPhone Dev. adventures I have come across a helpful book. As expected Deitel provided a no assumption approach to explaining what they were doing in their tutorials. I have completed the first two apps and already see a big difference in explanations of why I am doing what I am doing in the code. I am also seeing a better lead in from simple to complex. Each chapter is laid out in a fashion that is like a meeting (i.e., agenda, goal, discussion, code explanation, conclusion). Thumbs up as of right now.

Monday, August 16, 2010

iPhone Development Start

I can't say that it was really started right now. I am re-engaging this problem. I started out trying to learn iPhone development right at the time when Apple was switching over to iOS 4, so it made it difficult to utilize source code from any book that was out at the time. None of them worked since they were for different versions of the OS. I dived into Learn Cocoa on the Mac (terrible first step), then I went to Beginning iPhone 3 Development (not bad, but could have been better), I finally came to More iPhone 3 Development (same as last one). None of these helped me understand technically why I was doing what I was doing. My background is C#, so that might have something to do with it all, but I find it as just a higher hurdle to jump then just going from C# to Java. This is also my first time of getting involved into MVC style programming, and my experience is in Domain Model. All this colliding together made for a first attempt bad experience. So here I am now renewing my vows to the iPod Touch, iPhone, and, hopefully, iPad.

My first step is trying a new book for teaching. I am going with a Deitel production, "iPhone For Developers: An App-Driven Approach". Deitel & Deitel is a well known college book author. I used the Java and C++ one in school, so hopefully this is a good first start. My first application, simple, a picture and label on the screen. That couldn't be easier.

Tuesday, July 20, 2010

PHP: Check to see if you have a postback.

I looked all over for a simple answer to find out how you check to see if the page is a postback. It was simple, but yet out of all the web pages I trolled through nothing had come up.

The situation is that if you submit a form and the action is set to blank, then how do you do some work if there is postback data and do other work if there is no postback data? This a common occurrence that I came across all the time while doing development in the .NET world, but there was a simple boolean variable to check in C#. How do you do that in PHP?

if ($_POST) {

}

It IS that simple (well, at least for me it was). It just checks to see if the $_POST array has been set. I don't know why no one else can answer that simple question just like that.

Monday, May 10, 2010

SharePoint HttpHandler Example

This past week I needed a solution to do customized server-side work from the EditControlBlock menu in a list. I had to lace together a few solutions that I found when googling the net.


1) Creating a CustomAction as a feature to install on the SharePoint server.
2) Creating a custom WebControl for the CustomAction.
3) Utilize jQuery and a Generic Handler to perform server side code.

For the CustomAction it was pretty easy. You need to place the following XML in the elements.xml file for your feature.


elements.xml
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id="Unique Id Here"
Title="Action Name in Menu"
Description="Description of Action"
RegistrationType="List"
RegistrationId="101"
Location="EditControlBlock"
Sequence="1000"
ControlAssembly="[Fully Qualified Assembly Name]"
ControlClass="ImportXML.Import">
<UrlAction Url="javascript:ExecuteAJAXCall();"/>
</CustomAction>
</Elements>

This will create a CustomAction for the Edit Control Block menu. The Edit Control Block menu is the pop down menu that appears for List Items. RegistrationId can change based on the type of list you want to attach this CustomAction to.

The second part is creating a generic handler to handle the server side functionality.
HandlerRequest.ashx
<%@ Assembly Name="[Fully Qualified Assembly Name]" %>
<%@ WebHandler Language="C#" CodeBehind="HandlerRequest.ashx.cs" Class="HttpHandler.HandlerRequest" %>
HandlerRequest.ashx.cs
namespace HttpHandler
{
public class HandlerRequest : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{
string webUrl = context.Request.Form["thisWebUrl"];
string listName = context.Request.Form["thisListName"];
string stringListId = context.Request.Form["thisListItemId"];

int itemId = Convert.ToInt32(stringListId);

List<string> response = new List<string>();

try
{
using (SPSite site = new SPSite(webUrl))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists[listName];

SPListItem item = list.Items[itemId];


response.Add("1");
response.Add(item.ID.ToString());
response.Add(item.Title);
}
}
}
catch(Exception ex)
{
response.Add("0");
response.Add("Operations failed.");
response.Add(ex.Message);
response.Add(ex.StackTrace);
}

JavaScriptSerializer JSSerializer = new JavaScriptSerializer();
context.Response.ContentType = "text/plain";
context.Response.Write(JSSerializer.Serialize(response));
}

public bool IsReusable
{
get
{
return false;
}
}
}
}


Finally I am using javascript in the default.master to compose the ExecuteAJAXCall() method. I utilized SharePoint Designer to access default.master.
Javascript
<script type='text/javascript' src='jquery.js' ></script>
<script>
function ExecuteAJAXCall() {
var userResponse = confirm("Are you sure you want to import this data?");

if (userResponse) {
$.post("/_layouts/ImportXML/ImportRequest.ashx",
{thisWebUrl:ctx.HttpRoot,thisListName:ctx.ListTitle,thisListItemId:currentItemID},
function(data, status, request){
Callback_AJAXCall(data, status, request);
},
'json'
);
}
};

function Callback_AJAXCall(data, status, request) {
if (data[0] == "1") {
alert(data[1]);
} else {
alert(data[1] + "\r\n\r\nError Message:" + data[2] + "\r\n\r\nStack Trace:" + data[3]);
}
};
</script>


After the creation of all these files you are ready to start putting it all together for the server.

1) The generic handler needs to be placed in the "12\TEMPLATE\LAYOUTS" folder.
2) The .dll file from the handler code needs to be placed in "InetPub\wwwroot\wss\VirtualDirectories\80\bin"
3) Last step is to install the feature through stsadm.exe command line utility and you are set!

Hope that helps out someone.

Thursday, January 21, 2010

Silverlight TextBlock Control

The TextBlock control in Silverlight is used in the same manner as an ASP Label control. However, from my experience you have a lot more control with a TextBlock control.

There is some background you should know about Silverlight controls. Silverlight uses a mark up language known as XAML. The Silverlight Controls can have attributes embedded in a tag or they can be in the sub elements of a control. For example when you want to change the Text of a TextBlock control you have multiple options to do this. Here are a couple of examples.

or...


Both of these code blocks will do the exact same thing. Explore through the attributes to see what you can get out of them. You can create a bit more robust text with some effort.

You can put your own creative spin on Text in a text block without having to go in to the code behind to do something really crazy like this...


So you can see that there is some great power behind the embedded tags on the XAML side. Check out all the different options that you have available to build some very robust Labels.

Wednesday, January 20, 2010

Interested Topics

Languages
  • C#
  • Java
  • Groovy
  • Grails
  • XBasic
  • XAML
  • T-SQL (<-- does this count?)
Technologies
  • ASP.NET
  • Silverlight
  • SharePoint
  • AlphaFive
  • WPF

IDEs
  • Visual Studio 2005/2008/2010
  • AlphaFive Software
  • Eclipse
  • NetBeans

Experience
  • Full Life Cycle development
  • Prototyping
  • Documentation
  • Web Development


I have a degree in Computer Science, and I didn't start a career in software engineering until after my time in the military. I have only been at this for less than a year so far.

Is there something about the Software Engineering community that I missing? I get the feeling that people stick to one know how and let that be their weapon of choice. Is this true? My perspective about life is to learn as much as possible. Is that a waste of time. I am taking the necessary steps to learn new languages, technologies, etc. to be more versatile. However, the people that work around me are focused on one area (i.e., Desktop Applications with C# and SQL or Web Development with Groovy & Grails). Am I just missing something here?

I am not talking about just scraping the top of these techniques and procedures. I dive into the deep end. Whether that is reading a book from cover to cover, or searching the internet for blogs, forums, nick nacks, etc. to get the ins and outs. I have recreated a web application in two different ways to "prototype" it.

I would like to know if I am headed down the wrong path with being so versatile. Someone let me know if I need to be focusing in on something.