private static Dictionary <string, string> GetCourseDetails(int detailsId, SqlConnection con) { Dictionary <string, string> toReturn = new Dictionary <string, string>(); string cmdString = "SELECT * FROM Course_Details WHERE ID=@Id;"; SqlDataAdapter da = new SqlDataAdapter(cmdString, con); da.SelectCommand.Parameters.AddWithValue("@Id", detailsId); DataSet set = new DataSet(); try { da.Fill(set); if (set.Tables[0].Rows.Count > 0) { toReturn.Add("Початок", set.Tables[0].Rows[0]["START_DATE"].ToString()); toReturn.Add("Кінець", set.Tables[0].Rows[0]["END_DATE"].ToString()); List <PaymentMeasure> measures = JsonConvert.DeserializeObject <List <PaymentMeasure> >( set.Tables[0].Rows[0]["PAYMENT_MEASURES"].ToString() ); toReturn.Add("Вартість", StringifyPaymentMeasures(measures)); if (set.Tables[0].Rows[0]["COURSE_PARAMS"].ToString() != "null") { bool isDefined = Convert.ToBoolean(set.Tables[0].Rows[0]["IS_DEFINED"].ToString()); if (isDefined) { DefinedCourseParams parameters = JsonConvert.DeserializeObject <DefinedCourseParams>( set.Tables[0].Rows[0]["COURSE_PARAMS"].ToString() ); toReturn.Add("Розклад", StringifyDaysMeasures(parameters.Days)); } else { UndefinedCourseParams parameters = JsonConvert.DeserializeObject <UndefinedCourseParams>( set.Tables[0].Rows[0]["COURSE_PARAMS"].ToString() ); StringBuilder daysBuilder = new StringBuilder(""); foreach (var node in parameters.Days) { daysBuilder.AppendFormat("День {0} : {1} хв <br/>", node.Key.ToString(), node.Value.ToString()); } toReturn.Add("Розклад", daysBuilder.ToString()); } } } else { toReturn = null; } } catch { toReturn = null; } return(toReturn); }
private static Course GenerateCourse(FormCollection collection) { Course toReturn = new Course(); toReturn.StartDate = Convert.ToDateTime(collection["service_start_date"]); toReturn.EndDate = Convert.ToDateTime(collection["service_end_date"]); toReturn.PaymentMeasures = new List <PaymentMeasure>(); int a = 1; while (collection["currency_" + a.ToString()] != null) { PaymentMeasure measure = new PaymentMeasure(); measure.Currency = collection["currency_" + a.ToString()]; measure.ValueMeasure = collection["measure_" + a.ToString()]; measure.PricePerUnit = Convert.ToDouble(collection["price_" + a.ToString()]); measure.Description = collection["price_description_" + a.ToString()]; toReturn.PaymentMeasures.Add(measure); ++a; } if (collection["is_time_defined"] == "on") { toReturn.StartDate = toReturn.StartDate.AddHours(Convert.ToDouble(collection["service_start_time"].Split(':')[0])); toReturn.StartDate = toReturn.StartDate.AddMinutes(Convert.ToDouble(collection["service_start_time"].Split(':')[1])); toReturn.EndDate = toReturn.EndDate.AddHours(Convert.ToDouble(collection["service_end_time"].Split(':')[0])); toReturn.EndDate = toReturn.EndDate.AddMinutes(Convert.ToDouble(collection["service_end_time"].Split(':')[1])); } if (collection["week_gradation_type"] == "day_hour") { toReturn.IsDefined = true; string[] days = new string[] { "mon", "tue", "wed", "thu", "fri", "sat", "sun" }; DefinedCourseParams parameters = new DefinedCourseParams(); parameters.Days = new List <Day>(); for (int i = 0; i < days.Count(); ++i) { if (collection[days[i]] == "on") { parameters.Days.Add(new Day { DayOfWeek = (DayOfWeek)(i + 1), StartTime = new TimeSpan( Convert.ToInt32(collection[days[i] + "StartTime"].Split(':')[0]), Convert.ToInt32(collection[days[i] + "StartTime"].Split(':')[1]), 0), EndTime = new TimeSpan( Convert.ToInt32(collection[days[i] + "EndTime"].Split(':')[0]), Convert.ToInt32(collection[days[i] + "EndTime"].Split(':')[1]), 0), }); } } toReturn.Parameters = parameters; } else if (collection["week_gradation_type"] == "day_duration") { int b = 1; UndefinedCourseParams parameters = new UndefinedCourseParams(); parameters.Days = new Dictionary <int, int>(); while (collection["day" + b.ToString() + "Duration"] != null) { parameters.Days.Add(b, int.Parse(collection["day" + b.ToString() + "Duration"])); ++b; } toReturn.Parameters = parameters; } return(toReturn); }