public void TakeScreenShot(string filePath) { FileInfo f = new FileInfo(filePath); if (!f.Directory.Exists) { f.Directory.Create(); } GuiFrameWindow win = _sapGuiSession.ActiveWindow; win.Restore(); byte[] screenData = (byte[])win.HardCopyToMemory(); System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality; ImageCodecInfo jpgEncoder = getEncoder(ImageFormat.Jpeg); using (var ms = new MemoryStream(screenData)) { Bitmap bmp = new Bitmap(ms); EncoderParameters paras = new EncoderParameters(1); EncoderParameter para1 = new EncoderParameter(myEncoder, 50L); paras.Param[0] = para1; bmp.Save(filePath, jpgEncoder, paras); } }
public string GetWindowText(string strWindowID) { GuiSession SapSession = getCurrentSession(); var wndWindow = SapSession.ActiveWindow.FindById(strWindowID, "GuiMainWindow"); if (wndWindow.Type == "GuiMessageWindow") { GuiMessageWindow wndMsgWindow = (GuiMessageWindow)wndWindow; return(wndMsgWindow.MessageText); } else if (wndWindow.Type == "GuiFrameWindow") { GuiFrameWindow wndFrmWindow = (GuiFrameWindow)wndWindow; return(wndFrmWindow.AccText); } else if (wndWindow.Type == "GuiMainWindow") { GuiMainWindow wndMainWindow = (GuiMainWindow)wndWindow; return(wndMainWindow.AccText); } else if (wndWindow.Type == "GuiModalWindow") { GuiModalWindow wndMainWindow = (GuiModalWindow)wndWindow; return(wndMainWindow.PopupDialogText); } else { return(""); } }
public static T FindDescendantByProperty <T>(this GuiFrameWindow FrameWindow, Func <T, bool> Property = null) where T : class { if (Property == null) { Property = new Func <T, bool>(t => true); } return(findDescendantByPropertyTemplate <T>(FrameWindow.Children, Property)); }
private static bool isMatch(GuiFrameWindow window, GuiVComponent comp, int X1, int Y1, int X2, int Y2) { int x1 = comp.ScreenLeft - window.ScreenLeft; int y1 = comp.ScreenTop - window.ScreenTop; int x2 = x1 + comp.Width; int y2 = y1 + comp.Height; if (x1 >= X1 && y1 >= Y1 && x2 <= X2 && y2 <= Y2) { return(true); } return(false); }
public void Research2() { Thread.Sleep(500); //FirstSessionProvider provider = new FirstSessionProvider(); GuiSessionProvider provider = new ActiveSessionProvider(); GuiCTextField field = (GuiCTextField)provider.GetSession().FindById("/app/con[0]/ses[0]/wnd[0]/usr/ctxtSEOCLASS-CLSNAME"); System.Console.WriteLine(field.AccText); System.Console.WriteLine(field.AccLabelCollection); System.Console.WriteLine(field.DisplayedText); System.Console.WriteLine(field.Highlighted); GuiFrameWindow window = (GuiFrameWindow)provider.GetSession().FindById("/app/con[0]/ses[0]/wnd[0]"); }
public static TSapControl FindByName <TSapControl>(this GuiFrameWindow window, string name) { try { return((TSapControl)window.FindByName(name, typeof(TSapControl).Name)); } catch (COMException e) { var writer = new StringWriter(); writer.WriteLine("The control could not be found by name and type."); writer.WriteLine("Name : " + name); writer.WriteLine("Type : " + typeof(TSapControl).Name); throw new Exception(writer.ToString(), e); } }
public static void Maximize(string id, GuiFrameWindow window, GuiSession session) { if (window == null && string.IsNullOrEmpty(id)) { throw new Exception("Parameters for the Target object not provided: id or GuiFrameWindow object"); } if (session == null) { throw new Exception("SAP session parameter is required and was not provided."); } if (window == null) { window = (GuiFrameWindow)(session).FindById(id); } window.Maximize(); }
public static TSapControl FindByName <TSapControl>(this GuiFrameWindow window, string name) { try { return((TSapControl)window.FindByName(name, typeof(TSapControl).Name)); } catch (COMException e) { const string Message = "The control could not be found by name and type."; var context = new Dictionary <string, object> { { "Name", name }, { "Type", typeof(TSapControl).Name }, }.Prettify(); Logger.Instance.ErrorException("The control could not be found by name and type: " + context, e); throw new InvalidOperationException(Message + Environment.NewLine + context, e); } }
public static T FindById <T>(this GuiFrameWindow FrameWindow, string Id) where T : class { return(findByIdTemplate <T>(Id, FrameWindow.FindById)); }
public static IEnumerable <GuiVComponent> FindByRegion(this GuiFrameWindow Window, int X1, int Y1, int X2, int Y2) { return(Window.FindDescendantsByProperty <GuiVComponent>(c => isMatch(Window, c, X1, Y1, X2, Y2))); }
public static T FindByName <T>(this GuiFrameWindow FrameWindow, string Name) where T : class { return(findByNameTemplate <T>(Name, FrameWindow.FindByName)); }
public HrEntry(GuiFrameWindow window, GuiTableRow row) { this.window = window; this.row = row; }
public static T FindByNameEx <T>(this GuiFrameWindow FrameWindow, string Name, int TypeId) where T : class { return(findByNameExTemplate <T>(Name, TypeId, FrameWindow.FindByNameEx)); }
public static void SendKey(this GuiFrameWindow Window, SAPKeys key) { Window.SendVKey((int)key); }
private void btn_run_Click(object sender, EventArgs e) { if (tb_id.Text == "" || tb_plant.Text == "") { return; } if (tb_id.TextLength > 4) { MessageBox.Show("ID item not valid", "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (tb_plant.TextLength != 4) { MessageBox.Show("Centro inválido", "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } //INICIAR ALTERAÇÃO #region if (dataGridView1.RowCount == 1) { return; } try { //Get the Windows Running Object Table SapROTWr.CSapROTWrapper sapROTWrapper = new SapROTWr.CSapROTWrapper(); //Get the ROT Entry for the SAP Gui to connect to the COM object SapGuilRot = sapROTWrapper.GetROTEntry("SAPGUI"); //Get the reference to the Scripting Engine object engine = SapGuilRot.GetType().InvokeMember("GetScriptingEngine", System.Reflection.BindingFlags.InvokeMethod, null, SapGuilRot, null); //Get the reference to the running SAP Application Window GuiApplication GuiApp = (GuiApplication)engine; //Get the reference to the first open connection GuiConnection connection = (GuiConnection)GuiApp.Connections.ElementAt(0); //get the first available session GuiSession session = (GuiSession)connection.Children.ElementAt(0); //Get the reference to the main "Frame" in which to send virtual key commandss //GuiFrameWindow frame = session.ActiveWindow; GuiFrameWindow frame = (GuiFrameWindow)session.FindById("wnd[0]"); //((GuiFrameWindow)frame.FindById("wnd[0]")); ((GuiOkCodeField)frame.FindById("wnd[0]/tbar[0]/okcd")).Text = "/nztvc025"; frame.SendVKey(0); int linhas1 = dataGridView1.RowCount; int i; ((GuiTextField)frame.FindById("wnd[0]/usr/ctxtP_PRFID")).Text = "0001"; ((GuiTextField)frame.FindById("wnd[0]/usr/ctxtP_WERKS")).Text = tb_plant.Text; for (i = 0; i < linhas1 - 1; i++) { try { ((GuiButton)frame.FindByName("btn[8]", "GuiButton")).Press(); string material = dataGridView1.Rows[i].Cells[0].Value.ToString(); int tam = material.Length; string component1 = dataGridView1.Rows[i].Cells[1].Value.ToString(); if (tam == 11) { ((GuiTextField)session.ActiveWindow.FindById("wnd[1]/usr/sub:SAPLSPO4:0300/ctxtSVALD-VALUE[1,21]")).Text = material; } else { ((GuiTextField)session.ActiveWindow.FindById("wnd[1]/usr/sub:SAPLSPO4:0300/ctxtSVALD-VALUE[0,21]")).Text = material; } ((GuiButton)frame.FindByName("btn[0]", "GuiButton")).Press(); ((GuiToolbarControl)frame.FindById("wnd[0]/usr/subSUBSCR_TIPOS:SAPLZRVC_ZBOM_POS_ESP:0200/cntlCONT_TIPOS/shellcont/shell/shellcont[1]/shell[0]")).PressButton("&FIND"); ((GuiTextField)session.ActiveWindow.FindById("wnd[1]/usr/txtLVC_S_SEA-STRING")).Text = tb_id.Text.ToString(); ((GuiButton)frame.FindByName("btn[0]", "GuiButton")).Press(); ((GuiButton)frame.FindByName("btn[0]", "GuiButton")).Press(); if (session.Children.Count != 2) { dataGridView1.Rows[i].Cells[2].Value = "N/A"; goto acabou; } ((GuiButton)frame.FindByName("btn[0]", "GuiButton")).Press(); for (int j = 1; j < 100; j++) { string esp; if (j < 10) { esp = " "; } else { esp = " "; } ((GuiTree)frame.FindById("wnd[0]/usr/subSUBSCR_TIPOS:SAPLZRVC_ZBOM_POS_ESP:0200/cntlCONT_TIPOS/shellcont/shell/shellcont[1]/shell[1]")).SelectItem(esp + j, "&Hierarchy"); ((GuiTree)frame.FindById("wnd[0]/usr/subSUBSCR_TIPOS:SAPLZRVC_ZBOM_POS_ESP:0200/cntlCONT_TIPOS/shellcont/shell/shellcont[1]/shell[1]")).EnsureVisibleHorizontalItem(esp + j, "&Hierarchy"); ((GuiTree)frame.FindById("wnd[0]/usr/subSUBSCR_TIPOS:SAPLZRVC_ZBOM_POS_ESP:0200/cntlCONT_TIPOS/shellcont/shell/shellcont[1]/shell[1]")).DoubleClickItem(esp + j, "&Hierarchy"); if (((GuiCTextField)session.ActiveWindow.FindByName("ZTBVC_657-ID_ITEM", "GuiCTextField")).Text == tb_id.Text.ToString()) { ((GuiToolbarControl)frame.FindById("wnd[0]/usr/subSUBSCR_TIPOS:SAPLZRVC_ZBOM_POS_ESP:0200/cntlCONT_TIPOS/shellcont/shell/shellcont[1]/shell[0]")).PressButton("EDIT_ESP"); ((GuiTextField)frame.FindById("wnd[0]/usr/subSUBSCR_ESPEC:SAPLZRVC_ZBOM_POS_ESP:0300/subSUBSCR_ESP:SAPLZRVC_ZBOM_POS_ESP:0340/ctxtZTBVC_658-IDNRK")).Text = component1; ((GuiButton)frame.FindByName("btn[8]", "GuiButton")).Press(); dataGridView1.Rows[i].Cells[2].Value = "OK"; break; } } acabou : ((GuiButton)frame.FindByName("btn[2]", "GuiButton")).Press(); } catch { ((GuiButton)frame.FindByName("btn[2]", "GuiButton")).Press(); } #endregion } MessageBox.Show("Alteração Concluída", "Alteração Concluída", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } catch { MessageBox.Show("Erro ao conectar com SAP", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }
public static IEnumerable <T> FindDescendantsByProperty <T>(this GuiFrameWindow FrameWindow, Func <T, bool> Property = null) where T : class { return(findDescendantsByPropertyTemplate <T>(FrameWindow.Children, Property)); }
public static IEnumerable <T> FindAllByName <T>(this GuiFrameWindow FrameWindow, string Name) where T : class { return(findAllByNameTemplate <T>(Name, FrameWindow.FindAllByName)); }
public static T FindChildByProperty <T>(this GuiFrameWindow FrameWindow, Func <T, bool> Property = null) where T : class { return(findChildByPropertyTemplate <T>(FrameWindow.Children, Property)); }
public HrDetail(GuiFrameWindow window) { this.window = window; }