public ReservationView GetUnusedMachines(int ServiceID) { ReservationView viewmodel = new ReservationView(); List <Machine> machines = db.Machines.Include(m => m.Reservations).Where(m => m.ServiceID == ServiceID && m.InUse == false).ToList(); List <Machine> active = new List <Machine>(); List <Reservation> reservations = db.Reservations.Include(_res => _res.Machines).Where(_res => _res.SID == ServiceID && _res.Finished == false).ToList(); reservations.ForEach(_res => { WashTime time = db.WashTimes.FirstOrDefault(wt => wt.Id == _res.TimeID); DateTime date = _res.Date + time.Length; DateTime max = _res.Date + time.Length + new TimeSpan(0, 15, 0); if (date <= DateTime.Now && max > DateTime.Now) { _res.Active = true; machines.ForEach(_m => { active.Add(_m); }); } }); active.ForEach(m => machines.Remove(m)); viewmodel.Machines = machines; viewmodel.WashTimes = db.WashTimes.Where(wt => wt.ServiceID == ServiceID).ToList(); return(viewmodel); }
public Boolean BookTime(WashTimeViewModel vm) { if (vm.Time > DateTime.Now) { WashTime currentbooking = db.WashTimes.Find(vm.ID); if (currentbooking == null) { return(false); } currentbooking.IsBooked = true; currentbooking.RoomNumber = vm.RoomNumber; db.Entry(currentbooking).State = EntityState.Modified; try { db.SaveChangesAsync(); return(true); } catch (Exception) { return(false); } } else { return(false); } }
public ActionResult WashTimePicked(int washid, int resid) { Reservation r = Service.Service.FindReservation(resid); WashTime washTime = Service.Service.FindWashTime(washid); Service.Service.AddWashTimeReservation(r, washTime); return(RedirectToAction("Reservation", new { userid = r.LaundryUser })); }
public WashTimeViewModel(WashTime washTime) { ID = washTime.ID; Time = washTime.Time; TimeString = Time.ToShortTimeString(); IsBooked = washTime.IsBooked; Machine = washTime.Machine; RoomNumber = washTime.RoomNumber; }
/// <inheritdoc/> public string ToDelimitedString() { CultureInfo culture = CultureInfo.CurrentCulture; return(string.Format( culture, StringHelper.StringFormatSequence(0, 38, Configuration.FieldSeparator), Id, CycleStartTime.HasValue ? CycleStartTime.Value.ToString(Consts.TimeFormatPrecisionSecond, culture) : null, CycleCount.HasValue ? CycleCount.Value.ToString(Consts.NumericFormat, culture) : null, TempMax?.ToDelimitedString(), TempMin?.ToDelimitedString(), LoadNumber.HasValue ? LoadNumber.Value.ToString(Consts.NumericFormat, culture) : null, ConditionTime?.ToDelimitedString(), SterilizeTime?.ToDelimitedString(), ExhaustTime?.ToDelimitedString(), TotalCycleTime?.ToDelimitedString(), DeviceStatus?.ToDelimitedString(), CycleStartDateTime.HasValue ? CycleStartDateTime.Value.ToString(Consts.DateTimeFormatPrecisionSecond, culture) : null, DryTime?.ToDelimitedString(), LeakRate?.ToDelimitedString(), ControlTemperature?.ToDelimitedString(), SterilizerTemperature?.ToDelimitedString(), CycleCompleteTime.HasValue ? CycleCompleteTime.Value.ToString(Consts.TimeFormatPrecisionSecond, culture) : null, UnderTemperature?.ToDelimitedString(), OverTemperature?.ToDelimitedString(), AbortCycle?.ToDelimitedString(), Alarm?.ToDelimitedString(), LongInChargePhase?.ToDelimitedString(), LongInExhaustPhase?.ToDelimitedString(), LongInFastExhaustPhase?.ToDelimitedString(), Reset?.ToDelimitedString(), OperatorUnload?.ToDelimitedString(), DoorOpen?.ToDelimitedString(), ReadingFailure?.ToDelimitedString(), CycleType?.ToDelimitedString(), ThermalRinseTime?.ToDelimitedString(), WashTime?.ToDelimitedString(), InjectionRate?.ToDelimitedString(), ProcedureCode?.ToDelimitedString(), PatientIdentifierList != null ? string.Join(Configuration.FieldRepeatSeparator, PatientIdentifierList.Select(x => x.ToDelimitedString())) : null, AttendingDoctor?.ToDelimitedString(), DilutionFactor?.ToDelimitedString(), FillTime?.ToDelimitedString(), InletTemperature?.ToDelimitedString() ).TrimEnd(Configuration.FieldSeparator.ToCharArray())); }
public Boolean CancelBooking(WashTimeViewModel vm) { WashTime currentbooking = db.WashTimes.Find(vm.ID); if (currentbooking == null) { return(false); } currentbooking.IsBooked = false; currentbooking.RoomNumber = 0; db.Entry(currentbooking).State = EntityState.Modified; try { db.SaveChanges(); return(true); } catch (Exception) { return(false); } }
protected override void Seed(ModelsAndContext.Context.VaskeriContext context) { // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. // Services WasherService service1 = new WasherService() { Id = 1, Name = "Vaskeri Tomsen", DaytimeOnly = true, AllowedMaxReservations = 2 }; WasherService service2 = new WasherService() { Id = 2, Name = "Johns Vaskeri", DaytimeOnly = false, AllowedMaxReservations = 1 }; // Machines Machine machine1 = new Machine() { Id = 1, ServiceID = 1, Number = 1, StartTime = DateTime.Now, EndTime = DateTime.Now.AddMinutes(1), Type = MachineType.WASHER, InUse = true }; Machine machine2 = new Machine() { Id = 2, ServiceID = 1, Number = 2, Type = MachineType.WASHER, InUse = false }; Machine machine3 = new Machine() { Id = 3, ServiceID = 1, Number = 3, StartTime = DateTime.Now, EndTime = DateTime.Now.AddMinutes(1), Type = MachineType.DRYER, InUse = true }; Machine machine4 = new Machine() { Id = 4, ServiceID = 1, Number = 4, Type = MachineType.DRYER, InUse = false }; Machine machine5 = new Machine() { Id = 5, ServiceID = 1, Number = 5, Type = MachineType.DRYER, InUse = false }; Machine machine6 = new Machine() { Id = 6, ServiceID = 2, Number = 1, Type = MachineType.WASHER, InUse = false }; Machine machine7 = new Machine() { Id = 7, ServiceID = 2, Number = 2, Type = MachineType.DRYER, InUse = false }; Machine machine8 = new Machine() { Id = 8, ServiceID = 2, Number = 3, Type = MachineType.WASHER, InUse = false }; // Vasketider WashTime washTime1 = new WashTime() { Id = 1, ServiceID = 1, Description = "Morgen (6-9)", Length = new TimeSpan(6, 0, 0) }; WashTime washTime2 = new WashTime() { Id = 2, ServiceID = 1, Description = "Formiddag (9-12)", Length = new TimeSpan(9, 0, 0) }; WashTime washTime3 = new WashTime() { Id = 3, ServiceID = 1, Description = "Eftermiddag(12-15)", Length = new TimeSpan(12, 0, 0) }; WashTime washTime4 = new WashTime() { Id = 4, ServiceID = 2, Description = "Morgen (7-10)", Length = new TimeSpan(7, 0, 0) }; WashTime washTime5 = new WashTime() { Id = 5, ServiceID = 2, Description = "Formiddag (10-12)", Length = new TimeSpan(10, 0, 0) }; WashTime washTime6 = new WashTime() { Id = 6, ServiceID = 2, Description = "Eftermiddag(12-15)", Length = new TimeSpan(12, 0, 0) }; WashTime washTime7 = new WashTime() { Id = 7, ServiceID = 2, Description = "Aften (15-20)", Length = new TimeSpan(15, 0, 0) }; // Machine programs WashingProgram washingProgram1 = new WashingProgram() { Id = 1, ServiceID = 1, Name = "Favoritvask 1", Length = 146, ElectricityUsed = 5f, Temperatur = 40, WaterUsed = 25f }; WashingProgram washingProgram2 = new WashingProgram() { Id = 2, ServiceID = 1, Name = "Uldvask", Length = 180, ElectricityUsed = 4f, Temperatur = 30, WaterUsed = 30f }; WashingProgram washingProgram3 = new WashingProgram() { Id = 3, ServiceID = 1, Name = "Turbovask", Length = 90, ElectricityUsed = 10f, Temperatur = 60, WaterUsed = 40f }; WashingProgram washingProgram4 = new WashingProgram() { Id = 4, ServiceID = 2, Name = "Farvevask", Length = 120, ElectricityUsed = 7f, Temperatur = 60, WaterUsed = 40f }; WashingProgram washingProgram5 = new WashingProgram() { Id = 5, ServiceID = 2, Name = "Turbovask", Length = 90, ElectricityUsed = 5f, Temperatur = 60, WaterUsed = 20f }; WashingProgram washingProgram6 = new WashingProgram() { Id = 6, ServiceID = 1, Name = "1 Minute", Length = 1, ElectricityUsed = 5f, Temperatur = 60, WaterUsed = 20f }; WashingProgram washingProgram7 = new WashingProgram() { Id = 7, ServiceID = 2, Name = "1 Minute", Length = 1, ElectricityUsed = 5f, Temperatur = 60, WaterUsed = 20f }; DryerProgram dryerProgram1 = new DryerProgram() { Id = 1, ServiceID = 1, Name = "Skabstoert", Length = 150, Temperatur = 55, ElectricityUsed = 5f }; DryerProgram dryerProgram2 = new DryerProgram() { Id = 2, ServiceID = 1, Name = "Oerken", Length = 125, Temperatur = 75, ElectricityUsed = 8f }; DryerProgram dryerProgram3 = new DryerProgram() { Id = 3, ServiceID = 2, Name = "Skabstoert+", Length = 150, Temperatur = 70, ElectricityUsed = 5f }; DryerProgram dryerProgram4 = new DryerProgram() { Id = 4, ServiceID = 2, Name = "QuickDry", Length = 45, Temperatur = 80, ElectricityUsed = 10f }; DryerProgram dryerProgram5 = new DryerProgram() { Id = 5, ServiceID = 1, Name = "1 Minute", Length = 1, Temperatur = 80, ElectricityUsed = 10f }; DryerProgram dryerProgram6 = new DryerProgram() { Id = 5, ServiceID = 2, Name = "1 Minute", Length = 1, Temperatur = 80, ElectricityUsed = 10f }; // Users User user1 = new User() { Id = 1, ServiceID = 1, Username = "******", Password = "******", Alias = "John" }; User user2 = new User() { Id = 2, ServiceID = 1, Username = "******", Password = "******", Alias = "T00mz" }; User user3 = new User() { Id = 3, ServiceID = 2, Username = "******", Password = "******", Alias = "Anna" }; // Reservations FINISHED List <Machine> res1m = new List <Machine> { machine1, machine4 }; List <Machine> res2m = new List <Machine> { machine2 }; Reservation reservation1 = new Reservation() { Id = 1, UserID = 1, SID = 1, Machines = res1m, Date = DateTime.Now, TimeID = 2, Finished = true }; Reservation reservation2 = new Reservation() { Id = 2, UserID = 2, SID = 1, Machines = res2m, Date = DateTime.Now, TimeID = 1, Finished = true }; List <WashingProgram> wps1 = new List <WashingProgram>() { washingProgram1 }; List <WashingProgram> wps2 = new List <WashingProgram>() { washingProgram5 }; List <DryerProgram> dps1 = new List <DryerProgram>() { dryerProgram2 }; DoneReservation done1 = new DoneReservation() { Id = 1, UID = 1, Paid = true, Reservation = reservation1, DryerProgs = dps1, WashingProgs = wps1 }; DoneReservation done2 = new DoneReservation() { Id = 2, UID = 2, Paid = true, Reservation = reservation2, WashingProgs = wps2 }; // Add to Database context.WasherServices.AddOrUpdate(s => s.Id, service1); context.WasherServices.AddOrUpdate(s => s.Id, service2); context.Machines.AddOrUpdate(m => m.Id, machine1); context.Machines.AddOrUpdate(m => m.Id, machine2); context.Machines.AddOrUpdate(m => m.Id, machine3); context.Machines.AddOrUpdate(m => m.Id, machine4); context.Machines.AddOrUpdate(m => m.Id, machine5); context.Machines.AddOrUpdate(m => m.Id, machine6); context.Machines.AddOrUpdate(m => m.Id, machine7); context.Machines.AddOrUpdate(m => m.Id, machine8); context.WashTimes.AddOrUpdate(wt => wt.Id, washTime1); context.WashTimes.AddOrUpdate(wt => wt.Id, washTime2); context.WashTimes.AddOrUpdate(wt => wt.Id, washTime3); context.WashTimes.AddOrUpdate(wt => wt.Id, washTime4); context.WashTimes.AddOrUpdate(wt => wt.Id, washTime5); context.WashTimes.AddOrUpdate(wt => wt.Id, washTime6); context.WashTimes.AddOrUpdate(wt => wt.Id, washTime7); context.WashingPrograms.AddOrUpdate(wp => wp.Id, washingProgram1); context.WashingPrograms.AddOrUpdate(wp => wp.Id, washingProgram2); context.WashingPrograms.AddOrUpdate(wp => wp.Id, washingProgram3); context.WashingPrograms.AddOrUpdate(wp => wp.Id, washingProgram4); context.WashingPrograms.AddOrUpdate(wp => wp.Id, washingProgram5); context.WashingPrograms.AddOrUpdate(wp => wp.Id, washingProgram6); context.WashingPrograms.AddOrUpdate(wp => wp.Id, washingProgram7); context.DryerPrograms.AddOrUpdate(dp => dp.Id, dryerProgram1); context.DryerPrograms.AddOrUpdate(dp => dp.Id, dryerProgram2); context.DryerPrograms.AddOrUpdate(dp => dp.Id, dryerProgram3); context.DryerPrograms.AddOrUpdate(dp => dp.Id, dryerProgram4); context.DryerPrograms.AddOrUpdate(dp => dp.Id, dryerProgram5); context.DryerPrograms.AddOrUpdate(dp => dp.Id, dryerProgram6); context.Users.AddOrUpdate(s => s.Id, user1); context.Users.AddOrUpdate(s => s.Id, user2); context.Users.AddOrUpdate(s => s.Id, user3); context.Reservations.AddOrUpdate(r => r.Id, reservation1); context.Reservations.AddOrUpdate(r => r.Id, reservation2); context.DoneReservations.AddOrUpdate(dr => dr.Id, done1); context.DoneReservations.AddOrUpdate(dr => dr.Id, done2); }
public static void AddWashTimeReservation(Reservation reservation, WashTime washTime) { reservation.WashTime1 = washTime; Db.SaveChanges(); }
private void buttonBook_Click(object sender, EventArgs e) { DateTime getPickerTime; string getWashTime, getWaterTime, getDay, getTime, getStartTime; getWashTime = textBoxWashTime.Text; getWaterTime = textBoxWaterTime.Text; if (getWashTime == "" || getWaterTime == "") { MessageBox.Show("数据输入不完整,请填完整!"); textBoxWashTime.Text = ""; textBoxWaterTime.Text = ""; return; } int WashTime, WaterTime; float x = float.Parse(getWashTime); WashTime = Convert.ToInt32(Math.Round(x)); //Math在System namespace下 float y = float.Parse(getWaterTime); WaterTime = Convert.ToInt32(Math.Round(y)); //若输入小数,将parse为0,将round 四舍六入五凑偶 至最近整数 if (WashTime > 120 || WashTime < 0 || WaterTime > 120 || WaterTime < 0) //洗衣时间最长设置120min,脱水时间最长120min { MessageBox.Show("时间设置不规范!洗衣时间最长120min,脱水时间最长120min!"); textBoxWashTime.Text = ""; textBoxWaterTime.Text = ""; return; } else if (WashTime + WaterTime == 0) { MessageBox.Show("洗衣时间和脱水时间不能都为零!"); textBoxWashTime.Text = ""; textBoxWaterTime.Text = ""; return; } getPickerTime = dateTimePicker1.Value; getDay = DateTime.Now.ToString("yyyy-MM-dd"); getTime = getPickerTime.ToString("HH:mm:ss"); //hh小写不可以!否则12小时制 getStartTime = getDay + " " + getTime; DateTime StartTime = Convert.ToDateTime(getStartTime); //StartTime是设置当日开始时间 DateTime EndTime = new DateTime(2017, 5, 1, 0, 0, 0); if (StartTime <= DateTime.Now) { MessageBox.Show("不能选择过去的时刻!"); dateTimePicker1.Value = new DateTime(2017, 5, 1, 0, 0, 0); return; } EndTime = StartTime.AddMinutes(WashTime + WaterTime); DateTime dt; dt = DateTime.Now.Date.AddDays(1);// 格式化明日时间 00:00:00 if (EndTime > dt) { MessageBox.Show("不能选择结束时间在第二天!"); dateTimePicker1.Value = new DateTime(2017, 5, 1, 0, 0, 0); textBoxWashTime.Text = ""; textBoxWaterTime.Text = ""; return; } //若还往下执行,必然所有数据都设置好 if (listViewShow.Items.Count == 0) { if (labelWashState.Text != "空闲") //当前在洗既有可能是预约的洗衣,也有可能是非预约的洗衣。也有可能是预约等待状态! { if (ZaiXiEndTime > DateTime.Now) //小于仅在预约等待状态cancel时 { if (ZaiXiEndTime.AddMinutes(3) > StartTime) //仅当此才不能预约 { MessageBox.Show("您预约的时间太早或与结束时间差不足3min!当前洗衣结束时间为" + ZaiXiEndTime.ToLongTimeString()); dateTimePicker1.Value = new DateTime(2017, 5, 1, 0, 0, 0); textBoxWashTime.Text = ""; textBoxWaterTime.Text = ""; return; } } } } else //如果当前 listViewShow.Items.Count > 0 { int i = 0; while (StartTime > Convert.ToDateTime(listViewShow.Items[i].SubItems[1].Text)) { i++; if (i == listViewShow.Items.Count) { break; //此时插入StartTime值为最大 } } //找到第一个不小于StartTime的Item的Index i //预留5分钟???? if (i == 0) //如果应该插入在预约记录第一行 { if (labelWashState.Text != "空闲") //如果是预约等待状态,ZaiXiEndTime只能是前一条预约记录的;如果在洗,不一定,但无影响。 { if (ZaiXiEndTime > DateTime.Now) { if (ZaiXiEndTime.AddMinutes(3) > StartTime) //仅当此才不能预约 { MessageBox.Show("您预约的时间太早或与结束时间差不足3min!当前洗衣结束时间为" + ZaiXiEndTime.ToLongTimeString()); //时间为??? dateTimePicker1.Value = new DateTime(2017, 5, 1, 0, 0, 0); textBoxWashTime.Text = ""; textBoxWaterTime.Text = ""; return; } } } if (EndTime.AddMinutes(3) > Convert.ToDateTime(listViewShow.Items[i].SubItems[1].Text)) //如果空闲且... { MessageBox.Show("结束时间和他人预约开始时间冲突或不足3min!请缩短洗衣时间!"); textBoxWashTime.Text = ""; textBoxWaterTime.Text = ""; return; } /* if (EndTime > Convert.ToDateTime(listViewShow.Items[i].SubItems[1].Text)) * { * MessageBox.Show("结束时间和他人预约开始时间冲突!请缩短洗衣时间!"); * textBoxWashTime.Text = ""; * textBoxWaterTime.Text = ""; * return; * } */ } else if (i == listViewShow.Items.Count) { if (StartTime < Convert.ToDateTime(listViewShow.Items[i - 1].SubItems[2].Text).AddMinutes(3)) { MessageBox.Show("开始时间和他人预约结束时间冲突或不足3min!请重新设置!"); dateTimePicker1.Value = new DateTime(2017, 5, 1, 0, 0, 0); return; } } else { if (EndTime.AddMinutes(3) > Convert.ToDateTime(listViewShow.Items[i].SubItems[1].Text)) { MessageBox.Show("结束时间和他人预约开始时间冲突或不足3min!请缩短洗衣时间!"); textBoxWashTime.Text = ""; textBoxWaterTime.Text = ""; return; } if (StartTime < Convert.ToDateTime(listViewShow.Items[i - 1].SubItems[2].Text).AddMinutes(3)) { MessageBox.Show("开始时间和他人预约结束时间冲突或不足3min!请重新设置!"); dateTimePicker1.Value = new DateTime(2017, 5, 1, 0, 0, 0); return; } } } string stTime = StartTime.ToString(); string edTime = EndTime.ToString(); OleDbConnection strConnection = new OleDbConnection("Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" + strSys + "\\mydb1.accdb"); string sql = "insert into biao1 values(#" + stTime + "#,#" + edTime + "#," + WashTime.ToString() + "," + WaterTime.ToString() + " )"; OleDbCommand cmd = new OleDbCommand(sql, strConnection); //创建命令 try { strConnection.Open(); cmd.ExecuteNonQuery(); MessageBox.Show("预约成功!"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } strConnection.Close(); ReadFromDB(); createYuyueData(); //checkTimeAtStart(); }