Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            //try
            //{

            Console.WriteLine("Get Configuration");
            GetConfig();
            Log = new clsLog(_conStr);
            Console.WriteLine($"Connecting FTP {_ftpserver}...");
            clsSFTP sftp = new clsSFTP();

            sftp.sftpIP           = _ftpserver;
            sftp.Sftpuser         = _ftpuser;
            sftp.Sftppwd          = _ftppassword;
            sftp.Remotefolder     = _ftpFolder;
            _logDownloadProcessid = Log.LogProcessInsert(clsLog.Logger.Inventory, clsLog.ProcessCategory.Inventory, "Start Download File from SFTP", DateTime.Now);
            try
            {
                Console.WriteLine("Trying to download file from FTP...");
                if (sftp.DownloadLatestFile(true) != 0)
                {
                    Console.WriteLine("Problem on download file. So Quit job now");
                    Log.LogAlert(clsLog.Logger.Inventory, clsLog.ErrorLevel.MiddleImpact, clsLog.ProcessCategory.Inventory, $"Problem found on Download file");
                    return;
                }
                Log.LogProcessUpdate(_logDownloadProcessid, DateTime.Now);
                Console.WriteLine("Download file success");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Download file has an error {ex.Message}");
                Log.LogAlert(clsLog.Logger.Inventory, clsLog.ErrorLevel.MiddleImpact, clsLog.ProcessCategory.Inventory, $"Inventory snapshot download problem found:{ex.Message}");
            }

            try
            {
                Console.WriteLine("Trying to import data into O2D inventory...");
                Inventory inv = new Inventory(_conStr);
                inv.ImportOpening(sftp.LocalFile);
                Console.WriteLine("Import inventory is success");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error found on step ImportOpening:{ex.Message}");
                Log.LogAlert(clsLog.Logger.Inventory, clsLog.ErrorLevel.MiddleImpact, clsLog.ProcessCategory.Inventory, $"Inventory snapshot IMPORT problem found:{ex.Message}");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// For caller to call for ATPCTP result.
        /// </summary>
        /// <param name="materialID"></param>
        /// <param name=""></param>
        /// <returns></returns>
        //public DataSet Request(DataTable dtOrder, DataTable dtOrderItem, int atpCtpLogicId)
        public DataSet Request(clsDTOrder dtOrder, clsDTOrderItem dtOrderItem, int atpCtpLogicId, ref string WarningMsg)
        {
            try
            {
                WarningMsg = string.Empty;
                Console.WriteLine("Start Request ...");
                int logID;
                logID = log.LogProcessInsert(clsLog.Logger.ATPCTP, clsLog.ProcessCategory.RequestATPCTP, "ATPCTP Request", DateTime.Now);
                _ds   = new DataSet();
                LogInputParameter(dtOrder, dtOrderItem, atpCtpLogicId);
                string    procName = "proc_DUP_ATPCTPRequestSelect_4096";
                DataTable dt1;
                DataTable dt2;
                dt1 = dtOrder.DT;
                dt2 = dtOrderItem.DT;
                //ClsConnection con = new ClsConnection(_conStr);

                using (SqlConnection con = new SqlConnection(_conStr))
                {
                    con.Open();
                    using (SqlCommand cmd = con.CreateCommand())
                    {
                        cmd.CommandType    = CommandType.StoredProcedure;
                        cmd.CommandText    = procName;
                        cmd.CommandTimeout = 180;
                        cmd.Parameters.AddWithValue("@DTOrder", dt1);
                        cmd.Parameters.AddWithValue("@DTOrderItem", dt2);
                        cmd.Parameters.AddWithValue("@ATPCTPLogicID", atpCtpLogicId);
                        using (SqlDataAdapter sd = new SqlDataAdapter(cmd))
                        {
                            sd.Fill(_ds);
                        }
                    }
                }
                _ds.Tables[0].TableName = "DTOrderItem";
                _ds.Tables[1].TableName = "DTOrderItemOperation";
                _ds.Tables[2].TableName = "DTOrderItemOperationDetail";
                log.LogProcessUpdate(logID, DateTime.Now);
                WarningMsg = string.Empty;
                Console.WriteLine("End ATPCTPRequest");
                if (_ds.Tables.Count > 0)
                {
                    if (_ds.Tables[0].Rows.Count == 0 && WarningMsg == string.Empty)
                    {
                        WarningMsg = "No WIP found either in Balance inventory or Material Master";
                    }
                }
                LogOutputResult(_ds);
                return(_ds);
            }
            catch (Exception ex)
            {
                string errmsg     = ex.Message;
                string showerrmsg = string.Empty;
                if (_ds != null)
                {
                    _ds.Tables[0].TableName = "DTOrderItem";
                    _ds.Tables[1].TableName = "DTOrderItemOperation";
                    _ds.Tables[2].TableName = "DTOrderItemOperationDetail";
                }
                if (IsRealError(errmsg, ref showerrmsg) == true)
                {
                    WarningMsg = string.Empty;
                    Console.WriteLine($"Error found on Request:{ex.Message}");
                    throw ex;
                }
                else
                {
                    WarningMsg = showerrmsg;
                    if (_ds.Tables.Count > 0)
                    {
                        if (_ds.Tables[0].Rows.Count == 0 && WarningMsg == string.Empty)
                        {
                            WarningMsg = "No WIP found either in Balance inventory or Material Master";
                        }
                    }
                    return(_ds);
                }
            }
        }