コード例 #1
0
ファイル: Rubrics_Level.cs プロジェクト: SummenZahid/ProjectB
 private void btn_submit_Click(object sender, EventArgs e)
 {
     if (txt_details.Text != "" && cmb_level.Text != "")
     {
         SqlConnection conn = new SqlConnection("Data Source=DESKTOP-M9PBVHQ;Initial Catalog=ProjectB;Integrated Security=True");
         if (update == 1)
         {
             if (cmb_rubric_ID.Text != "")
             {
                 conn.Open();
                 string     RubricID       = (cmb_rubric_ID.SelectedItem as ComboboxItem).Value.ToString();
                 string     query2         = "Update RubricLevel set RubricId = '" + RubricID + " ',  Details = '" + txt_details.Text + " ', MeasurementLevel = '" + cmb_level.Text + " '  where Id = '" + this.id + "'";
                 SqlCommand update_command = new SqlCommand(query2, conn);
                 int        j = update_command.ExecuteNonQuery();
                 if (j != 0)
                 {
                     MessageBox.Show("Rubrics_Level Record Updated Successfully");
                     Rubrics_Level ff = new Rubrics_Level();
                     ff.Close();
                     rubric_level_details ss = new rubric_level_details(rubric_id);
                     ss.Show();
                     this.Hide();
                 }
                 conn.Close();
             }
             error_msg.Show();
         }
         else
         {
             cmb_rubric_ID.Hide();
             conn.Open();
             string     query   = "Insert into RubricLevel (RubricId,Details,MeasurementLevel) values('" + this.rubric_id + "', '" + txt_details.Text + "','" + cmb_level.Text + "' )";
             SqlCommand command = new SqlCommand(query, conn);
             int        i       = command.ExecuteNonQuery();
             if (i != 0)
             {
                 MessageBox.Show("Rubrics_level Record Inserted Successfully");
                 Rubrics_Level f = new Rubrics_Level();
                 f.Close();
                 rubric_level_details s = new rubric_level_details(rubric_id);
                 this.Hide();
                 s.Show();
             }
             conn.Close();
         }
     }
     else
     {
         error_msg.Show();
     }
 }
コード例 #2
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            SqlConnection conn = new SqlConnection("Data Source=DESKTOP-M9PBVHQ;Initial Catalog=ProjectB;Integrated Security=True");

            conn.Open();
            var senderGrid = (DataGridView)sender;

            if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn &&
                e.RowIndex >= 0 && e.ColumnIndex == 0)
            {
                int             row_index   = e.RowIndex;
                DataGridViewRow selectedRow = dataGridView1.Rows[row_index];
                string          a           = Convert.ToString(selectedRow.Cells["Id"].Value);
                string[]        values;
                values = new string[7];
                using (SqlConnection con = new SqlConnection("Data Source = DESKTOP - M9PBVHQ; Initial Catalog = ProjectB; Integrated Security = True"))
                {
                    string     oString = "Select * from Rubric where Id='" + a + "'";
                    SqlCommand oCmd    = new SqlCommand(oString, conn);
                    using (SqlDataReader oReader = oCmd.ExecuteReader())
                    {
                        while (oReader.Read())
                        {
                            values[0] = oReader["Id"].ToString();
                            values[1] = oReader["Details"].ToString();
                            values[2] = oReader["CloId"].ToString();
                            break;
                        }

                        conn.Close();
                    }
                }
                Rubrics s = new Rubrics(values[0], values[1], values[2]);
                this.Hide();
                s.Show();
            }
            else if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn &&
                     e.RowIndex >= 0 && e.ColumnIndex == 1)
            {
                int             row_index   = e.RowIndex;
                DataGridViewRow selectedRow = dataGridView1.Rows[row_index];
                string          a           = Convert.ToString(selectedRow.Cells["Id"].Value);
                string          query       = "DELETE FROM Rubric WHERE Id = '" + a + "'";
                SqlCommand      command     = new SqlCommand(query, conn);
                command.ExecuteNonQuery();
                MessageBox.Show("Row Deleted");
                conn.Close();

                SqlConnection cnn = new SqlConnection("Data Source=DESKTOP-M9PBVHQ;Initial Catalog=ProjectB;Integrated Security=True");
                conn.Open();
                string query1 = "select * from Rubric where CloId = '" + this.clo_id + "'  ";
                using (SqlDataAdapter am = new SqlDataAdapter(query1, cnn))
                {
                    DataTable t = new DataTable();
                    am.Fill(t);
                    dataGridView1.DataSource = t;
                }
            }
            else if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn &&
                     e.RowIndex >= 0 && e.ColumnIndex == 2)
            {
                int             row_index   = e.RowIndex;
                DataGridViewRow selectedRow = dataGridView1.Rows[row_index];
                string          a           = Convert.ToString(selectedRow.Cells["Id"].Value);
                Rubrics_Level   r           = new Rubrics_Level(a);
                this.Hide();
                rubric_level_details rr = new rubric_level_details(a);
                rr.Show();
                Rubric_details c = new Rubric_details();
                c.Hide();
            }
        }