Example #1
0
        private static void AdjustProgramPath(MazakWriteData w)
        {
            // snapshots contain forward slash since they were made on linux
            if (System.IO.Path.DirectorySeparatorChar == '/')
            {
                return;
            }

            foreach (var part in w.Parts)
            {
                foreach (var proc in part.Processes)
                {
                    if (!proc.MainProgram.Contains('/'))
                    {
                        continue;
                    }
                    var path = proc.MainProgram.Split('/');
                    proc.MainProgram = System.IO.Path.Combine(path);
                }
            }
            foreach (var prog in w.Programs)
            {
                if (!prog.MainProgram.Contains('/'))
                {
                    continue;
                }
                var path = prog.MainProgram.Split('/');
                prog.MainProgram = System.IO.Path.Combine(path);
            }
        }
Example #2
0
 public void Save(MazakWriteData data, string prefix)
 {
     if (prefix == "Delete Parts Pallets")
     {
         DeletePartsPals = data;
     }
     else if (prefix == "Fixtures")
     {
         Fixtures = data;
     }
     else if (prefix == "Add Parts")
     {
         AddParts = data;
     }
     else if (prefix == "Add Schedules")
     {
         AddSchedules = data;
     }
     else if (prefix == "Update schedules")
     {
         UpdateSchedules = data;
     }
     else
     {
         Assert.True(false, "Unexpected prefix " + prefix);
     }
     if (errorForPrefix == prefix)
     {
         throw new Exception("Sample error");
     }
 }
Example #3
0
 public void Save(MazakWriteData data, string prefix)
 {
     Schedules = data.Schedules;
     data.Pallets.Should().BeEmpty();
     data.Parts.Should().BeEmpty();
     data.Fixtures.Should().BeEmpty();
 }
Example #4
0
 private static void SortSchedulesByDate(MazakWriteData transSet)
 {
     transSet.Schedules =
         transSet.Schedules
         .OrderBy(x => x.DueDate)
         .ThenBy(x => - x.Priority)
         .ToList();
 }
        private void CheckSingleProcPalletGroup(MazakWriteData dset, int groupNum, string fix, IList <int> pals)
        {
            int angle = groupNum * 1000;

            foreach (int pal in pals)
            {
                CheckPallet(dset, fix, pal, angle, groupNum);
            }
        }
Example #6
0
            public void ChangeHoldMode(HoldMode newHold)
            {
                var transSet  = new MazakWriteData();
                var newSchRow = _schRow.Clone();

                newSchRow.Command  = MazakWriteCommand.ScheduleSafeEdit;
                newSchRow.HoldMode = (int)newHold;
                transSet.Schedules.Add(newSchRow);

                _parent.database.Save(transSet, "Hold Mode");
            }
 private void CheckPallet(MazakWriteData dset, string fix, int pal, int expectedAngle, int expectedFixGroup)
 {
     foreach (var row in dset.Pallets.ToList())
     {
         if (row.PalletNumber == pal && row.Fixture == fix)
         {
             row.AngleV1.Should().Be(expectedAngle);
             row.FixtureGroupV2.Should().Be(expectedFixGroup);
             dset.Pallets.Remove(row);
         }
     }
 }
        private void CheckPalletGroup(MazakWriteData dset, int groupNum, IEnumerable <string> fixs, IList <int> pals)
        {
            int angle = groupNum * 1000;

            foreach (int pal in pals)
            {
                foreach (var fix in fixs)
                {
                    CheckPallet(dset, fix, pal, angle, groupNum);
                }
            }
        }
 private void CheckPart(MazakWriteData dset, string part, string comment)
 {
     foreach (var row in dset.Parts)
     {
         if (row.PartName == part)
         {
             Assert.Equal(comment, row.Comment);
             row.Processes.Should().BeEmpty();
             dset.Parts.Remove(row);
             break;
         }
     }
 }
Example #10
0
        public void Save(MazakWriteData data, string prefix)
        {
            CheckReadyForConnect();

            int checkInterval = data.Schedules.Count() + data.Pallets.Count() + 2 * data.Parts.Count() + data.Fixtures.Count() + data.Programs.Count();

            Log.Debug("Writing {@data} to transaction db", data);

            foreach (var prog in data.Programs)
            {
                if (prog.Command == MazakWriteCommand.Add)
                {
                    System.IO.File.WriteAllText(prog.MainProgram, prog.ProgramContent);
                }
            }

            try
            {
                using (var conn = CreateConnection())
                {
                    var trans = conn.BeginTransaction(IsolationLevel.ReadCommitted);
                    try
                    {
                        ClearTransactionDatabase(conn, trans);
                        SaveData(data, conn, trans);
                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        throw;
                    }

                    for (int i = 0; i <= WaitCount; i++)
                    {
                        System.Threading.Thread.Sleep(TimeSpan.FromSeconds(checkInterval));
                        if (CheckTransactionErrors(conn, prefix))
                        {
                            return;
                        }
                    }
                    throw new Exception("Timeout during download: open database kit is not running or responding");
                }
#if USE_OLEDB
            } catch (OleDbException ex) {
                throw new Exception(ex.ToString());
#endif
            }
            finally { }
        }
Example #11
0
        private void AssertPartsPalletsDeleted(MazakWriteData dset)
        {
            foreach (var row in dset.Parts)
            {
                Assert.True(false, "Extra part row: " + row.PartName);
            }

            foreach (var row in dset.Pallets)
            {
                Assert.True(false, "Extra pallet row: " + row.PalletNumber.ToString() + " " + row.Fixture);
            }

            foreach (var row in dset.Fixtures)
            {
                Assert.True(false, "Extra fixture row: " + row.FixtureName);
            }
        }
Example #12
0
        private void ReducePlannedQuantity(ICollection <DecrSchedule> jobs)
        {
            var write = new MazakWriteData();

            foreach (var job in jobs)
            {
                if (job.Schedule.PlanQuantity > job.NewPlanQty)
                {
                    var newSchRow = job.Schedule.Clone();
                    newSchRow.Command      = MazakWriteCommand.ScheduleSafeEdit;
                    newSchRow.PlanQuantity = job.NewPlanQty;
                    newSchRow.Processes.Clear();
                    write.Schedules.Add(newSchRow);
                }
            }

            if (write.Schedules.Any())
            {
                _write.Save(write, "Decrement preventing new parts starting");
            }
        }
Example #13
0
 private void CheckPartProcess(MazakWriteData dset, string part, int proc, string fixture,
                               string fix, string rem, string cut)
 {
     foreach (var mpart in dset.Parts)
     {
         if (mpart.PartName != part)
         {
             continue;
         }
         foreach (var row in mpart.Processes)
         {
             if (row.PartName == part && row.ProcessNumber == proc)
             {
                 row.Fixture.Should().Be(fixture, because: "on " + part);
                 row.FixLDS.Should().Be(fix, because: "on " + part);
                 row.RemoveLDS.Should().Be(rem, because: "on " + part);
                 row.CutMc.Should().Be(cut, because: "on " + part);
                 mpart.Processes.Remove(row);
                 break;
             }
         }
     }
 }
Example #14
0
        private static void SchedulePart(
            MazakWriteData transSet, int SchID, string mazakPartName, string mazakComment, int numProcess,
            JobPlan part, int proc1path, int earlierConflicts, bool UseStartingOffsetForDueDate)
        {
            var newSchRow = new MazakScheduleRow();

            newSchRow.Command            = MazakWriteCommand.Add;
            newSchRow.Id                 = SchID;
            newSchRow.PartName           = mazakPartName;
            newSchRow.PlanQuantity       = part.GetPlannedCyclesOnFirstProcess(proc1path);
            newSchRow.CompleteQuantity   = 0;
            newSchRow.FixForMachine      = 0;
            newSchRow.MissingFixture     = 0;
            newSchRow.MissingProgram     = 0;
            newSchRow.MissingTool        = 0;
            newSchRow.MixScheduleID      = 0;
            newSchRow.ProcessingPriority = 0;
            newSchRow.Comment            = mazakComment;

            if (UseStartingOffsetForDueDate)
            {
                if (part.GetSimulatedStartingTimeUTC(1, proc1path) != DateTime.MinValue)
                {
                    var start = part.GetSimulatedStartingTimeUTC(1, proc1path);
                    newSchRow.DueDate  = start.ToLocalTime().Date;
                    newSchRow.Priority = 91 + Math.Min(earlierConflicts, 9);
                }
                else
                {
                    newSchRow.DueDate  = DateTime.Today;
                    newSchRow.Priority = 91;
                }
            }
            else
            {
                newSchRow.Priority = 75;
                newSchRow.DueDate  = DateTime.Parse("1/1/2008 12:00:00 AM");
            }

            bool entireHold = false;

            if (part.HoldEntireJob != null)
            {
                entireHold = part.HoldEntireJob.IsJobOnHold;
            }
            bool machiningHold = false;

            if (part.HoldMachining(1, proc1path) != null)
            {
                machiningHold = part.HoldMachining(1, proc1path).IsJobOnHold;
            }
            newSchRow.HoldMode = (int)HoldPattern.CalculateHoldMode(entireHold, machiningHold);

            int matQty = newSchRow.PlanQuantity;

            if (!string.IsNullOrEmpty(part.GetInputQueue(process: 1, path: proc1path)))
            {
                matQty = 0;
            }

            //need to add all the ScheduleProcess rows
            for (int i = 1; i <= numProcess; i++)
            {
                var newSchProcRow = new MazakScheduleProcessRow();
                newSchProcRow.MazakScheduleRowId = SchID;
                newSchProcRow.ProcessNumber      = i;
                if (i == 1)
                {
                    newSchProcRow.ProcessMaterialQuantity = matQty;
                }
                else
                {
                    newSchProcRow.ProcessMaterialQuantity = 0;
                }
                newSchProcRow.ProcessBadQuantity     = 0;
                newSchProcRow.ProcessExecuteQuantity = 0;
                newSchProcRow.ProcessMachine         = 0;

                newSchRow.Processes.Add(newSchProcRow);
            }

            transSet.Schedules.Add(newSchRow);
        }
Example #15
0
 private void CheckPalletGroup(MazakWriteData dset, int groupNum, string fix, int numProc, IList <int> pals)
 {
     CheckPalletGroup(dset, groupNum,
                      Enumerable.Range(1, numProc).Select(i => fix + ":" + i.ToString()),
                      pals);
 }
Example #16
0
 private void CheckPartProcessFromJob(MazakWriteData dset, string part, int proc, string fixture)
 {
     //checks stuff created with AddBasicStopsWithProg
     CheckPartProcess(dset, part, proc, fixture, "1000000000", "1000000000", "10000000");
 }
Example #17
0
        private void SaveData(MazakWriteData data, IDbConnection conn, IDbTransaction trans)
        {
            conn.Execute(
                @"INSERT INTO Fixture_t(
          Command,
          Comment,
          FixtureName,
          TransactionStatus
        ) VALUES (
          @Command,
          @Comment,
          @FixtureName,
          0
        )",
                data.Fixtures,
                transaction: trans
                );

            if (MazakType == MazakDbType.MazakVersionE)
            {
                // pallet version 1
                conn.Execute(
                    @"INSERT INTO Pallet_t(
            Angle,
            Command,
            Fixture,
            PalletNumber,
            RecordID,
            TransactionStatus
          ) VALUES (
            @AngleV1,
            @Command,
            @Fixture,
            @PalletNumber,
            @RecordID,
            0
          )",
                    data.Pallets,
                    transaction: trans
                    );
            }
            else
            {
                // pallet version 2
                conn.Execute(
                    @"INSERT INTO Pallet_t(
            Command,
            Fixture,
            FixtureGroup,
            PalletNumber,
            RecordID,
            TransactionStatus
          ) VALUES (
            @Command,
            @Fixture,
            @FixtureGroupV2,
            @PalletNumber,
            @RecordID,
            0
          )",
                    data.Pallets,
                    transaction: trans
                    );
            }

            if (MazakType == MazakDbType.MazakSmooth)
            {
                conn.Execute(
                    @"INSERT INTO ScheduleProcess_t(
            ScheduleID,
            ProcessNumber,
            ProcessMaterialQuantity,
            ProcessExecuteQuantity,
            ProcessBadQuantity,
            ProcessMachine,
            FixedMachineFlag,
            FixedMachineNumber,
            ScheduleProcess_1,
            ScheduleProcess_2,
            ScheduleProcess_3,
            ScheduleProcess_4,
            ScheduleProcess_5
          ) VALUES (
            @MazakScheduleRowId,
            @ProcessNumber,
            @ProcessMaterialQuantity,
            @ProcessExecuteQuantity,
            @ProcessBadQuantity,
            @ProcessMachine,
            @FixedMachineFlag,
            @FixedMachineNumber,
            @ScheduleProcess_1,
            @ScheduleProcess_2,
            @ScheduleProcess_3,
            @ScheduleProcess_4,
            @ScheduleProcess_5
          )",
                    data.Schedules.SelectMany(s => s.Processes),
                    transaction: trans
                    );
                conn.Execute(
                    @"INSERT INTO Schedule_t(
            ScheduleID,
            Comment,
            PartName,
            PlanQuantity,
            CompleteQuantity,
            Priority,
            DueDate,
            FixForMachine,
            HoldMode,
            MissingFixture,
            MissingProgram,
            MissingTool,
            MixScheduleID,
            ProcessingPriority,
            Command,
            TransactionStatus,
            Schedule_1,
            Schedule_2,
            Schedule_3,
            Schedule_4,
            Schedule_5,
            Schedule_6,
            StartDate,
            SetNumber,
            SetQuantity,
            SetNumberSets
          ) VALUES (
            @Id,
            @Comment,
            @PartName,
            @PlanQuantity,
            @CompleteQuantity,
            @Priority,
            @DueDate,
            @FixForMachine,
            @HoldMode,
            @MissingFixture,
            @MissingProgram,
            @MissingTool,
            @MixScheduleID,
            @ProcessingPriority,
            @Command,
            0,
            @Schedule_1,
            @Schedule_2,
            @Schedule_3,
            @Schedule_4,
            @Schedule_5,
            @Schedule_6,
            @StartDate,
            @SetNumber,
            @SetQuantity,
            @SetNumberSets
          )",
                    data.Schedules,
                    transaction: trans
                    );
                conn.Execute(
                    @"INSERT INTO PartProcess_t(
            PartName,
            ProcessNumber,
            FixQuantity,
            ContinueCut,
            CutMc,
            FixLDS,
            FixPhoto,
            Fixture,
            MainProgram,
            RemoveLDS,
            RemovePhoto,
            WashType,
            PartProcess_1,
            PartProcess_2,
            PartProcess_3,
            PartProcess_4,
            FixTime,
            RemoveTime,
            CreateToolList_RA
          ) VALUES(
            @PartName,
            @ProcessNumber,
            @FixQuantity,
            @ContinueCut,
            @CutMc,
            @FixLDS,
            @FixPhoto,
            @Fixture,
            @MainProgram,
            @RemoveLDS,
            @REmovePhoto,
            @WashType,
            @PartProcess_1,
            @PartProcess_2,
            @PartProcess_3,
            @PartProcess_4,
            @FixTime,
            @RemoveTime,
            @CreateToolList_RA
          )",
                    data.Parts.SelectMany(p => p.Processes),
                    transaction: trans
                    );
                conn.Execute(
                    @"INSERT INTO Part_t(
            PartName,
            Comment,
            Price,
            TotalProcess,
            Command,
            TransactionStatus,
            MaterialName,
            Part_1,
            Part_2,
            Part_3,
            Part_4,
            Part_5,
            CheckCount,
            ProductCount
          ) VALUES (
            @PartName,
            @Comment,
            @Price,
            @TotalProcess,
            @Command,
            0,
            @MaterialName,
            @Part_1,
            @Part_2,
            @Part_3,
            @Part_4,
            @Part_5,
            @CheckCount,
            @ProductCount
          )",
                    data.Parts,
                    transaction: trans
                    );
            }
            else
            {
                // mazak ver e and web
                conn.Execute(
                    @"INSERT INTO ScheduleProcess_t(
            ScheduleID,
            ProcessBadQuantity,
            ProcessExecuteQuantity,
            ProcessMachine,
            ProcessMaterialQuantity,
            ProcessNumber
          ) VALUES (
            @MazakScheduleRowId,
            @ProcessBadQuantity,
            @ProcessExecuteQuantity,
            @ProcessMachine,
            @ProcessMaterialQuantity,
            @ProcessNumber
          )",
                    data.Schedules.SelectMany(s => s.Processes),
                    transaction: trans
                    );
                conn.Execute(
                    @"INSERT INTO Schedule_t(
            Command,
            Comment,
            CompleteQuantity,
            DueDate,
            FixForMachine,
            HoldMode,
            ScheduleID,
            MissingFixture,
            MissingProgram,
            MissingTool,
            MixScheduleID,
            PartName,
            PlanQuantity,
            Priority,
            ProcessingPriority,
            TransactionStatus
          ) VALUES (
            @Command,
            @Comment,
            @CompleteQuantity,
            @DueDate,
            @FixForMachine,
            @HoldMode,
            @Id,
            @MissingFixture,
            @MissingProgram,
            @MissingTool,
            @MixScheduleID,
            @PartName,
            @PlanQuantity,
            @Priority,
            @ProcessingPriority,
            0
          )",
                    data.Schedules,
                    transaction: trans
                    );
                conn.Execute(
                    @"INSERT INTO PartProcess_t(
            ContinueCut,
            CutMc,
            FixLDS,
            FixPhoto,
            FixQuantity,
            Fixture,
            MainProgram,
            PartName,
            ProcessNumber,
            RemoveLDS,
            RemovePhoto,
            WashType
          ) VALUES(
            @ContinueCut,
            @CutMc,
            @FixLDS,
            @FixPhoto,
            @FixQuantity,
            @Fixture,
            @MainProgram,
            @PartName,
            @ProcessNumber,
            @RemoveLDS,
            @RemovePhoto,
            @WashType
          )",
                    data.Parts.SelectMany(p => p.Processes),
                    transaction: trans
                    );
                conn.Execute(
                    @"INSERT INTO Part_t(
            Command,
            Comment,
            PartName,
            Price,
            TotalProcess,
            TransactionStatus
          ) VALUES (
            @Command,
            @Comment,
            @PartName,
            @Price,
            @TotalProcess,
            0
          )",
                    data.Parts,
                    transaction: trans
                    );
            }

            if (MazakType == MazakDbType.MazakSmooth)
            {
                conn.Execute(
                    @"INSERT INTO MainProgram_t(
            Command,
            Comment,
            Count,
            CreateToolList_PMC,
            CutTime,
            CutTimeFlag,
            FileStatus,
            MainProgram,
            MainProgram_1,
            MainProgram_2,
            MainProgram_3,
            MainProgram_4,
            MainProgram_5,
            SingleBlockStop,
            TransactionStatus
          ) VALUES (
            @Command,
            @Comment,
            0,
            0,
            0,
            1,
            0,
            @MainProgram,
            0,
            0,
            0,
            0,
            0,
            0,
            0
          )",
                    data.Programs,
                    transaction: trans
                    );
            }
            else
            {
                throw new Exception("Downloading programs only supported on Smooth-PMC");
            }
        }
Example #18
0
        public static MazakWriteData AddSchedules(
            MazakSchedulesPartsPallets mazakData,
            IEnumerable <JobPlan> jobs,
            bool UseStartingOffsetForDueDate)
        {
            var transSet = new MazakWriteData();

            var usedScheduleIDs = new HashSet <int>();
            var scheduledParts  = new HashSet <string>();

            foreach (var schRow in mazakData.Schedules)
            {
                usedScheduleIDs.Add(schRow.Id);
                scheduledParts.Add(schRow.PartName);
            }

            //now add the new schedule
            foreach (JobPlan part in jobs)
            {
                for (int proc1path = 1; proc1path <= part.GetNumPaths(1); proc1path++)
                {
                    if (part.GetPlannedCyclesOnFirstProcess(proc1path) <= 0)
                    {
                        continue;
                    }

                    //check if part exists downloaded
                    int    downloadUid   = -1;
                    string mazakPartName = "";
                    string mazakComment  = "";
                    foreach (var partRow in mazakData.Parts)
                    {
                        if (MazakPart.IsSailPart(partRow.PartName))
                        {
                            MazakPart.ParseComment(partRow.Comment, out string u, out var ps, out bool m);
                            if (u == part.UniqueStr && ps.PathForProc(proc: 1) == proc1path)
                            {
                                downloadUid   = MazakPart.ParseUID(partRow.PartName);
                                mazakPartName = partRow.PartName;
                                mazakComment  = partRow.Comment;
                                break;
                            }
                        }
                    }
                    if (downloadUid < 0)
                    {
                        throw new BlackMaple.MachineFramework.BadRequestException(
                                  "Attempting to create schedule for " + part.UniqueStr + " but a part does not exist");
                    }

                    if (!scheduledParts.Contains(mazakPartName))
                    {
                        int schid            = FindNextScheduleId(usedScheduleIDs);
                        int earlierConflicts = CountEarlierConflicts(part, proc1path, jobs);
                        SchedulePart(transSet, schid, mazakPartName, mazakComment, part.NumProcesses, part, proc1path, earlierConflicts, UseStartingOffsetForDueDate);
                    }
                }
            }

            if (UseStartingOffsetForDueDate)
            {
                SortSchedulesByDate(transSet);
            }

            return(transSet);
        }
Example #19
0
 private void CheckPartProcess(MazakWriteData dset, string part, int proc, string fixture)
 {
     CheckPartProcess(dset, part, proc, fixture, "0000000000", "0000000000", "00000000");
 }