도구 - 확장 및 업데이트에서 Entity framework를 검색 한 후, 다운로드 받고 새로 edmx를 추가한다.
데이터베이스에 있는 테이블과 구조를 똑같이 설정 만든 클래스를 호출해주면 된다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | private void SetGameStart() { try { if (GetGameStartValidation() == true) { //경기 기본 데이터베이스 입력 EntityObject obj = new EntityObject(); ControlUtil.Game.Set_GameEntry gameEntry = new ControlUtil.Game.Set_GameEntry(); obj.paramTable["GAMEDATE"] = dateTimeGame.Value; obj.paramTable["HOME_ENTRY"] = arrAllPosition[Convert.ToInt32(((TextValue)cboAllTeam.Items[0]).Value)]; obj.paramTable["AWAY_ENTRY"] = arrAllPosition[Convert.ToInt32(((TextValue)cboAllTeam.Items[1]).Value)]; obj.paramTable["HOME_INDEX"] = ((TextValue)cboAllTeam.Items[0]).Value; obj.paramTable["AWAY_INDEX"] = ((TextValue)cboAllTeam.Items[1]).Value; gameEntry.SetEntityObject(obj); obj = gameEntry.Entity; if (obj.success != true) { Lib.ShowBox.ShowOK.ShowDialog(Lib.ShowBox.ShowType.MessageType.Emergency, "경기 라인업 입력 도중 오류가 발생했습니다."); } } } catch (Exception ex) { ExceptionLog.Log(ex); } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 | using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using BaselBall.Interface; using Lib; using System.Collections; namespace BaselBall.View.Game { public partial class GameEntry : UserControl, IView { private Button[] btnPosition; private Label[] lblPosition; private Color controlColor; private Dictionary<int, ListViewItem> arrHomePosition = new Dictionary<int, ListViewItem>(); private Dictionary<int, ListViewItem> arrAwayPosition = new Dictionary<int, ListViewItem>(); private Dictionary<int, Dictionary<int, ListViewItem>> arrAllPosition = new Dictionary<int, Dictionary<int, ListViewItem>>(); public GameEntry() { InitializeComponent(); SetInit(); } #region 초기화 private void SetInit() { try { controlColor = btn9.BackColor; SetPositionInfomation(); SetTeamGroup(); SetTeamList(); SetSelectTeamPlayer(); } catch (Exception ex) { ExceptionLog.Log(ex); } } private void SetPositionInfomation() { try { const int positionCount = 10; btnPosition = new Button[positionCount]; lblPosition = new Label[positionCount]; for (int i = 0; i < positionCount; i++) { string btnKey = string.Format("btn{0}", i + 1); string lblKey = string.Format("lbl{0}", i + 1); btnPosition[i] = (Button)this.Controls.Find(btnKey, true)[0]; lblPosition[i] = (Label)this.Controls.Find(lblKey, true)[0]; } } catch (Exception ex) { ExceptionLog.Log(ex); } } private void SetTeamGroup() { try { List<TextValue> arrGroup = new List<TextValue>(); arrGroup.Add(new TextValue("전체", "전체")); arrGroup.Add(new TextValue("초/중등부", "초/중등부")); arrGroup.Add(new TextValue("고등부", "고등부")); arrGroup.Add(new TextValue("대학팀", "대학팀")); ControlSource.GetComboData(cboTeam_Group, arrGroup); } catch (Exception ex) { ExceptionLog.Log(ex); } } #endregion #region 이벤트 private void cboTeam_Group_SelectionChangeCommitted(object sender, EventArgs e) { SetTeamGroupChange(); } private void cboTeam_SelectionChangeCommitted(object sender, EventArgs e) { SetHomeAwayTeamList(GetSelectTeamIndex(sender)); } private void cboAllTeam_SelectionChangeCommitted(object sender, EventArgs e) { SetSelectTeamPlayer(); SetAllPositionPlayer(); } private void btnPosition_Click(object sender, EventArgs e) { SetPositionRemove(sender, e); } private void listAllPlayer_MouseDoubleClick(object sender, MouseEventArgs e) { SetAllPositionInsert(e); } private void listHitter_MouseDoubleClick(object sender, MouseEventArgs e) { SetHitOrder(e); } private void btnGameStart_Click(object sender, EventArgs e) { SetGameStart(); } #endregion #region Get Method private int GetSelectTeamIndex(object sender) { int index = 0; try { ComboBox cbo = (ComboBox)sender; if (cbo.Name.IndexOf("Away") > -1) { index = 1; } } catch (Exception ex) { ExceptionLog.Log(ex); } return index; } private int GetLastBatOrder() { int number = 1; try { SortedList<int, int> list = new SortedList<int, int>(); foreach (ListViewItem lvItem in listHitter.Items) { if (lvItem.SubItems["ORDER"].Text.Length > 0) { int lastOrder = Convert.ToInt32(lvItem.SubItems["ORDER"].Text); list.Add(lastOrder, lastOrder); } } if (list.Count > 0) { foreach (int lastNumber in list.Keys) { if (number == lastNumber) { number = number + 1; } else { number = lastNumber - 1; break; } } } } catch (Exception ex) { ExceptionLog.Log(ex); } return number; } private int GetFieldPosition() { int position = 1; try { for (int i = 0; i < btnPosition.Length; i++) { if (btnPosition[i].BackColor == controlColor) { position = i + 1; break; } } } catch (Exception ex) { ExceptionLog.Log(ex); } return position; } private bool GetGameStartValidation() { bool validation = true; try { string message = ""; TextValue tvHome = (TextValue)cboAllTeam.Items[0]; TextValue tvAway = (TextValue)cboAllTeam.Items[1]; if (arrAllPosition.ContainsKey(Convert.ToInt32(tvAway.Value)) == true && arrAllPosition.ContainsKey(Convert.ToInt32(tvAway.Value)) == true) { Dictionary<int, ListViewItem> arrHomePosition = ConvertManager.GetDictionaryCopy(arrAllPosition[Convert.ToInt32(tvHome.Value)]); Dictionary<int, ListViewItem> arrAwayPosition = ConvertManager.GetDictionaryCopy(arrAllPosition[Convert.ToInt32(tvAway.Value)]); if (10 > arrHomePosition.Count) { message = string.Format("홈 팀의 선수가 {0} 명 입니다. {1}", arrHomePosition.Count, Environment.NewLine); } foreach (int key in arrHomePosition.Keys) { ListViewItem item = arrHomePosition[key]; if (key > 1 && item.SubItems["ORDER"].Text.Length == 0) { message = string.Format("{0}홈 팀의 타격순서가 정해지지 않았습니다. {1}", message, Environment.NewLine); break; } } if (10 > arrAwayPosition.Count) { message = string.Format("{0}원정 팀의 선수가 {1} 명 입니다. {2}", message, arrAwayPosition.Count, Environment.NewLine); } foreach (int key in arrAwayPosition.Keys) { ListViewItem item = arrAwayPosition[key]; if (key > 1 && item.SubItems["ORDER"].Text.Length == 0) { message = string.Format("{0}원정 팀의 타격순서가 정해지지 않았습니다. {1}", message, Environment.NewLine); break; } } if (message.Length > 0) { Lib.ShowBox.ShowOK.ShowDialog(Lib.ShowBox.ShowType.MessageType.Warning, message); validation = false; } } } catch (Exception ex) { ExceptionLog.Log(ex); } return validation; } #endregion #region Set Method private void SetTeamGroupChange() { try { SetTeamList(); } catch (Exception ex) { ExceptionLog.Log(ex); } } private void SetTeamList() { try { string teamType = ((TextValue)cboTeam_Group.SelectedItem).Value.ToString(); teamType = string.Format("TEAM_GROUP = '{0}'", teamType); if (teamType.IndexOf("전체") > -1) { teamType = ""; } Reference.userManager.GetTeamList(cboHome, teamType); Reference.userManager.GetTeamList(cboAway, teamType); const int teamIndex = 0; SetHomeAwayTeamList(teamIndex); } catch (Exception ex) { ExceptionLog.Log(ex); } } private void SetHomeAwayTeamList(int index) { try { cboAllTeam.DataSource = null; string home = string.Format("홈 : {0}", ((DataRowView)cboHome.SelectedItem).Row["NAME"]); string away = string.Format("어웨이 : {0}", ((DataRowView)cboAway.SelectedItem).Row["NAME"]); TextValue tvHome = new TextValue(home, cboHome.SelectedValue.ToString()); TextValue tvAway = new TextValue(away, cboAway.SelectedValue.ToString()); ControlSource.GetComboData(cboAllTeam, new List<TextValue>() { tvHome, tvAway }); cboAllTeam.SelectedIndex = index; cboAllTeam_SelectionChangeCommitted(cboAllTeam, EventArgs.Empty); } catch (Exception ex) { ExceptionLog.Log(ex); } } private void SetSelectTeamPlayer() { try { TextValue selectTeam = (TextValue)cboAllTeam.SelectedItem; listAllPlayer.Items.Clear(); List<object> arrParams = new List<object>(); arrParams.Add(Reference.userInfomation.GetInstance().company); arrParams.Add(cboAllTeam.SelectedValue); DataTable table = SQLConnection.GetExcuteDataTable(ProcedureName.S_PLAYER_INFOMATION, arrParams, Convert.ToInt32(SQLConnection.TableIndex.Zero), "SetPlayerInfomation"); arrHomePosition.Clear(); arrAwayPosition.Clear(); Dictionary<int, ListViewItem> arrPosition = new Dictionary<int, ListViewItem>(); if(arrAllPosition.ContainsKey(Convert.ToInt32(selectTeam.Value)) == true) { if (cboAllTeam.Text.IndexOf("홈") > -1) { arrHomePosition = ConvertManager.GetDictionaryCopy(arrAllPosition[Convert.ToInt32(selectTeam.Value)]); arrPosition = ConvertManager.GetDictionaryCopy(arrAllPosition[Convert.ToInt32(selectTeam.Value)]); } else { arrAwayPosition = ConvertManager.GetDictionaryCopy(arrAllPosition[Convert.ToInt32(selectTeam.Value)]); arrPosition = ConvertManager.GetDictionaryCopy(arrAllPosition[Convert.ToInt32(selectTeam.Value)]); } } string[] column = { "NAME", "POSITION", "NUMBER"}; foreach (DataRow row in table.Rows) { ListViewItem item = new ListViewItem(row["CODE"].ToString()); //이미 있는 선수는 제외한다. if (arrPosition.Values.FirstOrDefault(o => o.Text.Contains(item.Text)) == null) { foreach (string key in column) { ListViewItem.ListViewSubItem subItem = new ListViewItem.ListViewSubItem(item, row[key].ToString()); subItem.Name = key; item.SubItems.Add(subItem); } listAllPlayer.Items.Add(item); } } } catch (Exception ex) { ExceptionLog.Log(ex); } } private void SetAllPositionPlayer() { try { Dictionary<int, ListViewItem> arrPosition = new Dictionary<int, ListViewItem>(); if (arrAllPosition.ContainsKey(Convert.ToInt32(cboAllTeam.SelectedValue)) == true) { arrPosition = ConvertManager.GetDictionaryCopy(arrAllPosition[Convert.ToInt32(cboAllTeam.SelectedValue)]); } SetAllPositionUpdate(arrPosition); SetHitOrderUpdate(arrPosition); } catch (Exception ex) { ExceptionLog.Log(ex); } } //기존에 작업된 것이 존재할 시 복원 시켜주고, 리스트에서 삭제해야 한다. private void SetAllPositionUpdate(Dictionary<int, ListViewItem> arrPosition) { try { //그라운드 string[] arrText = { "투수", "포수", "1루수", "2루수", "3루수", "유격수", "좌익수", "중견수", "우익수", "지명타자"}; for (int i = 0; i < arrText.Length; i++) { lblPosition[i].Text = arrText[i]; btnPosition[i].BackColor = controlColor; } foreach (int key in arrPosition.Keys) { ListViewItem item = arrPosition[key]; btnPosition[key - 1].BackColor = Color.LightYellow; lblPosition[key - 1].Text = item.SubItems["NAME"].Text; } } catch (Exception ex) { ExceptionLog.Log(ex); } } //더블 클릭 시 리스트 이동 private void SetAllPositionInsert(MouseEventArgs e) { try { ListViewItem item = listAllPlayer.GetItemAt(e.X, e.Y);//listAllPlayer.GetItemAt(listAllPlayer.SelectedIndices[0], 1); if (item != null) { int playerCode = Convert.ToInt32(item.Text); int position = GetFieldPosition(); //그라운드에 해당 포지션으로 추가 lblPosition[position - 1].Text = item.SubItems["NAME"].Text; btnPosition[position - 1].BackColor = Color.LightYellow; //라인업에 투수가 아닐 경우 추가 SetHitterList(item, position, btnPosition[position - 1].Text); //전부 추가 후, 리스트에서 삭제 한다. listAllPlayer.Items.Remove(item); } } catch (Exception ex) { ExceptionLog.Log(ex); } } private void SetHitterList(ListViewItem item, int position, string positionName) { try { //listHitter string playerCode = item.Text; string name = item.SubItems["NAME"].Text; string number = item.SubItems["NUMBER"].Text; string[] key = { "ORDER", "NAME", "POSITION", "NUMBER" }; string[] value = { "", name, positionName, number }; ListViewItem playeritem = new ListViewItem(playerCode); for (int i = 0; i < key.Length; i++) { ListViewItem.ListViewSubItem subItem = new ListViewItem.ListViewSubItem(playeritem, value[i]); subItem.Name = key[i]; playeritem.SubItems.Add(subItem); } const int pitcherPosition = 1; if (position > pitcherPosition) { listHitter.Items.Insert(position - 2, playeritem); } else { lblPitcher.Text = item.SubItems["NAME"].Text; } SetDictinaryItem(playeritem, position); } catch (Exception ex) { ExceptionLog.Log(ex); } } private void SetDictinaryItem(ListViewItem item, int position) { try { if (cboAllTeam.Text.IndexOf("홈") > -1) { arrHomePosition[position] = item; arrAllPosition[Convert.ToInt32(cboAllTeam.SelectedValue)] = ConvertManager.GetDictionaryCopy(arrHomePosition); } else { arrAwayPosition[position] = item; arrAllPosition[Convert.ToInt32(cboAllTeam.SelectedValue)] = ConvertManager.GetDictionaryCopy(arrAwayPosition); } } catch (Exception ex) { ExceptionLog.Log(ex); } } private void SetHitOrder(MouseEventArgs e) { try { ListViewItem item = listHitter.GetItemAt(e.X, e.Y); if (item != null) { if (e.Button == System.Windows.Forms.MouseButtons.Left) { SetHitOrderAdd(item); } else if (e.Button == System.Windows.Forms.MouseButtons.Right) { SetHitOrderRemove(item); } } } catch (Exception ex) { ExceptionLog.Log(ex); } } private void SetHitOrderAdd(ListViewItem item) { try { if (item.SubItems["ORDER"].Text.Length == 0) { Dictionary<string, string> arrHitOrder = new Dictionary<string, string>(); //Input 번호 int number = GetLastBatOrder(); item.SubItems["ORDER"].Text = number.ToString(); arrHitOrder[item.SubItems["NAME"].Text] = number.ToString(); } } catch (Exception ex) { ExceptionLog.Log(ex); } } private void SetHitOrderRemove(ListViewItem item) { try { item.SubItems["ORDER"].Text = ""; } catch (Exception ex) { ExceptionLog.Log(ex); } } private void SetHitOrderUpdate(Dictionary<int, ListViewItem> arrPosition) { try { listHitter.Items.Clear(); foreach (ListViewItem item in arrPosition.Values) { if (item.SubItems["POSITION"].Text != "투수") { listHitter.Items.Add(item); } } } catch (Exception ex) { ExceptionLog.Log(ex); } } private void SetPositionRemove(object sender, EventArgs e) { try { Button btn = (Button)sender; int position = Convert.ToInt32(btn.Name.Replace("btn", "")); //리스트에서 삭제 if (cboAllTeam.Text.IndexOf("홈") > -1) { arrHomePosition.Remove(position); arrAllPosition[Convert.ToInt32(cboAllTeam.SelectedValue)] = ConvertManager.GetDictionaryCopy(arrHomePosition); } else { arrAwayPosition.Remove(position); arrAllPosition[Convert.ToInt32(cboAllTeam.SelectedValue)] = ConvertManager.GetDictionaryCopy(arrAwayPosition); } SetAllPositionPlayer(); SetSelectTeamPlayer(); } catch (Exception ex) { ExceptionLog.Log(ex); } } private void SetGameStart() { try { if (GetGameStartValidation() == true) { //경기 기본 데이터베이스 입력 EntityObject obj = new EntityObject(); ControlUtil.Game.Set_GameEntry gameEntry = new ControlUtil.Game.Set_GameEntry(); obj.paramTable["GAMEDATE"] = dateTimeGame.Value; obj.paramTable["HOME_ENTRY"] = arrAllPosition[Convert.ToInt32(((TextValue)cboAllTeam.Items[0]).Value)]; obj.paramTable["AWAY_ENTRY"] = arrAllPosition[Convert.ToInt32(((TextValue)cboAllTeam.Items[1]).Value)]; obj.paramTable["HOME_INDEX"] = ((TextValue)cboAllTeam.Items[0]).Value; obj.paramTable["AWAY_INDEX"] = ((TextValue)cboAllTeam.Items[1]).Value; gameEntry.SetEntityObject(obj); obj = gameEntry.Entity; if (obj.success != true) { Lib.ShowBox.ShowOK.ShowDialog(Lib.ShowBox.ShowType.MessageType.Emergency, "경기 라인업 입력 도중 오류가 발생했습니다."); } } } catch (Exception ex) { ExceptionLog.Log(ex); } } #endregion } } | cs |
2년 전쯤 만들어봤던 것 같은데, 조금 아쉬운감이 있다.
새로이 클래스를 정의해서 했지만.. 안에서 무언가 실행할 때 부모 클래스나 인터페이스로 했으면 더 좋았을 것 같은 느낌이 있다.
'C#' 카테고리의 다른 글
09# 중복 없는 랜덤키 값 추출 (0) | 2017.04.18 |
---|---|
08# 키보드 후킹 (0) | 2016.05.11 |
06# 네트워크 활성화/비활성화 (0) | 2016.05.11 |
05# 소켓 비동기식 처리 (0) | 2016.04.18 |
04# 속성(Property) 객체 생성 시 초기화 (0) | 2016.04.18 |