Board index » delphi » Managing Production Day and Shift
Larry
![]() Delphi Developer |
Managing Production Day and Shift2006-11-20 03:34:41 AM delphi27 MS/SQL 2000 Delphi 2006 Ent This should not be hard but it is kicking my {*word*82}right now. And I swear I have done this before. I am righting a middle-ware app that retrieves data from a PLC controller and writes it to the database. The data has : Line Group Weight DateTime and other stuff The controller is capable of caching the data for up to 12 hours so the DateTime record may not be the same as system datatime. The plants where I will install this software often do not start and stop their day at midnight. They have a Production day which may not be the same as the present day. For exampl, if they start production at 10:45 PM, the records gernerated between 10:45 PM and 11:59:59 will be assigned to the production day of the following day. I believe I have Production day figured. I have a simple setup GUI with a ComboBox and two radio buttons. case rgMidNightOffset.ItemIndex of 0: GetTimeAfterMidnight; 1: GetTimeBeforeMidnight; end; procedure TfrmLots.GetTimeAfterMidnight; begin cbOffset.Clear; cbOffset.Items.Add('None'); cbOffset.Items.Add('1 AM'); cbOffset.Items.Add('2 AM'); cbOffset.Items.Add('3 AM'); ... end; procedure TfrmLots.GetTimeBeforeMidnight; begin cbOffset.Clear; cbOffset.Items.Add('None'); cbOffset.Items.Add('11 PM'); cbOffset.Items.Add('10 PM'); cbOffset.Items.Add(' 9 PM'); ... end; =========================================================================== Declare @MyDate DateTime, @HoursMultiple Int, @TypeOffset Int, @AmtOffSet Int, @AdjDateTime DateTime, @ProdWorkDate DateTime Set @MyDate = :WeighTime Set @TypeOffset = :TypeOffset Set @AmtOffSet = :AmtOffSet Set @HoursMultiple = (case @TypeOffset when 0 then -1 -- After midnight when 1 then 1 -- before midnight when -1 then 0 -- no offset end) Set @AdjDateTime = DATEADD ( hh ,(@AmtOffSet * @HoursMultiple ) , @MyDate ) Set @ProdWorkDate = DateAdd(d,DATEDIFF(d,0,@AdjDateTime),0) print @ProdWorkDate =========================================================================== This always returns the correct Production work day. What is eating my lunch are the Shifts. A shift may or may not cross midnight though only one shift will. It may start or end with the ProdWorkDay but need not. Of course, it may never cross a ProdWorkDay. When I write the data to the database, I need to stamp both the ProdWorkDay and Shift. eg. Shift1 and ProdWorkDay start at 10:30 PM Shift2 begins 10:30PM ^ | 8:00AM ^ <----|----------|-12:00AM---------------------------------------------------------------------|------------|-12:00AM-----> | | ProdWorkDay ends | | 6:30AM Shift2 Ends Shift 1 Ends 3:00 PM In the Setup, I make the user (normally our tech) set the offset for the Shift, just as I do for ProdWorkDay. I only expect two shifts but three is possible. I have a table as: CREATE TABLE [dbo].[ShiftSetUp] ( [Line] [tinyint] NOT NULL , [Shift] [tinyint] NULL , [ShiftStart] [datetime] NULL , [StartOffset] [smallint] NULL , //number of hours before or after midnight [StartTypeOffSet] [smallint] NULL , //if starting before midnight then will be 1, if after 0, else -1 [ShiftStop] [datetime] NULL , [StopOffset] [smallint] NULL , //number of hours before or after midnight [StopTypeOffSet] [smallint] NULL //if starting before midnight then will be 1, if after 0, else -1 ) I have worked with this for three days and still have not figured it out. It is like a Sudoku in greek. Obviously, someone else has run across this. Two many business and manufacturing have to deal with the same thing. Can some one give me a start?? Thanks. |