private void button1_Click(object sender, EventArgs e) { using (OpenFileDialog op = new OpenFileDialog()) { op.Filter = "CSV FIles|*.csv"; if (op.ShowDialog() == DialogResult.OK) { StreamReader reader = new StreamReader(op.FileName); reader.ReadLine(); string line = ""; while ((line = reader.ReadLine()) != null) { //Departure,Arrival,Age,Gender,CabinType,Q1,Q2,Q3,Q4 string[] data = line.Split(','); int? departure = data[0] == "" ? null : (int?)db.Airports.Where(x => x.IATACode == data[0]).FirstOrDefault().ID; int? arrival = data[1] == "" ? null : (int?)db.Airports.Where(x => x.IATACode == data[1]).FirstOrDefault().ID; int? age = data[2] == "" ? null : (int?)int.Parse(data[2]); string gender = data[3] == "" ? null : data[3]; int? cabinType = data[4] == "" ? null : (int?)db.CabinTypes.Where(x => x.CabinType1 == data[4]).FirstOrDefault().ID; int?a1 = data[5] == "0" ? null : (int?)int.Parse(data[5]); int?a2 = data[6] == "0" ? null : (int?)int.Parse(data[6]); int?a3 = data[7] == "0" ? null : (int?)int.Parse(data[7]); int?a4 = data[8] == "0" ? null : (int?)int.Parse(data[8]); Survey s = new Survey() { SurveyDate = new DateTime(2017, 7, 1), Departure = departure, Arrival = arrival, CabinType = cabinType, Age = age, Gender = gender }; db.Surveys.InsertOnSubmit(s); db.SubmitChanges(); DetailSurvey ds1 = new DetailSurvey() { SurveyID = s.ID, QuestionID = 1, AnswerID = a1 }; db.DetailSurveys.InsertOnSubmit(ds1); db.SubmitChanges(); DetailSurvey ds2 = new DetailSurvey() { SurveyID = s.ID, QuestionID = 2, AnswerID = a2 }; db.DetailSurveys.InsertOnSubmit(ds2); db.SubmitChanges(); DetailSurvey ds3 = new DetailSurvey() { SurveyID = s.ID, QuestionID = 3, AnswerID = a3 }; db.DetailSurveys.InsertOnSubmit(ds3); db.SubmitChanges(); DetailSurvey ds4 = new DetailSurvey() { SurveyID = s.ID, QuestionID = 4, AnswerID = a4 }; db.DetailSurveys.InsertOnSubmit(ds4); db.SubmitChanges(); } MessageBox.Show("Test"); } } }
private void detach_DetailSurveys(DetailSurvey entity) { this.SendPropertyChanging(); entity.Question = null; }
private void attach_DetailSurveys(DetailSurvey entity) { this.SendPropertyChanging(); entity.Survey = this; }
partial void DeleteDetailSurvey(DetailSurvey instance);
partial void UpdateDetailSurvey(DetailSurvey instance);
partial void InsertDetailSurvey(DetailSurvey instance);