/// <summary> /// 삭제할 전표리스트 담음 /// </summary> /// <param name="전표리스트">삭제할 전표리스트</param> private void Fill전표리스트ForDelete(out 전표리스트 전표리스트) { 전표리스트 = new 전표리스트(); 전표리스트.순번 = int.Parse(dgv전표리스트.CurrentRow.Cells[0].Value.ToString()); 전표리스트.구분 = dgv전표리스트.CurrentRow.Cells[1].Value.ToString(); 전표리스트.계정과목코드번호 = dgv전표리스트.CurrentRow.Cells[2].Value.ToString(); if (dgv전표리스트.CurrentRow.Cells[4].Value != null) { 전표리스트.거래처코드번호 = dgv전표리스트.CurrentRow.Cells[4].Value.ToString(); } 전표리스트.금액 = int.Parse(dgv전표리스트.CurrentRow.Cells[7].Value.ToString()); 전표리스트.적요명 = dgv전표리스트.CurrentRow.Cells[8].Value.ToString(); 전표리스트.입력날짜 = input.Date; 전표리스트.전표번호 = dgv전표.Rows[전표단위.Index].Cells[2].Value.ToString(); }
private void Dgv전표리스트_KeyDown(object sender, KeyEventArgs e) { // Enter 입력시 다음 셀로 이동, 마지막 셀에서 데이터가 없으면 개행추가 금지 if (e.KeyData == Keys.Enter) { e.SuppressKeyPress = true; 전표리스트단위.ColumnIndex = dgv전표리스트.CurrentCell.ColumnIndex; 전표리스트단위.RowIndex = dgv전표리스트.CurrentCell.RowIndex; 전표리스트단위.Index = dgv전표리스트.CurrentRow.Index; 전표리스트단위.ColumnCnt = dgv전표리스트.Columns.Count; 전표리스트단위.RowCnt = dgv전표리스트.Rows.Count; // 마지막 열 체크 if (전표리스트단위.ColumnIndex == (전표리스트단위.ColumnCnt - 1)) { // 마지막 행 체크 및 그 행의 마지막 열에 데이터가 있을 경우 행 추가 if ((전표리스트단위.RowCnt - 1 == 전표리스트단위.RowIndex) && (dgv전표리스트.Rows[전표리스트단위.Index].Cells[전표리스트단위.ColumnCnt - 1].Value != null)) { bool check = IsPossibleToAddByStatementList(); if (check == true) { dgv전표리스트.Rows.Add(); } } // 그 행의 마지막 열에 데이터가 있을 경우 행 추가 else if (dgv전표리스트.Rows[전표리스트단위.Index].Cells[전표리스트단위.ColumnCnt - 1].Value != null) { dgv전표리스트.CurrentCell = dgv전표리스트[0, 전표리스트단위.RowIndex + 1]; } } // 마지막 열이 아닐 경우 다음 열로 이동 else { dgv전표리스트.CurrentCell = dgv전표리스트[전표리스트단위.ColumnIndex + 1, 전표리스트단위.RowIndex]; } } // 전표로 돌아감, Insert, Update if (e.KeyData == Keys.Escape) { e.SuppressKeyPress = true; 전표단위.RowCnt = dgv전표.RowCount; 전표리스트단위.RowCnt = dgv전표리스트.RowCount; 전표리스트단위.Index = dgv전표리스트.CurrentRow.Index; List <전표리스트> 전표리스트s = new List <전표리스트>(); List <전표> 전표s = new List <전표>(); string number = null; List <int> resultIndex1 = new List <int>(); List <int> resultIndex2 = new List <int>(); // 불러온 데이터 수가 현재 Dgv전표리스트의 행보다 적으면 기존데이터에 해당 if (전표리스트단위.LoadCnt > 0) { DB.전표리스트.FillIn전표리스트List(input.Date, dgv전표리스트, 전표리스트s, number, 전표리스트단위.LoadCnt); if (dgv전표.Rows[전표단위.Index].Cells[2].Value != null) { number = dgv전표.Rows[전표단위.Index].Cells[2].Value.ToString(); } var listForCheck2 = DB.전표리스트.GetAllMatchedNumber(number); if (listForCheck2.Count == 전표리스트s.Count) { DB.전표리스트.UpdateNonOverlapList(전표리스트s, listForCheck2, 전표리스트단위.LoadCnt, out resultIndex2); } } // 불러온 데이터 수가 현재 Dgv전표의 행보다 적으면 기존데이터에 해당 if (전표단위.LoadCnt > 0) { DB.전표.FillIn전표List(input.Date, dgv전표, 전표s, 전표단위.LoadCnt); var listForCheck = DB.전표.GetAllMatchedDay(input.Date); if (listForCheck.Count == 전표s.Count) { DB.전표.UpdateNonOverlapList(전표s, listForCheck, 전표단위.LoadCnt, out resultIndex1); } } // 불러온 데이터 개수보다 현재 행 개수가 더 많으면 추가할 데이터 if (전표단위.LoadCnt < 전표단위.RowCnt) { if (dgv전표.Rows[전표단위.Index].Cells[2].Value == null) { SetDefaultBy전표(); for (int i = 전표단위.LoadCnt + 1; i < 전표단위.RowCnt; i++) { Insert전표(i); } for (int i = 전표리스트단위.LoadCnt; i < 전표리스트단위.RowCnt; i++) { if (dgv전표리스트.Rows[전표리스트단위.Index].Cells[0].Value != null) { 전표리스트 전표리스트 = new 전표리스트(); 전표리스트.순번 = int.Parse(dgv전표리스트.Rows[i].Cells[0].Value.ToString()); if (dgv전표리스트.Rows[i].Cells[1].Value != null) { 전표리스트.구분 = dgv전표리스트.Rows[i].Cells[1].Value.ToString(); } if (dgv전표리스트.Rows[i].Cells[2].Value != null) { 전표리스트.계정과목코드번호 = dgv전표리스트.Rows[i].Cells[2].Value.ToString(); } if (dgv전표리스트.Rows[i].Cells[4].Value != null) { 전표리스트.거래처코드번호 = dgv전표리스트.Rows[i].Cells[4].Value.ToString(); } if (dgv전표리스트.Rows[i].Cells[7].Value != null) { 전표리스트.금액 = int.Parse(dgv전표리스트.Rows[i].Cells[7].Value.ToString()); } if (dgv전표리스트.Rows[i].Cells[8].Value != null) { 전표리스트.적요명 = dgv전표리스트.Rows[i].Cells[8].Value.ToString(); } 전표리스트.입력날짜 = input.Date; 전표리스트.전표번호 = dgv전표.Rows[전표단위.Index].Cells[2].Value.ToString();; DB.전표리스트.Insert(전표리스트); } } } } // 일치하지 않은 데이터가 있을 경우 메시지 경고박스를 띄움 if (resultIndex1.Count > 0 || resultIndex2.Count > 0) { if (DialogResult.Yes == MessageBox.Show("수정된 내용이 있습니다.\n변경사항을 저장하시겠습니까?", "저장", MessageBoxButtons.YesNo)) { if (resultIndex1.Count > 0) { foreach (int i in resultIndex1) { DB.전표.Update(전표s[i]); } } if (resultIndex2.Count > 0) { foreach (int i in resultIndex2) { DB.전표리스트.Update(전표리스트s[i]); } } } } dgv전표.CurrentCell = dgv전표.Rows[전표단위.Index].Cells[2]; dgv전표.Focus(); if ((dgv전표.Rows.Count - 1 == 전표단위.RowIndex) && (dgv전표.Rows[전표단위.Index].Cells[전표단위.ColumnCnt - 1].Value != null)) { dgv전표.Rows.Add(); } } // F2 코드 도움창 열기 if (e.KeyData == Keys.F2) { if (dgv전표리스트.CurrentCell.ColumnIndex == 2) { e.SuppressKeyPress = true; 계정코드구분Control control = new 계정코드구분Control(); CodeHelperForm menuForm = new CodeHelperForm(control); menuForm.ShowDialog(); dgv전표리스트.Rows[전표리스트단위.Index].Cells[2].Value = 전표리스트단위.AccountCode; dgv전표리스트.Rows[전표리스트단위.Index].Cells[3].Value = 전표리스트단위.AccountName; dgv전표리스트.CurrentCell = dgv전표리스트.Rows[xPoint].Cells[4]; } if (dgv전표리스트.CurrentCell.ColumnIndex == 4) { string comparer = dgv전표리스트.Rows[전표리스트단위.Index].Cells[1].Value.ToString(); if (comparer == "출금" || comparer == "입금") { 금융거래처구분Control control = new 금융거래처구분Control(); CodeHelperForm form = new CodeHelperForm(control); form.ShowDialog(); dgv전표리스트.Rows[전표리스트단위.Index].Cells[4].Value = 전표리스트단위.FinanceCustomerCode; dgv전표리스트.Rows[전표리스트단위.Index].Cells[5].Value = 전표리스트단위.FinanceCustomerName; dgv전표리스트.Rows[전표리스트단위.Index].Cells[6].Value = 전표리스트단위.FinanceCorporateRegistrationNumber; } if (comparer == "차변" || comparer == "대변") { 일반거래처구분Control control = new 일반거래처구분Control(); CodeHelperForm form = new CodeHelperForm(control); form.ShowDialog(); dgv전표리스트.Rows[전표리스트단위.Index].Cells[4].Value = 전표리스트단위.GeneralCustomerCode; dgv전표리스트.Rows[전표리스트단위.Index].Cells[5].Value = 전표리스트단위.GeneralCustomerName; dgv전표리스트.Rows[전표리스트단위.Index].Cells[6].Value = 전표리스트단위.GeneralCorporateRegistrationNumber; } //dgv전표리스트.CurrentCell = dgv전표리스트.Rows[xPoint].Cells["dataGridViewTextBoxColumn8"]; } } // 한 줄 삭제 if (e.KeyData == Keys.Delete) { Fill전표리스트ForDelete(out 전표리스트 전표리스트); if (DialogResult.Yes == MessageBox.Show("현재 행을 삭제하시겠습니까?", "삭제", MessageBoxButtons.YesNo)) { DB.전표리스트.Delete(전표리스트); } } }
private void Dgv전표리스트_KeyDown(object sender, KeyEventArgs e) { if (e.KeyData == Keys.Enter) { e.SuppressKeyPress = true; int column = dgv전표리스트.CurrentCell.ColumnIndex; int row = dgv전표리스트.CurrentCell.RowIndex; 전표리스트Index = row; if (column == (dgv전표리스트.Columns.Count - 1)) { if ((dgv전표리스트.Rows.Count - 1 == row) && (dgv전표리스트.Rows[전표리스트Index].Cells[dgv전표리스트.Columns.Count - 1].Value != null)) { dgv전표리스트.Rows.Add(); dgv전표리스트.CurrentCell = dgv전표리스트[0, row + 1]; } } else { dgv전표리스트.CurrentCell = dgv전표리스트[column + 1, row]; } } if (e.KeyData == Keys.Escape) { 전표리스트 전표리스트 = new 전표리스트(); 전표리스트.전표리스트ID = int.Parse(dgv전표리스트.CurrentRow.Cells[0].Value.ToString()); 전표리스트.구분 = dgv전표리스트.CurrentRow.Cells[1].Value.ToString(); 전표리스트.계정과목코드번호 = int.Parse(dgv전표리스트.CurrentRow.Cells[2].Value.ToString()); if (dgv전표리스트.CurrentRow.Cells[4].Value != null) { 전표리스트.거래처코드번호 = dgv전표리스트.CurrentRow.Cells[4].Value.ToString(); } 전표리스트.금액 = int.Parse(dgv전표리스트.CurrentRow.Cells[7].Value.ToString()); 전표리스트.적요명 = dgv전표리스트.CurrentRow.Cells[8].Value.ToString(); dgv전표.Focus(); dgv전표.CurrentCell = dgv전표.Rows[전표Index].Cells[2]; int year = int.Parse(lbl회계년도.Text); int month = int.Parse(cbb월.Text); int day = int.Parse(txb일.Text); DateTime dateTime = new DateTime(year, month, day); 전표 전표 = new 전표(); 전표.입력날짜 = dateTime; 전표.전표번호 = int.Parse(dgv전표.CurrentRow.Cells[1].Value.ToString()); 전표.품의내역 = dgv전표.CurrentRow.Cells[1].Value.ToString(); dgv전표.CurrentRow.Cells[5].Value = $"{dateTime}" + "-" + $"000{dgv전표.CurrentRow.Index}"; dgv전표.CurrentRow.Cells[6].Value = "승인"; 전표.형 = dgv전표.CurrentRow.Cells[4].Value.ToString(); 전표.기표번호 = dgv전표.CurrentRow.Cells[5].Value.ToString(); 전표.승인상태 = dgv전표.CurrentRow.Cells[6].Value.ToString(); 전표.승인자 = loginMember.Name; 전표.작업자 = loginMember.Name; // DB.전표.Insert(전표); // DB.전표리스트.Insert(전표리스트); } }