private static RotorSetting GetRotorSetting(SqlDataReader rdr) { RotorSetting result = new RotorSetting(); result.Id = rdr.GetInt32(rdr.GetOrdinal("Id")); result.ParentId = rdr.GetInt32(rdr.GetOrdinal("DailySettingId")); result.RotorName = (RotorName)rdr.GetInt32(rdr.GetOrdinal("RotorName")); result.AlphabetRingPosition = rdr.GetInt32(rdr.GetOrdinal("AlphabetRingPosition")); result.NotchRingName = (NotchRingName)rdr.GetInt32(rdr.GetOrdinal("NotchRingName")); result.NotchRingPosition = rdr.GetInt32(rdr.GetOrdinal("NotchRingPosition")); return(result); }
private static string InsertRotorSettingSql(RotorSetting rs, int i, out SqlParameter[] parameters) { StringBuilder sb = new StringBuilder(); sb.AppendLine("INSERT INTO[dbo].[RotorSetting]"); sb.AppendLine(" ([Ordinal]"); sb.AppendLine(" ,[RotorName]"); sb.AppendLine(" ,[AlphabetRingPosition]"); sb.AppendLine(" ,[NotchRingName]"); sb.AppendLine(" ,[NotchRingPosition]"); sb.AppendLine(" ,[DailySettingId])"); sb.AppendLine(" VALUES"); sb.AppendLine(" (@Ordinal"); sb.AppendLine(" ,@RotorName"); sb.AppendLine(" ,@AlphabetRingPosition"); sb.AppendLine(" ,@NotchRingName"); sb.AppendLine(" ,@NotchRingPosition"); sb.AppendLine(" ,@DailySettingId);"); sb.AppendLine("SELECT @Id = SCOPE_IDENTITY()"); List <SqlParameter> p = new List <SqlParameter>(); p.Add(new SqlParameter { ParameterName = "@Id", DbType = System.Data.DbType.Int32, Direction = System.Data.ParameterDirection.Output }); p.Add(new SqlParameter { ParameterName = "@Ordinal", DbType = System.Data.DbType.Int32, Direction = System.Data.ParameterDirection.Input, Value = i }); p.Add(new SqlParameter { ParameterName = "@RotorName", DbType = System.Data.DbType.Int32, Direction = System.Data.ParameterDirection.Input, Value = rs.RotorName }); p.Add(new SqlParameter { ParameterName = "@AlphabetRingPosition", DbType = System.Data.DbType.Int32, Direction = System.Data.ParameterDirection.Input, Value = rs.AlphabetRingPosition }); p.Add(new SqlParameter { ParameterName = "@NotchRingName", DbType = System.Data.DbType.Int32, Direction = System.Data.ParameterDirection.Input, Value = rs.NotchRingName }); p.Add(new SqlParameter { ParameterName = "@NotchRingPosition", DbType = System.Data.DbType.Int32, Direction = System.Data.ParameterDirection.Input, Value = rs.NotchRingPosition }); p.Add(new SqlParameter { ParameterName = "@DailySettingId", DbType = System.Data.DbType.Int32, Direction = System.Data.ParameterDirection.Input, Value = rs.ParentId }); parameters = p.ToArray(); return(sb.ToString()); }
private static List <YearlySettings> GetYearlySettingsFromDb(SqlDataReader rdr) { List <YearlySettings> results = new List <YearlySettings>(); if (rdr.Read()) { YearlySettings result = GetYearlySettings(rdr); Dictionary <int, MonthlySettings> monthLookup = new Dictionary <int, MonthlySettings>(); Dictionary <int, Settings> dayLookup = new Dictionary <int, Settings>(); Dictionary <int, Wiring> wiringLookup = new Dictionary <int, Wiring>(); if (rdr.NextResult()) { while (rdr.Read()) { MonthlySettings monSet = GetMonthlySettings(rdr); monSet.ParentSettings = result; result.MonthlySettings.Add(monSet); monthLookup.Add(monSet.Id, monSet); } } if (rdr.NextResult()) { while (rdr.Read()) { Settings daySet = GetDailySettings(rdr); daySet.ParentSettings = monthLookup[daySet.ParentId]; monthLookup[daySet.ParentId].DailySettings.Add(daySet); dayLookup.Add(daySet.Id, daySet); } } if (rdr.NextResult()) { while (rdr.Read()) { RotorSetting rotSet = GetRotorSetting(rdr); rotSet.ParentSettings = dayLookup[rotSet.ParentId]; dayLookup[rotSet.ParentId].Rotors.Add(rotSet); } } if (rdr.NextResult()) { while (rdr.Read()) { Wiring wir = GetWiring(rdr); wir.ParentSettings = monthLookup[wir.ParentId]; monthLookup[wir.ParentId].Wiring = wir; wiringLookup.Add(wir.Id, wir); } } if (rdr.NextResult()) { while (rdr.Read()) { GetRotor(wiringLookup, rdr); } } if (rdr.NextResult()) { while (rdr.Read()) { GetNotch(wiringLookup, rdr); } } if (rdr.NextResult()) { while (rdr.Read()) { GetMove(wiringLookup, rdr); } } results.Add(result); } return(results); }