コード例 #1
0
ファイル: Program.cs プロジェクト: wangscript007/MetricSoft
        static void Main(string[] args)
        {
            initialReminderHours = new TimeSpan(48, 0, 0);            // Number of hours to remind before due date
            repeatReminderHours  = new TimeSpan(24, 0, 0);            // Number of hours to wait before repeating reminder
            output = new StringBuilder();

            WriteLine("Started.");
            WriteLine("Reading pending emails...");

            entities = new SQM.Website.PSsqmEntities();
            List <TASK_STATUS> pendingTasks = (from t in entities.TASK_STATUS
                                               where t.COMPLETE_DT != null &&
                                               t.RESPONSIBLE_ID != null
                                               select t).ToList();

            foreach (var task in pendingTasks)
            {
                try
                {
                    var responsiblePerson = (from p in entities.PERSON.Include("PERSON_RESP") where p.PERSON_ID == task.RESPONSIBLE_ID select p).FirstOrDefault();

                    WriteLine("----------");
                    WriteLine(string.Format("Tasklist ID: {0} | Task Num: {1} | Due: {2:yyyy-MM-dd} | Last Notified: {3:yyyy-MM-dd}",
                                            0, task.TASK_ID, task.DUE_DT, task.NOTIFY_DT));
                    if (responsiblePerson != null)
                    {
                        if (responsiblePerson.PERSON_RESP != null)
                        {
                            if (responsiblePerson.PERSON_RESP.DELEGATE_1 != null)
                            {
                                WriteLine(string.Format("Responsible ID: {0} | Delegate ID: {1}",
                                                        task.RESPONSIBLE_ID, responsiblePerson.PERSON_RESP.DELEGATE_1));
                            }
                        }
                    }

                    if (!task.NOTIFY_DT.HasValue)
                    {
                        // First time email sent
                        WriteLine("No last notification date");
                        PrepareRecipient(task);
                    }
                    else if (task.DUE_DT.HasValue)
                    {
                        if (((DateTime)task.DUE_DT).Subtract(DateTime.Now) < initialReminderHours)
                        {
                            // First time reminder email sent (e.g. 48 hours before due date)
                            WriteLine("Within 48 hours or past due date");
                            if (DateTime.Now.Subtract(((DateTime)task.NOTIFY_DT)) >= repeatReminderHours)
                            {
                                PrepareRecipient(task);
                            }
                            else
                            {
                                WriteLine("- Already notified within past 24 hours - skipping");
                            }
                        }
                    }
                    //else if (DateTime.Now.Subtract(((DateTime)task.LAST_NOTIFICATION_DT)) < _repeatReminderHours)
                    //{
                    //	// Subsequent reminder sent (e.g. 24 hours after previous reminder)
                    //	WriteLine("24 Hours after last notification date");
                    //	PrepareRecipient(task);
                    //}
                }
                catch (Exception ex)
                {
                    WriteLine("pendingTasks Error: " + ex.ToString());
                    WriteLine("pendingTasks Detailed Error: " + ex.InnerException.ToString());
                }
            }


            try
            {
                // New task notification method
                TaskNotification();
            }
            catch (Exception ex)
            {
                WriteLine("Main TaskNotification Error: " + ex.ToString());
                WriteLine("Main TaskNotification Detailed Error: " + ex.InnerException.ToString());
            }

            WriteLogFile();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            output   = new StringBuilder();
            entities = new PSsqmEntities();

            List <SETTINGS> MailSettings = SQMSettings.SelectSettingsGroup("MAIL", "");

            foreach (SETTINGS set in MailSettings)
            {
                switch (set.SETTING_CD)
                {
                case "MailServer":
                    mailServer = set.VALUE;
                    break;

                case "MailFrom":
                    mailFrom = set.VALUE;
                    break;

                case "MailSMTPPort":
                    mailSMTPPort = set.VALUE;
                    break;

                case "MailEnableSSL":
                    mailEnableSSL = set.VALUE;
                    break;

                case "MailURL":
                    mailURL = set.VALUE;
                    break;

                case "MailPassword":
                    mailPassword = set.VALUE;
                    break;

                default:
                    break;
                }
            }

            List <SETTINGS> ImportSettings = SQMSettings.SelectSettingsGroup("FILE_UPLOAD", "");

            foreach (SETTINGS ris in ImportSettings)
            {
                switch (ris.SETTING_CD)
                {
                case "CompanyID":
                    companyID = Convert.ToInt16(ris.VALUE);
                    break;

                case "FileLocation":
                    fileLocation = ris.VALUE;
                    break;

                case "UploadSources":
                    try
                    {
                        uploadSource = Convert.ToInt32(ris.VALUE);
                    }
                    catch
                    {
                        WriteLine("Source file locations have not been defined correctly in the configuration file. No files were processed.");
                        uploadSource = 0;
                    }
                    break;

                case "CompanyFile":
                    companyFile = ris.VALUE;
                    break;

                case "PlantFile":
                    plantFile = ris.VALUE;
                    break;

                case "PartFile":
                    partFile = ris.VALUE;
                    break;

                case "PlantDataFile":
                    plantDataFile = ris.VALUE;
                    break;

                case "CurrencyFile":
                    currencyFile = ris.VALUE;
                    break;

                case "DefaultPartProgram":
                    defaultPartProgram = ris.VALUE;
                    break;

                default:
                    break;
                }
            }

            timestamp = string.Format("{0:yyyy-MM-dd-HHmm}", DateTime.Now);
            emailBody = "";

            for (int i = 1; i <= uploadSource; i++)
            {
                string   fileLocationKey = "UploadFileLocation" + i.ToString();
                SETTINGS result          = ImportSettings.Find(x => x.SETTING_CD == fileLocationKey);
                fileLocation        = result.VALUE;
                result              = ImportSettings.Find(x => x.SETTING_CD == "FileDelimiter" + i.ToString());
                fileDelimiter       = result.VALUE.ToCharArray();
                result              = ImportSettings.Find(x => x.SETTING_CD == "UploadFileType" + i.ToString());
                fileType            = result.VALUE;
                result              = ImportSettings.Find(x => x.SETTING_CD == "PlantDataMultiplier" + i.ToString());
                plantDataMultiplier = Convert.ToDouble(result.VALUE);
                WriteLine("Processing files in: " + fileLocation);
                if (fileType.ToLower().Equals("ftp"))
                {
                    try
                    {
                        // check for each file separately and process
                        WriteLine("Start Company file processing.");
                        // Process each file type
                        ProcessFTPInputFile("COMPANY");
                        WriteLine("<br/>Start Plant file processing.");
                        ProcessFTPInputFile("PLANT");
                        WriteLine("<br/>Start Part file processing.");
                        ProcessFTPInputFile("PART");
                        WriteLine("<br/>Start Plant Data file processing.");
                        ProcessFTPInputFile("PLANT_DATA");
                        //WriteLine("<br/>Start Currency Data file processing.");
                        //ProcessFTPInputFile("CURRENCY_DATA");
                        WriteLine("<br/><br/>");
                    }
                    catch (Exception ex)
                    {
                        WriteLine("Error: " + ex.ToString());
                    }
                }
                else
                {
                    string[] fileEntries;
                    try
                    {
                        // check for each file separately and process
                        WriteLine("Start Company file processing.");
                        // Process each file type
                        //originalFile = fileLocation + ConfigurationSettings.AppSettings["CompanyFile"];
                        fileEntries = Directory.GetFiles(fileLocation, companyFile);
                        fileCount   = 0;
                        foreach (string fileName in fileEntries)
                        {
                            fileCount += 1;
                            ProcessInputFile("COMPANY", fileName);
                        }
                        WriteLine("<br/>Start Plant file processing.");
                        //originalFile = fileLocation + ConfigurationSettings.AppSettings["PlantFile"];
                        fileEntries = Directory.GetFiles(fileLocation, plantFile);
                        fileCount   = 0;
                        foreach (string fileName in fileEntries)
                        {
                            if (!fileName.ToLower().Contains("_data"))
                            {
                                fileCount += 1;
                                ProcessInputFile("PLANT", fileName);
                            }
                        }
                        WriteLine("<br/>Start Part file processing.");
                        //originalFile = fileLocation + ConfigurationSettings.AppSettings["PartFile"];
                        fileEntries = Directory.GetFiles(fileLocation, partFile);
                        fileCount   = 0;
                        foreach (string fileName in fileEntries)
                        {
                            fileCount += 1;
                            ProcessInputFile("PART", fileName);
                        }
                        WriteLine("<br/>Start Plant Data file processing.");
                        //originalFile = fileLocation + ConfigurationSettings.AppSettings["PlantDataFile"];
                        fileEntries = Directory.GetFiles(fileLocation, plantDataFile);
                        fileCount   = 0;
                        foreach (string fileName in fileEntries)
                        {
                            fileCount += 1;
                            ProcessInputFile("PLANT_DATA", fileName);
                        }
                        //WriteLine("<br/>Start Currency Data file processing.");
                        //originalFile = fileLocation + currencyFile;
                        //ProcessInputFile("CURRENCY_DATA", originalFile);
                        WriteLine("<br/><br/>");
                    }
                    catch (Exception ex)
                    {
                        WriteLine("Error: " + ex.ToString());
                    }
                }
            }

            WriteLogFile();
        }
コード例 #3
0
        static void Main(string[] args)
        {
            output   = new StringBuilder();
            entities = new PSsqmEntities();

            List <SETTINGS> MailSettings = SQMSettings.SelectSettingsGroup("MAIL", "");

            foreach (SETTINGS set in MailSettings)
            {
                switch (set.SETTING_CD)
                {
                case "MailServer":
                    mailServer = set.VALUE;
                    break;

                case "MailFrom":
                    mailFrom = set.VALUE;
                    break;

                case "MailSMTPPort":
                    mailSMTPPort = set.VALUE;
                    break;

                case "MailEnableSSL":
                    mailEnableSSL = set.VALUE;
                    break;

                case "MailURL":
                    mailURL = set.VALUE;
                    break;

                case "MailPassword":
                    mailPassword = set.VALUE;
                    break;

                default:
                    break;
                }
            }

            List <SETTINGS> ReceiptImportSettings = SQMSettings.SelectSettingsGroup("IMPORT_RECEIPT", "");

            foreach (SETTINGS ris in ReceiptImportSettings)
            {
                switch (ris.SETTING_CD)
                {
                case "CompanyID":
                    companyID = Convert.ToInt16(ris.VALUE);
                    break;

                case "FileLocation":
                    fileLocation = ris.VALUE;
                    break;

                case "FileDelimiter":
                    fileDelimiter = ris.VALUE.ToCharArray();
                    break;

                case "LogFileEmail":
                    logFileEmail = ris.VALUE;
                    break;

                case "ReceiptFile":
                    receiptFile = ris.VALUE + "*";
                    break;

                case "InspectionFile":
                    inspectionFile = ris.VALUE + "*";
                    break;

                default:
                    break;
                }
            }

            timestamp = string.Format("{0:yyyy-MM-dd-HHmm}", DateTime.Now);
            emailBody = "";

            WriteLine("Processing files in: " + fileLocation);
            string[] fileEntries;
            try
            {
                // check for each file separately and process
                WriteLine("Start Receipt file processing.");
                // Process each file type
                fileEntries = Directory.GetFiles(fileLocation, receiptFile);
                fileCount   = 0;
                foreach (string fileName in fileEntries)
                {
                    fileCount += 1;
                    ProcessInputFile("RECEIPT", fileName);
                }
                WriteLine("<br/>Start Inspection file processing.");
                //originalFile = fileLocation + ConfigurationSettings.AppSettings["PlantFile"];
                fileEntries = Directory.GetFiles(fileLocation, inspectionFile);
                fileCount   = 0;
                foreach (string fileName in fileEntries)
                {
                    fileCount += 1;
                    ProcessInputFile("INSPECT", fileName);
                }
                WriteLine("<br/><br/>");
            }
            catch (Exception ex)
            {
                WriteLine("Error: " + ex.ToString());
            }

            WriteLogFile();
        }