private string ExcuteAbapCode(string Code)
        {
            SAPINT.Utils.ABAPCode abap = new SAPINT.Utils.ABAPCode(this.cboxSystemList1.Text.Trim().ToUpper());

            abap.ResetCode();
            //使用TEXTBOX转换字符串。
            TextBox box = new TextBox();

            box.Text = Code;

            foreach (string line in box.Lines)
            {
                abap.AddCodeLine(line);
            }
            box.Text = "";
            try
            {
                if (abap.InstallAndRun())
                {
                    for (int i = 0; i < abap.ResultLineCount; i++)
                    {
                        box.Text += abap.GetResultLine(i) + "\r\n";
                    }
                }
                else
                {
                    box.Text = "ABAP Error: " + abap.LastABAPSyntaxError;
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
            return(box.Text);
        }
        private string LoadOneObject(String obj)
        {
            try
            {
                this.SapSysName = cboxSystemList1.Text;
                if (String.IsNullOrEmpty(SapSysName))
                {
                    MessageBox.Show("请选择系统");
                    return(string.Empty);
                }
                else
                {
                    this.AbapCode = new SAPINT.Utils.ABAPCode(SapSysName);
                    var codes = AbapCode.GetSourceCode(obj);


                    var sb = new StringBuilder();

                    codes.ForEach(x => sb.AppendLine(x));
                    var s = sb.ToString();


                    //   this.syntaxBoxControl1.Document.Text = s;
                    return(s);
                }
            }


            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(string.Empty);
        }
        private string ExcuteAbapCode(String code, String sapSystem)
        {
            SAPINT.Utils.ABAPCode abap = new SAPINT.Utils.ABAPCode(sapSystem);
            var result = string.Empty;

            try
            {
                result = abap.InstallAndRun(code);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            return(result);
        }
 private void btnSearchReport_Click(object sender, EventArgs e)
 {
     try
     {
         dt.Clear();
         this.SapSysName = this.cboxSystemList1.Text.Trim().ToUpper();
         SAPINT.Utils.ABAPCode abap = new SAPINT.Utils.ABAPCode(SapSysName);
         var list = abap.SearchProgram(this.txtSapProgram.Text, this.txtObject.Text, this.txtDevClass.Text);
         //list.ForEach(x => { });
         int index = 0;
         foreach (var item in list)
         {
             var r = dt.NewRow();
             r["Index"] = index;
             index++;
             r["NAME"] = item.prog;     // ABAP Program Name
             //r["PROG"] = item.prog;// ABAP 程序名
             r["CLAS"]   = item.clas;   // 程序类别
             r["SUBC"]   = item.subc;   //   程序类型
             r["APPL"]   = item.appl;   // 应用程序
             r["CDAT"]   = item.cdat;   // 创建日期
             r["VERN"]   = item.vern;   // 版本号
             r["RMAND"]  = item.rmand;  // 集团
             r["RLOAD"]  = item.rload;  // 主语言
             r["UNAM"]   = item.unam;   // 最后修改人
             r["UDAT"]   = item.udat;   // 更改日期
             r["UTIME"]  = item.utime;  // 字典: 最后修改时间
             r["DATALG"] = item.datalg; // ABAP/4: 程序组件的长度
             r["VARCL"]  = item.varcl;  // 区分大小写
             dt.Rows.Add(r);
         }
         this.dataGridView1.AutoResizeColumns();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        private bool LoadObjectFromSap(BackgroundWorker bw, bool Saved = true)
        {
            List <Code>            list = new List <Code>();
            Dictionary <int, Code> pos  = new Dictionary <int, Code>();

            this.AbapCode = new SAPINT.Utils.ABAPCode(SapSysName);
            var itemCount = 0;
            var processed = 0;

            var m_isCacelling = false;

            foreach (DataRow item in dt.Rows)
            {
                if (this.backgroundWorker1.CancellationPending)
                {
                    m_isCacelling = true;
                }
                if (String.IsNullOrWhiteSpace(item["Select"].ToString()))
                {
                    continue;
                }
                var isSelect = (bool)item["Select"];
                if (isSelect)
                {
                    var obj = item["NAME"].ToString();
                    if (String.IsNullOrEmpty(obj))
                    {
                        continue;
                    }

                    var codes = AbapCode.GetSourceCode(obj);

                    var sb = new StringBuilder();

                    codes.ForEach(x => sb.AppendLine(x));
                    item["Lines"] = codes.Count;


                    var abapCode = sb.ToString();
                    item["Length"] = Util.FileUtil.FormatFileSize(abapCode.Length);
                    item["Header"] = abapCode;

                    if (String.IsNullOrEmpty(abapCode))
                    {
                        continue;
                    }
                    var comments = new StringBuilder();
                    foreach (var comment in codes)
                    {
                        if (comment.StartsWith("*"))
                        {
                            comments.AppendLine(comment);
                        }
                        if (comments.ToString().ToList().Count > 10)
                        {
                            break;
                        }
                    }
                    Code code = new Code();

                    code.Content = abapCode;
                    code.Desc    = comments.ToString();
                    code.Title   = obj;
                    if (!String.IsNullOrEmpty(this.TreeId))
                    {
                        code.TreeId = TreeId;
                    }
                    list.Add(code);
                    var index = int.Parse(item["Index"].ToString());
                    pos.Add(index, code);
                    var pTime = new System.TimeSpan(pauseTime);
                    Thread.Sleep(pTime);//必须暂停,因为在SAP系统中读取程序不会那么快。
                    //每100行保存一次
                    itemCount++;
                    if (itemCount == 100 && dt.Rows.Count >= 100 && m_isCacelling == false)
                    {
                        if (true == Saved)
                        {
                            this.cbxDbSources.Enabled = false;
                            db.SaveCodeList(list);
                            this.cbxDbSources.Enabled = true;
                        }
                        foreach (var positem in pos)
                        {
                            dt.Rows[positem.Key]["CodeId"] = positem.Value.Id;
                            dt.Rows[positem.Key]["Select"] = false;
                        }
                        pos.Clear();
                        list.Clear();
                        itemCount = 0;
                    }
                    else
                    {
                        if (true == Saved)
                        {
                            this.cbxDbSources.Enabled = false;
                            db.SaveCodeList(list);
                            this.cbxDbSources.Enabled = true;
                        }

                        foreach (var positem in pos)
                        {
                            dt.Rows[positem.Key]["CodeId"] = positem.Value.Id;
                            dt.Rows[positem.Key]["Select"] = false;
                        }
                        pos.Clear();
                        list.Clear();
                        itemCount = 0;
                    }
                    processed++;
                    ImportMessage m = new ImportMessage()
                    {
                        current = processed, total = selectedItems, progName = obj
                    };
                    bw.ReportProgress(processed, m);
                    //如果要取消,保存后退出.
                    if (m_isCacelling == true)
                    {
                        break;
                    }
                }
            }
            return(true);
            //if (db.SaveCodeList(list))
            //{
            //    foreach (var item in pos)
            //    {
            //        dt.Rows[item.Key]["CodeId"] = item.Value.Id;
            //    }
            //    return true;
            //}
            //else
            //{
            //    return false;
            //}
        }
        private string ExcuteAbapCode(String code, String sapSystem)
        {
            SAPINT.Utils.ABAPCode abap = new SAPINT.Utils.ABAPCode(sapSystem);
            var result = string.Empty;
            try
            {
                result = abap.InstallAndRun(code);
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }

            return result;
        }
        private string ExcuteAbapCode(string Code)
        {
            SAPINT.Utils.ABAPCode abap = new SAPINT.Utils.ABAPCode(this.cboxSystemList1.Text.Trim().ToUpper());

            abap.ResetCode();
            //使用TEXTBOX转换字符串。
            TextBox box = new TextBox();
            box.Text = Code;

            foreach (string line in box.Lines)
            {
                abap.AddCodeLine(line);
            }
            box.Text = "";
            try
            {
                if (abap.InstallAndRun())
                {
                    for (int i = 0; i < abap.ResultLineCount; i++)
                    {
                        box.Text += abap.GetResultLine(i) + "\r\n";
                    }
                }
                else
                {
                    box.Text = "ABAP Error: " + abap.LastABAPSyntaxError;
                }

            }
            catch (Exception ee)
            {

                MessageBox.Show(ee.Message);
            }
            return box.Text;
        }
        private void btnSearchReport_Click(object sender, EventArgs e)
        {
            try
            {
                dt.Clear();
                this.SapSysName = this.cboxSystemList1.Text.Trim().ToUpper();
                SAPINT.Utils.ABAPCode abap = new SAPINT.Utils.ABAPCode(SapSysName);
                var list = abap.SearchProgram(this.txtSapProgram.Text, this.txtObject.Text, this.txtDevClass.Text);
                //list.ForEach(x => { });
                int index = 0;
                foreach (var item in list)
                {
                    var r = dt.NewRow();
                    r["Index"] = index;
                    index++;
                    r["NAME"] = item.prog;// ABAP Program Name
                    //r["PROG"] = item.prog;// ABAP 程序名
                    r["CLAS"] = item.clas;// 程序类别
                    r["SUBC"] = item.subc;//   程序类型
                    r["APPL"] = item.appl;// 应用程序
                    r["CDAT"] = item.cdat;// 创建日期
                    r["VERN"] = item.vern;// 版本号
                    r["RMAND"] = item.rmand;// 集团
                    r["RLOAD"] = item.rload;// 主语言
                    r["UNAM"] = item.unam;// 最后修改人
                    r["UDAT"] = item.udat;// 更改日期
                    r["UTIME"] = item.utime;// 字典: 最后修改时间
                    r["DATALG"] = item.datalg;// ABAP/4: 程序组件的长度
                    r["VARCL"] = item.varcl;// 区分大小写
                    dt.Rows.Add(r);
                }
                this.dataGridView1.AutoResizeColumns();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }