| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 | 
							- using iBemsDataService.Controllers.Bems.Common;
 
- using System;
 
- using System.Collections.Generic;
 
- using System.Linq;
 
- using System.Web;
 
- namespace iBemsDataService.Controllers.Bems.Formula
 
- {
 
-     public class ParameterBox
 
-     {
 
-         public DateTime DateTime { get ; set; }
 
-         Box[] boxes;
 
-         public ParameterBox( CalculationParameter[] parameters )
 
-         {
 
-             this.boxes = new Box[parameters.Length];
 
-             for( int i = 0 ; i < parameters.Length ; i++ )
 
-             {
 
-                 var box = this.boxes[i] = new Box();
 
-                 box.parameter = parameters[i];
 
-             }
 
-         }
 
-         public bool NextStage()
 
-         {
 
-             for( var i = 0 ; i < this.boxes.Length ; i++ )
 
-             {
 
-                 var box = this.boxes[i];
 
-                 box.Set = false;
 
-                 if( box.Next() == false )
 
-                 {
 
-                     return false;
 
-                 }
 
-             }
 
-             return true;
 
-         }
 
-         public bool Sync()
 
-         {
 
-             if (this.boxes == null || this.boxes.Length == 0) return false;
 
-             var value = this.boxes[0].GetValue();
 
-             if( value == null )
 
-                 return false;
 
-             var dateTime = value.DateTime;
 
-         Loop:
 
-             for( var i = 0 ; i < this.boxes.Length ; i++ )
 
-             {
 
-                 var box = this.boxes[i];
 
-                 if( box.Set )
 
-                 {
 
-                     continue;
 
-                 }
 
-                 switch( box.Sync( dateTime ) )
 
-                 {
 
-                     case -1: // 없다. 더이상 계산이 필요 없다.
 
-                         return false;
 
-                     case 0:  // 동일한 것이 있다. 
 
-                         box.Set = true;
 
-                         break;
 
-                     case 1:  // 초과한 시간이 있다. 
 
-                         dateTime = box.GetValue().DateTime;
 
-                         goto Loop;
 
-                 }
 
-             }
 
-             this.DateTime = dateTime;
 
-             return true;
 
-         }
 
-         class Box
 
-         {
 
-             public enum IndexAtDateTimeResult
 
-             {
 
-                 
 
-             };
 
-             public bool Set { get; set; }
 
-             public int currentIndex = 0;
 
-             public CalculationParameter parameter;
 
-             public IndexAtDateTimeResult Result { get; set; }
 
-             public Box()
 
-             {
 
-                 Set = false;
 
-             }
 
-             public bool Next()
 
-             {
 
-                 this.currentIndex++;
 
-                 return (this.currentIndex < parameter.Values.Length);
 
-             }
 
-             public int Sync( DateTime dateTime )
 
-             {
 
-                 var values = parameter.Values;
 
-                 if( values != null )
 
-                 {
 
-                     for( var i = currentIndex ; i < values.Length ; i++ )
 
-                     {
 
-                         if( values[i].DateTime == dateTime )
 
-                         {
 
-                             this.currentIndex = i;
 
-                             this.Setup();
 
-                             return 0;
 
-                         }
 
-                         if( dateTime < values[i].DateTime )
 
-                         {
 
-                             this.currentIndex = i;
 
-                             return 1;
 
-                         }
 
-                     }
 
-                 }
 
-                 return -1;
 
-             }
 
-             public CalculationValue GetValue()
 
-             {
 
-                 if( parameter.Values == null )
 
-                     return null;
 
-                 if( parameter.Values.Length <= currentIndex )
 
-                     return null;
 
-                 return parameter.Values[currentIndex];
 
-             }
 
-             public void Setup()
 
-             {
 
-                 this.Set = true;
 
-                 this.parameter.SetValueFromIndex( currentIndex );
 
-             }
 
-         }
 
-     }
 
- }
 
 
  |