I have the following code. I was wondering if anyone can give me any pointers on how to make this more concise and neater? Should I be splitting this down into smaller functions?
private void ReturnValue()
{
//create our WebService object
var sample = new TestProjectService.Service1();
//create our string to hold the Command information returned
//select which web service to use
var Command = new SimpleWebServiceApp.TestProjectService.CommandMessages();
switch (WebServiceRadio.SelectedIndex)
{
case 0:
Command = sample.GetData();
break;
case 1:
Command = sample.GetDataLINQ();
break;
}
//Check if a value is returned
if (Command != null)
{
//Display result on screen
LatestCommandLabel.Text = String.Format("Last Command Called (Using {0}) : {1}",WebServiceRadio.SelectedItem.ToString(),Command.Command);
//Get the current logged in username
string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
//Write command to the database
TestProjectLinqSQLDataContext dc = new TestProjectLinqSQLDataContext();
TestProjectCommandMessage msg = new TestProjectCommandMessage();
msg.Command_Type = Command.CommandType;
msg.Command = Command.Command;
msg.DateTimeSent = Command.DateTimeSent;
msg.DateTimeCreated = Command.DateTimeCreated;
msg.Created_User = userName;
msg.Created_Dttm = DateTime.Now;
dc.TestProjectCommandMessages.InsertOnSubmit(msg);
dc.SubmitChanges();
}
else
{
LatestCommandLabel.Text = "No Commands Available";
}
}
protected void GetCommandButton_Click(object sender, EventArgs e)
{
ReturnValue();
}