private void btnReadSAPTable_Click(object sender, EventArgs e)
        {
            try
            {
                ReadTable dt;
                if (!check())
                {
                    return;
                }
                dt = new ReadTable(_systemName.ToUpper().Trim());
                dt.TableName = _tableName;
                ReadTableFieldCollection fields = dt.GetAllFieldsOfTable();
                if (fields == null || fields.Count == 0)
                {
                    return;
                }
                this.dataGridView1.Rows.Clear();
                for (int i = 0; i < fields.Count; i++)
                {
                    this.dataGridView1.Rows.Add(fields[i].Active, fields[i].FieldName, fields[i].FieldText, fields[i].CheckTable);

                }
                dataGridView1.AutoResizeColumns();
                //  saveContext();
            }
            catch (Exception ee)
            {

                MessageBox.Show(ee.Message);
            }
        }
示例#2
0
        /// <summary>
        /// 返回表或结构的定义细节。
        /// </summary>
        /// <param name="p_sysName">SAP系统</param>
        /// <param name="p_TableName">表或结构</param>
        /// <returns>结构定义</returns>
        private static DataTable _GetSAPTableDef(String p_sysName, String p_TableName)
        {
            //有时读取的参数是表类型,无法使用函数DDIF_FIELDINFO_GET直接读取到表的定义。
            //首先到表DD40L里查出表类型对应的结构类型。
            var criteria          = String.Format("TYPENAME = '{0}'", p_TableName);
            var readTableFunction = ConfigFileTool.SAPGlobalSettings.GetReadTableFunction();
            var dd40l             = new SAPINT.Utils.ReadTable(p_sysName);

            dd40l.TableName = "DD40L";
            dd40l.RowCount  = 1;
            dd40l.SetCustomFunctionName(readTableFunction);
            dd40l.AddCriteria(criteria);
            dd40l.Run();

            var dd40lt        = dd40l.Result;
            var structureName = string.Empty;

            if (dd40lt.Rows.Count == 1)
            {
                structureName = dd40lt.Rows[0]["ROWTYPE"].ToString();
            }
            if (!string.IsNullOrEmpty(structureName))
            {
                p_TableName = structureName;
            }

            try
            {
                RfcDestination destination         = SAPDestination.GetDesByName(p_sysName);
                IRfcFunction   RFC_FUNCTION_SEARCH = destination.Repository.CreateFunction("DDIF_FIELDINFO_GET");
                RFC_FUNCTION_SEARCH.SetValue("TABNAME", p_TableName);
                RFC_FUNCTION_SEARCH.Invoke(destination);
                IRfcTable DFIES_TAB = RFC_FUNCTION_SEARCH.GetTable("DFIES_TAB");
                DataTable dt        = _Convert_rfctable_to_dt(DFIES_TAB);
                return(dt);
            }
            catch (RfcAbapException abapException)
            {
                throw new SAPException(p_TableName + abapException.Key + abapException.Message);
            }
            catch (RfcAbapBaseException abapbaseException)
            {
                throw new SAPException(abapbaseException.PlainText + abapbaseException.Message);
            }
            catch (Exception ex)
            {
                throw new SAPException(ex.Message);
            }
        }
示例#3
0
        internal void FillMessageText(string sysName)
        {
            ReadTable      table = new ReadTable(sysName);
            RfcDestination des   = SAPDestination.GetDesByName(sysName);

            table.AddField("TEXT");
            table.AddCriteria("SPRSL = '" + Converts.languageIsotoSap(des.Language) + "' ");
            table.AddCriteria("AND ARBGB = '" + this.MessageID + "' ");
            table.AddCriteria("AND MSGNR = '" + this.MessageNumber + "' ");
            table.TableName = "T100";
            table.RowCount  = 10;
            table.Run();
            DataTable result = table.Result;

            if (result.Rows.Count == 0)
            {
                //this.Message = "Message could not be found";// Messages.Messagecouldnotbefound;
                this.Message = Messages.Messagecouldnotbefound;
            }
            else
            {
                this.Message = result.Rows[0]["TEXT"].ToString().Trim();
                int length = 0;
                length = this.Message.IndexOf("&");
                if (length >= 0)
                {
                    this.Message = this.Message.Substring(0, length).Trim() + " " + this.MessageVariable1 + " " + this.Message.Substring(length + 1).Trim();
                }
                length = this.Message.IndexOf("&");
                if (length >= 0)
                {
                    this.Message = this.Message.Substring(0, length).Trim() + " " + this.MessageVariable2 + " " + this.Message.Substring(length + 1).Trim();
                }
                length = this.Message.IndexOf("&");
                if (length >= 0)
                {
                    this.Message = this.Message.Substring(0, length).Trim() + " " + this.MessageVariable3 + " " + this.Message.Substring(length + 1).Trim();
                }
                length = this.Message.IndexOf("&");
                if (length >= 0)
                {
                    this.Message = this.Message.Substring(0, length).Trim() + " " + this.MessageVariable4 + " " + this.Message.Substring(length + 1).Trim();
                }
                this.Message = this.Message.Trim();
            }
        }
        void SetDataToExcel(ReadTable p_dt, Worksheet p_ws)
        {
            //在当前激活的工作表上存放数据
            p_ws = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet);

            ListObject ls;

            if (!p_ws.Controls.Contains(_tableName))
            {
                int count = p_ws.ListObjects.Count;
                for (int i = 1; i < count + 1; i++)
                {
                    if (p_ws.ListObjects[i].Name == _tableName)
                    {
                        p_ws.ListObjects[i].Delete();
                        // ws.Controls.Remove(_tableName);
                    }
                }

                ls = p_ws.Controls.AddListObject(p_ws.Range["A2"], _tableName);

            }
            else
            {

                ls = (ListObject)p_ws.Controls[_tableName];
            }
            ls.SetDataBinding(p_dt.Result);
            p_ws.Rows[1].Clear();
            // ReadTableFieldCollection co = dt.Fields;
            for (int i = 0; i < p_dt.Fields.Count; i++)
            {
                p_ws.Cells.set_Item(1, i + 1, p_dt.Fields[i].FieldText);
                ls.ListColumns[i + 1].Name = p_dt.Fields[i].FieldName;

            }

            //清空两行抬头,并重新设置。

            p_ws.Columns.AutoFit();
            p_ws.Columns.ShrinkToFit = true;

            //saveContext();

            p_ws = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet);
            p_ws.Name = _tableName;
            p_ws.ActivateEvent += new Microsoft.Office.Interop.Excel.DocEvents_ActivateEventHandler(ws_ActivateEvent);
            p_ws.Deactivate += new Microsoft.Office.Interop.Excel.DocEvents_DeactivateEventHandler(ws_Deactivate);
            MessageBox.Show("加载完成");
        }
        //加载表数据
        void loadTableData()
        {
            try
            {
                dt = new ReadTable(_systemName.ToUpper().Trim());
                dt.SetCustomFunctionName("ZVI_RFC_READ_TABLE");
                dt.TableName = _tableName;
                //  dt.Fields.Clear();
                // dt.Options.Clear();
                //从界面上加载条件与字段列表
                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    if (dataGridView1.Rows[i].Cells["FieldName"].Value != null)
                    {
                        if (dataGridView1.Rows[i].Cells["Select"] != null & (bool)dataGridView1.Rows[i].Cells["Select"].Value == true)
                        {
                            string s = dataGridView1.Rows[i].Cells["FieldName"].Value.ToString();
                            if (!string.IsNullOrEmpty(s))
                            {
                                dt.AddField(s);
                            }
                        }

                    }

                }

                for (int i = 0; i < dataGridView2.Rows.Count; i++)
                {
                    if (dataGridView2[0, i].Value != null)
                    {
                        string s = dataGridView2[0, i].Value.ToString();
                        if (!string.IsNullOrEmpty(s))
                        {
                            dt.AddCriteria(s);
                        }
                    }

                }

                dt.RowCount = Convert.ToInt32(rowNum.Text);
                dt.Run();

            }
            catch (Exception ee)
            {

                MessageBox.Show(ee.Message);
            }
        }
        /// <summary>
        /// 返回表或结构的定义细节。
        /// </summary>
        /// <param name="p_sysName">SAP系统</param>
        /// <param name="p_TableName">表或结构</param>
        /// <returns>结构定义</returns>
        private static DataTable _GetSAPTableDef(String p_sysName, String p_TableName)
        {
            //有时读取的参数是表类型,无法使用函数DDIF_FIELDINFO_GET直接读取到表的定义。
            //首先到表DD40L里查出表类型对应的结构类型。
            var criteria = String.Format("TYPENAME = '{0}'", p_TableName);
            var readTableFunction = ConfigFileTool.SAPGlobalSettings.GetReadTableFunction();
            var dd40l = new SAPINT.Utils.ReadTable(p_sysName);
            dd40l.TableName = "DD40L";
            dd40l.RowCount = 1;
            dd40l.SetCustomFunctionName(readTableFunction);
            dd40l.AddCriteria(criteria);
            dd40l.Run();

            var dd40lt = dd40l.Result;
            var structureName = string.Empty;

            if (dd40lt.Rows.Count == 1)
            {
                structureName = dd40lt.Rows[0]["ROWTYPE"].ToString();
            }
            if (!string.IsNullOrEmpty(structureName))
            {
                p_TableName = structureName;
            }

            try
            {
                RfcDestination destination = SAPDestination.GetDesByName(p_sysName);
                IRfcFunction RFC_FUNCTION_SEARCH = destination.Repository.CreateFunction("DDIF_FIELDINFO_GET");
                RFC_FUNCTION_SEARCH.SetValue("TABNAME", p_TableName);
                RFC_FUNCTION_SEARCH.Invoke(destination);
                IRfcTable DFIES_TAB = RFC_FUNCTION_SEARCH.GetTable("DFIES_TAB");
                DataTable dt = _Convert_rfctable_to_dt(DFIES_TAB);
                return dt;
            }
            catch (RfcAbapException abapException)
            {
                throw new SAPException(p_TableName + abapException.Key + abapException.Message);
            }
            catch (RfcAbapBaseException abapbaseException)
            {
                throw new SAPException(abapbaseException.PlainText + abapbaseException.Message);
            }
            catch (Exception ex)
            {

                throw new SAPException(ex.Message);
            }
        }
        //加载表数据
        void loadTableData()
        {
            try
            {
                SendMessage("开始");
                dt = new ReadTable(_systemName);
                dt.EventMessage += dt_eventMessage;
                // dt.SetCustomFunctionName("Z_XTRACT_IS_TABLE");
                dt.SetCustomFunctionName("ZVI_RFC_READ_TABLE");
                dt.TableName = _tableName;
                dt.Delimiter = _delimiter;
                //  dt.Fields.Clear();
                // dt.Options.Clear();
                //从界面上加载条件与字段列表
                SendMessage("加载字段列表");
                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    if (dataGridView1.Rows[i].Cells["FieldName"].Value != null)
                    {
                        if (dataGridView1.Rows[i].Cells[0].Value != null)
                        {
                            if ((bool)dataGridView1.Rows[i].Cells[0].Value == true)
                            {
                                string s = dataGridView1.Rows[i].Cells["FieldName"].Value.ToString();
                                if (!string.IsNullOrEmpty(s))
                                {
                                    dt.AddField(s);
                                }
                            }
                        }
                    }
                }
                SendMessage("加载条件");
                for (int i = 0; i < dataGridView2.Rows.Count; i++)
                {
                    if (dataGridView2[0, i].Value != null)
                    {
                        string s = dataGridView2[0, i].Value.ToString();
                        if (!string.IsNullOrEmpty(s))
                        {
                            dt.AddCriteria(s);
                        }
                    }
                }
                dt.RowCount = Convert.ToInt32(rowNum.Text);
                SendMessage("开始异步调用");
                try
                {
                    Thread thread = new Thread(new ThreadStart(excute));
                    thread.Start();
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                }

            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }
        internal void FillMessageText(string sysName)
        {
            ReadTable table = new ReadTable(sysName);
            RfcDestination des = SAPDestination.GetDesByName(sysName);

            table.AddField("TEXT");
            table.AddCriteria("SPRSL = '" + Converts.languageIsotoSap(des.Language)+ "' ");
            table.AddCriteria("AND ARBGB = '" + this.MessageID + "' ");
            table.AddCriteria("AND MSGNR = '" + this.MessageNumber + "' ");
            table.TableName = "T100";
            table.RowCount = 10;
            table.Run();
            DataTable result = table.Result;
            if (result.Rows.Count == 0)
            {
                //this.Message = "Message could not be found";// Messages.Messagecouldnotbefound;
                this.Message = Messages.Messagecouldnotbefound;
            }
            else
            {
                this.Message = result.Rows[0]["TEXT"].ToString().Trim();
                int length = 0;
                length = this.Message.IndexOf("&");
                if (length >= 0)
                {
                    this.Message = this.Message.Substring(0, length).Trim() + " " + this.MessageVariable1 + " " + this.Message.Substring(length + 1).Trim();
                }
                length = this.Message.IndexOf("&");
                if (length >= 0)
                {
                    this.Message = this.Message.Substring(0, length).Trim() + " " + this.MessageVariable2 + " " + this.Message.Substring(length + 1).Trim();
                }
                length = this.Message.IndexOf("&");
                if (length >= 0)
                {
                    this.Message = this.Message.Substring(0, length).Trim() + " " + this.MessageVariable3 + " " + this.Message.Substring(length + 1).Trim();
                }
                length = this.Message.IndexOf("&");
                if (length >= 0)
                {
                    this.Message = this.Message.Substring(0, length).Trim() + " " + this.MessageVariable4 + " " + this.Message.Substring(length + 1).Trim();
                }
                this.Message = this.Message.Trim();
            }
        }