Webservice He!p - Response error: "An existing connection was forcibly closed by the remote host" e

Discussion in 'ASP .Net Web Services' started by iKiLL, Dec 20, 2006.

  1. iKiLL

    iKiLL Guest

    Hi All



    Code Below for this problem

    ERROR: "An existing connection was forcibly closed by the remote host"



    My Background.

    I am New to OOP, web services and C#.

    I used to be a VB6 Developer but i have been asked to take over the
    development of a Windows mobile 5.0 Application that communicates with a web
    service.



    Every thing was going swimmingly until yesterday when something strange
    happened.

    Now as I am still relatively new to the MS VS2005 IDE, I am battling to
    debug this issue. I have spent All day on this and I am really behind
    schedule on this project so it is time I don't have. Any help would be much
    appreciated. Any Idea's for debuging would be great aswell.





    This is my thought on what the problem is.

    It is what seems like a never ending loop of Object creation which is
    causing a Webservice request Time Out and there for causing the Error seen
    above.



    What has changed to cause this problem.

    The most significant thing that has changed is the amount of Data.

    Yesterday there was 21 and today there is 40 records.

    If I limit the Records to anything below 30 then the error does not happen.



    What the web method is doing is loading up Parent/Child Objects. And the
    consolidates them into a Response Object before returning it to the Client
    application.



    When I step through the code line by line I get to the web method return and
    all is well and I can see in the Locals window all the data as expected.



    After the "Return Response" and exiting the Web method as expected you then
    go through Executing the GET method for each of the Objects held in the
    Response.



    This is the Web method that is being called

    public Response GetTasks(string sessionid)



    GET is called in this order after the Return of the above web method:

    public class TasksData

    public class PartsData

    public class ClientNotesData

    public class QuestionsData

    public class OptionsData



    I thought that maybe there was an infinite loop of these that was causing
    the problem but I have gone through line by line and it only calls them as
    is needed.



    Now when there is 30 or more records this seems to be taking to long and
    causing an error. The error seen above.



    I have Changed the TimeOut property for the WebService Object as you can see
    below, and my web reference is up to date.



    Any help would be much appreciated.





    Thanks

    Ink



    Code below.



    //This is the Code from the Client app that calls the Web Service

    public bool GetTasks()

    {

    Response rGetTasks = null;



    try

    {



    this.wsObject.Timeout = -1;

    rGetTasks = this.wsObject.GetTasks(wsObject.SessionID);



    if (rGetTasks.success)

    {

    Tasks tasks = (Tasks)rGetTasks.obj;

    if (tasks != null)

    {

    foreach (Task task in ((Tasks)rGetTasks.obj).Items)

    {

    this.user.GetTasks.AddTask(task);

    }



    if (tasks.Items.Count > 0)

    {

    if (this.NewTasksRecievedEvent != null)

    NewTasksRecievedEvent();

    }



    Response rRecieved =
    wsObject.TasksRecieved(wsObject.SessionID);



    if (!rRecieved.success)

    {

    AddLine("Failed to notify server of tasks as
    recieved OK," + rRecieved.error);

    return false;

    }

    }

    return true;

    }

    else

    {

    AddLine("Getting New Tasks Failed, " + rGetTasks.error);



    }



    }

    catch (Exception e)

    {

    AddLine("GetTasks Failed: " + e.Message);

    #if (DEBUG)//Debuging code

    debugLogging.writeLog("StartFiltering Calc Time:",
    e.Message);

    #endif

    }



    return false;





    }









    //This is the Web Service I am sending the whole thing for easy reading if
    you copy into //VS2005.



    using System;

    using System.Web;

    using System.Web.Services;

    using System.Web.Services.Protocols;

    using System.Data.SqlClient;

    using System.Data;

    using System.Collections.Generic;

    using System.Text;

    using System.Runtime.InteropServices;

    using System.Xml.Serialization;

    using System.Collections;

    using System.Reflection;

    using System.Diagnostics;

    using System.ComponentModel;



    [WebService(Namespace = "http://tempuri.org/")]

    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

    public class PPCAssetWS : System.Web.Services.WebService

    {

    public PPCAssetWS()

    {



    //Uncomment the following line if using designed components

    //InitializeComponent();





    try

    {

    System.Configuration.AppSettingsReader ReadSetting = new
    System.Configuration.AppSettingsReader();

    this.debug = bool.Parse(ReadSetting.GetValue("Logging",
    typeof(String)).ToString());



    }

    catch (Exception)

    {

    this.debug = false;

    }

    }



    private UserData CheckUser(string userid, string password, string
    softwareversion, bool register)

    {



    WriteLog("CheckUser Called");



    if (password == null) { password = ""; }



    SqlConnection connection = null;



    SqlDataReader reader = null;

    UserData user = new UserData();



    try

    {

    connection = this.CreateConnection();



    SqlCommand command = null;

    command = connection.CreateCommand();

    command.CommandType = System.Data.CommandType.StoredProcedure;

    command.CommandText = "sp_GetUser";

    command.Parameters.AddWithValue("@userid", userid);



    reader = command.ExecuteReader();



    if (reader.Read())

    {



    bool pdaAccess = false;



    user.id = reader.GetInt32(reader.GetOrdinal("User_userid"));
    ;

    user.uniqueid = userid;

    user.firstname =
    CheckNull(reader.GetValue(reader.GetOrdinal("User_Firstname")));

    user.lastname =
    CheckNull(reader.GetValue(reader.GetOrdinal("User_Lastname")));





    object homelat =
    reader.GetValue(reader.GetOrdinal("user_HomeLatitude"));

    object homelong =
    reader.GetValue(reader.GetOrdinal("user_HomeLong"));



    if (homelat != DBNull.Value)

    user.homelatitude = Convert.ToDouble(homelat);



    if (homelong != DBNull.Value)

    user.homelong = Convert.ToDouble(homelong);





    user.password
    =CheckNull(reader.GetValue(reader.GetOrdinal("user_auditlogonpsw")));





    //The Users Shop Address

    AddressData address = new AddressData();



    object oPreviousAddressID =
    reader.GetValue(reader.GetOrdinal("addr_addressID"));



    if (oPreviousAddressID != DBNull.Value)

    {

    address.previousaddressid = (int )oPreviousAddressID;

    }



    object oAddressID =
    reader.GetValue(reader.GetOrdinal("addr_addressID"));



    if (oAddressID != DBNull.Value)

    {

    address.addressid = (int)oAddressID;

    }



    address.address1 =
    CheckNull(reader.GetValue(reader.GetOrdinal("addr_address1")));

    address.address2 =
    CheckNull(reader.GetValue(reader.GetOrdinal("addr_address2")));

    address.address3 =
    CheckNull(reader.GetValue(reader.GetOrdinal("addr_address3")));

    address.city =
    CheckNull(reader.GetValue(reader.GetOrdinal("addr_City")));

    address.postcode =
    CheckNull(reader.GetValue(reader.GetOrdinal("addr_Postcode")));

    address.state =
    CheckNull(reader.GetValue(reader.GetOrdinal("addr_state")));

    address.phone =
    CheckNull(reader.GetValue(reader.GetOrdinal("addr_PhoneNo")));





    object oLatitude =
    reader.GetValue(reader.GetOrdinal("addr_latitude"));



    if (oLatitude != DBNull.Value)

    {

    address.latitude = Convert.ToDouble(oLatitude);

    }



    object oLongitude =
    reader.GetValue(reader.GetOrdinal("addr_longitude"));



    if (oLongitude != DBNull.Value)

    {

    address.longitude = Convert.ToDouble(oLongitude);

    }



    //Add the Address to the User

    user.shopaddress = address;





    object allowAudit =
    reader.GetValue(reader.GetOrdinal("User_AllowAuditPDA"));



    if (allowAudit != DBNull.Value)

    {

    if (allowAudit.ToString().Trim().CompareTo("N") == 0)

    {

    pdaAccess = false;

    }

    else

    {

    pdaAccess = true;

    }

    }

    else

    {

    pdaAccess = true;

    }



    if (!pdaAccess)

    {

    throw new NoAccessException("User Has No PDA Access");

    }

    if (password.Trim().CompareTo(user.password.Trim()) != 0)

    throw new IncorrectPassword("Incorrect password!");



    object opdaRegistered =
    reader.GetValue(reader.GetOrdinal("user_AuditPDAReg"));



    if ((opdaRegistered != DBNull.Value) && (register))

    {

    if (opdaRegistered.ToString().Trim().CompareTo("Y") ==
    0)

    {

    throw new AlreadyRegisteredException("User is
    already registered for a PDA access, please contact the Systems
    Administrator");

    }

    else

    {

    RegisterPDAUser(user.id, softwareversion);

    }

    }

    else if ((opdaRegistered == DBNull.Value) ||
    (opdaRegistered.ToString().Trim().CompareTo("N") == 0))

    {

    if (register)

    {

    RegisterPDAUser(user.id, softwareversion);

    }

    else

    {

    throw new NotRegisteredException("User is not
    registered for a PDA access, please contact the Systems Administrator");

    }



    }

    else if ((opdaRegistered == DBNull.Value) ||
    (opdaRegistered.ToString().CompareTo("Y") == 0))

    {

    //Its ok to proceed

    }



    return user;





    }

    else

    {

    throw new NoSuchUserException("No Such User");

    }



    }

    catch (SqlException e)

    {

    string error = "CheckUser : Error, Reason : " + e.Message;

    WriteLog(error, true);



    throw new Exception(error);

    }

    catch (Exception e) {

    string error = "CheckUser : Error, Reason : " + e.Message;

    WriteLog(error, true);



    throw new Exception(error);



    }

    finally

    {

    if (connection != null)

    connection.Close();



    }



    }



    private SqlConnection CreateConnection()

    {

    WriteLog("CreateConnection Called");

    try

    {

    System.Configuration.AppSettingsReader ReadSetting = new
    System.Configuration.AppSettingsReader();

    string dbConnectionString =
    ReadSetting.GetValue("ConnectionString", typeof(String)).ToString();



    dbConnectionString = dbConnectionString.Replace("%PASSWORD%",
    "");



    if (dbConnectionString.Length == 0)

    throw new Exception("Database Connection String not set
    check app.config");



    SqlConnection connection = new
    SqlConnection(dbConnectionString);

    connection.Open();



    return connection;



    }

    catch (Exception e)

    {

    string error = "DB Connection Failure, Reason : " + e.Message;

    WriteLog(error, true);

    throw new Exception(error);



    }





    }











    [WebMethod(EnableSession = true)]

    [XmlInclude(typeof(RemoveItems))]

    public Response CheckDeviceTasks(string sessionid, int[] taskids)

    {

    WriteLog("CheckDeviceTasks Called");



    Response response = new Response();



    SqlConnection connection = null;



    try

    {



    UserInfo user = this.CheckLogin(sessionid);



    if (user != null)

    {

    connection = this.CreateConnection();



    SqlCommand command = null;

    command = connection.CreateCommand();

    command.CommandType =
    System.Data.CommandType.StoredProcedure;

    command.CommandText = "sp_CheckDeviceTasks";

    command.Parameters.AddWithValue("@tasks",
    GetList(taskids));

    command.Parameters.AddWithValue("@userid",
    user.User.id);



    SqlDataReader reader = command.ExecuteReader();



    RemoveItems removeitems = new RemoveItems();



    while (reader.Read())

    {

    removeitems.Items.Add(reader.GetInt32(reader.GetOrdinal("value")));

    }

    response.obj = removeitems;

    response.success = true;



    }

    else

    {

    response.error = "Not logged in!";

    response.success = false;

    }



    }

    catch (SqlException e)

    {

    response.error = "CheckDeviceTasks : Error, " + e.Message;

    response.success = false;

    WriteLog(response.error, true);

    }

    finally

    {

    if (connection != null)

    connection.Close();



    }

    return response;

    }



    [WebMethod(EnableSession = true)]

    public Response Register(UserData user)

    {

    WriteLog("Register Called");



    Response response = new Response();



    try

    {

    UserData udUser = CheckUser(user.uniqueid, user.password,
    user.clientversion, true);

    response.success = true;

    response.obj = udUser;



    }

    catch (Exception e)

    {

    response.error = "Registration Error, " + e.Message;

    WriteLog(response.error, true);

    }

    return response;



    }



    private string GetList(int[] ids)

    {

    StringBuilder builder = new StringBuilder();



    for(int iPos =0 ; iPos < ids.Length; iPos++)

    {

    if ((iPos != 0) && ((iPos != 0) || (iPos < ids.Length - 1)))

    {

    builder.Append(",");

    }



    builder.Append(ids[iPos].ToString());

    }



    return builder.ToString();

    }



    private Response MarkTasksRecieved(TasksData tasks)

    {

    WriteLog("MarkTasksRecieved Called");



    Response response = new Response();



    if (tasks != null)

    {

    SqlConnection connection = null;



    try

    {

    connection = this.CreateConnection();



    SqlCommand command = null;

    command = connection.CreateCommand();

    command.CommandType =
    System.Data.CommandType.StoredProcedure;

    command.CommandText = "sp_MarkTasksSent";

    command.Parameters.AddWithValue("@tasks", tasks.GetList());



    command.ExecuteNonQuery();



    response.success = true;



    }

    catch (SqlException e)

    {

    response.error = "MarkTasksRecieved : Error, " + e.Message;

    response.success = false;

    WriteLog(response.error, true);

    }

    finally

    {

    if (connection != null)

    connection.Close();



    }



    }

    else

    {

    response.success = true;

    }

    return response;



    }





    [WebMethod(EnableSession = true)]

    public Response TasksRecieved(string sessionid)

    {

    WriteLog("TasksRecieved Called");



    Response response = new Response();



    if (IsLoggedIn(sessionid))

    {

    UserInfo info = CheckLogin(sessionid);



    if (info.SentTasks != null)

    {

    return MarkTasksRecieved(info.SentTasks);

    }

    else

    {

    response.error = "TasksRecieved, error no tasks were sent!";

    WriteLog(response.error, true);

    }

    }

    else

    {

    response.error = "Not logged in!";

    }



    return response;

    }



    [WebMethod(EnableSession = true)]

    [XmlInclude(typeof(PartsData))]

    public Response UpdateUserPos(string sessionid, double latitude, double
    longitude)

    {

    WriteLog("UpdateUserPos Called");



    Response response = new Response();

    if (IsLoggedIn(sessionid))

    {

    UserInfo userinfo = CheckLogin(sessionid);

    SqlConnection connection = null;



    try

    {

    connection = this.CreateConnection();



    SqlCommand command = null;

    command = connection.CreateCommand();

    command.CommandType =
    System.Data.CommandType.StoredProcedure;

    command.CommandText = "sp_UpdateUserPos";



    command.Parameters.AddWithValue("@userid",
    userinfo.User.id);

    command.Parameters.AddWithValue("@lat", latitude);

    command.Parameters.AddWithValue("@long", longitude);



    command.ExecuteNonQuery();



    response.success = true;

    }

    catch (SqlException e)

    {

    response.error = "UpdateUserPos : Updating the last know
    user postion failed, Reason : " + e.Message;

    WriteLog(response.error, true);

    }

    finally

    {

    if (connection != null)

    connection.Close();



    }

    response.success = true;



    }

    else

    {



    response.error = "Not logged in!";

    response.success = false;



    }



    return response;



    }



    private OptionsData GetOptions(string items)

    {



    OptionsData options = new OptionsData();



    string[] soptions = items.Split(',');



    foreach (string soption in soptions)

    {

    OptionData optiondata = new OptionData();

    optiondata.value = soption.Trim();

    optiondata.created = DateTime.Now;



    options.Add(optiondata);

    }



    return options;



    }



    private QuestionsData GetQuestions(int ppmid)

    {

    WriteLog("GetQuestions Called");

    SqlConnection connection = null;



    try

    {

    connection = this.CreateConnection();



    SqlCommand command = null;

    command = connection.CreateCommand();

    command.CommandType = System.Data.CommandType.StoredProcedure;

    command.CommandText = "sp_GetQuestions";

    command.Parameters.AddWithValue("@ppmid", ppmid);



    SqlDataReader reader = command.ExecuteReader();



    QuestionsData questions = new QuestionsData();



    while (reader.Read())

    {

    QuestionData question = new QuestionData();



    try

    {

    question.id =
    reader.GetInt32(reader.GetOrdinal("ppms_ppmstepsID"));



    object oType =
    reader.GetValue(reader.GetOrdinal("ppms_type"));

    if (oType != DBNull.Value)

    {

    if (Enum.IsDefined(typeof(QuestionType),
    oType.ToString().Trim()))

    {



    question.type =
    (QuestionType)Enum.Parse(typeof(QuestionType), oType.ToString().Trim(),
    true);



    }

    else

    {

    question.type = QuestionType.Invalid;

    }

    }

    else

    {

    question.type = QuestionType.Invalid;

    }

    }

    catch (Exception)

    {

    question.type = QuestionType.Invalid;

    }





    question.id =
    (int)reader.GetInt32(reader.GetOrdinal("ppms_ppmstepsID"));



    object oPickList =
    reader.GetValue(reader.GetOrdinal("ppms_picklist"));



    if (oPickList != DBNull.Value)

    {



    question.options = GetOptions((string)oPickList);



    }



    question.question =
    CheckNull(reader.GetValue(reader.GetOrdinal("ppms_Question")));



    object oHasComments =
    reader.GetValue(reader.GetOrdinal("ppms_hascomments"));

    if (CheckNull(oHasComments) == "Y")

    {

    question.comments = true;

    }

    else

    {

    question.comments = false;

    }



    questions.Add(question);

    }



    return questions;



    }

    catch (SqlException se)

    {

    throw se;

    }

    catch (Exception e)

    {

    throw e;

    }

    finally

    {

    if (connection != null)

    connection.Close();



    }





    }



    [WebMethod(EnableSession = true)]

    [XmlInclude(typeof(PartsData))]

    public Response GetParts(string sessionid)

    {

    WriteLog("GetParts Called");



    Response response = new Response();

    if (IsLoggedIn(sessionid))

    {

    UserInfo userinfo = CheckLogin(sessionid);

    SqlConnection connection = null;



    try

    {

    connection = this.CreateConnection();



    SqlCommand command = null;

    command = connection.CreateCommand();

    command.CommandType =
    System.Data.CommandType.StoredProcedure;

    command.CommandText = "sp_GetParts";



    SqlDataReader reader = command.ExecuteReader();



    PartsData parts = new PartsData();



    while (reader.Read())

    {

    PartData part = new PartData();

    part.partid =
    (int)reader.GetValue(reader.GetOrdinal("PartsID"));



    object oPartNumber =
    reader.GetValue(reader.GetOrdinal("Part_Number"));



    if (oPartNumber != DBNull.Value)

    {

    part.partnumber = (int)oPartNumber;

    }



    part.description =
    CheckNull(reader.GetValue(reader.GetOrdinal("Part_Description")));

    part.partname =
    CheckNull(reader.GetValue(reader.GetOrdinal("Part_Description")));



    parts.Items.Add(part);

    }



    response.obj = parts;

    response.success = true;

    }

    catch (SqlException e)

    {

    response.error = "GetParts : Failed to get task list, Reason
    : " + e.Message;

    WriteLog(response.error, true);

    }

    finally

    {

    if (connection != null)

    connection.Close();



    }

    response.success = true;



    }

    else

    {



    response.error = "Not logged in!";

    response.success = false;



    }



    return response;



    }



    private Response ProcessQuestions(SqlTransaction transaction,
    QuestionsData questions)

    {

    Response response = new Response();

    response.success = true;



    foreach (QuestionData question in questions.Items)

    {

    //Save the answer to the DB.

    Response rAnswer = SaveAnswer(transaction, question,
    question.answer);

    if (!rAnswer.success)

    {

    response.success = false;

    response.error = rAnswer.error;

    break;

    }

    }



    return response;

    }





    public Response SaveAnswer(SqlTransaction transaction,QuestionData
    question, AnswerData answer)

    {

    Response response = new Response();

    response.success = false;



    try

    {

    SqlCommand command = null;

    command = transaction.Connection.CreateCommand();

    command.CommandType = System.Data.CommandType.StoredProcedure;

    command.CommandText = "sp_SaveAnswer";

    command.Transaction = transaction;



    command.Parameters.AddWithValue("@ppmstepsID", question.id);

    command.Parameters.AddWithValue("@answervalue",
    answer.answervalue.ToString());

    command.Parameters.AddWithValue("@answertext",
    answer.answertext.ToString());

    command.Parameters.AddWithValue("@comment", answer.comment);



    command.ExecuteNonQuery();



    response.success = true;



    }

    catch (SqlException e)

    {

    response.error = "SaveAnswers : Failed to submit task, Reason :
    " + e.Message;

    WriteLog(response.error, true);



    }



    return response;

    }









    [WebMethod(EnableSession = true)]

    [XmlInclude(typeof(TasksData))]

    public Response SubmitTask(string sessionid,TaskData task)

    {

    //TASK MUST BE CLOSED;



    WriteLog("SubmitTask Called");



    Response response = new Response();

    response.success = true;



    if (IsLoggedIn(sessionid))

    {

    UserInfo userinfo = CheckLogin(sessionid);

    SqlConnection connection = null;

    SqlTransaction transaction = null;

    try

    {

    connection = this.CreateConnection();

    transaction = connection.BeginTransaction();



    SqlCommand command = null;

    command = connection.CreateCommand();

    command.Transaction = transaction;



    command.CommandType =
    System.Data.CommandType.StoredProcedure;

    command.CommandText = "sp_SubmitTask";

    command.Parameters.AddWithValue("@taskdetailsid",
    task.taskdetailsid);

    command.Parameters.AddWithValue("@userid",
    userinfo.User.id);



    command.Parameters.AddWithValue("@startdate",
    task.startdate);

    command.Parameters.AddWithValue("@completeddate",task.completeddate);

    command.Parameters.AddWithValue("@status",task.status.ToString());



    command.ExecuteNonQuery();



    if (task.questions.Items.Count > 0)

    {

    //Process question answers

    Response rQuestions = ProcessQuestions(transaction,
    task.questions);



    if (!rQuestions.success)

    {

    response.error = rQuestions.error;

    response.success = false;

    }

    }

    else

    {

    response.success = true;

    }





    if (response.success)

    {

    if (transaction != null)

    {

    transaction.Commit();

    }

    }





    }

    catch (SqlException e)

    {

    response.error = "SubmitTask : Failed to submit task, Reason
    : " + e.Message;

    WriteLog(response.error, true);



    response.success = false;

    }

    finally

    {

    if (connection != null)

    connection.Close();



    }





    }

    else

    {



    response.error = "Not logged in!";

    response.success = false;



    }



    return response;





    }



    [WebMethod(EnableSession = true)]

    [XmlInclude(typeof(TasksData))]

    public Response GetTasks(string sessionid)

    {

    ////This is DEBUG CODE Must be removed

    //int i = 1;

    ////===





    WriteLog("GetTasks Called");

    Response response = new Response();





    if (IsLoggedIn(sessionid))

    {

    UserInfo userinfo = CheckLogin(sessionid);

    SqlConnection connection = null;



    try

    {

    connection = this.CreateConnection();



    SqlCommand command = null;

    command = connection.CreateCommand();

    command.CommandType =
    System.Data.CommandType.StoredProcedure;

    command.CommandText = "sp_GetTasks";

    command.Parameters.AddWithValue("@userid",
    userinfo.User.id);



    SqlDataReader reader = command.ExecuteReader();



    TasksData tasks = new TasksData();



    while (reader.Read())

    {

    TaskData task = new TaskData();



    task.taskdetailsid =
    reader.GetInt32(reader.GetOrdinal("TaskD_TasksDtlsID")); ;



    task.name =
    CheckNull(reader.GetValue(reader.GetOrdinal("TaskD_Name")));

    task.description =
    CheckNull(reader.GetValue(reader.GetOrdinal("taskd_Description")));

    task.companyname =
    CheckNull(reader.GetValue(reader.GetOrdinal("Comp_Name")));



    object oOriginalScheduledDate =
    reader.GetValue(reader.GetOrdinal("taskd_schedDateTime"));

    if (oOriginalScheduledDate != DBNull.Value)

    task.originalscheduleddate =
    (DateTime)oOriginalScheduledDate;



    object oScheduledDate =
    reader.GetValue(reader.GetOrdinal("taskd_schedDateTime"));

    if (oScheduledDate != DBNull.Value)

    task.scheduleddate = (DateTime)oScheduledDate;



    object oStartDate =
    reader.GetValue(reader.GetOrdinal("taskd_StDateTime"));

    if (oStartDate != DBNull.Value)

    task.startdate = (DateTime)oStartDate;



    object oCompletedDate =
    reader.GetValue(reader.GetOrdinal("taskd_cmpltedDateTime"));

    if (oCompletedDate != DBNull.Value)

    task.completeddate = (DateTime)oStartDate;



    try

    {

    object oPriority =
    reader.GetValue(reader.GetOrdinal("taskd_Priority"));

    if (oPriority != DBNull.Value)

    {

    if (Enum.IsDefined(typeof(TaskPriority),
    oPriority.ToString()))

    {



    task.priority =
    (TaskPriority)Enum.Parse(typeof(TaskPriority), oPriority.ToString().Trim(),
    true);



    }

    else

    {

    task.priority = TaskPriority.Invalid;

    }

    }

    else

    {

    task.priority = TaskPriority.Invalid;

    }

    }

    catch (Exception)

    {

    task.priority = TaskPriority.Invalid;

    }



    try

    {

    object oTaskType =
    reader.GetValue(reader.GetOrdinal("taskd_Type"));



    if (oTaskType != DBNull.Value)

    {

    if (Enum.IsDefined(typeof(TaskType),
    oTaskType.ToString().Trim()))

    {

    task.tasktype =
    (TaskType)Enum.Parse(typeof(TaskType), oTaskType.ToString().Trim(), true);

    }

    else

    {

    task.tasktype = TaskType.Invalid;

    }

    }

    else

    {

    task.tasktype = TaskType.Invalid;

    }

    }

    catch (Exception)

    {

    task.tasktype = TaskType.Invalid;

    }





    try

    {

    object oStatus =
    reader.GetValue(reader.GetOrdinal("taskd_Status"));



    if (oStatus != DBNull.Value)

    {

    if (Enum.IsDefined(typeof(TaskStatus),
    oStatus.ToString().Trim()))

    {

    task.status =
    (TaskStatus)Enum.Parse(typeof(TaskStatus), oStatus.ToString().Trim(), true);

    }

    else

    {

    task.status = TaskStatus.Invalid;

    }

    }

    else

    {



    task.status = TaskStatus.Invalid;

    }

    }

    catch (Exception)

    {

    task.status = TaskStatus.Invalid;

    }



    object oEngineerID =
    reader.GetValue(reader.GetOrdinal("taskd_EngineerID"));



    if (oEngineerID != DBNull.Value)

    task.engineerid = (int)oEngineerID;







    AddressData address = new AddressData();



    object oPreviousAddressID =
    reader.GetValue(reader.GetOrdinal("addr_addressID"));



    if (oPreviousAddressID != DBNull.Value)

    {

    address.previousaddressid = (int)oPreviousAddressID;

    }



    object oAddressID =
    reader.GetValue(reader.GetOrdinal("addr_addressID"));



    if (oAddressID != DBNull.Value)

    {

    address.addressid = (int)oAddressID;

    }



    address.address1 =
    CheckNull(reader.GetValue(reader.GetOrdinal("addr_address1")));

    address.address2 =
    CheckNull(reader.GetValue(reader.GetOrdinal("addr_address2")));

    address.address3 =
    CheckNull(reader.GetValue(reader.GetOrdinal("addr_address3")));

    address.city =
    CheckNull(reader.GetValue(reader.GetOrdinal("addr_City")));

    address.postcode =
    CheckNull(reader.GetValue(reader.GetOrdinal("addr_Postcode")));

    address.state =
    CheckNull(reader.GetValue(reader.GetOrdinal("addr_state")));

    address.phone =
    CheckNull(reader.GetValue(reader.GetOrdinal("addr_PhoneNo")));



    object oLatitude =
    reader.GetValue(reader.GetOrdinal("addr_latitude"));



    if (oLatitude != DBNull.Value)

    {

    address.latitude = Convert.ToDouble(oLatitude);

    //address.latitude = (double)oLatitude;

    }



    object oLongitude =
    reader.GetValue(reader.GetOrdinal("addr_longitude"));



    if (oLongitude != DBNull.Value)

    {

    address.longitude = Convert.ToDouble(oLongitude);

    //address.longitude = (double)oLongitude;

    }



    task.address = address;





    AssetData asset = new AssetData();



    asset.assetid =
    reader.GetInt32(reader.GetOrdinal("asst_assetid"));

    asset.name =
    CheckNull(reader.GetValue(reader.GetOrdinal("asst_name")));

    asset.description =
    CheckNull(reader.GetValue(reader.GetOrdinal("asst_ExtraInformation")));

    asset.serialnumber =
    CheckNull(reader.GetValue(reader.GetOrdinal("asst_SerialNo")));



    asset.manufactur =
    CheckNull(reader.GetValue(reader.GetOrdinal("equip_ManufacturerName")));



    object oBarcode =
    reader.GetValue(reader.GetOrdinal("asst_barcode"));

    if (oBarcode != DBNull.Value)

    {

    asset.barcode = (int)oBarcode;

    }



    object oStandardtime =
    reader.GetValue(reader.GetOrdinal("ppm_standardtime"));

    if (oStandardtime != DBNull.Value)

    {

    asset.standardtime = (int)oStandardtime;

    }



    //Attach the asset to a site

    asset.site = address;



    task.asset = asset;









    object oPPMID =
    reader.GetValue(reader.GetOrdinal("taskd_ppmid"));

    if (oPPMID != DBNull.Value)

    {

    task.questions = GetQuestions((int)oPPMID);

    }



    //Add the new task to the Tasks Colection

    tasks.Add(task);





    ////This is DEBUG CODE Must be removed

    //if (tasks.Items.Count == i)

    //{

    // break; //Hear for debuging

    //}

    ////==========================



    }



    response.success = true;

    response.obj = tasks;

    //userinfo.SentTasks = tasks;

    //userinfo.TaskSent = true;

    }

    catch (SqlException e)

    {

    response.error = "GetTasks : Failed to get task list, Reason
    : " + e.Message;

    WriteLog(response.error, true);

    } catch (Exception e) {

    response.error = e.Message.ToString();

    response.success = false;

    }

    finally

    {

    if (connection != null)

    connection.Close();



    }

    response.success = true;



    }

    else

    {



    response.error = "Not logged in!";

    response.success = false;



    }









    return response;





    }



    private UserData CheckUser(string userid, string password)

    {

    return CheckUser(userid, password, null);

    }



    private UserData CheckUser(string userid, string password, string
    softwareversion)

    {

    return CheckUser(userid, password, softwareversion, false);

    }

    [WebMethod(EnableSession = true)]

    public bool LoggedIn(string sessionid)

    {



    return this.IsLoggedIn(sessionid);

    }



    [WebMethod(EnableSession = true)]

    public string GetUpdateDownloadURL()

    {

    WriteLog("GetUpdateDownloadURL Called");



    try

    {

    System.Configuration.AppSettingsReader ReadSetting = new
    System.Configuration.AppSettingsReader();

    string sUpdateDownloadURL =
    ReadSetting.GetValue("UpdateDownloadURL", typeof(String)).ToString();

    return sUpdateDownloadURL;

    }

    catch (Exception e)

    {

    WriteLog("GetUpdateDownloadURL : " + e.Message,true);

    }



    return null;

    }





    private Response RegisterPDAUser(int id, string softwareversion)

    {

    WriteLog("RegisterPDAUser Called");



    Response response = new Response();



    SqlConnection connection = null;



    try

    {

    connection = this.CreateConnection();



    SqlCommand command = null;

    command = connection.CreateCommand();

    command.CommandType = System.Data.CommandType.StoredProcedure;

    command.CommandText = "sp_RegisterUser";

    command.Parameters.AddWithValue("@id", id);

    command.Parameters.AddWithValue("@softwareversion",
    softwareversion);



    int iOk = command.ExecuteNonQuery();



    if (iOk > 0)

    {

    response.success = true;

    }

    else

    {

    response.success = false;

    }





    }

    catch (SqlException e)

    {

    response.error = "RegisterPDAUser : Failed to register user,
    Reason : " + e.Message;

    WriteLog(response.error, true);

    }

    finally

    {

    if (connection != null)

    connection.Close();



    }



    return response;

    }



    private Response UnRegisterPDAUser(int id)

    {

    WriteLog("UnRegisterPDAUser Called");



    Response response = new Response();



    SqlConnection connection = null;



    try

    {

    connection = this.CreateConnection();



    SqlCommand command = null;

    command = connection.CreateCommand();

    command.CommandType = System.Data.CommandType.StoredProcedure;

    command.CommandText = "sp_UnRegisterUser";

    command.Parameters.AddWithValue("@id", id);



    int iOk = command.ExecuteNonQuery();



    if (iOk > 0)

    {

    response.success = true;

    }

    else

    {

    response.success = false;

    }



    }

    catch (SqlException e)

    {

    response.error = "RegisterPDAUser : Failed to register user,
    Reason : " + e.Message;

    WriteLog(response.error, true);

    }

    finally

    {

    if (connection != null)

    connection.Close();



    }



    return response;



    }





    [WebMethod(EnableSession = true)]

    [XmlInclude(typeof(OptionsData))]

    public Response Login(UserData user)

    {

    WriteLog("Login Called");



    Response response = new Response();



    try

    {



    UserData udUser = CheckUser(user.uniqueid, user.password,
    user.clientversion);



    UserInfo userinfo = new UserInfo();

    userinfo.User = udUser;

    userinfo.isLoggedIn = true;

    userinfo.LastActivity = DateTime.Now;



    System.Web.HttpContext.Current.Cache.Add(Session.SessionID,
    userinfo, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new
    TimeSpan(0, 0, 30, 0), System.Web.Caching.CacheItemPriority.High, null);



    response.success = true;

    response.sessionid = Session.SessionID;



    }

    catch (Exception e)

    {



    response.error = e.Message;

    WriteLog(response.error, true);



    }

    return response;

    }







    public abstract class VersionComparer

    {



    //Returns false if

    public static VersionNumberDifferenceLevel UpgradeAvailble(string
    clientversion, string currentversion)

    {



    //FORMAT 4 Segments, XXXX.XXXX.XXXX.XXXX



    string[] saVersion1 = clientversion.Split('.');

    string[] saVersion2 = currentversion.Split('.');



    if (saVersion1.Length == saVersion2.Length)

    {

    int iThreshold =
    decimal.ToInt32(Math.Round(((decimal)saVersion1.Length / 2), 1));



    int iVersionNumber = 0;

    //Make sure they are the same format

    foreach (string versionvalue in saVersion1)

    {



    try

    {

    int iClientVersion = int.Parse(versionvalue);

    int iCurrentVersion =
    int.Parse(saVersion2[iVersionNumber]);



    if (iClientVersion > iCurrentVersion)

    {

    //NewVersion

    if (iVersionNumber > iThreshold)

    {

    return
    VersionNumberDifferenceLevel.MinorNewer;

    }

    else

    {

    return
    VersionNumberDifferenceLevel.MajorNewer;

    }

    }

    else if (iClientVersion == iCurrentVersion)

    {

    //Same version

    }

    else if (iClientVersion < iCurrentVersion)

    {

    //Older version

    if (iVersionNumber > iThreshold)

    {

    return
    VersionNumberDifferenceLevel.MinorOlder;

    }

    else

    {

    return
    VersionNumberDifferenceLevel.MajorOlder;

    }

    }

    }

    catch (Exception)

    {

    //Not a valid number

    }



    iVersionNumber++;



    }



    }



    return VersionNumberDifferenceLevel.None;

    }





    }

    [WebMethod(EnableSession = true)]

    public UpgradeRequired CheckVersion(string clientversion)

    {

    WriteLog("CheckVersion Called");



    System.Configuration.AppSettingsReader ReadSetting = new
    System.Configuration.AppSettingsReader();

    string sCurrentClientVersion =
    ReadSetting.GetValue("CurrentClientVersion", typeof(String)).ToString();



    if (sCurrentClientVersion != null)

    {

    VersionNumberDifferenceLevel level =
    VersionComparer.UpgradeAvailble(clientversion, sCurrentClientVersion);



    if (level == VersionNumberDifferenceLevel.MajorOlder)

    {

    return UpgradeRequired.Force;

    }

    else if (level == VersionNumberDifferenceLevel.MajorNewer)

    {

    return UpgradeRequired.None;

    }

    else if (level == VersionNumberDifferenceLevel.MinorNewer)

    {

    return UpgradeRequired.None;

    }

    else if (level == VersionNumberDifferenceLevel.MinorOlder)

    {

    return UpgradeRequired.Option;

    }

    else

    {

    //Its the same

    return UpgradeRequired.None;

    }



    }

    else

    {

    string error = "CheckVersion : No current version information in
    web.conf";

    WriteLog(error, true);



    throw new Exception(error);

    }

    }



    private void WriteLog(string msg)

    {

    WriteLog(msg, false);

    }



    bool debug = false;



    private void WriteLog(string msg, bool error)

    {

    if (this.debug)

    {

    EventLog ev = new EventLog("Application");



    // Event's Source name

    ev.Source = "MitieTransportWS";





    try

    {



    if (!EventLog.SourceExists(ev.Source))

    {

    EventLog.CreateEventSource(ev.Source, "Application");

    }



    if (!error)

    {

    ev.WriteEntry(msg, EventLogEntryType.Information);

    }

    else

    {

    ev.WriteEntry(msg, EventLogEntryType.Error);

    }

    }

    catch (Exception e)

    {

    //Event log error

    Console.WriteLine("Event Logging Failed, " + e.Message);

    }

    finally

    {

    ev.Dispose();



    }



    }

    }





    [WebMethod(EnableSession = true)]

    public void Logout(string sessionid)

    {

    WriteLog("Logout Called");



    if (System.Web.HttpContext.Current.Cache[sessionid] != null)

    {

    UserInfo info =
    (UserInfo)System.Web.HttpContext.Current.Cache[sessionid];

    info.isLoggedIn = false;



    System.Web.HttpContext.Current.Cache[sessionid] = info;

    }

    }



    private UserInfo CheckLogin(string sessionid)

    {

    WriteLog("CheckLogin Called");

    if (sessionid != null)

    {

    if (System.Web.HttpContext.Current.Cache[sessionid] != null)

    {

    return
    (UserInfo)System.Web.HttpContext.Current.Cache[sessionid];

    }

    else

    {

    return null;

    }

    }

    else

    {

    return null;

    }

    }



    private bool IsLoggedIn(string sessionid)

    {

    WriteLog("IsLoggedIn Called");



    UserInfo user = this.CheckLogin(sessionid);



    if (user != null)

    {

    if (user.isLoggedIn)

    {

    return true;

    }

    else

    {

    return false;

    }

    }



    return false;

    }



    [WebMethod(EnableSession = true)]

    public bool ClientTest()

    {

    WriteLog("ClientTest Called");



    return true;

    }









    [WebMethod(EnableSession = true)]

    [XmlInclude(typeof(SearchResultsData))]

    public Response SearchAsset(string sessionid ,SearchTypeData iType,
    string sSearchValue)

    {



    Response response = new Response();



    if (IsLoggedIn(sessionid))

    {

    try

    {



    SqlConnection connection = null;



    connection = this.CreateConnection();



    SqlCommand command = null;

    command = connection.CreateCommand();

    command.CommandType =
    System.Data.CommandType.StoredProcedure;

    command.CommandText = "sp_SearchAsset";

    command.Parameters.AddWithValue("@Type", iType);

    command.Parameters.AddWithValue("@SearchValue",
    sSearchValue);



    SqlDataReader reader = command.ExecuteReader();



    SearchResultsData results = new SearchResultsData();



    while (reader.Read())

    {



    AssetData asset = new AssetData();



    asset.assetid =
    reader.GetInt32(reader.GetOrdinal("asst_AssetID"));

    asset.barcode =
    reader.GetInt32(reader.GetOrdinal("asst_barcode"));



    //For testing.================================

    //asset.comment =
    CheckNull(reader.GetValue(reader.GetOrdinal("")));

    //asset.description =
    CheckNull(reader.GetValue(reader.GetOrdinal("")));

    //asset.manufactur =
    CheckNull(reader.GetValue(reader.GetOrdinal("")));

    asset.comment = "";

    asset.manufactur =
    CheckNull(reader.GetValue(reader.GetOrdinal("equip_ManufacturerName")));

    asset.description = "";

    //===========================



    asset.name =
    CheckNull(reader.GetValue(reader.GetOrdinal("Asst_Name")));

    asset.serialnumber =
    CheckNull(reader.GetValue(reader.GetOrdinal("asst_SerialNo")));



    object oServiceLength =
    reader.GetValue(reader.GetOrdinal("asst_ServiceLength"));

    if (oServiceLength != DBNull.Value)

    {

    asset.standardtime =
    Convert.ToInt32(oServiceLength);

    }



    object oStatus =
    reader.GetValue(reader.GetOrdinal("asst_status"));

    if (oStatus != DBNull.Value)

    {

    if (Enum.IsDefined(typeof(AssetStatus),
    oStatus.ToString()))

    {

    asset.status =
    (AssetStatus)Enum.Parse(typeof(AssetStatus), oStatus.ToString().Trim(),
    true);

    }

    else {

    asset.status = AssetStatus.Invalid;

    }

    }



    if
    (CheckNull(reader.GetValue(reader.GetOrdinal("appm_NextPATDate"))) != "")

    {

    asset.NextPATDate =
    reader.GetDateTime(reader.GetOrdinal("appm_NextPATDate"));

    }







    AddressData site = new AddressData();

    //Asset site address

    site.companyname =
    CheckNull(reader.GetValue(reader.GetOrdinal("Comp_Name")));

    site.previousaddressid =
    reader.GetInt32(reader.GetOrdinal("Addr_AddressId"));

    site.addressid =
    reader.GetInt32(reader.GetOrdinal("Addr_AddressId"));

    site.address1 =
    CheckNull(reader.GetValue(reader.GetOrdinal("Addr_Address1")));

    site.address2 =
    CheckNull(reader.GetValue(reader.GetOrdinal("Addr_Address2")));

    site.address3 =
    CheckNull(reader.GetValue(reader.GetOrdinal("Addr_Address3")));

    site.city =
    CheckNull(reader.GetValue(reader.GetOrdinal("Addr_City")));

    site.postcode =
    CheckNull(reader.GetValue(reader.GetOrdinal("Addr_PostCode")));

    site.state =
    CheckNull(reader.GetValue(reader.GetOrdinal("Addr_State")));

    site.phone =
    CheckNull(reader.GetValue(reader.GetOrdinal("addr_PhoneNo")));

    //site.latitude =
    reader.GetDouble(reader.GetOrdinal("addr_latitude"));

    //site.longitude =
    reader.GetDouble(reader.GetOrdinal("addr_longitude"));

    //===========================



    asset.site = site;



    results.Items.Add(asset);



    }



    response.obj = results;

    response.success = true;



    }

    catch (SqlException sqe)

    {

    response.error = "SearchAsset : Error, " + sqe.Message;

    response.success = false;

    WriteLog(response.error, true);

    }

    catch (Exception e)

    {

    response.error = "SearchAsset : Error, " + e.Message;

    response.success = false;

    WriteLog(response.error, true);

    }



    }

    else

    {

    response.error = "Not logged in!";

    response.success = false;

    }





    return response;



    }



    [WebMethod(EnableSession = true)]

    [XmlInclude(typeof(AssetSiteData))]

    public Response SubmitAssetMove(string sessionid, AssetSiteData asset)

    {

    //ASSET MUST BE MOVED;



    WriteLog("SubmitAsset Called");



    Response response = new Response();

    response.success = true;



    if (IsLoggedIn(sessionid))

    {

    UserInfo userinfo = CheckLogin(sessionid);

    SqlConnection connection = null;

    SqlTransaction transaction = null;

    try

    {

    connection = this.CreateConnection();

    transaction = connection.BeginTransaction();



    SqlCommand command = null;

    command = connection.CreateCommand();

    command.Transaction = transaction;



    command.CommandType =
    System.Data.CommandType.StoredProcedure;

    command.CommandText = "sp_SubmitAssetMove";

    command.Parameters.AddWithValue("@assetid", asset.assetid);

    command.Parameters.AddWithValue("@previousaddressid",
    asset.previousaddressid);

    command.Parameters.AddWithValue("@addressid",
    asset.addressid);

    command.ExecuteNonQuery();



    if (response.success)

    {

    if (transaction != null)

    {

    transaction.Commit();

    }

    }





    }

    catch (SqlException e)

    {

    response.error = "SubmitTask : Failed to submit task, Reason
    : " + e.Message;

    WriteLog(response.error, true);



    response.success = false;

    }

    finally

    {

    if (connection != null)

    connection.Close();



    }





    }

    else

    {



    response.error = "Not logged in!";

    response.success = false;



    }



    return response;





    }







    private string CheckNull(object oObject)

    {

    if (oObject != DBNull.Value)

    {

    return Convert.ToString(oObject).Trim();

    }

    else

    {

    return "";

    }





    }











    }











    [XmlRoot("SearchResultsData")]

    [XmlInclude(typeof(AssetData))]

    public class SearchResultsData : DefaultObj

    {

    private ArrayList searchresults = new ArrayList();



    [XmlArray("Items"), XmlArrayItem(typeof(AssetData))]

    public ArrayList Items

    {

    get { return searchresults; }

    set { searchresults = value; }

    }



    }





    [XmlRoot("AssetSiteData")]

    public class AssetSiteData : DefaultObj

    {

    public int addressid;

    public int previousaddressid;

    public int assetid;

    }









    public class AlreadyRegisteredException : Exception

    {

    private string msg = "";



    public AlreadyRegisteredException(string message)

    {

    this.msg = message;

    }



    public override string Message

    {

    get { return msg; }

    }

    }

    public class NotRegisteredException : Exception

    {

    private string msg = "";



    public NotRegisteredException(string message)

    {

    this.msg = message;

    }



    public override string Message

    {

    get { return msg; }

    }

    }

    public class IncorrectPassword : Exception

    {

    private string msg = "";



    public IncorrectPassword(string message)

    {

    this.msg = message;

    }



    public override string Message

    {

    get { return msg; }

    }

    }



    public class NoAccessException : Exception

    {

    private string msg = "";



    public NoAccessException(string message)

    {

    this.msg = message;

    }



    public override string Message

    {

    get { return msg; }

    }

    }



    public class NoSuchUserException : Exception

    {

    private string msg = "";



    public NoSuchUserException(string message)

    {

    this.msg = message;

    }



    public override string Message

    {

    get { return msg; }

    }

    }



    public class Response

    {

    public int id = -1;

    public string sessionid = "";

    public string error = "";

    public bool success = false;

    public DefaultObj obj = null;

    public bool returned = false;

    }



    public class OptionsData : DefaultObj

    {

    private ArrayList items = new ArrayList();



    [XmlArray("Items"), XmlArrayItem(typeof(OptionData))]

    public ArrayList Items

    {

    get { return items; }

    }

    public void Add(OptionData item)

    {

    items.Add(item);

    }

    }

    public class OptionData : DefaultObj

    {

    public int id = -1;

    public string answervalue = "";//gemma

    public string value = "";

    public DateTime created = DateTime.Now;



    }



    public class UserInfo : DefaultObj

    {

    private UserData user = new UserData();

    private bool loggedin = false;

    private bool senttasks = false;

    public TasksData taskssent = null;

    private DateTime lastactive;



    public DateTime LastActivity

    {

    get { return lastactive; }

    set { lastactive = value; }

    }



    public bool TaskSent

    {

    get { return senttasks; }

    set { senttasks = value; }

    }



    public TasksData SentTasks

    {

    get { return taskssent; }

    set { taskssent = value; }

    }

    public bool isLoggedIn

    {

    get { return loggedin; }

    set { loggedin = value; }

    }



    public UserData User

    {

    get { return user; }

    set { user = value; }

    }

    }



    public class DefaultObj

    {

    }



    [XmlInclude(typeof(AddressData))]

    public class UserData : DefaultObj

    {



    public enum UserType

    {

    Cleaner = 0, Auditor = 1



    }



    public int id = -1;

    public string uniqueid = "";

    public string firstname = "";

    public string lastname = "";

    public string password = "";

    public UserType usertype = UserType.Cleaner;

    public string clientversion = "";

    public double homelatitude = 0;

    public double homelong = 0;

    public AddressData shopaddress = new AddressData();



    }



    public enum UpgradeRequired

    {

    Force,

    Option,

    None

    }







    public enum VersionNumberDifferenceLevel

    {

    None,

    MinorOlder,

    MajorOlder,

    MajorNewer,

    MinorNewer,

    NoAccess

    }



    public abstract class VersionComparer

    {



    //Returns false if

    public static VersionNumberDifferenceLevel UpgradeAvailble(string
    clientversion, string currentversion)

    {



    //FORMAT 4 Segments, XXXX.XXXX.XXXX.XXXX



    string[] saVersion1 = clientversion.Split('.');

    string[] saVersion2 = currentversion.Split('.');



    if (saVersion1.Length == saVersion2.Length)

    {

    int iThreshold =
    decimal.ToInt32(Math.Round(((decimal)saVersion1.Length / 2), 1));



    int iVersionNumber = 0;

    //Make sure they are the same format

    foreach (string versionvalue in saVersion1)

    {



    try

    {

    int iClientVersion = int.Parse(versionvalue);

    int iCurrentVersion =
    int.Parse(saVersion2[iVersionNumber]);



    if (iClientVersion > iCurrentVersion)

    {

    //NewVersion

    if (iVersionNumber > iThreshold)

    {

    return VersionNumberDifferenceLevel.MinorNewer;

    }

    else

    {

    return VersionNumberDifferenceLevel.MajorNewer;

    }

    }

    else if (iClientVersion == iCurrentVersion)

    {

    //Same version

    }

    else if (iClientVersion < iCurrentVersion)

    {

    //Older version

    if (iVersionNumber > iThreshold)

    {

    return VersionNumberDifferenceLevel.MinorOlder;

    }

    else

    {

    return VersionNumberDifferenceLevel.MajorOlder;

    }

    }

    }

    catch (Exception)

    {

    //Not a valid number

    }



    iVersionNumber++;



    }



    }



    return VersionNumberDifferenceLevel.None;

    }





    }

    public enum TaskPriority

    {

    High = 1, Low = 2, Medium = 3, Invalid = 0

    }



    public enum TaskStatus

    {

    Scheduled = 1, Confirmed = 2, Rescheduled = 3, OnHold = 4, Started = 5,
    Closed = 6,Visited=7, Invalid = 0

    }



    public enum AssetStatus

    {

    Invalid = 0, Condemned = 1, Active = 2

    }



    public enum TaskType

    {

    Scheduled = 1, Reactive = 2, Invalid = 0

    }



    [XmlRoot("TaskData")]

    [XmlInclude(typeof(AddressData))]

    [XmlInclude(typeof(RevisitData))]

    [XmlInclude(typeof(PostponeData))]

    [XmlInclude(typeof(ClientNotesData))]

    [XmlInclude(typeof(QuestionsData))]

    public class TaskData : DefaultObj

    {

    public int taskid;

    public int taskdetailsid = 0;

    public string name = "";

    public string description = "";

    public string companyname = "";

    public DateTime originalscheduleddate;

    public DateTime scheduleddate;

    public DateTime startdate;

    public DateTime completeddate;

    public TaskType tasktype;

    public int engineerid = 0;

    public TaskStatus status;

    public int ppmid = 0;

    public int reactivetaskid = 0;

    public TaskPriority priority;

    public bool safetycritical;

    public bool postponed;

    public bool revisitneeded;

    public AddressData address = new AddressData();

    public AssetData asset = new AssetData();

    public RevisitData revisit = new RevisitData();

    public PostponeData postone = new PostponeData();

    public ClientNotesData notes = new ClientNotesData();

    public QuestionsData questions = new QuestionsData();



    }





    [XmlRoot("AssetData")]

    [XmlInclude(typeof(AssetStatus))]

    [XmlInclude(typeof(AddressData))]

    public class AssetData : DefaultObj

    {

    public int assetid ;

    public string name;

    public int barcode;

    public string serialnumber;

    public string description;

    public int standardtime;

    public string manufactur;

    public AssetStatus status;

    public string comment;

    public AddressData site = new AddressData();

    public DateTime NextPATDate;



    }











    [XmlRoot("PostponeData")]

    public class PostponeData : DefaultObj

    {

    public DateTime postponedate;

    public string reason;

    public string comment;

    }



    [XmlRoot("AddressData")]

    public class AddressData : DefaultObj

    {

    public int previousaddressid;

    public int addressid;

    public string address1;

    public string address2;

    public string address3;

    public string postcode;

    public string city;

    public string state;

    public string phone;

    public double latitude;

    public double longitude;

    public string companyname;

    }



    [XmlRoot("RevisitData")]

    [XmlInclude(typeof(PartsData))]

    public class RevisitData : DefaultObj

    {

    public PartsData parts = new PartsData();

    public DateTime revisitdate;

    public string reason = "";

    public string comment = "";

    }



    [XmlRoot("PartData")]

    public class PartData : DefaultObj

    {

    public int partid;

    public string partname;

    public int quantity;

    public int partnumber ;

    public string description;

    }



    [XmlRoot("PartsData")]

    [XmlInclude(typeof(PartData))]

    public class PartsData : DefaultObj

    {

    ArrayList parts = new ArrayList();



    [XmlArray("Items"), XmlArrayItem(typeof(PartData))]

    public ArrayList Items

    {

    get { return parts; }

    set { parts = value; }



    }

    }



    public class RemoveItems : DefaultObj

    {

    private ArrayList items = new ArrayList();



    [XmlArray("Items"), XmlArrayItem(typeof(int))]

    public ArrayList Items

    {

    get { return items; }

    set { items = value; }





    }







    }







    [XmlRoot("ClientNoteData")]

    [XmlType("ClientNoteData")]

    public class ClientNoteData

    {



    public DateTime revisitdate;

    public string comment = "";





    }



    [XmlRoot("ClientNotesData")]

    [XmlInclude(typeof(ClientNoteData))]

    public class ClientNotesData : DefaultObj

    {

    private ArrayList items = new ArrayList();



    [XmlArray("Items"), XmlArrayItem(typeof(ClientNoteData))]

    public ArrayList Items

    {

    get { return items; }

    }

    public void Add(ClientNoteData item)

    {

    items.Add(item);

    }



    }





    public class AnswerData : DefaultObj

    {

    public int id = -1;

    public string answertext = "";

    public string answervalue = "";//gemma

    public string comment = "";

    }





    public enum SearchTypeData

    {

    Site = 0, AssetNo = 1, SerialNo = 2

    }





    public enum QuestionType

    {

    Radio,

    Check,

    Text,

    Date,

    Selection,

    Invalid





    }





    public class QuestionData : DefaultObj

    {



    public int id = -1;

    public string question = "";

    public AnswerData answer = new AnswerData();

    public QuestionType type = QuestionType.Check;

    public OptionsData options = new OptionsData();

    public bool comments = false;



    }





    public class AnswersData : DefaultObj

    {

    ArrayList items = new ArrayList();

    private DateTime created = DateTime.Now;





    [XmlArray("Items"), XmlArrayItem(typeof(AnswerData))]

    public ArrayList Items

    {

    get { return items; }

    }



    public void Add(AnswerData item)

    {

    items.Add(item);

    }





    }







    [XmlRoot("TasksData")]

    [XmlInclude(typeof(TaskData))]

    public class TasksData : DefaultObj

    {

    private ArrayList items = new ArrayList();



    [XmlArray("Items"), XmlArrayItem(typeof(TaskData))]

    public ArrayList Items

    {

    get { return items; }

    }

    public void Add(TaskData item)

    {

    items.Add(item);

    }



    public string GetList()

    {

    StringBuilder builder = new StringBuilder();

    int iPos = 0;

    foreach (TaskData task in this.items)

    {

    if ((iPos != 0) && ((iPos != 0) || (iPos < this.items.Count -
    1)))

    {

    builder.Append(",");

    }



    builder.Append(task.taskdetailsid);



    iPos++;

    }



    return builder.ToString();

    }





    }



    [XmlRoot("QuestionsData")]

    [XmlInclude(typeof(QuestionData))]

    public class QuestionsData : DefaultObj

    {

    private ArrayList items = new ArrayList();



    [XmlArray("Items"), XmlArrayItem(typeof(QuestionData))]

    public ArrayList Items

    {

    get { return items; }

    }

    public void Add(QuestionData item)

    {

    items.Add(item);

    }



    public string GetList()

    {

    StringBuilder builder = new StringBuilder();

    int iPos = 0;

    foreach (QuestionData question in this.items)

    {

    if ((iPos != 0) && ((iPos != 0) || (iPos < this.items.Count -
    1)))

    {

    builder.Append(",");

    }



    builder.Append(question.id);



    iPos++;

    }



    return builder.ToString();

    }

    }
     
    iKiLL, Dec 20, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. iKiLL
    Replies:
    0
    Views:
    497
    iKiLL
    Dec 20, 2006
  2. Anbu
    Replies:
    4
    Views:
    566
    Juan T. Llibre
    Mar 13, 2007
  3. Artur
    Replies:
    1
    Views:
    578
  4. HP
    Replies:
    0
    Views:
    305
  5. Wil Peck
    Replies:
    2
    Views:
    942
    Wil Peck
    Jan 17, 2008
Loading...

Share This Page