private void _btnGetFromAgresso_Click(object sender, EventArgs e) { IHTMLDocument3 doc3 = null; try { doc3 = InternetExplorerUtilities.GetTimesheetDocument(); if (doc3 == null) { MessageBox.Show("Can't find Agresso timesheet page. Please check and try again", "Can't find page", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { IEnumerable <string> currentProjectCodes = Projects.Projects.Select(p => p.Code.ToUpper()); IEnumerable <Tuple <string, string> > allCodesAndDescriptions = InternetExplorerUtilities.GetProjectCodesAndDescriptions(doc3); List <Tuple <string, string> > toAdd = new List <Tuple <string, string> >(); if (currentProjectCodes.Count() == 0) { toAdd.AddRange(allCodesAndDescriptions); } else { foreach (var project in allCodesAndDescriptions) { if (!currentProjectCodes.Contains(project.Item1)) { toAdd.Add(project); } } } foreach (var newProject in toAdd) { Project p = new Project(); p.Code = newProject.Item1; p.Title = newProject.Item2; Projects.Projects.Add(p); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error when getting workorders", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (doc3 != null) { Marshal.ReleaseComObject(doc3); } } }
private void FillAgresso() { IHTMLDocument3 doc3 = null; try { doc3 = InternetExplorerUtilities.GetTimesheetDocument(); if (doc3 == null) { MessageBox.Show("Can't find Agresso timesheet page. Please check and try again", "Can't find page", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Now add each line in turn for (int row = 0; row < _textItems.GetLength(0); row++) { Color originalColour = _dgvText.Rows[row].DefaultCellStyle.BackColor; _dgvText.Rows[row].DefaultCellStyle.BackColor = Color.LightGoldenrodYellow; string[] rowItems = new string[_textItems.GetLength(1)]; for (int col = 0; col < _textItems.GetLength(1); col++) { rowItems[col] = _textItems[row, col]; } try { ProcessLine(row, rowItems, doc3); _dgvText.Rows[row].Cells[_dgvText.Rows[row].Cells.Count - 1].Value = "✔"; } catch (Exception ex) { _dgvText.Rows[row].Cells[_dgvText.Rows[row].Cells.Count - 1].Value = "✖ " + ex.Message; } _dgvText.Rows[row].DefaultCellStyle.BackColor = originalColour; System.Threading.Thread.Sleep(500); } } finally { if (doc3 != null) { Marshal.ReleaseComObject(doc3); } } }
/// <summary> /// Inserts a line of items, the first two of which should be project code and description /// </summary> public void ProcessLine(int rowIndex, string[] items, IHTMLDocument3 doc3) { InternetExplorerUtilities.SelectAgressoLine(items[0], items[1], doc3); InternetExplorerUtilities.PushToSelectedLine(rowIndex, items, doc3, _dgvText); }