private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex]; if (selectedItem == 0) { studentId = Convert.ToInt32(row.Cells["id"].Value.ToString()); TB_studentNo.Text = row.Cells["studentNo"].Value.ToString(); TB_name.Text = row.Cells["name"].Value.ToString(); TB_lastName.Text = row.Cells["lastName"].Value.ToString(); TB_birthPlace.Text = row.Cells["birthPlace"].Value.ToString(); TB_birthYear.Text = row.Cells["birthYear"].Value.ToString(); } else if (selectedItem == 1) { TB_lessonsStudentNo.Text = row.Cells["studentNo"].Value.ToString(); if (row.Cells["bm100"].Value.ToString() == "1") { CLB_studentLessons.SetItemChecked(0, true); } if (row.Cells["bm200"].Value.ToString() == "1") { CLB_studentLessons.SetItemChecked(1, true); } if (row.Cells["bm300"].Value.ToString() == "1") { CLB_studentLessons.SetItemChecked(2, true); } } else if (selectedItem == 2) { updateResultGroup.Controls.Clear(); int i = 4; TB_resultsStudentNo.Text = row.Cells["studentNo"].Value.ToString(); while (i < 7) { if (row.Cells[i].Value.ToString() != "0") { row.HeaderCell.Value = "BM" + (i * 100 - 300).ToString(); Control[] objs = new Control[2]; Label side = new Label(); TextBox results = new TextBox(); objs[0] = side; objs[1] = results; side.Text = row.HeaderCell.Value.ToString(); side.Location = new Point(6, 63 + loc); results.Location = new Point(112, 60 + loc); results.Name = "TB_" + row.HeaderCell.Value.ToString(); updateResultGroup.Controls.AddRange(objs); loc += 30; } i++; } loc = 0; } } }
private void B_updateLesson_Click(object sender, EventArgs e) { MessageBox.Show(CLB_studentLessons.GetItemCheckState(0).ToString()); string query = "UPDATE lessons SET bm100 = " + (int)CLB_studentLessons.GetItemCheckState(0) + " , bm200 = " + (int)CLB_studentLessons.GetItemCheckState(1) + ", bm300 = " + (int)CLB_studentLessons.GetItemCheckState(2) + " WHERE studentNo = '" + TB_lessonsStudentNo.Text + "'"; updateData(query); updateDataGridView(1); }
private void getInfo(int b) { string studentNo = ""; if (b != 0) { for (int i = 0; i < table.Rows.Count; i++) { if (table.Rows[i][1].ToString() == TB_studentNo.Text) { studentNo = table.Rows[i][1].ToString(); TB_name.Text = table.Rows[i][2].ToString(); TB_lastName.Text = table.Rows[i][3].ToString(); TB_birthYear.Text = table.Rows[i][4].ToString(); TB_birthPlace.Text = table.Rows[i][5].ToString(); num = i; break; } } } else { if (num < table.Rows.Count && num >= 0) { studentNo = table.Rows[num][1].ToString(); TB_name.Text = table.Rows[num][2].ToString(); TB_lastName.Text = table.Rows[num][3].ToString(); TB_birthYear.Text = table.Rows[num][4].ToString(); TB_birthPlace.Text = table.Rows[num][5].ToString(); } } // Ders Kayıtlarını Al string query = "SELECT * FROM lessons WHERE studentNo = '" + studentNo + "'"; SqlCommand cmd = new SqlCommand(query, conn); conn.Open(); SqlDataReader read = cmd.ExecuteReader(); while (read.Read()) { if (read[2].ToString() == "1") { CLB_studentLessons.SetItemChecked(0, true); } if (read[3].ToString() == "1") { CLB_studentLessons.SetItemChecked(1, true); } if (read[4].ToString() == "1") { CLB_studentLessons.SetItemChecked(2, true); } } read.Close(); // Ders Kayıtlarını Al query = "SELECT * FROM examsResults WHERE studentNo = '" + studentNo + "'"; cmd.CommandText = query; read = cmd.ExecuteReader(); while (read.Read()) { TB_bm100.Text = read[2].ToString(); TB_bm200.Text = read[3].ToString(); TB_bm300.Text = read[4].ToString(); } conn.Close(); }
private bool addData(dataType type) { void addDatabase(string query) { conn.Open(); try { using (SqlCommand command = new SqlCommand(query, conn)) { command.ExecuteNonQuery(); MessageBox.Show(type.ToString() + " başarıyla eklendi."); } } catch { MessageBox.Show("Kişiyi Eklerken Hata Oluştu"); } conn.Close(); } if (type == dataType.student) { if (!String.IsNullOrEmpty(TB_studentNo.Text) || !String.IsNullOrEmpty(TB_name.Text) || !String.IsNullOrEmpty(TB_lastName.Text) || !String.IsNullOrEmpty(TB_birthYear.Text) || !String.IsNullOrEmpty(TB_birthPlace.Text)) { addDatabase("INSERT INTO studentInformations(studentNo, name,lastName,birthYear,birthPlace) VALUES('" + TB_studentNo.Text + "','" + TB_name.Text + "', '" + TB_lastName.Text + "', '" + TB_birthYear.Text + "','" + TB_birthPlace.Text + "')"); } else { MessageBox.Show("Lütfen değerleri boş girmeyiniz !", "Uyarı !", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else if (type == dataType.lesson) { addDatabase("INSERT INTO lessons(studentNo, bm100,bm200,bm300) VALUES('" + TB_lessonsStudentNo.Text + "','" + Convert.ToInt16(CLB_studentLessons.GetItemChecked(0)) + "', '" + Convert.ToInt16(CLB_studentLessons.GetItemChecked(1)) + "', '" + Convert.ToInt16(CLB_studentLessons.GetItemChecked(2)) + "')"); } else { TextBox bm100 = new TextBox(), bm200 = new TextBox(), bm300 = new TextBox(); bm100.Text = "0.0"; bm200.Text = "0.0"; bm300.Text = "0.0"; foreach (Control c in addNewResultGroup.Controls) { if (c is TextBox) { TextBox txt = (TextBox)c; if (txt.Name == "TB_BM100") { bm100 = txt; } if (txt.Name == "TB_BM200") { bm200 = txt; } if (txt.Name == "TB_BM300") { bm300 = txt; } } } addDatabase("INSERT INTO examsResults(studentNo, bm100,bm200,bm300) VALUES('" + TB_resultsStudentNo.Text + "'," + Convert.ToDouble(bm100.Text) + ", " + Convert.ToDouble(bm200.Text) + ", " + Convert.ToDouble(bm300.Text) + ")"); } return(true); }