private void RowAdd(DataTable dataTable, WebToDB RowAdd_wtd, string numBonus) { DataRow dr = dataTable.NewRow(); dr["회차"] = RowAdd_wtd.DrwNo; int sum = RowAdd_wtd.No1 + RowAdd_wtd.No2 + RowAdd_wtd.No3 + RowAdd_wtd.No4 + RowAdd_wtd.No5 + RowAdd_wtd.No6 + RowAdd_wtd.BonusNo; if (sum >= 60) { dr["등수"] = 1; } else if (sum == 51) { dr["등수"] = 2; } else if (sum == 50) { dr["등수"] = 3; } else if (sum >= 40) { dr["등수"] = 4; } else if (sum >= 30) { dr["등수"] = 5; } dr["No1\n" + this.txtNo1.Text] = convert1or0(RowAdd_wtd.No1); dr["No2\n" + this.txtNo2.Text] = convert1or0(RowAdd_wtd.No2); dr["No3\n" + this.txtNo3.Text] = convert1or0(RowAdd_wtd.No3); dr["No4\n" + this.txtNo4.Text] = convert1or0(RowAdd_wtd.No4); dr["No5\n" + this.txtNo5.Text] = convert1or0(RowAdd_wtd.No5); dr["No6\n" + this.txtNo6.Text] = convert1or0(RowAdd_wtd.No6); dr["Bonus\n"] = convert1or0(RowAdd_wtd.BonusNo) + " " + numBonus; dataTable.Rows.Add(dr); }
private void button1_Click(object sender, EventArgs e) { ExamineNum();//중복 검사 #region 중복일때 초기화작업 if (temp == true) { txtNo1.Text = txtNo2.Text = txtNo3.Text = txtNo4.Text = txtNo5.Text = txtNo6.Text = ""; numList.Clear(); DBGridView.DataSource = ""; beforeList.Clear(); return; } #endregion DataTable dataTable = new DataTable(); #region 공백제거 this.txtNo1.Text = this.txtNo1.Text.Replace(" ", "").Trim(); this.txtNo2.Text = this.txtNo2.Text.Replace(" ", "").Trim(); this.txtNo3.Text = this.txtNo3.Text.Replace(" ", "").Trim(); this.txtNo4.Text = this.txtNo4.Text.Replace(" ", "").Trim(); this.txtNo5.Text = this.txtNo5.Text.Replace(" ", "").Trim(); this.txtNo6.Text = this.txtNo6.Text.Replace(" ", "").Trim(); #endregion #region 데이터테이블 컬럼추가 dataTable.Columns.Add("회차"); dataTable.Columns.Add("등수"); dataTable.Columns.Add("No1\n" + this.txtNo1.Text); dataTable.Columns.Add("No2\n" + this.txtNo2.Text); dataTable.Columns.Add("No3\n" + this.txtNo3.Text); dataTable.Columns.Add("No4\n" + this.txtNo4.Text); dataTable.Columns.Add("No5\n" + this.txtNo5.Text); dataTable.Columns.Add("No6\n" + this.txtNo6.Text); dataTable.Columns.Add("Bonus\n"); #endregion DBGridView.DataSource = ""; beforeList.Clear(); string[] num = new string[] { this.txtNo1.Text, this.txtNo2.Text, this.txtNo3.Text, this.txtNo4.Text, this.txtNo5.Text, this.txtNo6.Text }; #region 당첨여부 저장 foreach (var item in WebToDB.dataLst) { wtd = new WebToDB(); wtd.No1 = wtd.No2 = wtd.No3 = wtd.No4 = wtd.No5 = wtd.No6 = wtd.BonusNo = 0; int[] numOX = new int[6]; //당첨여부에 대한 Array for (int i = 0; i < num.Length; i++) { if (num[i] == item.No1 + "") { numOX[i] = 10; } else if (num[i] == item.No2 + "") { numOX[i] = 10; } else if (num[i] == item.No3 + "") { numOX[i] = 10; } else if (num[i] == item.No4 + "") { numOX[i] = 10; } else if (num[i] == item.No5 + "") { numOX[i] = 10; } else if (num[i] == item.No6 + "") { numOX[i] = 10; } } string numBonus = ""; wtd.No1 = numOX[0]; wtd.No2 = numOX[1]; wtd.No3 = numOX[2]; wtd.No4 = numOX[3]; wtd.No5 = numOX[4]; wtd.No6 = numOX[5]; if (wtd.No1 + wtd.No2 + wtd.No3 + wtd.No4 + wtd.No5 + wtd.No6 == 50) { for (int i = 0; i < numOX.Length; i++) { if (numOX[i] == 0) { if (Int32.Parse(num[i]) == item.BonusNo) { numBonus = num[i]; wtd.BonusNo = 1; //2,3등을 구분하기 위해 1로 저장 } } } } if (wtd.No1 + wtd.No2 + wtd.No3 + wtd.No4 + wtd.No5 + wtd.No6 > 21) // 5등이상 리스트에 저장 { wtd.DrwNo = item.DrwNo; beforeList.Add(wtd); RowAdd(dataTable, wtd, numBonus);//등수 매기기 } } #endregion #region 컬럼 header 이름 변경 DBGridView.DataSource = dataTable; DBGridView.Columns["회차"].Width = 40; DBGridView.Columns["등수"].Width = 40; DBGridView.Columns["No1\n" + this.txtNo1.Text].Width = 40; DBGridView.Columns["No2\n" + this.txtNo2.Text].Width = 40; DBGridView.Columns["No3\n" + this.txtNo3.Text].Width = 40; DBGridView.Columns["No4\n" + this.txtNo4.Text].Width = 40; DBGridView.Columns["No5\n" + this.txtNo5.Text].Width = 40; DBGridView.Columns["No6\n" + this.txtNo6.Text].Width = 40; DBGridView.Columns["Bonus\n"].Width = 70; DBGridView.Sort(DBGridView.Columns["등수"], ListSortDirection.Ascending); #endregion //DBGridView.Sort txtNo1.Text = txtNo2.Text = txtNo3.Text = txtNo4.Text = txtNo5.Text = txtNo6.Text = ""; }