Example #1
0
        /// <summary>
        /// parse material master data and insert data into SQL
        /// </summary>
        private static void material()
        {
            string timeStart = DateTime.Now.ToString();

            bool          success      = true;
            int           errorCount   = 0;
            int           newLineCount = 0;
            List <string> errors       = new List <string>();

            string[] lines;
            string   transaction = "Material";

            try
            {
                lines = File.ReadAllLines(fileCTOCatalog);
            }
            catch (Exception e)
            {
                success = false;
                lines   = null;
                string buildError = "No file found: \n\t" + e.ToString();
                errorCount++;
                txtWriter.Log(buildError, transaction, errorCount, newLineCount);
            }
            //define counters for info tracker to count each pass in the foreach function

            int countPassedUpdate = 0;
            int countInserCommand = 0;

            if (success)
            {
                MaterialModel materialModel;
                foreach (string line in lines)
                {
                    materialModel = new MaterialModel();
                    materialModel.ParseMaterial(line);
                    materialModel.ID = sqlTransactions.SelectMaterialID(materialModel);
                    if (materialModel.ID < 1)
                    {
                        try
                        {
                            sqlTransactions.InsertMaterial(materialModel);
                            newLineCount++;
                            countInserCommand++;
                        }
                        catch (Exception ee)
                        {
                            txtWriter.Log(ee.ToString(), materialModel.MaterialNumber);
                        }
                    }
                    else
                    {
                        countPassedUpdate++;
                    }
                }
                string strgInfo = $"{transaction} started at {timeStart}: \n \tInserts:{countInserCommand}\n\tUpdates:NA\n\tNo Transaction: {countPassedUpdate}\n\n";

                txtWriter.writeInfo(strgInfo);
                //define streams and send to log writer
                if (errorCount > 0)
                {
                    txtWriter.Log(errors, transaction, errorCount, newLineCount);
                }
            }
            success = true;
        }