private void btnAdd_Click(object sender, EventArgs e)
        {
            EmployeeModifyQuestionForm addedQuestion = new EmployeeModifyQuestionForm((int)Department.Count);

            addedQuestion.ShowDialog();

            // Insert
            // 맨 뒤에 추가할 경우
            // Version갱신 후 Add + Department테이블 Count값+1
            // 중간에 추가할 경우 추가로
            // 바뀌는(밀리는) 문제들에 대해 변화되는 Index변화 + Version갱신 후 Add

            if (addedQuestion.IsChaneged)
            {
                // department 추가
                addedQuestion.Question.DepartmentID = Department.DepartmentID;

                // version 추가
                addedQuestion.Question.Version =
                    Dao.Question.GetNewestVersionNumber(AfterQuestions, addedQuestion.Question.DepartmentID,
                                                        addedQuestion.Question.Index) + 1;

                if (addedQuestion.Question.Index != Department.Count)
                {
                    List <Question> questions = new List <Question>();

                    for (int i = addedQuestion.Question.Index;
                         i <= Department.Count; i++)
                    {
                        // 나머지 문제들을 깊은 복사하여 index와 version을 바꾸고 추가
                        var data = AfterQuestions.FindAll(x => x.Index == i)
                                   .OrderByDescending(x => x.Version)
                                   .FirstOrDefault();
                        Question question = (Question)data.Clone();
                        question.Index++;
                        question.Version = Dao.Question.GetNewestVersionNumber(AfterQuestions, question.DepartmentID, question.Index) + 1;
                        questions.Add(question);
                    }

                    foreach (Question item in questions)
                    {
                        AfterQuestions.Add(item);
                    }
                }

                AfterQuestions.Add(addedQuestion.Question);

                Department.Count++;
            }

            ReloadGridView();
        }
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            int beforeQuestionIndex = ((Question)bdsQuestion.Current).Index;
            EmployeeModifyQuestionForm modifyQuestion = new EmployeeModifyQuestionForm((Question)bdsQuestion.Current, (int)Department.Count);

            modifyQuestion.ShowDialog();

            // Update
            // Index가 안변할경우
            // Version갱신 후 Add
            // Index가 변할경우
            // 변한 Index에 대하여 Version갱신 후 Add 및
            // 바뀌는(밀리거나 당겨지는) 문제들에 대해 변화되는 Index변화 + Version갱신 후 Add

            if (modifyQuestion.IsChaneged)
            {
                modifyQuestion.Question.Version =
                    Dao.Question.GetNewestVersionNumber(AfterQuestions, modifyQuestion.Question.DepartmentID,
                                                        modifyQuestion.Question.Index) + 1;

                List <Question> questions = new List <Question>();

                if (modifyQuestion.Question.Index < beforeQuestionIndex)
                {
                    for (int i = modifyQuestion.Question.Index;
                         i <= beforeQuestionIndex - 1; i++)
                    {
                        var data = AfterQuestions.FindAll(x => x.Index == i)
                                   .OrderByDescending(x => x.Version)
                                   .FirstOrDefault();
                        Question question = (Question)data.Clone();
                        question.Index++;
                        question.Version = Dao.Question.GetNewestVersionNumber(AfterQuestions, question.DepartmentID, question.Index) + 1;
                        questions.Add(question);
                    }
                }
                else
                {
                    for (int i = beforeQuestionIndex + 1;
                         i <= modifyQuestion.Question.Index; i++)
                    {
                        var data = AfterQuestions.FindAll(x => x.Index == i)
                                   .OrderByDescending(x => x.Version)
                                   .FirstOrDefault();
                        Question question = (Question)data.Clone();
                        question.Index--;
                        question.Version = Dao.Question.GetNewestVersionNumber(AfterQuestions, question.DepartmentID, question.Index) + 1;
                        questions.Add(question);
                    }
                }

                foreach (Question item in questions)
                {
                    AfterQuestions.Add(item);
                }

                AfterQuestions.Add(modifyQuestion.Question);
            }

            ReloadGridView();
        }