/DICK.B1/B1Browser.cs
C# | 185 lines | 152 code | 20 blank | 13 comment | 12 complexity | 87bed39f4a1b1a9702da8b25b2c7eb7d MD5 | raw file
- using System;
- using System.Collections.Generic;
- using System.Collections;
- using System.Text;
- using System.Reflection;
- using SAPbobsCOM;
-
- namespace DICK.B1
- {
-
- public class PythonListBrowser : IEnumerable<object>
- {
- IronPython.Runtime.List list;
-
- public PythonListBrowser(IronPython.Runtime.List _list)
- {
- list = _list;
- }
-
- public int GetCount(object dummy)
- {
- return list.Count;
- }
-
- System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); }
-
- public IEnumerator<object> GetEnumerator()
- {
- foreach (object o in list)
- {
- yield return o;
- }
- }
- }
- /// <summary>
- /// Used to browse a SAPbobsCOM "lines" object
- /// </summary>
- public class Browser : IEnumerable<object>
- {
- object lines;
- Type t;
- public Browser(object _lines)
- {
- lines = _lines;
- t = _lines.GetType();
- }
-
- System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); }
-
- public int GetCount(object dummy)
- {
- try
- {
- object countobj = t.InvokeMember("Count", BindingFlags.GetProperty | BindingFlags.GetField, null, lines, new object[] { });
- int count = (int)countobj;
- return count;
- }
- catch (Exception ex)
- {
- B1Engine.GetInstance().LogDebug("Exception when accessing Count in B1Wrapper: " + ex.Message);
- throw;
- }
- }
-
- public IEnumerator<object> GetEnumerator()
- {
- object countobj = t.InvokeMember("Count", BindingFlags.GetProperty | BindingFlags.GetField, null, lines, new object[] { });
- int count = (int)countobj;
- for (int index = 0; index < count; index++)
- {
- t.InvokeMember("SetCurrentLine", BindingFlags.InvokeMethod, null, lines, new object[] { index });
- yield return lines;
- }
- }
- }
-
- /// <summary>
- /// Used to browse a set of SAPbobsCOM objects that all are of the specified type.
- /// </summary>
- public class BOBSObjectRecordSetBrowser : IEnumerable<object>
- {
- object o;
- Recordset rs;
- Type t;
- public BOBSObjectRecordSetBrowser(object _o, SAPbobsCOM.Recordset _rs)
- {
- o = _o;
- rs = _rs;
- t = o.GetType();
- }
-
- IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
-
- public IEnumerator<object> GetEnumerator()
- {
- bool originalAutoRelease = B1Engine.AutoRelease;
- B1Engine.AutoRelease = false;
- try
- {
- object browserobj = t.InvokeMember("Browser", BindingFlags.GetProperty | BindingFlags.GetField, null, o, new object[] { });
- DataBrowser br = (DataBrowser)browserobj;
- Type brt = br.GetType();
- brt.InvokeMember("Recordset", BindingFlags.SetField | BindingFlags.SetProperty, null, br, new object[] { rs });
- if (br != null && br.RecordCount > 0)
- {
- br.MoveFirst();
- while (!br.EoF)
- {
- yield return o;
- br.MoveNext();
- }
- }
- }
- finally
- {
- B1Engine.AutoRelease = originalAutoRelease;
- }
- }
- }
-
- /// <summary>
- /// Used to iterate through a single column from the specified dataset
- /// </summary>
- public class ColumnBrowser : IEnumerable<object>
- {
- string column;
- Recordset rs;
-
- public ColumnBrowser(string _column, Recordset _rs)
- {
- column = _column;
- rs = _rs;
- }
-
- IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
-
- public IEnumerator<object> GetEnumerator()
- {
- int columnindex = 0;
- if (rs.Fields.Count > 1 && column != null)
- {
- for (int i = 0; i < rs.Fields.Count; i++)
- {
- Field f = rs.Fields.Item(i);
- if (f.Name.ToUpper().Equals(column.ToUpper()))
- {
- columnindex = i;
- }
- }
- }
- rs.MoveFirst();
- while (!rs.EoF)
- {
- yield return rs.Fields.Item(columnindex).Value;
- rs.MoveNext();
- }
- }
- }
-
- /// <summary>
- /// Used to iterate through a recordset, returning a Fields object for each record.
- /// </summary>
- public class RowBrowser : IEnumerable<object>
- {
- Recordset rs;
-
- public RowBrowser(Recordset _rs)
- {
- rs = _rs;
- }
-
- IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
-
- public IEnumerator<object> GetEnumerator()
- //public IEnumerator<Fields> GetEnumerator()
- {
- rs.MoveFirst();
- while (!rs.EoF)
- {
- yield return rs.Fields;
- rs.MoveNext();
- }
- }
- }
- }