Sunteți pe pagina 1din 4

1.

Scrieti forma generala sau o implementare scurta pentru urmatoarele instructiuni: IF, SELECT CASE,
FOR, WHILE.

IF

if (conditie)
{
Instrutiune_A;
}
else
{
Instrutiune_B;
}


SELECT CASE

switch(strAnimal)
{
case Pisica:
...
break;
case Catel:
...
break;
default:
...
break;
}


FOR

for (initializareCiclu; coditieFinal; pas)
Instructiuni;


FOR EACH

public void Each<T>(Action<T> action)
{
foreach (var item in items)
{
action(item);
}
}


WHILE

While(conditie)
{
Instructiune;
}




2. Numarati caracterele, cuvintele si randurile din textul introdus intr-o caseta de text (textbox) cu
proprietatea Multiline=true. Rezultatele se pot afisa in label-uri separate, variabile individuale sau
folosind MessageBox.Show().

private void textBox1_TextChanged(object sender, EventArgs e)
{
lblcaractere.Text = textBox1.Text.Length.ToString();
lblcuvinte.Text = textBox1.Text.Split(new Char[] { ' ', ',', '.' },
StringSplitOptions.RemoveEmptyEntries).Length.ToString();
lblranduri.Text = textBox1.Text.Split(new Char[] {'\n'},
StringSplitOptions.RemoveEmptyEntries).Length.ToString();
}

3. Enumerati metodele necesare pentru preluarea informatiei dintr-o baza de date SQL Server minim 3,
si scrieti sintaxa standard pentru instructiunile SELECT, INSERT, UPDATE, DELETE, INNER JOIN.

DataTable dt = new DataTable();
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS; Initial
Catalog=name;Integrated Security=SSPI;");
SqlCommand cmd = new SqlCommand("SELECT value.* FROM table_name ", conn);
SqlCommand cmd = new SqlCommand("DELETE FROM table_name WHERE x_id= ", conn);
SqlCommand cmd = new SqlCommand(INSERT INTO table_name VALUES (
value1,value2,value3,...), conn);
SqlCommand cmd = new SqlCommand(UPDATE table_name SET
column1=value1,column2=value2,...
WHERE some_column=some_value; , conn);
SqlCommand cmd = new SqlCommand(SELECT files.* , users.user_name FROM files INNER
JOIN users ON files.upload_user_id=users.user_id, conn);
SqlDataAdapter sa = new SqlDataAdapter(cmd);

4. Pe un formular exista o caseta de text numita txtPhoneNumber. Scrieti un cod care sa verifice daca
textul introdus de utlizator in acea caseta este plauzibil ca numar de telefon pentru Romania. (de ex.
+40251123456 se considera tudent, la fel si 0251123456, iar din 0251.123.456 se scot caracterele suplimentare
puncte, virgule, spatii etc si se verifica daca sirul de caractere rezultat este conform)

string nr = txtPhoneNumber.Text;
nr = nr.Replace(".", "");
nr = nr.Replace(",", "");
nr = nr.Replace(" ", "");
if(nr.Length == 10 || nr.Length == 12);
{
MessageBox.Show("Este un numar de telefon.");
}
if(nr.StartsWith("+4"));
{
MessageBox.Show(("Este un numar de telefon pentru RO");
}

5. Care este cea mai scurta varanta(in nr. de linii de cod) de a reda sunet intr-un program scris in C#?
(obs. Sunetul este in format .wav). Ce coloane veti avea pentru un tabel melodii, un tabel artisti si un tabel
albume?

System.Media.SoundPlayer sound = new System.Media.SoundPlayer(@"C:\a.wav");
sound.Play();

artisti: artist_id (tip int); artist_nume (tip nvarchar(50)); artist_gen_muzica(tip nvarchar(50));
albume: album_id (tip int); album_nume (tip nvarchar(50)); album_data_lansarii (tip datetime); artist_id(tip int);
melodii: melodie_id (tip int); melodie_nume (tip nvarchar(50)); melodie_durata (tip int); album_id (tip int);

6. Depuneti o oferta pentru crearea unei aplicatii de gestiune a bazei de date de student dintr-o
facultate. Ce coloane (denumire, tip de date si lungime daca este cazul) veti include obligatoriu pentru tabelele
student, grupe, note, planificare_examene? Scrieti 1 sintaxa pentru operatia INSERT in unul dintre cele
4 tabele.


student : student_id (tip int) ; student_nume (tip nvarchar(50)) ; student_cnp (tip int) ; student_telefon (tip int) ;
grupe : grupa_id (tip int) ; grupa_nume (tip nvarchar(50)) ; grupa_cod (tip int) ;
note : nota_id (tip int) ; nota_nota (tip int) ;
planificare_examene : examen_id (tip int) ; examen_nume (tip nvarchar(50)) ; examen_profesor (tip
nvarchar(50)) ; examen_data (tip datetime) ; examen_sala (tip nvarchar(50)) ;

string query = "INSERT INTO student " +
"(student_nume, student_cnp, stundent_telefon)" +
"values (' " + txtNume.Text +
"', '" + txtCNP.Text +
"', '" + txtTelefon.Text + " ');";


7. Aveti de realizat o baza de date pentru stocarea facturilor de studii dintr-o universitate cu mai multe
facultati. Ce tabele si ce structura (coloane si tipuri de date) ati tuden pentru o astfel de baza de date? Scrieti o
instructiune INSERT sau UPDATE pentru unul dintre tabele.

student : student_id (tip int) ; student_nume (tip nvarchar(50)) ; student_CNP (tip int) ; upload_factura_id (tip
int) ; upload_facultate_id (tip int) ;
facturi : factura_id (tip int) ; factura_numar (tip int) ; upload_rfactura_id (tip int) ;
randuri_facturi : rfactura_id (tip int) ; rfactura_data (tip datetime) ; rfactura_suma (tip int) ;
facultati : facultate_id (tip int) ; facultate_nume (tip nvarchar(50)) ; facultate_decan (tip nvarchar(50)) ;
facultate_telefon (tip int) ;

string query = "INSERT INTO student " +
"(student_nume, student_CNP, upload_factura_id, upload_facultate_id)" +
"values (' " + txtNume.Text +
"', '" + txtCNP.Text +
"', '" + txtFacturaID.Text +
"', '" + txtFacultateID.Text + " ');";

8. Dati exemplu de populare automata a unui control de tip combo box avand ca sursa un table in sql
server Studenti (id_student, numeS). Preluati id-ul campului selectat la evenimentul de click.

DataTable dt = new DataTable();
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS; Initial
Catalog=name;Integrated Security=SSPI;");
SqlCommand sqlcmd = new SqlCommand("SELECT id_student, numeS FROM
Studenti", conn);
SqlDataAdapter sa = new SqlDataAdapter(sqlcmd);
conn.Open();
sa.Fill(dt);
conn.Close();
sa.Dispose();
sqlcmd.Dispose();
conn.Dispose();
cbStudent.DataSource = dt;
cbStudent.DisplayMember = "numeS";
cbStudent.ValueMember = "id_student";

int id_student;
private void btnGetID_Click(object sender, EventArgs e)
{
id_student = Convert.ToInt32(cboUser.SelectedValue);
}
9. Dati exemplu de metoda pentru tratarea erorilor si folositi si validare de camp cu mesaj msgbox daca
datele introduce nu corespund cerintelor.

O metoda pentru tratarea erorilor este folosirea instructiunii try-catch.

try
{
int x = 0;
int y = 4 / x;
}
catch
{
MessageBox.Show("X trebuie sa fie mai mare ca 0");
}

10. Exemplu de query pt operatia de UPDATE si DELETE din tabelul STUDENTI avand id_student
salvat din evenimentul de click generat de un combo box populat cu numele studentilor si text box-uri pentru
nume adresa cnp etc.

string query = "UPDATE studenti SET " +
"student_nume='" + txtNume.Text + "'," +
"student_adresa='" + txtAdresa.Text + "'," +
"student_CNP='" + txtCNP.Text + "'," +
"student_telefon='" + txtTelefon.Text + "'" +
"WHERE id_student='" + id_student.ToString() + "';";

string query = "DELETE FROM studenti WHERE id_student=" +
id_student.ToString() + ";"

11. Popularea unui control de tip listview folosind un query Select din tabela profesori.

DataTable dt = new DataTable();
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS; Initial
Catalog=name;Integrated Security=SSPI;");
SqlCommand sqlcmd = new SqlCommand("SELECT id_profesor, nume_profesor FROM
profesori", conn);
SqlDataAdapter sa = new SqlDataAdapter(sqlcmd);
conn.Open();
sa.Fill(dt);
conn.Close();
sa.Dispose();
sqlcmd.Dispose();
conn.Dispose();

lstProfesori.DataSource = dt;
lstProfesori.DisplayMember = "nume_profesor";
lstProfesori.ValueMember = "id_profesor";

S-ar putea să vă placă și