static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); DKClinicEntities.Initialize(); Application.Run(new MainForm()); }
// CustomerQuestionnareControl에서 작성 완료 이벤트 및 초기 화면으로 돌아가는 이벤트 핸들러 private void CustomerQuestionnareControl_QuestionnareConfirm(object sender, CustomerQuestionnareControl.QuestionnareConfirmEventArgs e) { // 데이터 입력하기 using (var context = DKClinicEntities.Create()) { // Customer if (ConnectedCustomer.CustomerID == 0) { context.Customers.Add(ConnectedCustomer); } // Questionnare CreatedQuestionnare.Date = DateTime.Now; context.Questionnares.Add(CreatedQuestionnare); // Response foreach (Response item in e.Responses) { Response response = new Response { Questionnare = CreatedQuestionnare }; response.Answer = item.Answer; response.QuestionID = item.QuestionID; context.Responses.Add(response); } context.SaveChanges(); } // 초기 화면으로 돌아가기 btnHome.PerformClick(); }
//문제 출력 함수 private string printQuestionnaires(Questionnare currentQuestionnare) { questionnairesForQuery = currentQuestionnare; string unionQuestions = ""; using (var context = DKClinicEntities.Create()) { var query = from x in context.Responses where x.QuestionnareID == questionnairesForQuery.QuestionnareID orderby x.Question.Index select new { questionIndex = x.Question.Index, questionItem = x.Question.Item, questionChoices = x.Question.Choices, questionType = x.Question.Type, questionResponse = x }; var list = query.ToList(); foreach (var item in list) { unionQuestions += $" {item.questionIndex}. {item.questionItem}\n"; if (item.questionType != 1) { string[] choices = item.questionChoices.Split(','); for (int i = 0; i < choices.Length; i++) { unionQuestions += $" {i + 1}) {choices[i]}\n"; } } unionQuestions += "\n"; unionQuestions += $" 답안 => {item.questionResponse.Answer}\n\n"; } return(unionQuestions); } }
private void btnSave_Click(object sender, EventArgs e) { // 작업하는 사이에 데이터베이스에 변화가 있었나 검사하기 위해 데이터를 가져온다 List <Question> questions = Dao.Question.GetNewestVersionByDepartmentID(CurrentEmployeeInHere.DepartmentID); // 사용한 클래스 간 비교 로직 //var firstNotSecond = list1.Except(list2).ToList(); //var secondNotFirst = list2.Except(list1).ToList(); //return !firstNotSecond.Any() && !secondNotFirst.Any(); var firstNotSecond = questions.Except(BeforeQuestions).ToList(); var secondNotFirst = BeforeQuestions.Except(questions).ToList(); // 있었다면 보내버린다(응?) if (!firstNotSecond.Any() && !secondNotFirst.Any() == false) { MessageBox.Show("서버의 다른 변화를 감지하여 저장을 취소합니다. 처음부터 다시 시도해주세요."); btnGoBack.PerformClick(); return; } // 트랜잭션 방식으로 수정된 데이터들을 데이베이스에 저장 using (var context = DKClinicEntities.Create()) { // Department 테이블 업데이트 context.Entry(Department).State = System.Data.Entity.EntityState.Modified; // Question 테이블에 afterQuestion에 추가된 값을 업데이트(Insert) for (int i = BeforeQuestions.Count; i < AfterQuestions.Count; i++) { context.Questions.Add(AfterQuestions[i]); } context.SaveChanges(); btnGoBack.PerformClick(); } }