private void ReadItemFromFile(string fileName, int id) { string line = null; using (var reader = new StreamReader(Application.Context.Assets.Open(fileName))) { while((line = reader.ReadLine()) != null) { if (!String.IsNullOrWhiteSpace(line)) { var rows = line.Split(';'); if (rows.Length == 2) { var question = new Question(id, rows[0], rows[1]); InsertAndUpdate(question); questionCount++; } if (rows.Length == 4) { var option = new OptionAnswers(questionCount, rows); InsertAndUpdate(option); } } } } }
private void AddToDatabase(int checkedOption) { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.SetTitle(Resource.String.AddRecordToDatabase); alert.SetPositiveButton(Resource.String.closeDialogPositive, (senderAlert, args) => { dbSupport = new QuizDatabase(Resources.GetString(Resource.String.quizDatabaseName)); Question question = new Question { BranchId = Intent.GetIntExtra("BranchId", -1), Content = tvQuestion.Text, CorrectAnswers = rbtnOption[checkedOption].Text }; dbSupport.InsertAndUpdate(question); OptionAnswers options = new OptionAnswers { QuestionId = GetQuestionCount(question.BranchId) + 1, FirstOption = rbtnOption[0].Text, SecondOption = rbtnOption[1].Text, ThirdOption = rbtnOption[2].Text, FourthOption = rbtnOption[3].Text }; dbSupport.InsertAndUpdate(options); Finish(); }); alert.SetNegativeButton(Resource.String.closeDialogNegative, (senderAlert, args) => { rbtnOption[checkedOption].Checked = false; }); Dialog dialog = alert.Create(); dialog.Show(); }