示例#1
0
        // GET: CaseStudy
        public ActionResult Index()
        {
            // 30/08/2015
            var choosenList2 = _iScheduleService.GetAllSchedule().Where(x => x.Date <new DateTime(2015, 8, 30, 23, 59, 59) && x.Date> new DateTime(2015, 8, 30, 0, 0, 0)).Select(x => x.ProgramCode).Distinct().ToList();
            List <ViewModelProgram> progamList2 = _iProgramService.GetAllProgramsHaveQuantity(new DateTime(2015, 8, 30)).Where(x => choosenList2.Contains(x.ProgramCode)).ToList();

            ViewBag.realProgram = progamList2;
            List <ViewModelProgram> progamList1 = _iProgramService.GetAllProgram().Where(x => choosenList2.Contains(x.ProgramCode)).ToList();

            ViewBag.originalProgram = progamList1;

            // 31/08/2015
            var choosenList2next = _iScheduleService.GetAllSchedule().Where(x => x.Date <new DateTime(2015, 8, 31, 23, 59, 59) && x.Date> new DateTime(2015, 8, 31, 0, 0, 0)).Select(x => x.ProgramCode).Distinct().ToList();
            List <ViewModelProgram> progamList2next = _iProgramService.GetAllProgramsHaveQuantity(new DateTime(2015, 8, 31)).Where(x => choosenList2next.Contains(x.ProgramCode)).ToList();

            ViewBag.realProgramnext = progamList2next;
            List <ViewModelProgram> progamList1next = _iProgramService.GetAllProgram().Where(x => choosenList2next.Contains(x.ProgramCode)).ToList();

            ViewBag.originalProgramnext = progamList1next;

            // predict 31/08/2015
            var result = _iMakeScheduleService.makeSchedule(progamList2next, new DateTime(2015, 8, 31, 10, 30, 0), new DateTime(2015, 8, 31));

            ViewBag.predictResult = result;

            // real result 31/08/2015
            var realResult = _iProgramService.GetProgramQuantity(progamList2next, new DateTime(2015, 8, 31));

            ViewBag.realresult = realResult;

            // compare
            var compare = new List <ViewModelProgram>();

            for (int i = 0; i < result.Count(); i++)
            {
                if (result[i].quantityList.FirstOrDefault().NoTimes == realResult[i].quantityList.FirstOrDefault().NoTimes)
                {
                    var temp = new ViewModelProgram();
                    temp.ProgramCode  = result[i].ProgramCode;
                    temp.Name         = result[i].Name;
                    temp.quantityList = new List <ViewModelQuantity>();
                    ViewModelQuantity a1 = new ViewModelQuantity()
                    {
                        NoTimes  = result[i].quantityList.FirstOrDefault().NoTimes,
                        quantity = result[i].quantityList.FirstOrDefault().quantity - realResult[i].quantityList.FirstOrDefault().quantity
                    };
                    temp.quantityList.Add(a1);
                    temp.quantityList.Add(result[i].quantityList.FirstOrDefault());
                    temp.quantityList.Add(realResult[i].quantityList.FirstOrDefault());
                    compare.Add(temp);
                }
            }
            ViewBag.compare = compare;

            // use the total real schedule to predict


            return(View());
        }
示例#2
0
 public void InsertOrUpdate(ViewModelProgram vProgram)
 {
     try
     {
         _iProgramRepository.InsertOrUpdate(Mapper.Map <ViewModelProgram, Program>(vProgram));
         _iProgramRepository.Save();
     }
     catch (Exception e)
     {
     }
 }
示例#3
0
 public ActionResult Delete(int id, ViewModelProgram collection)
 {
     try
     {
         // TODO: Add delete logic here
         var result = _iProgramService.Delete(collection);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
示例#4
0
 public ActionResult Edit(int id, ViewModelProgram collection)
 {
     try
     {
         // TODO: Add update logic here
         _iProgramService.InsertOrUpdate(collection);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
示例#5
0
 public ActionResult Create(ViewModelProgram collection)
 {
     try
     {
         // TODO: Add insert logic here
         _iProgramService.AddProgram(collection);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
示例#6
0
 public ViewModelProgram Delete(ViewModelProgram vProgram)
 {
     try
     {
         _iProgramRepository.Delete(vProgram.Id);
         _iProgramRepository.Save();
         return(vProgram);
     }
     catch (Exception e)
     {
         return(null);
     }
 }
示例#7
0
        public List <ViewModelProgram> FindMaxQuantity(List <ViewModelProgram> programlist)
        {
            List <ViewModelProgram> result = new List <ViewModelProgram>();
            var temp             = programlist;
            ViewModelProgram max = new ViewModelProgram();

            foreach (var pro in programlist)
            {
                max.ProgramCode  = pro.ProgramCode;
                max.ProductName  = pro.ProductName;
                max.quantityList = new List <ViewModelQuantity>();
                foreach (var index in pro.quantityList)
                {
                    if (max.quantityList.Count() == 0)
                    {
                        max.quantityList.Add(index);
                    }
                    else
                    {
                        if (max.quantityList.FirstOrDefault().quantity < index.quantity)
                        {
                            max.quantityList.FirstOrDefault().quantity = index.quantity;
                            max.quantityList.FirstOrDefault().NoTimes  = index.NoTimes;
                        }
                    }
                }
            }
            result.Add(max);
            ViewModelProgram a = temp.Find(x => x.ProgramCode == max.ProgramCode);

            temp.Remove(a);
            if (temp.Count() != 0)
            {
                var result2 = FindMaxQuantity(temp);
                return(result.Concat(result2).ToList());
            }
            else
            {
                return(result);
            }
        }
示例#8
0
        public List <ViewModelProgram> randomAlgrithm(List <ViewModelProgram> programlist, DateTime totaltime)
        {
            while (true)
            {
                //Guid seed = new Guid("0f8fad5b-d9cb-469f-a165-70867728950e");
                Random a = new Random();

                List <ViewModelProgram> result = new List <ViewModelProgram>();
                foreach (var item in programlist)
                {
                    ViewModelProgram program1 = new ViewModelProgram();
                    double           index    = a.NextDouble() * 4.0;
                    program1.Name         = item.Name;
                    program1.ProgramCode  = item.ProgramCode;
                    program1.quantityList = new List <ViewModelQuantity>();
                    program1.quantityList.Add(item.quantityList.ElementAt(Convert.ToInt32(index)));
                    program1.Duration = item.Duration;
                    result.Add(program1);
                }
                int totalminute = 0;
                foreach (var item in result)
                {
                    var      no       = item.quantityList.FirstOrDefault().NoTimes;
                    DateTime dateTime = DateTime.ParseExact(item.Duration, "h:m:s", CultureInfo.InvariantCulture);
                    totalminute = dateTime.Minute * no;
                }

                if (totalminute < totaltime.Hour * 60 + totaltime.Minute + 1)
                {
                    if (checkValidResult(result))
                    {
                        return(result);
                    }
                }
            }
        }
示例#9
0
 public void AddProgram(ViewModelProgram vProgram)
 {
     _iProgramRepository.InsertOrUpdate(Mapper.Map <ViewModelProgram, Program>(vProgram));
     _iProgramRepository.Save();
 }
        public MainWindow()
        {
            InitializeComponent();

            _viewModel = (ViewModelProgram)DataContext;
        }