private WorkItemHours WorkItemToWIHours(WorkItemRegister oTFSI, long?haxcomId, DataSource oDataSource, decimal dHours)
        {
            var oWI = new WorkItemHours();

            oWI.HaxComID = haxcomId;
            if (int.TryParse(oTFSI.ID, out int iID))
            {
                oWI.TfsId = iID;
            }
            oWI.ID             = oTFSI.ID;
            oWI.ProjectId      = CheckReplacesProject(oTFSI.ProjectId);
            oWI.Function       = 25; //dev
            oWI.Description    = $"TFS {oWI.TfsId.ToString()} {oTFSI.Title}";
            oWI.Title          = oTFSI.Title;
            oWI.FromDatasource = oDataSource;
            oWI.TFSType        = oTFSI.Type;
            if (!string.IsNullOrWhiteSpace(oTFSI.Type))
            {
                if (oTFSI.Type.ToUpperInvariant().Contains("BUG") || oTFSI.Title.Contains("3.0"))
                {
                    oWI.BillingType = BillingType.Capitalized;
                }
                else
                {
                    oWI.BillingType = BillingType.Billable;
                }
            }
            oWI.HaxComHours = dHours;
            return(oWI);
        }
        private void deleteThisItemFromDatesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmDeleteDates      oDel     = new frmDeleteDates();
            WorkItemHours       oselItem = (WorkItemHours)oSelectedHour.Tag;
            List <WorkItemsDay> oItems   = new List <WorkItemsDay>();
            WorkItemsDay        oItg;

            foreach (ListViewGroup oLvg in lvwHistory.Groups)
            {
                oItg = (WorkItemsDay)oLvg.Tag;
                if (oItg.WorkItems.Any(x => x.ID == oselItem.ID && x.Title == oselItem.Title))
                {
                    oItems.Add(oItg);
                }
            }
            oDel.dateFrom = oItems.Min(x => x.Date).Date;
            oDel.dateTo   = oItems.Max(x => x.Date).Date;
            if (oDel.ShowDialog() == DialogResult.OK)
            {
                List <ListViewItem> lstLviDel = FindListItemsfromWorkItem(oselItem, oDel.dateFrom, oDel.dateTo);
                foreach (ListViewItem oLvi in lstLviDel)
                {
                    lvwHistory.Items.Remove(oLvi);
                }
            }
        }
        public static List <WorkItemsDay> GroupItemsPerDay(List <WorkItemRegister> itemList)
        {
            DateTime            dateFrom    = itemList.Select(x => x.DateFrom).Min();
            DateTime            dateThru    = itemList.Select(x => x.DateFrom).Max();
            List <WorkItemsDay> groupedList = new List <WorkItemsDay>();
            WorkItemsDay        oRow;
            WorkItemHours       oTemp;

            for (var day = dateFrom.Date; day.Date <= dateThru.Date; day = day.AddDays(1))
            {
                oRow = new WorkItemsDay(day);
                foreach (WorkItemRegister wi in itemList.Where(x => x.DateFrom.Date == day.Date))
                {
                    oTemp = oRow.WorkItems.Where(x => x.ID == wi.ID).FirstOrDefault();
                    if (oTemp == null)
                    {
                        oTemp = new WorkItemHours(wi);
                        oRow.WorkItems.Add(oTemp);
                    }
                    else
                    {
                        oTemp.Hours = oTemp.Hours.Add(wi.timeSpan);
                    }
                }
                groupedList.Add(oRow);
            }
            return(groupedList);
        }
        private void LoadTFSCSV()
        {
            frmLoginSendHaxCom oLogin = new frmLoginSendHaxCom {
                LoginURL = TimeKeeperBaseURL
            };

            oLogin.openMode        = frmLoginSendHaxCom.OpenMode.Search;
            oLogin.optDays.Enabled = false;
            oLogin.optSel.Enabled  = false;
            if (oLogin.ShowDialog() == DialogResult.OK)
            {
                List <WorkItemsDay> oItems = new List <WorkItemsDay>();
                List <CsvReg>       regs   = getHaxComTFSTime(oLogin.PHPSession, dtpFrom.Value, DateTime.Today, oLogin.chkAll.Checked, (oLogin.CHKBug.Checked || oLogin.chkPBI.Checked || oLogin.chkOther.Checked), oLogin.chkMeeting.Checked, oLogin.chkPrjtLess.Checked, oLogin.chkNonBillable.Checked, oLogin.chkCapitalized.Checked);
                var oDataSource            = oDataSources.First(x => x.Type == Datasourcetype.TFS);
                var outlookDataSource      = oDataSources.FirstOrDefault(x => x.Type == Datasourcetype.Outlook);
                //gets rest of TFS data using the TFS IDS
                var tfsItems = WorkItemMapper.GetHistoricalWorkitemsByIDs(oDataSource.ServerUrl, oDataSource.ProjectName, oDataSource.User, regs.Select(x => x.TFSId).Distinct());
                //assembles the listview
                foreach (DateTime dDate in regs.Select(x => x.Date).Distinct())
                {
                    var oTemp = new WorkItemsDay(dDate);
                    foreach (CsvReg oReg in regs.Where(x => x.Date == dDate))
                    {
                        if (oReg.TFSId == 0) //meetings
                        {
                            var oWI = new WorkItemHours();
                            oWI.HaxComID       = oReg.EntryID;
                            oWI.ID             = "meeting";
                            oWI.ProjectId      = 0;
                            oWI.ClientId       = 166;
                            oWI.SubClientId    = 5;
                            oWI.Function       = 41; //dev meeting
                            oWI.Description    = oReg.Title;
                            oWI.Title          = oReg.Title;
                            oWI.FromDatasource = outlookDataSource;
                            oWI.BillingType    = BillingType.Capitalized;
                            oWI.HaxComHours    = oReg.Hours;
                            oTemp.WorkItems.Add(oWI);
                        }
                        else
                        {
                            var oTFSI = tfsItems.FirstOrDefault(x => x.ID == oReg.TFSId.ToString());
                            if (oTFSI != null)
                            {
                                string sType = oTFSI.Type.ToUpperInvariant();
                                if (oLogin.chkAll.Checked || (sType == "BUG" && oLogin.CHKBug.Checked) || (sType == "USER STORY" && oLogin.chkPBI.Checked) ||
                                    (sType != "BUG" && sType != "PRODUCT BACKLOG ITEM" && oLogin.chkOther.Checked))
                                {
                                    oTemp.WorkItems.Add(WorkItemToWIHours(oTFSI, oReg.EntryID, oDataSource, oReg.Hours));
                                }
                            }
                        }
                    }
                    oItems.Add(oTemp);
                }
                UpdateListview(oItems, false);
            }
        }
        private void toggleVerifiedToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bool                bVerified = oSelectedHour.SubItems[1].BackColor == Color.Green;
            WorkItemHours       oselItem  = (WorkItemHours)oSelectedHour.Tag;
            List <ListViewItem> lstLviH   = FindListItemsfromWorkItem(oselItem, null, null);

            foreach (ListViewItem oLVI in lstLviH)
            {
                oLVI.SubItems[1].BackColor = bVerified ? Color.White : Color.Green;
            }
        }
        private void highlightItemToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem oLVI in lvwHistory.Items)
            {
                oLVI.BackColor = Color.White;
            }
            WorkItemHours       oselItem = (WorkItemHours)oSelectedHour.Tag;
            List <ListViewItem> lstLviH  = FindListItemsfromWorkItem(oselItem, null, null);

            foreach (ListViewItem oLVI in lstLviH)
            {
                oLVI.BackColor = Color.Yellow;
            }
        }
        private List <ListViewItem> FindListItemsfromWorkItem(WorkItemHours oselItem, DateTime?dateFrom, DateTime?dateTo)
        {
            List <ListViewItem> lstLvi = new List <ListViewItem>();

            foreach (ListViewGroup oLvg in lvwHistory.Groups)
            {
                DateTime dateGroup = DateTime.ParseExact(oLvg.Name, "dddd, MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture);
                if (dateGroup >= (dateFrom ?? dateGroup) && dateGroup <= (dateTo ?? dateGroup))
                {
                    foreach (ListViewItem oLvi in oLvg.Items)
                    {
                        if (((WorkItemHours)oLvi.Tag).ID == oselItem.ID && ((WorkItemHours)oLvi.Tag).Title == oselItem.Title)
                        {
                            lstLvi.Add(oLvi);
                        }
                    }
                }
            }
            return(lstLvi);
        }
        private ListViewItem WorkItemHoursToLVWItem(ListViewGroup oGroup, WorkItemHours oItem)
        {
            ListViewItem oReturn = new ListViewItem(new string[] { oItem.ID.ToString(),
                                                                   oItem.TFSType,
                                                                   oItem.ProjectId.ToString(),
                                                                   oItem.Hours.ToString(),
                                                                   oItem.HaxComHours.ToString("0.##"),
                                                                   oItem.Title.ToString(),
                                                                   BillTypeToStr(oItem.BillingType),
                                                                   oItem.ResponseError })
            {
                Tag   = oItem,
                Group = oGroup,
                UseItemStyleForSubItems = false
            };

            if (oItem.ProjectId == 0 && oItem.ID.ToLower() != "meeting")
            {
                oReturn.SubItems[2].BackColor = Color.Red;
            }
            return(oReturn);
        }
 private string GetURL(WorkItemHours oWIH)
 {
     return(oWIH.FromDatasource.ServerUrl + @"/" + oWIH.FromDatasource.ProjectName + "/_workitems?id=" + oWIH.ID);
 }
        private void OpenInWebBrowser()
        {
            WorkItemHours oWIH = ((WorkItemHours)oSelectedHour.Tag);

            System.Diagnostics.Process.Start(GetURL(oWIH));
        }
        /*private static string TrySubmitTime(DateTime date, WorkItemHours input, string sessionId, List<HaxComClient.Project> clients)
         * {
         *  return "Success!";  //This function is for testing purposes
         * }*/
        private static string TrySubmitTime(DateTime date, WorkItemHours input, string sessionId, List <HaxComClient.Project> clients)
        {
            string result = "Success!";

            try
            {
                using (WebClient client = new WebClient())
                {
                    client.Headers.Add(HttpRequestHeader.Cookie, $"PHPSESSID={sessionId}");
                    client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
                    NameValueCollection vals = new NameValueCollection();
                    if (input.HaxComID.HasValue)                        //entryId
                    {
                        vals.Add("entryId", input.HaxComID.ToString()); //for edit
                    }
                    vals.Add("date", date.ToString("MM/dd/yyyy"));
                    vals.Add("tfsId", ConvertZeroToEmptyString(input.TfsId));
                    vals.Add("ticketId", "");
                    bool bClientFromDb = false;
                    if (input.ProjectId > 0)
                    {
                        var HCCLient = clients.FirstOrDefault(x => x.name.Contains(input.ProjectId.ToString()));
                        if (HCCLient == null)
                        {
                            HCCLient = clients.FirstOrDefault(x => x.id.Trim() == input.ProjectId.ToString().Trim());
                            if (HCCLient != null)
                            {
                                result = $"Couldn't find Project Code {input.ProjectId.ToString()} on drop down list description, using it as ID instead, {HCCLient.name} selected";
                            }
                        }
                        if (HCCLient != null)
                        {
                            vals.Add("projectId", HCCLient.id);
                            var ProjInfo = GetProjectInfo(client, HCCLient.id);
                            if (ProjInfo != null)
                            {
                                vals.Add("clientId", ProjInfo.clientID);
                                vals.Add("subclientId", ProjInfo.subclientID);
                                bClientFromDb = true;
                            }
                        }
                        else
                        {
                            vals.Add("projectId", ConvertZeroToEmptyString(input.ProjectId));
                        }
                    }
                    if (!bClientFromDb)
                    {
                        if (input.ID != "meeting")
                        {
                            result = "Client and Project not populated from API";
                        }
                        vals.Add("clientId", ConvertZeroToEmptyString(input.ClientId));
                        vals.Add("subclientId", ConvertZeroToEmptyString(input.SubClientId));
                    }
                    vals.Add("funct", input.Function.ToString());
                    vals.Add("description", input.Title);
                    vals.Add("billingType", ((int)input.BillingType).ToString());
                    vals.Add("hours", input.HaxComHours.ToString("#.##"));
                    vals.Add("fromPage", "my");
                    byte[] webClientResult = client.UploadValues($"{TimeKeeperBaseURL}/time/index/save-update", vals);
                    string resultantString = Encoding.UTF8.GetString(webClientResult);
                    Console.WriteLine(resultantString);
                    if (resultantString.ToUpperInvariant().Contains("ERROR"))
                    {
                        if (resultantString.ToUpperInvariant().Contains("TFS"))
                        {
                            input.Description += $" TFS: {input.TfsId}";
                            input.TfsId        = 0;
                            result             = TrySubmitTime(date, input, sessionId, clients);
                        }
                        else
                        {
                            result = resultantString;
                        }
                    }
                }
            }
            catch (Exception err)
            {
                result = err.Message;
            }

            return(result);
        }
Exemple #12
0
        public static List <WorkItemsDay> GetHistoricalWorkitemsByUser(string tfsURL, string projectName, string userName, DateTime dFilter, DataSource oDataSource)
        {
            try
            {
                Uri tfsUrl = new Uri(tfsURL);
                TfsTeamProjectCollection collection = new TfsTeamProjectCollection(tfsUrl);
                collection.EnsureAuthenticated();
                var workItemStore = collection.GetService <WorkItemStore>();
                var Ids           = workItemStore.Query("select [System.Id] from WorkItems " +
                                                        "where " +
                                                        (projectName != "*" ? "[System.TeamProject] = '" + projectName + "' " + "and " : "") +
                                                        "(ever [System.ChangedBy] ='" + userName + "' or [System.AssignedTo] ='" + userName + "')" +
                                                        (oDataSource.ExcludeTasks ? " and [Work Item Type] <> 'Task'" : ""));
                var              itemList = new List <WorkItemRegister>();
                DateTime         dAcum;
                WorkItemRegister oWIR = new WorkItemRegister();
                foreach (WorkItem wi in Ids)
                {
                    dAcum = wi.CreatedDate;
                    foreach (Revision revision in wi.Revisions)
                    {
                        if (revision.Fields["Assigned To"].Value.ToString() == userName)
                        {
                            if (oWIR.ID == null)
                            {
                                string PrjCode = "";
                                if (wi.Fields.Contains("Project Code"))
                                {
                                    PrjCode = wi.Fields["Project Code"].Value.ToString();
                                }
                                else if (wi.Fields.Contains("ProjectCode"))
                                {
                                    PrjCode = wi.Fields["ProjectCode"].Value.ToString();
                                }
                                oWIR = new WorkItemRegister(revision.Fields["ID"].Value.ToString(),
                                                            revision.Fields["Title"].Value.ToString(),
                                                            revision.Fields["Changed By"].Value.ToString(),
                                                            PrjCode,
                                                            revision.Fields["Work Item Type"].Value.ToString())
                                {
                                    DateFrom = dAcum
                                };
                            }
                        }
                        else
                        {
                            if (oWIR.ID != null)
                            {
                                oWIR.DateTo = (DateTime)revision.Fields["Changed Date"].Value;
                                itemList.Add(oWIR);
                                oWIR = new WorkItemRegister();
                            }
                        }
                        if (revision.Index == wi.Revisions.Count - 1)
                        {
                            dAcum = DateTime.Now;
                        }
                        else
                        {
                            dAcum = (DateTime)revision.Fields["Changed Date"].Value;
                        }
                    }
                    if (oWIR.ID != null)
                    {
                        oWIR.DateTo = dAcum;
                        itemList.Add(oWIR);
                        oWIR = new WorkItemRegister();
                    }
                }

                var      SplittedItemList = new List <WorkItemRegister>();
                DateTime dTempF;
                DateTime dTempT;
                foreach (WorkItemRegister oRow in itemList)
                {
                    dTempF = oRow.DateFrom;
                    while (dTempF < oRow.DateTo)
                    {
                        dTempT = dTempF.AddDays(1).Date;
                        if (dTempT > oRow.DateTo)
                        {
                            dTempT = oRow.DateTo;
                        }
                        SplittedItemList.Add(oRow.DuplicateWithDates(dTempF, dTempT));
                        dTempF = dTempT;
                    }
                }


                dTempF = dFilter;//SplittedItemList.Select(x => x.DateFrom).Min();
                dTempT = SplittedItemList.Select(x => x.DateFrom).Max();
                List <WorkItemsDay> groupedList = new List <WorkItemsDay>();
                WorkItemHours       oTemp;
                for (var day = dTempF.Date; day.Date <= dTempT.Date; day = day.AddDays(1))
                {
                    WorkItemsDay oRow = new WorkItemsDay(day);
                    foreach (WorkItemRegister wi in SplittedItemList.Where(x => x.DateFrom.Date == day.Date))
                    {
                        oTemp = oRow.WorkItems.FirstOrDefault(x => x.ID == wi.ID);
                        if (oTemp == null)
                        {
                            oTemp = new WorkItemHours(wi)
                            {
                                FromDatasource = oDataSource
                            };
                            oRow.WorkItems.Add(oTemp);
                        }
                        else
                        {
                            oTemp.Hours = oTemp.Hours.Add(wi.timeSpan);
                        }
                    }
                    groupedList.Add(oRow);
                }
                return(groupedList);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception retrieving data: {0}", ex.Message);
                return(new List <WorkItemsDay>());
            }
        }