Wymiary importWymiar(SqlCeConnection oldConnection, int wymiarId) { Log.WriteInfo("Importing wymiar id={0}", wymiarId); SqlCeCommand cmd = new SqlCeCommand(); cmd.Connection = oldConnection; cmd.CommandText = "SELECT DateTime, NaCzczo,Klatka,Pas,Udo,Weight,RightBiceps,LeftBiceps FROM Wymiar WHERE ID=" + wymiarId; var reader = cmd.ExecuteReader(); Log.WriteInfo("wymiar reader executed"); if (reader.Read()) { Log.WriteInfo("Wymiar exists"); Wymiary wymiary = new Wymiary(); wymiary.DateTime = getDateTime(reader, "DateTime").Value; wymiary.IsNaCzczo = getBoolean(reader, "NaCzczo").Value; wymiary.Klatka = getFloat(reader, "Klatka").Value; wymiary.LeftBiceps = getFloat(reader, "LeftBiceps").Value; wymiary.LeftUdo = wymiary.RightUdo = getFloat(reader, "Udo").Value; wymiary.Pas = getFloat(reader, "Pas").Value; wymiary.RightBiceps = getFloat(reader, "RightBiceps").Value; wymiary.Weight = getFloat(reader, "Weight").Value; wymiary.Save(); Log.WriteInfo("Wymiar saved"); return(wymiary); } return(null); }
public Pralka(Pralka CopyPralka) { WymiaryPralki = new Wymiary(CopyPralka.WymiaryPralki); ZuzycieMedia = new Zuzycie(CopyPralka.ZuzycieMedia); DanePralki = new DaneTechniczne(CopyPralka.DanePralki); KolorObudowy = CopyPralka.KolorObudowy; ProgramPracy = CopyPralka.ProgramPracy; NazwaProgramu = CopyPralka.NazwaProgramu; CzyPodlaczonaDoPradu = CopyPralka.CzyPodlaczonaDoPradu; CzyWlaczona = CopyPralka.CzyWlaczona; CzyOdkreconaWoda = CopyPralka.CzyOdkreconaWoda; }
public Pralka(KolorPralki NewKolorPralki, NazwaProgramyPrania NewNazwaProgramyPrania, int wysokosc, int szerokosc, int glebokosc) { WymiaryPralki = new Wymiary(wysokosc, szerokosc, glebokosc); ZuzycieMedia = new Zuzycie(44, 0.80); DanePralki = new DaneTechniczne(36, 1600, 10); KolorObudowy = NewKolorPralki; ProgramPracy = (int)NewNazwaProgramyPrania; NazwaProgramu = NewNazwaProgramyPrania; CzyPodlaczonaDoPradu = false; CzyWlaczona = false; CzyOdkreconaWoda = false; }
public Pralka() { WymiaryPralki = new Wymiary(); ZuzycieMedia = new Zuzycie(); DanePralki = new DaneTechniczne(); KolorObudowy = 0; ProgramPracy = 0; NazwaProgramu = 0; CzyPodlaczonaDoPradu = false; CzyWlaczona = false; CzyOdkreconaWoda = false; }
public virtual object Clone() { SizeEntryDTO sizeEntry = new SizeEntryDTO(); sizeEntry.Comment = Comment; sizeEntry.ReportStatus = ReportStatus; sizeEntry.Name = Name; if (Wymiary != null) { sizeEntry.Wymiary = Wymiary.Clone(false); } return(sizeEntry); }
public IList <MeasurementsTimeReportResultItem> ReportMeasurementsTime(ReportMeasurementsTimeParams param) { if (!SecurityInfo.Licence.IsPremium) { throw new LicenceException("Reports are available in Premium or Instructor account only"); } SizeEntry entry = null; TrainingDay day = null; Wymiary wymiary = null; //var query = Session.QueryOver<TrainingDay>(() => day). // JoinAlias(x => day.Objects, () => entry). // JoinAlias(x => entry.Entries, () => item). // JoinAlias(x => item.Series, () => set); var query = Session.QueryOver <SizeEntry>(() => entry). JoinAlias(x => entry.TrainingDay, () => day). JoinAlias(x => entry.Wymiary, () => wymiary) .Where(x => entry.Status == EntryObjectStatus.Done);//reports are generated only for done entries; var dbMyProfile = Session.Load <Profile>(SecurityInfo.SessionData.Profile.GlobalId); var dbProfile = dbMyProfile; if (param.UserId.HasValue) { dbProfile = Session.Get <Profile>(param.UserId.Value); } if (param.CustomerId != null && dbProfile.GlobalId != SecurityInfo.SessionData.Profile.GlobalId) { throw new CrossProfileOperationException("This customer doesn't belong to your profile"); } if (ServiceHelper.IsPrivateCalendar(dbProfile, dbMyProfile)) { return(new List <MeasurementsTimeReportResultItem>()); } query = query.Where(x => day.Profile == dbProfile); if (param.CustomerId.HasValue) { Customer customer = Session.Get <Customer>(param.CustomerId.Value); if (customer.Profile != dbProfile) { throw new CrossProfileOperationException("This customer doesn't belong to your profile"); } query = query.Where(x => day.Customer == customer); } else { query = query.Where(x => day.Customer == null); } if (!param.UseAllEntries) { query = query.Where(x => entry.ReportStatus == ReportStatus.ShowInReport); } if (param.StartDate.HasValue) { query = query.Where(x => day.TrainingDate >= param.StartDate); } if (param.EndDate.HasValue) { query = query.Where(x => day.TrainingDate <= param.EndDate); } //var purposeOr = Restrictions.Disjunction(); //foreach (var item in param.Items) //{ // if (item == MeasurementItem.Weight) // { // purposeOr.Add<SizeEntry>(x => item.Exercise.GlobalId == exerciseId); // } //} //query = query.And(purposeOr); //query = query.Where(x=>set.Weight>0).OrderBy(x => day.TrainingDate).Asc.Select(x => new Tuple<double,DateTime,Guid>(set.Weight.Value, day.TrainingDate, x.Exercise.GlobalId )); //query = query.OrderBy(x => day.TrainingDate).Asc // .SelectList(l => // { // foreach (var item in param.Items) // { // l = l.Select(Projections.Max(item.ToString())); // } // return l.SelectGroup(x => day.TrainingDate); // }); //query = query.OrderBy(x => day.TrainingDate).Asc // .SelectList(l => // { // l = l.SelectMax(x => x.Wymiary); // return l.SelectGroup(x => day.TrainingDate); // }); query = query.OrderBy(x => day.TrainingDate).Asc .SelectList(l => l.SelectMax(x => wymiary.Height) .SelectMax(x => wymiary.Klatka) .SelectMax(x => wymiary.RightBiceps) .SelectMax(x => wymiary.RightForearm) .SelectMax(x => wymiary.RightUdo) .SelectMax(x => wymiary.LeftBiceps) .SelectMax(x => wymiary.LeftForearm) .SelectMax(x => wymiary.LeftUdo) .SelectMax(x => wymiary.Pas) .SelectMax(x => wymiary.Weight) .SelectGroup(x => day.TrainingDate) .Select(x => x.GlobalId)); //Select(x => set.Weight.Value,x=> day.TrainingDate,x=> x.Exercise.GlobalId); var result1 = query.List <object[]>(); //MeasurementsTimeReportResultItem //var result=result1.Select(x => new Tuple<DateTime, WymiaryDTO>((DateTime) x[10], new WymiaryDTO() // { // Height = (float) x[0], // Klatka = (float) x[1], // RightBiceps = (float) x[2], // RightForearm = (float) x[3], // RightUdo = (float) x[4], // LeftBiceps = (float) x[5], // LeftForearm = (float) x[6], // LeftUdo = (float) x[7], // Pas = (float) x[8], // Weight = (float) x[9], // })).ToList(); var result = result1.Select(x => new MeasurementsTimeReportResultItem() { DateTime = (DateTime)x[10], Wymiary = new WymiaryDTO() { Height = (decimal)x[0], Klatka = (decimal)x[1], RightBiceps = (decimal)x[2], RightForearm = (decimal)x[3], RightUdo = (decimal)x[4], LeftBiceps = (decimal)x[5], LeftForearm = (decimal)x[6], LeftUdo = (decimal)x[7], Pas = (decimal)x[8], Weight = (decimal)x[9], }, SizeEntryId = (Guid)x[11] }).ToList(); return(result); }
SizeEntry AddTrainingDaySize(Profile profile, Customer customer, DateTime date, Wymiary wymiary, ReportStatus reportStatus = ReportStatus.ShowInReport) { var trainingDay = new TrainingDay(date); trainingDay.Customer = customer; trainingDay.Profile = profile; var entry = new SizeEntry(); entry.Wymiary = wymiary; entry.ReportStatus = reportStatus; trainingDay.AddEntry(entry); insertToDatabase(trainingDay); return(entry); }
public Wymiary(Wymiary CopyWymiar) { Wysokosc = CopyWymiar.Wysokosc; Szerokosc = CopyWymiar.Szerokosc; Glebokosc = CopyWymiar.Glebokosc; }
public CustomerDTO SaveCustomer(CustomerDTO customerDto) { Log.WriteWarning("SaveCustomer:Username={0},GlobalId={1}", SecurityInfo.SessionData.Profile.UserName, customerDto.GlobalId); if (!customerDto.IsNew && !SecurityInfo.Licence.IsInstructor) { throw new LicenceException("This feature is allowed for Instructor account"); } var db = customerDto.Map <Customer>(); using (var trans = Session.BeginSaveTransaction()) { Profile dbProfile = Session.Load <Profile>(SecurityInfo.SessionData.Profile.GlobalId); Picture oldPicture = null; Wymiary oldWymiary = null; Customer oldCustomer = null; Address oldAddress = null; CustomerSettings oldSettings = null; bool oldIsVirtual; //if (!customerDto.IsNew) //{ // db = Session.Get<Customer>(customerDto.GlobalId); // oldPicture = db.Picture; // oldWymiary = db.Wymiary; // oldSettings = db.Settings; // oldIsVirtual = db.IsVirtual; // Mapper.Map(customerDto, db); // if(oldIsVirtual!=db.IsVirtual) // { // throw new InvalidOperationException("Cannot change IsVirtual for existing customer"); // } //} //else //{ // db = customerDto.Map<Customer>(); // db.CreationDate = Configuration.TimerService.UtcNow; // db.Settings = new CustomerSettings(); // db.Profile = dbProfile; //} if (db.IsNew) { db.CreationDate = Configuration.TimerService.UtcNow; db.Settings = new CustomerSettings(); } else { oldCustomer = Session.QueryOver <Customer>().Where(x => x.GlobalId == db.GlobalId) .Fetch(x => x.Address).Eager .Fetch(x => x.Wymiary).Eager .Fetch(x => x.Settings).Eager .Fetch(x => x.Picture).Eager .SingleOrDefault(); if (oldCustomer != null) { if (dbProfile != oldCustomer.Profile) { throw new CrossProfileOperationException("Cannot modify Customer for another user"); } oldPicture = oldCustomer.Picture; oldWymiary = oldCustomer.Wymiary; oldAddress = oldCustomer.Address; oldSettings = oldCustomer.Settings; oldIsVirtual = oldCustomer.IsVirtual; if (oldIsVirtual != db.IsVirtual) { throw new InvalidOperationException("Cannot change IsVirtual for existing customer"); } } } db.Profile = dbProfile; if (customerDto.ConnectedAccount != null) { Guid connectedAccountId = customerDto.ConnectedAccount.GlobalId; var connectedAccountExists = Session.QueryOver <Customer>().Where(x => x.Profile == dbProfile && x.GlobalId != db.GlobalId && x.ConnectedAccount.GlobalId == connectedAccountId ).RowCount(); if (connectedAccountExists > 0) { throw new AlreadyOccupiedException("Specified ConnectedAccount is already used"); } db.ConnectedAccount = Session.Get <Profile>(connectedAccountId); } else { db.ConnectedAccount = null; } if (db.Wymiary != null && db.Wymiary.IsEmpty) { Log.WriteVerbose("Wymiary is empty."); if (!db.Wymiary.IsNew && (oldWymiary == null || db.Wymiary.GlobalId != oldWymiary.GlobalId)) { Log.WriteInfo("Delete wymiary from db"); Session.Delete(db.Wymiary); } db.Wymiary = null; } if (oldWymiary != null && (db.Wymiary == null || oldWymiary.GlobalId != db.Wymiary.GlobalId)) { Session.Delete(oldWymiary); } if (db.Settings == null) { throw new ArgumentNullException("Settings cannot be null"); } if (db.Address != null && db.Address.IsEmpty) { Log.WriteVerbose("Address is empty."); if (!db.Address.IsNew && (oldAddress == null || db.Address.GlobalId != oldAddress.GlobalId)) { Log.WriteInfo("Delete Address from db"); Session.Delete(db.Address); } db.Address = null; } if (oldAddress != null && (db.Address == null || oldAddress.GlobalId != db.Address.GlobalId)) { Session.Delete(oldAddress); } if (oldSettings != null && oldSettings.GlobalId != db.Settings.GlobalId) { Session.Delete(oldSettings); } if (db.Birthday != null) { var reminderService = new ReminderService(Session, SecurityInfo, Configuration); reminderService.PrepareReminder(dbProfile, customerDto, db, oldCustomer, db.Birthday.Value.Date, ReminderType.Birthday, ReminderRepetitions.EveryYear); } else if (oldCustomer != null && oldCustomer.Reminder != null) { Session.Delete(oldCustomer.Reminder); oldCustomer.Reminder = null; dbProfile.DataInfo.ReminderHash = Guid.NewGuid(); } //remove old picture; PictureService pictureService = new PictureService(Session, SecurityInfo, Configuration); pictureService.DeletePictureLogic(oldPicture, customerDto.Picture); db = Session.Merge(db); dbProfile.DataInfo.CustomerHash = Guid.NewGuid(); if (db.Reminder != null) { db.Reminder.ConnectedObject = string.Format("CustomerDTO:{0}", db.GlobalId); Session.Update(db.Reminder); //TODO:Update datainfo for reminder } if (db.Settings.AutomaticUpdateMeasurements) { MeasurementsAutomaticUpdater.Update(Session, dbProfile, db, Configuration.TimerService.UtcNow); } trans.Commit(); return(db.Map <CustomerDTO>()); } }