Пример #1
0
        public PartInfo GetAvailableStock(string line, string part)
        {
            try
            {
                RfcConfigParameters rfcParam = Connector3SapRfcConnGroup(_SAPConnectionString);
                RfcDestination      rfcDest  = RfcDestinationManager.GetDestination(rfcParam);
                RfcRepository       rfcRep   = rfcDest.Repository;

                IRfcFunction rfcFun = rfcRep.CreateFunction("ZRFC_WM_STOCK_0001");//SAP RFC

                rfcFun.SetValue("I_LGNUM", "049");
                rfcFun.SetValue("I_LGTYP", line);
                rfcFun.SetValue("I_WERKS", "");
                rfcFun.SetValue("I_LGORT", "");
                rfcFun.SetValue("I_MATNR", part);

                rfcFun.Invoke(rfcDest);

                IRfcTable rtSource         = rfcFun.GetTable("TAB_LQUA");
                DataTable dtMaterialMaster = ConvertToDoNetTable(rtSource);
                if (dtMaterialMaster == null || dtMaterialMaster.Rows.Count > 0)
                {
                    int    qty   = int.TryParse(dtMaterialMaster.Rows[0]["VERME"].ToString().Split('.')[0], out int _qty) ? _qty : -1;
                    string plant = dtMaterialMaster.Rows[0]["WERKS"].ToString();
                    return(new PartInfo
                    {
                        Plant = plant,
                        Qty = qty
                    });
                }
                else
                {
                    return(null);
                }
            }
            catch (RfcCommunicationException ex)
            {
                WriteLogs.Write("GetAvailableStock", ex);
                return(null);
            }
            catch (RfcAbapException ex)
            {
                WriteLogs.Write("GetAvailableStock", ex);
                return(null);
            }
            catch (RfcLogonException ex)
            {
                WriteLogs.Write("GetAvailableStock", ex);
                return(null);
            }
            catch (Exception ex)
            {
                WriteLogs.Write("GetAvailableStock", ex);
                return(null);
            }
        }
Пример #2
0
        public DataTable DownloadBoom(string plant, string parentMaterial)
        {
            try
            {
                RfcConfigParameters rfcParam = Connector3SapRfcConnGroup(_SAPConnectionString);
                RfcDestination      rfcDest  = RfcDestinationManager.GetDestination(rfcParam);
                RfcRepository       rfcRep   = rfcDest.Repository;
                IRfcFunction        rfcFun   = rfcRep.CreateFunction("ZRFC_CS_BOM_EXPL_0003");//SAP RFC
                rfcFun.SetValue("WERKS", "FI20");
                rfcFun.SetValue("DATUV", DateTime.Now.ToString("yyyyMMdd"));
                rfcFun.SetValue("MEHRS", "X");
                rfcFun.SetValue("MDMPS", "");

                // Get table PLANT
                IRfcTable rtSourceOuput = null;
                IRfcTable rtSource1     = rfcFun.GetTable("MATNR_IN");
                rtSource1.Append();

                rtSource1.SetValue("MATNR", "16KIGLW1A13");

                rfcFun.Invoke(rfcDest);
                rtSourceOuput = rfcFun.GetTable("BOM_INFO");

                DataTable dtBoom = ConvertToDoNetTable(rtSourceOuput);
                return(dtBoom);
            }
            catch (RfcCommunicationException ex)
            {
                WriteLogs.Write("DownloadBoom", ex);
                return(null);
            }
            catch (RfcAbapException ex)
            {
                WriteLogs.Write("DownloadBoom", ex);
                return(null);
            }
            catch (RfcLogonException ex)
            {
                WriteLogs.Write("DownloadBoom", ex);
                return(null);
            }
            catch (Exception ex)
            {
                WriteLogs.Write("DownloadBoom", ex);
                return(null);
            }
        }
Пример #3
0
 public RfcConfigParameters Connector3SapRfcConnGroup(string connStr)
 {
     try
     {
         string[]            arrConn = connStr.Split(' ');
         RfcConfigParameters rfcPar  = new RfcConfigParameters();
         rfcPar.Clear();
         //rfcPar.Add(RfcConfigParameters.Name, DateTime.Now.ToString("yyyyMMddHHmmss"));
         rfcPar.Add(RfcConfigParameters.AppServerHost, arrConn[0].Split('=')[1]);
         rfcPar.Add(RfcConfigParameters.Name, arrConn[1].Split('=')[1]);
         rfcPar.Add(RfcConfigParameters.LogonGroup, arrConn[2].Split('=')[1]);
         rfcPar.Add(RfcConfigParameters.Client, arrConn[3].Split('=')[1]);
         rfcPar.Add(RfcConfigParameters.User, arrConn[4].Split('=')[1]);
         rfcPar.Add(RfcConfigParameters.Password, arrConn[5].Split('=')[1]);
         rfcPar.Add(RfcConfigParameters.Language, arrConn[6].Split('=')[1]);
         //rfcPar.Add(RfcConfigParameters.RepositoryConnectionIdleTimeout, "1");
         //rfcPar.Add(RfcConfigParameters.ConnectionIdleTimeout, "1");
         //rfcPar.Add(RfcConfigParameters.PeakConnectionsLimit, "1000");
         return(rfcPar);
     }
     catch (RfcCommunicationException ex)
     {
         WriteLogs.Write("Connector3SapRfcConnGroup", ex);
         return(null);
     }
     catch (RfcAbapException ex)
     {
         WriteLogs.Write("Connector3SapRfcConnGroup", ex);
         return(null);
     }
     catch (RfcLogonException ex)
     {
         WriteLogs.Write("Connector3SapRfcConnGroup", ex);
         return(null);
     }
     catch (Exception ex)
     {
         WriteLogs.Write("Connector3SapRfcConnGroup", ex);
         return(null);
     }
 }
Пример #4
0
        public DataTable DownloadTODetail(string toNumber)
        {
            try
            {
                RfcConfigParameters rfcParam = Connector3SapRfcConnGroup(_SAPConnectionString);
                RfcDestination      rfcDest  = RfcDestinationManager.GetDestination(rfcParam);
                RfcRepository       rfcRep   = rfcDest.Repository;
                IRfcFunction        rfcFun   = rfcRep.CreateFunction("BAPI_WHSE_TO_GET_DETAIL");//SAP RFC
                rfcFun.SetValue("WHSENUMBER", "049");
                rfcFun.SetValue("TRANSFERORDERNO", toNumber);
                rfcFun.SetValue("TRANSFERORDERITEM", "");

                rfcFun.Invoke(rfcDest);
                IRfcTable rtSource         = rfcFun.GetTable("TOITEMDATA");
                DataTable dtMaterialMaster = ConvertToDoNetTable(rtSource);
                return(dtMaterialMaster);
            }
            catch (RfcCommunicationException ex)
            {
                WriteLogs.Write("DownloadTODetail", ex);
                return(null);
            }
            catch (RfcAbapException ex)
            {
                WriteLogs.Write("DownloadTODetail", ex);
                return(null);
            }
            catch (RfcLogonException ex)
            {
                WriteLogs.Write("DownloadTODetail", ex);
                return(null);
            }
            catch (Exception ex)
            {
                WriteLogs.Write("DownloadTODetail", ex);
                return(null);
            }
        }
Пример #5
0
        public DataTable GetListTO(DateTime from, DateTime to)
        {
            try
            {
                RfcConfigParameters rfcParam = Connector3SapRfcConnGroup(_SAPConnectionString);
                RfcDestination      rfcDest  = RfcDestinationManager.GetDestination(rfcParam);
                RfcRepository       rfcRep   = rfcDest.Repository;

                IRfcFunction rfcFun = rfcRep.CreateFunction("ZRFC_MM_GET_TOLIST");//SAP RFC

                string _hFrom = from.ToString("HHmmss");
                string _hTo   = to.ToString("HHmmss");

                rfcFun.SetValue("I_LGNUM", "049");
                rfcFun.SetValue("I_BDATUF", from);   //from date
                rfcFun.SetValue("I_BDATUT", to);     //to date
                rfcFun.SetValue("I_BZEITF", _hFrom); //from time
                rfcFun.SetValue("I_BZEITT", _hTo);   // to time

                rfcFun.Invoke(rfcDest);

                IRfcTable rtSource         = rfcFun.GetTable("TOLIST");
                DataTable dtMaterialMaster = ConvertToDoNetTable(rtSource);
                if (dtMaterialMaster == null || dtMaterialMaster.Rows.Count > 0)
                {
                    var data = new DataTable();
                    data.Columns.Add("ID", System.Type.GetType("System.Int64")).SetOrdinal(0);

                    var column = new DataColumn();
                    column.DataType   = System.Type.GetType("System.String");
                    column.ColumnName = "TO";
                    data.Columns.Add(column);

                    column            = new DataColumn();
                    column.DataType   = System.Type.GetType("	System.DateTime");
                    column.ColumnName = "CREATED_DATE";
                    data.Columns.Add(column);

                    column            = new DataColumn();
                    column.DataType   = System.Type.GetType("System.TimeSpan");
                    column.ColumnName = "CREATED_TIME";
                    data.Columns.Add(column);

                    column            = new DataColumn();
                    column.DataType   = System.Type.GetType("System.String");
                    column.ColumnName = "TO_ITEM";
                    data.Columns.Add(column);

                    column            = new DataColumn();
                    column.DataType   = System.Type.GetType("System.String");
                    column.ColumnName = "COMPONENT";
                    data.Columns.Add(column);

                    column            = new DataColumn();
                    column.DataType   = System.Type.GetType("System.String");
                    column.ColumnName = "SOURCE";
                    data.Columns.Add(column);

                    column            = new DataColumn();
                    column.DataType   = System.Type.GetType("System.String");
                    column.ColumnName = "LINE";
                    data.Columns.Add(column);

                    column            = new DataColumn();
                    column.DataType   = System.Type.GetType("System.Int32");
                    column.ColumnName = "QTY";
                    data.Columns.Add(column);

                    column            = new DataColumn();
                    column.DataType   = System.Type.GetType("System.String");
                    column.ColumnName = "PON";
                    data.Columns.Add(column);

                    column            = new DataColumn();
                    column.DataType   = System.Type.GetType("System.String");
                    column.ColumnName = "BIN";
                    data.Columns.Add(column);

                    column            = new DataColumn();
                    column.DataType   = System.Type.GetType("System.String");
                    column.ColumnName = "MATERIAL_DESCRIPTION";
                    data.Columns.Add(column);

                    column            = new DataColumn();
                    column.DataType   = System.Type.GetType("System.String");
                    column.ColumnName = "UNIT";
                    data.Columns.Add(column);

                    column            = new DataColumn();
                    column.DataType   = System.Type.GetType("System.String");
                    column.ColumnName = "PICK_AREA";
                    data.Columns.Add(column);

                    column            = new DataColumn();
                    column.DataType   = System.Type.GetType("System.String");
                    column.ColumnName = "PLANT";
                    data.Columns.Add(column);


                    foreach (DataRow item in dtMaterialMaster.Rows)
                    {
                        if (!string.IsNullOrEmpty(item["TANUM"].ToString()) /*&& balines.Contains(item["NLTYP"].ToString())*/ /*&& item["VLTYP"].ToString().Equals("BFO")*/)
                        {
                            DataRow row = data.NewRow();
                            row[1]  = item["TANUM"].ToString();
                            row[2]  = item["BDATU"].ToString();
                            row[3]  = item["BZEIT"].ToString();
                            row[4]  = item["TAPOS"].ToString();
                            row[5]  = item["MATNR"].ToString();
                            row[6]  = item["VLTYP"].ToString();
                            row[7]  = item["NLTYP"].ToString();
                            row[8]  = int.TryParse(item["NSOLM"].ToString().Split('.')[0], out int _qty) ? _qty : -1;
                            row[9]  = item["BENUM"].ToString();
                            row[10] = item["VLPLA"].ToString();
                            row[11] = item["MAKTX"].ToString();
                            row[12] = item["MEINS"].ToString();
                            row[13] = item["KOBER"].ToString();
                            row[14] = item["WERKS"].ToString();

                            data.Rows.Add(row);
                        }
                        return(data);
                    }
                }
                return(null);
            }
            catch (RfcCommunicationException ex)
            {
                WriteLogs.Write("GetListTO", ex);
                return(null);
            }
            catch (RfcAbapException ex)
            {
                WriteLogs.Write("GetListTO", ex);
                return(null);
            }
            catch (RfcLogonException ex)
            {
                WriteLogs.Write("GetListTO", ex);
                return(null);
            }
            catch (Exception ex)
            {
                WriteLogs.Write("GetListTO", ex);
                return(null);
            }
        }
Пример #6
0
        public DataTable DownloadDeliverySale(string plant, DateTime firstDate, DateTime lastDate)
        {
            try
            {
                RfcConfigParameters rfcParam = Connector3SapRfcConnGroup(_SAPConnectionString);
                RfcDestination      rfcDest  = RfcDestinationManager.GetDestination(rfcParam);
                RfcRepository       rfcRep   = rfcDest.Repository;
                IRfcFunction        rfcFun   = rfcRep.CreateFunction("ZRFC_SD_ZPSD01");//SAP RFC
                rfcFun.SetValue("ZCCS0", "X");
                rfcFun.SetValue("P_HMD", "X");

                DataTable loTable = new DataTable();


                // Get table PLANT
                IRfcTable rtSource = rfcFun.GetTable("PLANT");
                // FLANT
                rtSource.Append();
                rtSource.SetValue("SIGN", "I");
                rtSource.SetValue("OPTION", "EQ");
                rtSource.SetValue("LOW", plant);

                // SALES_ORGANIZATION
                IRfcTable rtSourceDoc = rfcFun.GetTable("SALES_ORGANIZATION");
                rtSourceDoc.Append();
                rtSourceDoc.SetValue("SIGN", "I");
                rtSourceDoc.SetValue("OPTION", "EQ");
                rtSourceDoc.SetValue("LOW", "FI03");


                // Document date
                IRfcTable rtSourceDocDate = rfcFun.GetTable("DOCUMENT_DATE");

                rtSourceDocDate.Append();
                rtSourceDocDate.SetValue("SIGN", "I");
                rtSourceDocDate.SetValue("OPTION", "BT");
                rtSourceDocDate.SetValue("LOW", firstDate.ToString("yyyyMMdd"));
                rtSourceDocDate.SetValue("HIGH", lastDate.ToString("yyyyMMdd"));

                rfcFun.Invoke(rfcDest);
                IRfcTable rtSourceOuput = rfcFun.GetTable("Z_OUTPUT");

                DataTable dtDN = ConvertToDoNetTable(rtSourceOuput);
                return(dtDN);
            }
            catch (RfcCommunicationException ex)
            {
                WriteLogs.Write("DownloadDeliverySale", ex);
                return(null);
            }
            catch (RfcAbapException ex)
            {
                WriteLogs.Write("DownloadDeliverySale", ex);
                return(null);
            }
            catch (RfcLogonException ex)
            {
                WriteLogs.Write("DownloadDeliverySale", ex);
                return(null);
            }
            catch (Exception ex)
            {
                WriteLogs.Write("DownloadDeliverySale", ex);
                return(null);
            }
        }