private void bunifuThinButton21_Click(object sender, EventArgs e)
        {
            SqlDataAdapter adapter = new SqlDataAdapter("select count(class_id) from classrooms where class_name= '" + ClassNameBox.Text + "' ", con);
            DataTable      dat     = new DataTable();

            adapter.Fill(dat);
            int Count = int.Parse(dat.Rows[0][0].ToString());

            if (string.IsNullOrWhiteSpace(ClassNameBox.Text) && ClassNameBox.Text.Length > 0 || ClassNameBox.Text == "")
            {
                Dialogue.Show("Invalid Input or Empty", "", "Ok", "Cancel");
            }//If End

            else if (Count != 0)
            {
                Dialogue.Show("Classroom Already Exist! Please use Other Name", "", "Ok", "Cancel");
            }


            else
            {
                DialogResult result = Dialogue1.Show("Are You Sure?", "", "Ok", "Cancel");
                if (result == DialogResult.Yes)
                {
                    SqlDataAdapter adapt = new SqlDataAdapter("select class_id from classrooms where class_name= '" + Cname + "'", con);
                    DataTable      dt    = new DataTable();
                    adapt.Fill(dt);
                    int ID = int.Parse(dt.Rows[0][0].ToString());//Getting the ID of The Classroom


                    con.Open();
                    String         query = "UPDATE classrooms SET class_name= '" + ClassNameBox.Text + " '  WHERE facilitator_id= '" + Program.user_id + "' AND class_id= '" + ID + "' ";
                    SqlDataAdapter sda   = new SqlDataAdapter(query, con);
                    int            n     = sda.SelectCommand.ExecuteNonQuery();

                    con.Close();


                    CreateMyClassroom CC = (CreateMyClassroom)Application.OpenForms["CreateMyClassroom"];


                    CC.Load_Class();
                    CC.Load_Participant();



                    this.Close();
                }

                else
                {
                    Dialogue.Show("Fail to Update", "", "Ok", "Cancel");
                }
            }
        }
Beispiel #2
0
        ////EXPORT TO EXCEL
        //private void ToExcel(DataGridView dGV, string filename)
        //{
        //    string stOutput = "";
        //    string sHeaders = "";
        //    for(int j = 0; j < dGV.Columns.Count; j++)
        //        sHeaders = sHeaders.ToString() + Convert.ToString(dGV.Columns[j].HeaderText) + "\t";
        //        stOutput += sHeaders + "\r\n";

        //    for(int i = 0; i < dGV.RowCount-1; i++)
        //    {
        //        string stline = "";
        //        for (int j = 0; j < dGV.Rows[i].Cells.Count; j++)
        //            stline = stline.ToString() + Convert.ToString(dGV.Rows[i].Cells[j].Value) + "\t";
        //        stOutput += stline + "\r\n";
        //    }

        //    Encoding utf16 = Encoding.GetEncoding(1254);
        //    byte[] output = utf16.GetBytes(stOutput);
        //    FileStream fs = new FileStream(filename, FileMode.Create);
        //    BinaryWriter bw = new BinaryWriter(fs);
        //    bw.Write(output, 0, output.Length);
        //    bw.Flush();
        //    bw.Close();
        //    fs.Close();

        //}



        private void buttonCreateClassroom_Click(object sender, EventArgs e)
        {
            CreateMyClassroom Create = new CreateMyClassroom();

            Create.ShowDialog();
        }