private void btnDelete_Click(object sender, EventArgs e) { int index = dataGridViewX1.SelectedRows[0].Index; if (index == -1) { MessageBox.Show("Bạn Chưa Chọn Dòng Cần Xóa !!!"); return; } if (dataGridViewX1.RowCount == 1) { MessageBox.Show("Bạn Không Được Xóa Khi Chỉ Còn 1 Dòng !!!"); return; } DataGridViewRow r = dataGridViewX1.SelectedRows[0]; clsTrainingExercise data = new clsTrainingExercise(); data.FEN = r.Cells["FEN"].Value.ToString(); DataTable tbl = clsTrainingDatabase.DeleteData(data); if (tbl == null) { MessageBox.Show("Không Thể Xóa Dữ Liệu"); } else { MessageBox.Show("Xóa Thành Công !!!"); dataGridViewX1.DataSource = tbl; } }
private void btnAdd_Click(object sender, EventArgs e) { if (cboType.SelectedIndex == -1) { MessageBox.Show("Bạn Chưa Chọn Loại !!!"); return; } if (PreviewFEN(textBoxX1.Text) == true) { clsTrainingExercise data = new clsTrainingExercise(); data.ExerciseName = cboType.SelectedItem.ToString(); data.FEN = textBoxX1.Text; if (cboType.SelectedIndex == 0) { data.MaxMoves = 10000; } else { data.MaxMoves = cboType.SelectedIndex; } DataTable tbl = clsTrainingDatabase.AddData(data); if (tbl != null) { dataGridViewX1.DataSource = tbl; MessageBox.Show("Thêm Thành Công !!!"); } } }
private void btnSelectGame_Click(object sender, EventArgs e) { frmTrainingDatabase frm = new frmTrainingDatabase(true); if (frm.ShowDialog() == DialogResult.OK) { CurrentExercise = frmTrainingDatabase.exe; LoadGame(); } }
void LoadExercises() { arrExercises = new ArrayList(); arrLastExercises = new ArrayList(); bool bEndgame, bMate1, bMate2, bMate3; bEndgame = frmTrainingOptions.Endgame; bMate1 = frmTrainingOptions.Mate1; bMate2 = frmTrainingOptions.Mate2; bMate3 = frmTrainingOptions.Mate3; DataTable tbl = clsTrainingDatabase.GetDataTable(); foreach (DataRow r in tbl.Rows) { clsTrainingExercise exe = new clsTrainingExercise(r["Name"].ToString(), r["FEN"].ToString(), Convert.ToInt32(r["Moves"])); if (bEndgame == true && exe.MaxMoves > 100) { arrExercises.Add(exe); } if (bMate1 == true && exe.MaxMoves == 1) { arrExercises.Add(exe); } if (bMate2 == true && exe.MaxMoves == 2) { arrExercises.Add(exe); } if (bMate3 == true && exe.MaxMoves == 3) { arrExercises.Add(exe); } } if (frmTrainingOptions.Random == true) { ArrayList arrTmp = new ArrayList(); Random rd = new Random(); while (arrExercises.Count > 0) { int i = rd.Next(arrExercises.Count); arrTmp.Add(arrExercises[i]); arrExercises.RemoveAt(i); } arrExercises.AddRange(arrTmp); arrTmp.Clear(); } intTotalExercises = arrExercises.Count; lblIndex.Text = (arrLastExercises.Count + 1) + "/" + intTotalExercises; }
void NextExercise() { if (arrExercises.Count == 0) { MessageBox.Show("Bài tập đã hết !!!"); } else { int i = arrExercises.Count - 1; CurrentExercise = (clsTrainingExercise)arrExercises[i]; arrExercises.RemoveAt(i); LoadGame(); lblIndex.Text = (arrLastExercises.Count + 1) + "/" + intTotalExercises; } }
void PreviousExercise() { if (arrLastExercises.Count == 0) { return; } int i = arrLastExercises.Count - 1; CurrentExercise = (clsTrainingExercise)arrLastExercises[i]; arrLastExercises.RemoveAt(i); LoadGame(); lblIndex.Text = (arrLastExercises.Count + 1) + "/" + intTotalExercises; }
private void buttonX1_Click(object sender, EventArgs e) { if (cboType.SelectedIndex == -1) { MessageBox.Show("Bạn Chưa Chọn Loại !!!"); return; } int index = dataGridViewX1.SelectedRows[0].Index; if (index == -1) { MessageBox.Show("Bạn Chưa Chọn Dòng Cần Cập Nhật !!!"); return; } if (PreviewFEN(textBoxX1.Text) == true) { clsTrainingExercise data = new clsTrainingExercise(); data.ExerciseName = cboType.SelectedItem.ToString(); data.FEN = textBoxX1.Text; if (cboType.SelectedIndex == 0) { data.MaxMoves = 10000; } else { data.MaxMoves = cboType.SelectedIndex; } DataTable tbl = clsTrainingDatabase.UpdateData(index, data); if (tbl != null) { dataGridViewX1.DataSource = tbl; MessageBox.Show("Cập Nhật Thành Công !!!"); } else { MessageBox.Show("Không Thể Cập Nhật !!!"); } } }
private void btnSelect_Click(object sender, EventArgs e) { int index = dataGridViewX1.SelectedRows[0].Index; if (index == -1) { MessageBox.Show("Bạn Chưa Chọn Dòng Nào Cả !!!"); return; } DataGridViewRow r = dataGridViewX1.SelectedRows[0]; exe = new clsTrainingExercise(); exe.FEN = r.Cells["FEN"].Value.ToString(); exe.ExerciseName = r.Cells["Name"].Value.ToString(); exe.MaxMoves = Convert.ToInt32(r.Cells["Moves"].Value); this.Close(); }
public static DataTable UpdateData(int index, clsTrainingExercise Data) { try { DataTable tbl = clsXMLProcess.GetTable(path); Data.FEN = Data.FEN.Trim(); DataRow r = tbl.Rows[index]; r["Name"] = Data.ExerciseName; r["FEN"] = Data.FEN; r["Moves"] = Data.MaxMoves; tbl.WriteXml(path); return(tbl); } catch (Exception ex) { MessageBox.Show(ex.Message); return(null); } }
public static DataTable AddData(clsTrainingExercise data) { try { string FEN = data.FEN; string Name = data.ExerciseName; int Moves = data.MaxMoves; FEN = FEN.Trim(); string[] s = FEN.Split(' '); FEN = s[0] + " " + s[1] + " " + s[2] + " " + s[3]; DataTable tbl = clsXMLProcess.GetTable(path); int i = 0; foreach (DataRow row in tbl.Rows) { i++; if (row["FEN"].ToString() == FEN) { MessageBox.Show("Thế cờ này đã có trong CSDL dòng " + i); return(null); } } DataRow r = tbl.NewRow(); r["Name"] = Name; r["FEN"] = FEN; r["Moves"] = Moves; //tbl.Rows.Add(r); tbl.Rows.InsertAt(r, 0); tbl.WriteXml(path); return(tbl); } catch (Exception ex) { MessageBox.Show(ex.Message); return(null); } }
public static DataTable DeleteData(clsTrainingExercise data) { try { DataTable tbl = clsXMLProcess.GetTable(path); foreach (DataRow r in tbl.Rows) { if (r["FEN"].ToString() == data.FEN) { tbl.Rows.Remove(r); break; } } tbl.WriteXml(path); return(tbl); } catch (Exception ex) { MessageBox.Show(ex.Message); return(null); } }