Beispiel #1
0
    private void WReturnShow_Load(object sender, EventArgs e)
    {
        CWaitForm b = new CWaitForm();

        b._wtVoid = 执行;
        b.ShowDialog();
        this.Text = sRFC.FunName;
        if (sRFCReturn.IsConnect)
        {
            tbDiaoYongJieGuo.Text  = "";
            tbDiaoYongJieGuo.Text += "调用函数名称:" + sRFCReturn.FunName + Environment.NewLine;
            tbDiaoYongJieGuo.Text += "函数执行时间(秒S):" + sRFCReturn.RunTime.TotalSeconds + " 秒" + Environment.NewLine + Environment.NewLine;
            if (sRFCReturn.OutPutZhiCanShus.Count > 0)//值参数
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("字段名");
                dt.Columns.Add("值");
                tbDiaoYongJieGuo.Text += "★★返回值类型【" + sRFCReturn.OutPutZhiCanShus.Count.ToString() + "个】★★" + Environment.NewLine;
                foreach (RFC_ZhiCanShu item in sRFCReturn.OutPutZhiCanShus)
                {
                    DataRow dr = dt.NewRow();
                    dr["字段名"] = item.Name;
                    dr["值"]   = item.Value;
                    dt.Rows.Add(dr);
                    tbDiaoYongJieGuo.Text += item.Name + ": " + item.Value + "   ;" + Environment.NewLine;
                }
                AddTP("tpChuanChuZhi", "传出值", "tgChuanChuZhi", dt);
                tbDiaoYongJieGuo.Text += Environment.NewLine;
            }
            if (sRFCReturn.OutPutTables.Count > 0)//表参数
            {
                tbDiaoYongJieGuo.Text += "★★返回表类型【" + sRFCReturn.OutPutTables.Count.ToString() + "个】★★" + Environment.NewLine;
                foreach (RFC_Table item in sRFCReturn.OutPutTables)
                {
                    AddTP("tp" + item.TableName, "表:" + item.TableName, "tg" + item.TableName, item.Table);
                    tbDiaoYongJieGuo.Text += item.TableName + ": 总行数" + item.RFC_Structures.Count.ToString() + ";" + Environment.NewLine;
                }
                tbDiaoYongJieGuo.Text += Environment.NewLine;
            }

            if (sRFCReturn.OutPutStructures.Count > 0)//结构
            {
                tbDiaoYongJieGuo.Text += "★★返回结构类型【" + sRFCReturn.OutPutStructures.Count.ToString() + "个】★★" + Environment.NewLine;
                foreach (RFC_Structure item in sRFCReturn.OutPutStructures)
                {
                    RFC_Table dt = new RFC_Table();
                    tbDiaoYongJieGuo.Text += item.StructureName + "【" + item.RFC_ZhiCanShus.Count.ToString() + "个】" + Environment.NewLine;
                    dt.RFC_Structures.Add(item);
                    foreach (RFC_ZhiCanShu item1 in item.RFC_ZhiCanShus)
                    {
                        tbDiaoYongJieGuo.Text += item1.Name + ": " + item1.Value + "   ;" + Environment.NewLine;
                    }
                    AddTP("tp" + item.StructureName, "结构" + item.StructureName, "tg" + item.StructureName, dt.Table);
                }
                tbDiaoYongJieGuo.Text += Environment.NewLine;
            }
        }
        else
        {
            tbDiaoYongJieGuo.Text  = "";
            tbDiaoYongJieGuo.Text += "SAP 连接失败";
        }
    }
Beispiel #2
0
        /// <summary>执行按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 函数执行ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                ttbFunName.Focus();
                //指定函数名称
                dsRFC.DataSetName = ttbFunName.Text.Trim();
                myfun             = SapRfcRepository.CreateFunction(ttbFunName.Text.Trim());//根据输入的函数名获取函数对象
                //传入值赋值
                foreach (DataTable item in dsRFC.Tables)
                {
                    //传入值赋值
                    if (item.Namespace == "IM")
                    {
                        int imrowindex = 0;
                        foreach (DataRow item1 in item.Rows)
                        {
                            if (myfun.Metadata[item1["Code"].ToString()].DataType != RfcDataType.TABLE && myfun.Metadata[item1["Code"].ToString()].DataType != RfcDataType.STRUCTURE)
                            {
                                if (!string.IsNullOrEmpty(item1["Value"].ToString()))
                                {
                                    myfun.SetValue(item1["Code"].ToString(), item1["Value"].ToString());
                                }
                            }
                            if (myfun.Metadata[item1["Code"].ToString()].DataType == RfcDataType.TABLE)
                            {
                                if (dsRFC.Tables.Contains("IMT." + item1["Code"].ToString() + "[R" + (imrowindex + 1).ToString() + ",C3]"))
                                {
                                    //setStructureByFun(myfun, myfun.Metadata[item1["Code"].ToString()].DataType.ToString(), "IMT." + item1["Code"].ToString(), "IMT." + item1["Code"].ToString() + "[R" + (imrowindex + 1).ToString() + ",C3]");
                                    setStructureByFun(myfun,
                                                      myfun.Metadata[item1["Code"].ToString()].DataType.ToString(),
                                                      "IMT." + item1["Code"].ToString() + "[R" + (imrowindex + 1).ToString() + ",C3]",
                                                      "IMT." + item1["Code"].ToString());
                                }
                            }
                            imrowindex++;
                        }
                    }
                    //传入结构赋值
                    if (item.Namespace == "IMS")
                    {
                        if (item.Rows.Count > 0)
                        {
                            setStructureByFun(myfun, "STRUCTURE", item.Namespace, item.TableName);
                        }
                    }
                    //表赋值
                    if (item.Namespace == "Tables")
                    {
                        if (item.Rows.Count > 0)
                        {
                            IRfcStructure import = null;
                            IRfcTable     table  = myfun.GetTable(item.TableName);
                            foreach (DataRow item1 in item.Rows)
                            {
                                import = SapRfcRepository.GetStructureMetadata(myfun.Metadata[item.TableName].ValueMetadataAsTableMetadata.LineType.Name).CreateStructure();
                                foreach (DataColumn item2 in item.Columns)
                                {
                                    item2.Namespace = "String";
                                    if (!string.IsNullOrEmpty(item1[item2.ColumnName].ToString()))
                                    {
                                        import.SetValue(item2.ColumnName, item1[item2.ColumnName]);
                                    }
                                }
                                table.Insert(import);
                            }
                        }
                    }
                }
                Stopwatch = new System.Diagnostics.Stopwatch();
                CWaitForm b = new CWaitForm();
                b._wtVoid = 执行;
                b.ShowDialog();
                toolStripMenuItem1.Text = "SAP端执行时间:" + Stopwatch.Elapsed.ToString();
                int exrowindex = -1;
                //获取返回值
                foreach (DataRow item in dtEX.Rows)
                {
                    exrowindex++;
                    string flag = "";
                    if (item["Value"].ToString().Length >= 4)
                    {
                        flag = item["Value"].ToString().Substring(0, 4);
                    }
                    if (flag == "点击赋值")
                    {
                        if (dsRFC.Tables.Contains("EXT." + item["Code"].ToString()))
                        {
                            DataTable dt = new DataTable();
                            if (!dsRFC.Tables.Contains("EXT." + item["Code"].ToString() + "[R" + (exrowindex + 1).ToString() + ",C3]"))
                            {
                                dt           = dsRFC.Tables["EXT." + item["Code"].ToString()].Clone();
                                dt.Namespace = "EXT." + item["Code"].ToString();
                                dt.TableName = "EXT." + item["Code"].ToString() + "[R" + (exrowindex + 1).ToString() + ",C3]";
                                dsRFC.Tables.Add(dt);
                            }
                            else
                            {
                                dt = dsRFC.Tables["EXT." + item["Code"].ToString() + "[R" + (exrowindex + 1).ToString() + ",C3]"];
                                dt.Clear();
                            }

                            IRfcTable irtb;
                            irtb = (IRfcTable)myfun.GetValue(item["Code"].ToString());
                            if (irtb.RowCount > 0)
                            {
                                for (int i = 0; i < irtb.RowCount; i++)
                                {
                                    DataRow dr = dt.NewRow();
                                    foreach (DataColumn item1 in dt.Columns)
                                    {
                                        item1.Namespace      = "String";
                                        irtb.CurrentIndex    = i;
                                        dr[item1.ColumnName] = irtb.CurrentRow[item1.ColumnName].GetValue();
                                    }
                                    dt.Rows.Add(dr);
                                }
                            }
                        }



                        //if (!dsRFC.Tables.Contains(linetablename))
                        //{
                        //    //不存在则创建
                        //    DataTable dt = new DataTable();
                        //    dt = dsRFC.Tables[linetabletypename].Clone();
                        //    dt.Namespace = linetabletypename;
                        //    dt.TableName = linetablename;
                        //    dsRFC.Tables.Add(dt);
                        //}
                    }
                    else
                    {
                        item["Value"] = myfun.GetValue(item["Code"].ToString());
                    }
                }
                //获取表结果,结构结果
                foreach (DataTable item in dsRFC.Tables)
                {
                    if (item.Namespace == "Tables")
                    {
                        IRfcTable irtb;
                        irtb = (IRfcTable)myfun.GetValue(item.TableName);
                        if (irtb.RowCount > 0)
                        {
                            item.Clear();
                            for (int i = 0; i < irtb.RowCount; i++)
                            {
                                DataRow dr = item.NewRow();
                                foreach (DataColumn item1 in item.Columns)
                                {
                                    item1.Namespace      = "String";
                                    irtb.CurrentIndex    = i;
                                    dr[item1.ColumnName] = irtb.CurrentRow[item1.ColumnName].GetValue();
                                }
                                item.Rows.Add(dr);
                            }
                        }
                    }
                    else if (item.Namespace == "EXS")
                    {
                        IRfcStructure irs;
                        String[]      ssname = item.TableName.Split('.');
                        irs = (IRfcStructure)myfun.GetValue(ssname[1]);
                        if (irs.Count > 0)
                        {
                            item.Clear();
                            DataRow dr = item.NewRow();
                            foreach (DataColumn item1 in item.Columns)
                            {
                                if (item1.Namespace == "STRUCTURE")
                                {
                                    dr[item1.ColumnName.ToString()] = "点击赋值";
                                }
                                else if (item1.Namespace == "TABLE")
                                {
                                    dr[item1.ColumnName.ToString()] = "点击赋值";
                                }
                                else
                                {
                                    dr[item1.ColumnName.ToString()] = irs.GetValue(item1.ColumnName.ToString());
                                }
                            }
                            item.Rows.Add(dr);
                        }
                    }
                }
                string filepath = "";
                filepath = System.Environment.CurrentDirectory +
                           "\\RFCFunConfig\\" +
                           dsRFC.DataSetName.ToString() +
                           "\\" + DateTime.Now.Year.ToString() +
                           DateTime.Now.Month.ToString() +
                           DateTime.Now.Day.ToString() +
                           DateTime.Now.Hour.ToString() +
                           DateTime.Now.Minute.ToString() +
                           DateTime.Now.Second.ToString() +
                           DateTime.Now.Millisecond.ToString() +
                           "\\";
                if (!File.Exists(filepath))
                {
                    FileInfo oInfo = new FileInfo(filepath);
                    if (!Directory.Exists(oInfo.DirectoryName))
                    {
                        Directory.CreateDirectory(oInfo.DirectoryName);
                    }
                }
                dsRFC.WriteXmlSchema(filepath + "\\JieGou.XML");
                dsRFC.WriteXml(filepath + "\\ShuZhi.XML");
                MessageBox.Show("执行成功,结果保存在" + filepath);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }