Exemple #1
0
        private void AddSchedules(IEnumerable <JobPlan> jobs)
        {
            var mazakData = readDatabase.LoadSchedulesPartsPallets();
            var transSet  = BuildMazakSchedules.AddSchedules(mazakData, jobs, UseStartingOffsetForDueDate);

            if (transSet.Schedules.Any())
            {
                writeDb.Save(transSet, "Add Schedules");
                foreach (var j in jobs)
                {
                    jobDB.MarkJobCopiedToSystem(j.UniqueStr);
                }
            }
        }
Exemple #2
0
        private void AddFixturesPalletsParts(NewJobs newJ)
        {
            var mazakData = readDatabase.LoadAllData();

            //first allocate a UID to use for this download
            int UID = 0;

            while (UID < int.MaxValue)
            {
                //check schedule rows for UID
                foreach (var schRow in mazakData.Schedules)
                {
                    if (MazakPart.ParseUID(schRow.PartName) == UID)
                    {
                        goto found;
                    }
                }

                //check fixture rows for UID
                foreach (var fixRow in mazakData.Fixtures)
                {
                    if (MazakPart.ParseUID(fixRow.FixtureName) == UID)
                    {
                        goto found;
                    }
                }

                break;
found:
                UID += 1;
            }
            if (UID == int.MaxValue)
            {
                throw new Exception("Unable to find unused UID");
            }
            Log.Debug("Creating new schedule with UID {uid}", UID);

            var(transSet, savedParts) = BuildMazakSchedules.RemoveCompletedAndDecrementSchedules(
                mazakData, UseStartingOffsetForDueDate
                );
            if (transSet.Schedules.Any())
            {
                writeDb.Save(transSet, "Update schedules");
            }

            Log.Debug("Saved Parts: {parts}", savedParts);

            var jobErrs   = new List <string>();
            var mazakJobs = ConvertJobsToMazakParts.JobsToMazak(
                newJ.Jobs,
                UID,
                mazakData,
                savedParts,
                writeDb.MazakType,
                CheckPalletsUsedOnce,
                fmsSettings,
                LookupProgram,
                jobErrs);

            if (jobErrs.Any())
            {
                throw new BlackMaple.MachineFramework.BadRequestException(
                          string.Join(Environment.NewLine, jobErrs)
                          );
            }

            //delete everything
            transSet = mazakJobs.DeleteOldPartPalletRows();
            if (transSet.Parts.Any() || transSet.Pallets.Any())
            {
                try
                {
                    writeDb.Save(transSet, "Delete Parts Pallets");
                }
                catch (ErrorModifyingParts e)
                {
                    foreach (var partName in e.PartNames)
                    {
                        if (readDatabase.CheckPartExists(partName))
                        {
                            throw new Exception("Mazak returned an error when attempting to delete part " + partName);
                        }
                    }
                }
            }

            //have to delete fixtures after schedule, parts, and pallets are already deleted
            //also, add new fixtures
            transSet = mazakJobs.CreateDeleteFixtureAndProgramDatabaseRows(jobDB.LoadProgramContent, ProgramDirectory);
            writeDb.Save(transSet, "Fixtures");

            //now save the pallets and parts
            transSet = mazakJobs.CreatePartPalletDatabaseRows();
            writeDb.Save(transSet, "Add Parts");
        }