public EpiForm()
        {
            // Change the sysconfig file name to the sysconfig file name you are using to connect to your app server from your client.
            // If you have web services licenses, use the Session.LicenseType.WebService else use Session.LicenseType.Default.
            using (var _session = new Ice.Core.Session("manager", "manager", Session.LicenseType.Default, @"config\ERP10.sysconfig"))
            {
                // 10.1.600.x For some forms a BASE currency must be added to the Session objects CurrencyInfo Hashtable. SalesOrder is
                // one of these forms.
                using (var svc = WCFServiceSupport.CreateImpl <Erp.Proxy.BO.CurrencyImpl>(_session, Erp.Proxy.BO.CurrencyImpl.UriPath))
                {
                    bool outbool;
                    var  defaultcurrency = svc.GetList("BaseCurr = 'TRUE'", 0, 0, out outbool);
                    if (defaultcurrency.Tables[0].Rows.Count == 0)
                    {
                        MessageBox.Show("No BASE currency code is set for Company " + _session.CompanyID, "No BASE Currency", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    var currencyrow = (Erp.BO.CurrencyListDataSet.CurrencyListRow)defaultcurrency.Tables[0].Rows[0];

                    Session.CurrencyInfo ci = new Session.CurrencyInfo("BASE", currencyrow.CurrSymbol,
                                                                       currencyrow.DecimalsGeneral, currencyrow.DecimalsPrice, currencyrow.DecimalsCost);
                    _session.CurrencyCodes.Add("BASE", ci);
                }

                var iLaunch = new ILauncher(_session);
                oTrans = new PartTransaction(iLaunch);


                // Run your methods here and always try to complete the execution of this using block.
                // If you terminate execution prior to that, you will leave an open session and continue to consume a license.
            }
        }
Пример #2
0
        private void ExecuteProcess(object stateData)
        {
            string sConfigFilePath = "";
            string sCSVFilePath    = "";

            string sUserID   = "";
            string sPassword = "";

            Session epiSession = null;

            try
            {
                oUtility.LogData("Start Connection to Epicor.");

                //  Use ConfigurationManager object to get values from App.config file.
                sConfigFilePath = ConfigurationManager.AppSettings["configFilePath"];

                sCSVFilePath = ConfigurationManager.AppSettings["CSVFilePath"];
                sCSVFilePath = stateData.ToString();

                sUserID   = ConfigurationManager.AppSettings["UserID"];
                sPassword = ConfigurationManager.AppSettings["Password"];

                //  Connect to Epicor
                epiSession = new Session(sUserID, sPassword, Session.LicenseType.Default, sConfigFilePath);
                oUtility.LogData("Connection to Epicor successful.");

                var client = oSFClient.CreateClient();

                //  Get UD25 Business Object
                Ice.Proxy.BO.UD25Impl oUD25 = WCFServiceSupport.CreateImpl <Ice.Proxy.BO.UD25Impl>((Ice.Core.Session)epiSession, Epicor.ServiceModel.Channels.ImplBase <Ice.Contracts.UD25SvcContract> .UriPath);

                //  ***************************************************************
                //  *** Start Get data from a CSV and populate an Epicor table. ***
                //  ***************************************************************
                //  Open and read a CSV file (sample).
                string sCSVFileData = oUtility.OpenAndReadCSVFile(sCSVFilePath);

                string[] sFileDataArray = sCSVFileData.Split('\n');     //  Split the CSV file data rows using the \n new line character.

                //  Check to set if there are any records in the CSV and loop thru the rows.
                if (sFileDataArray.Length > 0)
                {
                    //  Loop thru each row of the CSV file
                    for (int x = 0; x < sFileDataArray.Length - 1; x++)
                    {
                        if (x > 0)  // x > 0 to skip 1st row.
                        {
                            //  Initialize variables to hold field data.
                            string sColumn1 = "";
                            string sColumn2 = "";
                            string sColumn3 = "";
                            //  Get a single row from the CSV
                            string sFileDataLine = sFileDataArray[x].Replace("\r", "");;
                            //  Split the row on the "," comma to get the field values.
                            string[] sFileDataLineArray = sFileDataLine.Split(',');

                            //  Get columns data from CSV file.
                            sColumn1 = sFileDataLineArray[0];
                            sColumn2 = sFileDataLineArray[1];
                            sColumn3 = sFileDataLineArray[2];

                            //  Create Epicor UD25 dataset to store data.
                            UD25DataSet dsUD25 = new UD25DataSet();

                            //  Create a new UD25 record.
                            oUD25.GetaNewUD25(dsUD25);                                  //

                            //  Populate UD25 columns
                            dsUD25.Tables[0].Rows[0]["Key1"] = sColumn1;                //  UD25 Key1 field
                            dsUD25.Tables[0].Rows[0]["Key2"] = sColumn2;                //  UD25 Key2 field
                            Random r = new Random();                                    //  Random number generator
                            dsUD25.Tables[0].Rows[0]["Number01"]    = r.NextDouble();   //  Number01 field - Populate field with random number
                            dsUD25.Tables[0].Rows[0]["ShortChar01"] = sColumn3;         //  UD25DataSet Shortchar01 field
                            dsUD25.Tables[0].Rows[0]["Date01"]      = DateTime.Now;     //  Date01 field - Populate with current date

                            oUD25.Update(dsUD25);                                       //  Update UD25 with record data.

                            dsUD25.Dispose();
                        }
                    }
                }

                oUD25.Dispose();
                //  ***************************************************************
                //  *** End Get data from a CSV and populate an Epicor table. ***
                //  ***************************************************************
            }
            catch (Exception ex)
            {
            }

            //  Send an email.
            string sEmailFrom = ConfigurationManager.AppSettings["EmailFrom"];
            string sEmailTo   = "*****@*****.**";
            string sSubject   = "Program execution complete.";
            string sBody      = "Program execution complete.";

            oUtility.SendEmail(sEmailTo, sEmailFrom, sSubject, sBody);

            oUtility.ResetTimer();
        }