예제 #1
0
 private void getBudget()
 {
     try
     {
         //SAPLogonCtrl.SAPLogonControlClass login = new SAPLogonCtrl.SAPLogonControlClass();
         //login.ApplicationServer = "10.0.0.79";
         //login.Client = "800";
         //login.Language = "ZF";
         //login.User = "******";
         //login.Password = "******";
         //login.SystemNumber = 00;
         SapConnection _SapConn = SapConnection.GetInstance;
         //     if (!_SapConn.SapLogin) throw new Exception("登入SAP失敗");
         //    SAPFunctionsOCX.SAPFunctionsClass func = SapConnection.GetInstance_SAPFunctionsClass;
         //  SAPLogonCtrl.Connection conn = (SAPLogonCtrl.Connection)login.NewConnection();
         if (_SapConn.SapLogin)
         {
             SAPFunctionsOCX.SAPFunctionsClass func = SapConnection.GetInstance_SAPFunctionsClass;
             // SAPFunctionsOCX.SAPFunctionsClass func = new SAPFunctionsOCX.SAPFunctionsClass();
             // func.Connection = conn;
             //功能模組名稱
             SAPFunctionsOCX.IFunction ifunc = (SAPFunctionsOCX.IFunction)func.Add("Z_GET_IO_BUDGET");
             //查詢參數:成本控制範圍
             SAPFunctionsOCX.IParameter parameter1 = (SAPFunctionsOCX.IParameter)ifunc.get_Exports("I_KOKRS");
             parameter1.Value = Id; // BBB;
             //查詢參數:內部訂單
             SAPFunctionsOCX.IParameter parameter2 = (SAPFunctionsOCX.IParameter)ifunc.get_Exports("I_AUFNR");
             parameter2.Value = Kokrs; // AAA;// "P180001CLB";
             ifunc.Call();
             SAPTableFactoryCtrl.Tables tables    = (SAPTableFactoryCtrl.Tables)ifunc.Tables;
             SAPTableFactoryCtrl.Table  ENQEZKNAS = (SAPTableFactoryCtrl.Table)tables.get_Item("T_BUDGET");
             int n = ENQEZKNAS.RowCount;
             for (int i = 1; i <= n; i++)
             {
                 _Budget.MANDT          = ENQEZKNAS.get_Cell(i, "MANDT").ToString();
                 _Budget.KOKRS          = ENQEZKNAS.get_Cell(i, "KOKRS").ToString();
                 _Budget.AUFNR          = ENQEZKNAS.get_Cell(i, "AUFNR").ToString();
                 _Budget.WAERS          = ENQEZKNAS.get_Cell(i, "WAERS").ToString();
                 _Budget.START_AMT      = ENQEZKNAS.get_Cell(i, "START_AMT").ToString();
                 _Budget.USED_AMT       = ENQEZKNAS.get_Cell(i, "USED_AMT").ToString();
                 _Budget.END_AMT        = ENQEZKNAS.get_Cell(i, "END_AMT").ToString();
                 _Budget.COMMIT_AMT     = ENQEZKNAS.get_Cell(i, "COMMIT_AMT").ToString();
                 _Budget.START_AMT_TOL  = ENQEZKNAS.get_Cell(i, "START_AMT_TOL").ToString();
                 _Budget.USED_AMT_TOL   = ENQEZKNAS.get_Cell(i, "USED_AMT_TOL").ToString();
                 _Budget.END_AMT_TOL    = ENQEZKNAS.get_Cell(i, "END_AMT_TOL").ToString();
                 _Budget.COMMIT_AMT_TOL = ENQEZKNAS.get_Cell(i, "COMMIT_AMT_TOL").ToString();
             }
         }
         else
         {
             throw new Exception("登入SAP失敗");
         }
         //conn.Logoff();
         _SapConn.ConnLogoff();
     }
     catch (Exception ex)
     {
         logger.Error(ex);
     }
 }
예제 #2
0
        public void Main()
        {
            SAPLogonCtrl.SAPLogonControlClass login = new SAPLogonCtrl.SAPLogonControlClass();

            login.ApplicationServer = ConfigurationManager.AppSettings["lg_ApplicationServer"];
            login.Client            = ConfigurationManager.AppSettings["lg_Client"];
            login.Language          = ConfigurationManager.AppSettings["lg_Language"];
            login.User         = ConfigurationManager.AppSettings["lg_User"];
            login.Password     = ConfigurationManager.AppSettings["lg_Password"];
            login.SystemNumber = Int32.Parse(ConfigurationManager.AppSettings["lg_SystemNumber"]);

            SAPLogonCtrl.Connection conn = (SAPLogonCtrl.Connection)login.NewConnection();

            try
            {
                if (conn.Logon(0, true))
                {
                    //lblLogonStatus.Text = "登入SAP成功";

                    SAPFunctionsOCX.SAPFunctionsClass func = new SAPFunctionsOCX.SAPFunctionsClass();
                    func.Connection = conn;

                    SAPFunctionsOCX.IFunction ifunc = (SAPFunctionsOCX.IFunction)func.Add("RFC_READ_TABLE");

                    SAPFunctionsOCX.IParameter iQUERY_TABLE = (SAPFunctionsOCX.IParameter)ifunc.get_Exports("QUERY_TABLE");
                    iQUERY_TABLE.Value = iQueryTable;
                    SAPFunctionsOCX.IParameter iDELIMITER = (SAPFunctionsOCX.IParameter)ifunc.get_Exports("DELIMITER");
                    iDELIMITER.Value = "|";

                    SAPTableFactoryCtrl.Tables tables = (SAPTableFactoryCtrl.Tables)ifunc.Tables;

                    SAPTableFactoryCtrl.Table tOPTIONS = (SAPTableFactoryCtrl.Table)tables.get_Item("OPTIONS");
                    tOPTIONS.AppendGridData(1, 1, 1, "");

                    SAPTableFactoryCtrl.Table tFIELDS = (SAPTableFactoryCtrl.Table)tables.get_Item("FIELDS");
                    if (iQueryField != null)
                    {
                        int StringStart  = 0;
                        int iColumnIndex = 1;

                        int isDoExit = 0;
                        while (isDoExit == 0)
                        {
                            int StringEnd = iQueryField.ToString().IndexOf(",", StringStart);
                            if (StringEnd == -1)
                            {
                                StringEnd = iQueryField.ToString().Length;
                                isDoExit  = 1;
                            }
                            int StringLength = StringEnd - StringStart;
                            tFIELDS.AppendGridData(1, iColumnIndex, 1, iQueryField.ToString().Substring(StringStart, StringLength));
                            StringStart  = StringEnd + 1;
                            iColumnIndex = iColumnIndex + 1;
                        }
                    }

                    ifunc.Call();
                    oException = ifunc.Exception;

                    SAPTableFactoryCtrl.Table tDATA = (SAPTableFactoryCtrl.Table)tables.get_Item("DATA");

                    for (int m = 1; m <= tDATA.RowCount; m++)
                    {
                        int StringStart = 0;
                        Dictionary <string, object> listObject = new Dictionary <string, object>();
                        for (int n = 1; n <= tFIELDS.RowCount; n++)
                        {
                            int StringEnd = tDATA.get_Cell(m, 1).ToString().IndexOf("|", StringStart);
                            if (StringEnd == -1)
                            {
                                StringEnd = tDATA.get_Cell(m, 1).ToString().Length;
                            }
                            int StringLength = StringEnd - StringStart;

                            listObject.Add(tFIELDS.get_Cell(n, 1).ToString(), tDATA.get_Cell(m, 1).ToString().Substring(StringStart, StringLength));

                            StringStart = StringEnd + 1;
                        }

                        listResult.Add(listObject);
                    }
                    conn.Logoff();
                }
                else
                {
                    throw new Exception("Logon Fail");
                }

                Result = listResult;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #3
0
        /// <summary>
        /// test not success
        /// </summary>
        private void createOrder()
        {
            try
            {
                SapConnection _SapConn = SapConnection.GetInstance;
                if (_SapConn.SapLogin)
                {
                    SAPFunctionsOCX.SAPFunctionsClass func = SapConnection.GetInstance_SAPFunctionsClass;
                    //功能模組名稱
                    SAPFunctionsOCX.IFunction  ifunc              = (SAPFunctionsOCX.IFunction)func.Add("ZSD_CREATE_ORDER");
                    SAPTableFactoryCtrl.Tables _I_CREATE_ORDER    = (SAPTableFactoryCtrl.Tables)ifunc.Tables;
                    SAPTableFactoryCtrl.Table  _I_ORDER_HEADER_IN = (SAPTableFactoryCtrl.Table)_I_CREATE_ORDER.get_Item("I_ORDER_HEADER_IN");
                    _I_ORDER_HEADER_IN.AppendGridData(1, 1, 1, "doc_type  = 'ZOR1'");
                    _I_ORDER_HEADER_IN.AppendGridData(2, 1, 1, "sales_org   = '2000'");
                    _I_ORDER_HEADER_IN.AppendGridData(3, 1, 1, "distr_chan   = '30'");
                    _I_ORDER_HEADER_IN.AppendGridData(4, 1, 1, "division   = '30'");
                    _I_ORDER_HEADER_IN.AppendGridData(5, 1, 1, "purch_date   = '20190916'");
                    _I_ORDER_HEADER_IN.AppendGridData(6, 1, 1, "purch_no_c   = 'C#'");
                    SAPTableFactoryCtrl.Table _I_ORDER_PARTNERS = (SAPTableFactoryCtrl.Table)_I_CREATE_ORDER.get_Item("I_ORDER_PARTNERS");
                    _I_ORDER_PARTNERS.AppendGridData(1, 1, 1, "partn_role = 'AG'");
                    _I_ORDER_PARTNERS.AppendGridData(2, 1, 1, "partn_numb = '0010000242'");

                    SAPTableFactoryCtrl.Table _I_ORDER_ITEMS_IN = (SAPTableFactoryCtrl.Table)_I_CREATE_ORDER.get_Item("I_ORDER_ITEMS_IN");

                    _I_ORDER_ITEMS_IN.AppendGridData(1, 1, 1, "MATERIAL = '12D-04PFFP-SF8001'");
                    _I_ORDER_ITEMS_IN.AppendGridData(2, 1, 1, "itm_number = '000010'");
                    _I_ORDER_ITEMS_IN.AppendGridData(3, 1, 1, "target_qty = '20.000'");
                    _I_ORDER_ITEMS_IN.AppendGridData(4, 1, 1, "arget_qu = 'ST'");
                    _I_ORDER_ITEMS_IN.AppendGridData(5, 1, 1, "sales_unit = 'ST'");
                    SAPTableFactoryCtrl.Table _I_ORDER_SCHEDULES_IN = (SAPTableFactoryCtrl.Table)_I_CREATE_ORDER.get_Item("I_ORDER_SCHEDULES_IN");
                    _I_ORDER_SCHEDULES_IN.AppendGridData(1, 1, 1, "req_qty = '20.000'");
                    _I_ORDER_SCHEDULES_IN.AppendGridData(2, 1, 1, "ITM_NUMBER = '000010'");
                    _I_ORDER_SCHEDULES_IN.AppendGridData(3, 1, 1, "SCHED_LINE = '1'");
                    _I_ORDER_SCHEDULES_IN.AppendGridData(4, 1, 1, "REQ_DATE = '20190917'");

                    ifunc.Call();
                    SAPTableFactoryCtrl.Table _Return = (SAPTableFactoryCtrl.Table)_I_CREATE_ORDER.get_Item("E_RETURN");
                    int n = _Return.RowCount;
                    for (int i = 1; i <= n; i++)
                    {
                        _Budget.MANDT      = _Return.get_Cell(i, "TYPE").ToString();
                        _Budget.KOKRS      = _Return.get_Cell(i, "ID").ToString();
                        _Budget.AUFNR      = _Return.get_Cell(i, "NUMBER").ToString();
                        _Budget.WAERS      = _Return.get_Cell(i, "MESSAGE").ToString();
                        _Budget.START_AMT  = _Return.get_Cell(i, "LOG_NO").ToString();
                        _Budget.USED_AMT   = _Return.get_Cell(i, "MESSAGE_V1").ToString();
                        _Budget.END_AMT    = _Return.get_Cell(i, "PARAMETER").ToString();
                        _Budget.COMMIT_AMT = _Return.get_Cell(i, "ROW").ToString();
                    }
                }
                else
                {
                    throw new Exception("登入SAP失敗");
                }
                //conn.Logoff();
                _SapConn.ConnLogoff();
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
        }
예제 #4
0
        public void Main()
        {
            SAPLogonCtrl.SAPLogonControlClass login = new SAPLogonCtrl.SAPLogonControlClass();

            login.ApplicationServer = ConfigurationManager.AppSettings["lg_ApplicationServer"];
            login.Client            = ConfigurationManager.AppSettings["lg_Client"];
            login.Language          = ConfigurationManager.AppSettings["lg_Language"];
            login.User         = ConfigurationManager.AppSettings["lg_User"];
            login.Password     = ConfigurationManager.AppSettings["lg_Password"];
            login.SystemNumber = Int32.Parse(ConfigurationManager.AppSettings["lg_SystemNumber"]);

            string str_json = string.Empty;

            SAPLogonCtrl.Connection conn = (SAPLogonCtrl.Connection)login.NewConnection();
            //conn.SAPRouter
            try
            {
                if (conn.Logon(0, true))
                {
                    //lblLogonStatus.Text = "登入SAP成功";

                    SAPFunctionsOCX.SAPFunctionsClass func = new SAPFunctionsOCX.SAPFunctionsClass();
                    func.Connection = conn;

                    SAPFunctionsOCX.IFunction ifunc = (SAPFunctionsOCX.IFunction)func.Add("RFC_READ_TABLE");

                    SAPFunctionsOCX.IParameter iQUERY_TABLE = (SAPFunctionsOCX.IParameter)ifunc.get_Exports("QUERY_TABLE");
                    iQUERY_TABLE.Value = iQueryTable;
                    SAPFunctionsOCX.IParameter iDELIMITER = (SAPFunctionsOCX.IParameter)ifunc.get_Exports("DELIMITER");
                    iDELIMITER.Value = "|";

                    SAPTableFactoryCtrl.Tables tables = (SAPTableFactoryCtrl.Tables)ifunc.Tables;

                    SAPTableFactoryCtrl.Table tOPTIONS = (SAPTableFactoryCtrl.Table)tables.get_Item("OPTIONS");
                    tOPTIONS.AppendGridData(1, 1, 1, "");

                    SAPTableFactoryCtrl.Table tFIELDS = (SAPTableFactoryCtrl.Table)tables.get_Item("FIELDS");
                    //tFIELDS.AppendGridData(1, 1, 1, "BNAME");
                    //tFIELDS.AppendGridData(1, 2, 1, "TERMINAL");

                    ifunc.Call();

                    SAPTableFactoryCtrl.Table tDATA = (SAPTableFactoryCtrl.Table)tables.get_Item("DATA");

                    //得到一個DataTable物件
                    DataTable dt  = new DataTable();
                    DataTable dt2 = new DataTable();

                    for (int i = 1; i <= tFIELDS.RowCount; i++)
                    {
                        dt.Columns.Add(tFIELDS.get_Cell(i, 1).ToString());
                    }

                    for (int m = 1; m <= tDATA.RowCount; m++)
                    {
                        DataRow dr          = dt.NewRow();
                        int     StringStart = 0;
                        for (int n = 1; n <= tFIELDS.RowCount; n++)
                        {
                            int StringEnd = tDATA.get_Cell(m, 1).ToString().IndexOf("|", StringStart);
                            if (StringEnd == -1)
                            {
                                StringEnd = tDATA.get_Cell(m, 1).ToString().Length;
                            }
                            int StringLength = StringEnd - StringStart;
                            dr[tFIELDS.get_Cell(n, 1).ToString()] = tDATA.get_Cell(m, 1).ToString().Substring(StringStart, StringLength);
                            StringStart = StringEnd + 1;
                        }
                        dt.Rows.Add(dr);
                    }

                    //將DataTable轉成JSON字串
                    str_json = JsonConvert.SerializeObject(dt, Formatting.Indented);

                    dt2 = JsonConvert.DeserializeObject <DataTable>(str_json);


                    conn.Logoff();
                }
                else
                {
                    throw new Exception("Logon Fail");
                }
                Result = str_json;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }