Exemplo n.º 1
0
        public static void Longwork2(IProgress <string> progress, SalesforceClient client, Dictionary <string, string> assignDict)
        {
            int i = 0;

            foreach (KeyValuePair <string, string> entry in assignDict)
            {
                // do something with entry.Value or entry.Key
                String assignID = entry.Value;
                UpdateInspectorClass updateInspector = new UpdateInspectorClass();
                updateInspector.Inspector__c = assignID;
                client.Update("Inspection__c", entry.Key, updateInspector);
                i++;

                progress.Report("Orders Assigned: " + i + " of " + assignDict.Count);
            }
        }
Exemplo n.º 2
0
        static public List <OfficialInspectorClass> Longwork4(IProgress <string> progress, SalesforceClient client, List <OfficialInspectorClass> workingList, List <String> autoqueue)
        {
            InspectionJSONClass currentInspection = new InspectionJSONClass();
            List <String>       assignedarray     = new List <String>();
            List <String>       skippedarray      = new List <String>();
            string inspectorAssign  = "";
            string inspectorAssign1 = "";

            //List<OfficialInspectorClass> tempList = new List<OfficialInspectorClass>();
            //List<OfficialInspectorClass> templist2 = new List<OfficialInspectorClass>();
            for (int i = 0; i < autoqueue.Count; i++)
            {
                List <OfficialInspectorClass> tempList  = new List <OfficialInspectorClass>();
                List <OfficialInspectorClass> templist2 = new List <OfficialInspectorClass>();
                currentInspection = findInspectionbyOrderNumber(autoqueue[i].Substring(0, 6), client);

                if (currentInspection.Auto_Assign_Skip__c == false)
                {
                    List <string> historyList = new List <string>();
                    inspectorAssign  = "";
                    inspectorAssign1 = "";

                    workingList = sortByDistance(client, workingList, currentInspection);
                    for (int j = 0; j < workingList.Count; j++)
                    {
                        if (workingList[j].currentDistance <= 500)
                        {
                            tempList.Add(workingList[j]);
                        }
                    }
                    //Console.WriteLine(tempList.Count);
                    //Console.ReadLine();
                    var history = client.Query <HistoryClass>("SELECT CreatedDate, Field, OldValue, NewValue From Inspection__History WHERE ParentId='" + currentInspection.Id + "' AND Field='Rep_ID_Inspector_history_tracking__c'");
                    for (int j = 0; j < history.Count; j++)
                    {
                        if (history[j].NewValue.Equals("-") && history[j].OldValue != null)
                        {
                            historyList.Add(history[j].OldValue);
                        }
                    }
                    for (int j = 0; j < tempList.Count; j++)
                    {
                        String compareString = tempList[j].Rep_ID__c + " - " + tempList[j].Name;
                        if (!historyList.Contains(compareString) && tempList[j].Status__c != "On Hold")
                        {
                            templist2.Add(tempList[j]);
                        }
                    }
                    tempList  = templist2;
                    templist2 = new List <OfficialInspectorClass>();
                    if (tempList.Count > 0)
                    {
                        inspectorAssign1 = tempList[0].contactID;
                        inspectorAssign  = tempList[0].Name;
                        updateInspectorCount(tempList[0].contactID, workingList);
                        UpdateInspectorClass updateInspector = new UpdateInspectorClass();
                        updateInspector.Inspector__c = inspectorAssign1;
                        assignedarray.Add((currentInspection.Name + ": " + inspectorAssign));
                        //updateInspectorCount(tempList[0].contactID);
                        client.Update("Inspection__c", currentInspection.Id, updateInspector);
                    }
                    else
                    {
                        skippedarray.Add((currentInspection.Name + ": Skipped"));
                        UpdateAdhocClass repad = new UpdateAdhocClass();
                        if (currentInspection.ADHOC__c == null)
                        {
                            currentInspection.ADHOC__c = "";
                        }
                        if (!currentInspection.ADHOC__c.Contains("Rep Needed"))
                        {
                            repad.ADHOC__c = "Rep Needed " + currentInspection.ADHOC__c;
                            client.Update("Inspection__c", currentInspection.Id, repad);
                        }
                    }
                }
                progress.Report("Orders Assigned: " + i + " of " + autoqueue.Count);
            }
            System.IO.File.WriteAllLines(@"C:\Users\Public\S2 Inspections\HUD Assigned.txt", assignedarray);
            System.IO.File.WriteAllLines(@"C:\Users\Public\S2 Inspections\HUD Skipped.txt", skippedarray);
            return(workingList);
        }
Exemplo n.º 3
0
        public static List <OfficialInspectorClass> Longwork3(IProgress <string> progress, SalesforceClient client, List <OfficialInspectorClass> workingList, List <String> autoqueue)
        {
            InspectionJSONClass currentInspection = new InspectionJSONClass();
            List <String>       assignedarray     = new List <String>();
            List <String>       skippedarray      = new List <String>();
            string inspectorAssign  = "";
            string inspectorAssign1 = "";
            List <OfficialInspectorClass> tempList  = new List <OfficialInspectorClass>();
            List <OfficialInspectorClass> templist2 = new List <OfficialInspectorClass>();

            //SortNumber = 0;
            //List<String> autoqueue = sortAssignQueue();
            //these two lines can test the logic for a specific order
            //List<String> autoqueue = new List<string>();
            //autoqueue.Add("163707");
            for (int i = 0; i < autoqueue.Count; i++)
            {
                tempList  = new List <OfficialInspectorClass>();
                templist2 = new List <OfficialInspectorClass>();
                String searchnumber = autoqueue[i].Substring(0, 6);
                currentInspection = findInspectionbyOrderNumber(searchnumber, client);
                if (currentInspection.ADHOC__c == null)
                {
                    currentInspection.ADHOC__c = "";
                }
                if (currentInspection.Auto_Assign_Skip__c == false)
                {
                    List <string> historyList = new List <string>();
                    inspectorAssign  = "";
                    inspectorAssign1 = "";

                    workingList = sortByDistance(client, workingList, currentInspection);
                    for (int j = 0; j < workingList.Count; j++)
                    {
                        if (workingList[j].currentDistance <= Convert.ToInt32(workingList[j].Coverage_Area_Radius__c) && workingList[j].assignedInspections < workingList[j].Max_Insp_Count__c)
                        {
                            tempList.Add(workingList[j]);
                        }
                    }
                    //Console.WriteLine(tempList.Count);
                    //Console.ReadLine();
                    var history = client.Query <HistoryClass>("SELECT CreatedDate, Field, OldValue, NewValue From Inspection__History WHERE ParentId='" + currentInspection.Id + "' AND Field='Rep_ID_Inspector_history_tracking__c'");
                    for (int j = 0; j < history.Count; j++)
                    {
                        if (history[j].NewValue.Equals("-") && history[j].OldValue != null)
                        {
                            historyList.Add(history[j].OldValue);
                        }
                    }
                    for (int j = 0; j < tempList.Count; j++)
                    {
                        String compareString = tempList[j].Rep_ID__c + " - " + tempList[j].Name;
                        if (tempList[j].Blacklist__c == null)
                        {
                            tempList[j].Blacklist__c = "";
                        }
                        if (!historyList.Contains(compareString) && tempList[j].Status__c != "On Hold" && tempList[j].feeDictionary[currentInspection.Fee_Type_Text__c] != null && !tempList[j].Blacklist__c.Contains(currentInspection.Division__c))
                        {
                            templist2.Add(tempList[j]);
                        }
                    }
                    tempList  = templist2;
                    templist2 = new List <OfficialInspectorClass>();
                    if (tempList.Count > 0)
                    {
                        if (tempList.Count > 1)
                        {
                            for (int j = 0; j < tempList.Count; j++)
                            {
                                if (tempList[j].Status__c == "New Rep")
                                {
                                    templist2.Add(tempList[j]);
                                }
                            }
                            if (templist2.Count == 0)
                            {
                                //TOP REP LOGIC GOES HERE!!!
                                templist2 = new List <OfficialInspectorClass>();
                                for (int j = 0; j < tempList.Count; j++)
                                {
                                    if (tempList[j].Status__c == "Top Rep")
                                    {
                                        templist2.Add(tempList[j]);
                                    }
                                }
                                if (templist2.Count == 0)
                                {
                                    tempList.Sort((x, y) => y.Inspector_Ranking__c.CompareTo(x.Inspector_Ranking__c));
                                    if (tempList[0].Inspector_Ranking__c == tempList[1].Inspector_Ranking__c)
                                    {
                                        if (tempList[0].feeDictionary[currentInspection.Fee_Type_Text__c] < tempList[1].feeDictionary[currentInspection.Fee_Type_Text__c])
                                        {
                                            inspectorAssign1 = tempList[0].contactID;
                                            inspectorAssign  = tempList[0].Name;
                                            updateInspectorCount(tempList[0].contactID, workingList);
                                        }
                                        else if (tempList[0].feeDictionary[currentInspection.Fee_Type_Text__c] > tempList[1].feeDictionary[currentInspection.Fee_Type_Text__c])
                                        {
                                            inspectorAssign1 = tempList[1].contactID;
                                            inspectorAssign  = tempList[1].Name;
                                            updateInspectorCount(tempList[1].contactID, workingList);
                                        }
                                        else
                                        {
                                            if (tempList[0].currentDistance < tempList[1].currentDistance)
                                            {
                                                inspectorAssign1 = tempList[0].contactID;
                                                inspectorAssign  = tempList[0].Name;
                                                updateInspectorCount(tempList[0].contactID, workingList);
                                            }
                                            else if (tempList[0].currentDistance > tempList[1].currentDistance)
                                            {
                                                inspectorAssign1 = tempList[1].contactID;
                                                inspectorAssign  = tempList[1].Name;
                                                updateInspectorCount(tempList[1].contactID, workingList);
                                            }
                                            else
                                            {
                                                inspectorAssign1 = tempList[0].contactID;
                                                inspectorAssign  = tempList[0].Name;
                                                updateInspectorCount(tempList[0].contactID, workingList);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        inspectorAssign1 = tempList[0].contactID;
                                        inspectorAssign  = tempList[0].Name;
                                        updateInspectorCount(tempList[0].contactID, workingList);
                                    }
                                }
                                else if (templist2.Count == 1)
                                {
                                    inspectorAssign1 = templist2[0].contactID;
                                    inspectorAssign  = templist2[0].Name;
                                    updateInspectorCount(templist2[0].contactID, workingList);
                                }
                                else
                                {
                                    tempList = templist2;
                                    tempList.Sort((x, y) => x.Inspector_Ranking__c.CompareTo(y.Inspector_Ranking__c));
                                    if (tempList[0].Inspector_Ranking__c == tempList[1].Inspector_Ranking__c)
                                    {
                                        if (tempList[0].feeDictionary[currentInspection.Fee_Type_Text__c] < tempList[1].feeDictionary[currentInspection.Fee_Type_Text__c])
                                        {
                                            inspectorAssign1 = tempList[0].contactID;
                                            inspectorAssign  = tempList[0].Name;
                                            updateInspectorCount(tempList[0].contactID, workingList);
                                        }
                                        else if (tempList[0].feeDictionary[currentInspection.Fee_Type_Text__c] > tempList[1].feeDictionary[currentInspection.Fee_Type_Text__c])
                                        {
                                            inspectorAssign1 = tempList[1].contactID;
                                            inspectorAssign  = tempList[1].Name;
                                            updateInspectorCount(tempList[1].contactID, workingList);
                                        }
                                        else
                                        {
                                            if (tempList[0].currentDistance < tempList[1].currentDistance)
                                            {
                                                inspectorAssign1 = tempList[0].contactID;
                                                inspectorAssign  = tempList[0].Name;
                                                updateInspectorCount(tempList[0].contactID, workingList);
                                            }
                                            else if (tempList[0].currentDistance > tempList[1].currentDistance)
                                            {
                                                inspectorAssign1 = tempList[1].contactID;
                                                inspectorAssign  = tempList[1].Name;
                                                updateInspectorCount(tempList[1].contactID, workingList);
                                            }
                                            else
                                            {
                                                inspectorAssign1 = tempList[0].contactID;
                                                inspectorAssign  = tempList[0].Name;
                                                updateInspectorCount(tempList[0].contactID, workingList);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        inspectorAssign1 = tempList[0].contactID;
                                        inspectorAssign  = tempList[0].Name;
                                        updateInspectorCount(tempList[0].contactID, workingList);
                                    }
                                }
                            }
                            else if (templist2.Count == 1)
                            {
                                inspectorAssign1 = templist2[0].contactID;
                                inspectorAssign  = templist2[0].Name;
                                updateInspectorCount(templist2[0].contactID, workingList);
                            }
                            else
                            {
                                //NEW REP MULTIPLE GOES HERE
                                tempList = templist2;
                                tempList.Sort((x, y) => x.Inspector_Ranking__c.CompareTo(y.Inspector_Ranking__c));
                                if (tempList[0].Inspector_Ranking__c == tempList[1].Inspector_Ranking__c)
                                {
                                    if (tempList[0].feeDictionary[currentInspection.Fee_Type_Text__c] < tempList[1].feeDictionary[currentInspection.Fee_Type_Text__c])
                                    {
                                        inspectorAssign1 = tempList[0].contactID;
                                        inspectorAssign  = tempList[0].Name;
                                        updateInspectorCount(tempList[0].contactID, workingList);
                                    }
                                    else if (tempList[0].feeDictionary[currentInspection.Fee_Type_Text__c] > tempList[1].feeDictionary[currentInspection.Fee_Type_Text__c])
                                    {
                                        inspectorAssign1 = tempList[1].contactID;
                                        inspectorAssign  = tempList[1].Name;
                                        updateInspectorCount(tempList[1].contactID, workingList);
                                    }
                                    else
                                    {
                                        if (tempList[0].currentDistance < tempList[1].currentDistance)
                                        {
                                            inspectorAssign1 = tempList[0].contactID;
                                            inspectorAssign  = tempList[0].Name;
                                            updateInspectorCount(tempList[0].contactID, workingList);
                                        }
                                        else if (tempList[0].currentDistance > tempList[1].currentDistance)
                                        {
                                            inspectorAssign1 = tempList[1].contactID;
                                            inspectorAssign  = tempList[1].Name;
                                            updateInspectorCount(tempList[1].contactID, workingList);
                                        }
                                        else
                                        {
                                            inspectorAssign1 = tempList[0].contactID;
                                            inspectorAssign  = tempList[0].Name;
                                            updateInspectorCount(tempList[0].contactID, workingList);
                                        }
                                    }
                                }
                                else
                                {
                                    inspectorAssign1 = tempList[0].contactID;
                                    inspectorAssign  = tempList[0].Name;
                                    updateInspectorCount(tempList[0].contactID, workingList);
                                }
                            }
                        }
                        else
                        {
                            inspectorAssign1 = tempList[0].contactID;
                            inspectorAssign  = tempList[0].Name;
                            updateInspectorCount(tempList[0].contactID, workingList);
                        }
                        UpdateInspectorClass updateInspector = new UpdateInspectorClass();
                        updateInspector.Inspector__c = inspectorAssign1;
                        assignedarray.Add((currentInspection.Name + ": " + inspectorAssign));
                        //updateInspectorCount(tempList[0].contactID);
                        client.Update("Inspection__c", currentInspection.Id, updateInspector);
                    }
                    else
                    {
                        skippedarray.Add((currentInspection.Name + ": Skipped"));
                        UpdateAdhocClass repad = new UpdateAdhocClass();
                        if (currentInspection.ADHOC__c == null)
                        {
                            currentInspection.ADHOC__c = "";
                        }
                        if (!currentInspection.ADHOC__c.Contains("Rep Needed"))
                        {
                            repad.ADHOC__c = "Rep Needed " + currentInspection.ADHOC__c;
                            client.Update("Inspection__c", currentInspection.Id, repad);
                        }
                        //currentInspection.ADHOC__c = "Rep Needed " + currentInspection.ADHOC__c; this code isn't even correct, make sure to fix
                    }
                }
                //put progress here, end of for loop
                progress.Report("Orders Assigned: " + i + " of " + autoqueue.Count);
            }
            System.IO.File.WriteAllLines(@"C:\Users\Public\S2 Inspections\Assigned.txt", assignedarray);
            System.IO.File.WriteAllLines(@"C:\Users\Public\S2 Inspections\Skipped.txt", skippedarray);
            return(workingList);
        }