Example #1
0
 public AssignmentDetailsCollection GetAssignedInstances()
 {
     AssignmentDetailsCollection lReturn = new AssignmentDetailsCollection();
     if (this.Instances != null)
     {
         foreach (AssignmentDetails item in this.Instances)
         {
             if (item.Workers != null
                 && item.Workers.Count > 0)
             {
                 lReturn.Add(item);
                 break;
             }
         }
     }
     return lReturn;
 }
        private static SupportingAssignmentDetailsCollection BuildSupportingAssignmentDetailsCollection(AssignmentDetailsCollection assignments, Hashtable changeDates)
        {
            SupportingAssignmentDetailsCollection supportingAssignments = new SupportingAssignmentDetailsCollection();
            SupportingAssignmentDetails supportAssignment = null;

             foreach (AssignmentDetails objAssignment in assignments)
                {
                    int wmSourceID = objAssignment.ID;
                    supportAssignment = new SupportingAssignmentDetails();
                    supportAssignment.Assignment = objAssignment;
                    //Set the SupportingDataChangeDate ... look up in hashtable using WMSourceID as the key
                    if (changeDates.ContainsKey(wmSourceID))
                    {
                        supportAssignment.SupportingDataChangeDate = DateTime.Parse(changeDates[wmSourceID].ToString());
                    }
                    else
                    {
                        supportAssignment.SupportingDataChangeDate = DateTime.MinValue;
                    }
                    supportingAssignments.Add(supportAssignment);
                }

            return supportingAssignments;
        }
        public static SupportingAssignmentDetailsCollection GetSupportingAssignmentsChanged(string userID, string sourceSystem, DateTime lastRunDate)
        {
            AssignmentDetailsCollection assignments = new AssignmentDetailsCollection();
            SupportingAssignmentDetailsCollection supportingAssignments = new SupportingAssignmentDetailsCollection();
            Hashtable supportingDataChangesDates = new Hashtable();

            assignments = AssignmentDetailsCollection.GetAssignmentsSupportingDataChanged(userID, sourceSystem, lastRunDate, out supportingDataChangesDates);

            //Build a Support Assignment Details Collection.
            if (assignments.Count > 0 && supportingDataChangesDates.Count > 0)
            {
                supportingAssignments = BuildSupportingAssignmentDetailsCollection(assignments, supportingDataChangesDates);
            }

            return supportingAssignments;
        }
        public static AssignmentDetailsCollection GetAssignmentsSupportingDataChanged(string userID, string sourceSystem, DateTime lastRunDate, out Hashtable SupportingDataChangeDates)
        {
            AssignmentDetailsCollection assignments = new AssignmentDetailsCollection();
            FinalBuild.DataAccess objADO = Domain.GetADOInstance();
            System.Collections.ArrayList colParameters = new System.Collections.ArrayList();
            DataAccess.ArrayListParameter objParameter = null;
            DataSet dsResults = null;
            int[] wmSourceIDs = null;
            int[] candidateWMSourceIDs = null;
            string strStoredProcedure = "selSupportingDataChanged";
            SupportingDataChangeDates = new Hashtable();

            //Get a list of all unacknowledged Assignment IDs from Mobile WIP
            candidateWMSourceIDs = GetUnAcknowledgedSupportingDataAssignmentIDs(userID);

            // Assemble Parameters
            colParameters.Add(new SqlParameter("@UserID", userID));
            colParameters.Add(new SqlParameter("@LastRunDate", lastRunDate));
            if (sourceSystem != null)
            {
                colParameters.Add(new SqlParameter("@WMSourceSystem", sourceSystem));
            }
            if (candidateWMSourceIDs != null && candidateWMSourceIDs.Length > 0)
            {
                objParameter = new DataAccess.ArrayListParameter("WMSourceIDs", candidateWMSourceIDs);
                dsResults = objADO.GetDataSet(strStoredProcedure, objParameter, (SqlParameter[])colParameters.ToArray(typeof(SqlParameter)));

            }
            else
            {
                dsResults = objADO.GetDataSet(strStoredProcedure, (SqlParameter[])colParameters.ToArray(typeof(SqlParameter)));
            }

            if (dsResults != null && dsResults.Tables.Count > 0 && dsResults.Tables[0].Rows.Count > 0)
            {
                wmSourceIDs = PopulateSupportingDataAssignmentIDs(dsResults.Tables[0], out SupportingDataChangeDates);
                assignments = GetAssignments(userID, wmSourceIDs);
            }

            return assignments;
        }
        public static AssignmentDetailsCollection GetAssignments(int[] sourceIDs)
        {
            AssignmentDetailsCollection assignments = new AssignmentDetailsCollection();
            DataSet dsResults = null;
            FinalBuild.DataAccess objADO = Domain.GetADOInstance();
            System.Data.SqlClient.SqlParameter[] arrParameters;
            System.Collections.ArrayList colParameters = new System.Collections.ArrayList();
            DataAccess.ArrayListParameter objParameter = null;
            DataRow[] filteredRows = null;
            string strStoredProcedure = "selAssignmentsByJobAndUser";

            // Assemble Parameters
            objParameter = new DataAccess.ArrayListParameter("WMSourceIDs", sourceIDs);
            //colParameters.Add(new SqlParameter("@UserID", userID));
            arrParameters = (SqlParameter[])colParameters.ToArray(typeof(SqlParameter));

            dsResults = objADO.GetDataSet(strStoredProcedure, objParameter, arrParameters);
            dsResults.Tables[0].TableName = "Assignments";
            dsResults.Tables[1].TableName = "Assignees";
            dsResults.Tables[2].TableName = "Appointments";

            foreach (DataRow drAssignment in dsResults.Tables["Assignments"].Rows)
            {
                assignments.Add(new AssignmentDetails());
                assignments[assignments.Count - 1].ID = int.Parse(drAssignment["WMSourceID"].ToString());
                assignments[assignments.Count - 1].SourceSystem = (eWMSourceSystem)Enum.Parse(typeof(eWMSourceSystem), drAssignment["WMSourceSystem"].ToString());
                if (!drAssignment["DueDate"].Equals(DBNull.Value))
                {
                    assignments[assignments.Count - 1].DueDate = (DateTime)drAssignment["DueDate"];
                }
                assignments[assignments.Count - 1].Status = (eJobStatus)Enum.Parse(typeof(eJobStatus), drAssignment["JobStatus"].ToString());

                filteredRows = dsResults.Tables["Assignees"].Select(string.Format("WMSourceID='{0}'", assignments[assignments.Count - 1].ID));

                if (filteredRows.Length > 0)
                {
                    int userIDJobInstanceNumber = 0;
                    assignments[assignments.Count - 1].Workers = new WorkerCollection();
                    for (int assigneeIndex = 0; assigneeIndex < filteredRows.Length; assigneeIndex++)
                    {
                        assignments[assignments.Count - 1].Workers.Add(new Worker());
                        assignments[assignments.Count - 1].Workers[assigneeIndex].LoginName = filteredRows[assigneeIndex]["UserID"].ToString();
                        if (!filteredRows[assigneeIndex]["EmpSurname"].Equals(DBNull.Value))
                        {
                            assignments[assignments.Count - 1].Workers[assigneeIndex].Surname = filteredRows[assigneeIndex]["EmpSurname"].ToString();
                        }
                        if (!filteredRows[assigneeIndex]["EmpForenames"].Equals(DBNull.Value))
                        {
                            assignments[assignments.Count - 1].Workers[assigneeIndex].Forenames = filteredRows[assigneeIndex]["EmpForenames"].ToString();
                        }
                        if (!filteredRows[assigneeIndex]["EmpNo"].Equals(DBNull.Value))
                        {
                            assignments[assignments.Count - 1].Workers[assigneeIndex].EmpNo = filteredRows[assigneeIndex]["EmpNo"].ToString();
                        }
                        //if (filteredRows[assigneeIndex]["UserID"].ToString().ToUpper() == userID.ToUpper())
                        //{
                            userIDJobInstanceNumber = int.Parse(filteredRows[assigneeIndex]["JobInstanceNumber"].ToString());
                        //}
                    }
                    assignments[assignments.Count - 1].InstanceNumber = userIDJobInstanceNumber;
                }

                filteredRows = dsResults.Tables["Appointments"].Select(string.Format("WMSourceID={0}", assignments[assignments.Count - 1].ID));
                if (filteredRows.Length > 0)
                {
                    foreach (DataRow drSerializedInstance in filteredRows)
                    {
                        if (!drSerializedInstance["Appointment"].Equals(DBNull.Value))
                        {
                            System.Xml.XmlDocument objDOM = new System.Xml.XmlDocument();
                            objDOM.LoadXml(drSerializedInstance["Appointment"].ToString()); //.Replace(" xmlns=\"http://FinalBuild.co.uk/BusinessObjects.WorkManagement\"", string.Empty));
                            assignments[assignments.Count - 1].Appointment = (Appointment)BusinessObjects.Base.Deserialize(typeof(Appointment), objDOM);
                        }
                    }
                }
            }

            return assignments;
        }
        private static AssignmentDetailsCollection  Populate(DataTable collectionMembers)
        {
            AssignmentDetailsCollection colMembers = new AssignmentDetailsCollection();
            AssignmentDetails obj = null;

            foreach (DataRow drMember in collectionMembers.Rows)
            {
                obj = new AssignmentDetails();
                obj.ID = (int)drMember["WMSourceID"];
                obj.InstanceNumber = (int)drMember["JobInstanceNumber"];

                obj.Workers = new WorkerCollection();
                Worker objWorker = new Worker();
                objWorker.UserID = drMember["UserID"].ToString();
                obj.Workers.Add(objWorker);

                obj.DueDate = (DateTime)drMember["DateChangeDetected"];
                colMembers.Add(obj);
            }

            return colMembers;
        }