Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Data.SqlClient;
- namespace GestiunePacienti
- {
- public partial class ModifyForm : Form
- {
- SqlConnection conn;
- SqlDataAdapter da;
- DataSet ds;
- DataRow dr;
- int rowNumber, currentRow;
- public ModifyForm()
- {
- InitializeComponent();
- }
- private void panel1_Paint(object sender, PaintEventArgs e)
- {
- }
- private void AddForm_Load(object sender, EventArgs e)
- {
- string query = "SELECT p.*, r.* FROM pacient p LEFT JOIN rezultate r ON (p.id = r.id_pacient)";
- conn = new SqlConnection(Properties.Settings.Default.dbConn);
- da = new SqlDataAdapter(query, conn);
- ds = new DataSet("pacienti");
- da.Fill(ds, "pacienti");
- currentRow = 0;
- rowNumber = ds.Tables[0].Rows.Count;
- navigate();
- //MessageBox.Show(ds.Tables[0].Rows.Count.ToString());
- //MessageBox.Show(ds.Tables[0].Rows[0].ItemArray[2].ToString());
- }
- private void button3_Click(object sender, EventArgs e)
- {
- if (currentRow + 1 < rowNumber)
- currentRow++;
- else
- currentRow = 0;
- navigate();
- }
- private void prevBtn_Click(object sender, EventArgs e)
- {
- if (currentRow > 0)
- currentRow--;
- else
- currentRow = rowNumber - 1;
- navigate();
- }
- private void firstBtn_Click(object sender, EventArgs e)
- {
- currentRow = 0;
- navigate();
- }
- private void lastBtn_Click(object sender, EventArgs e)
- {
- currentRow = rowNumber - 1;
- navigate();
- }
- private void updateBtn_Click(object sender, EventArgs e)
- {
- //1. Construirea interogarii
- string query = "UPDATE pacient SET nume = '" + numeTxb.Text + "', prenume = '" + prenumeTxb.Text;
- query += "', email = '" + emailTxb.Text + "', gen = '";
- if (genFRbtn.Checked == true)
- query += 'F';
- else
- query += 'M';
- //to do: de adaugat varsta , email
- query += "' WHERE id = '" + dr.ItemArray[0].ToString() + "'; ";
- //2. Deschiderea conexiunii cu baza de date
- if (conn == null)
- conn = new SqlConnection(Properties.Settings.Default.dbConn);
- else
- if (conn.State == ConnectionState.Closed)
- conn.Open();
- //3. Execut interogarea pe baza de date
- SqlCommand cmd = new SqlCommand(query, conn);
- int result = cmd.ExecuteNonQuery();
- if (result > 0)
- {
- MessageBox.Show("Modificare cu success !", "ATENTIE!", MessageBoxButtons.OK, MessageBoxIcon.Information);
- //4. Reimprospatez setul de date (dateSet-ul)
- AddForm_Load(sender, e);
- }
- else
- {
- MessageBox.Show("Eroare la modificare datelor !", "ATENTIE!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- }
- }
- private void navigate()
- {
- dr = ds.Tables[0].Rows[currentRow];
- codTxb.Text = dr.ItemArray[0].ToString();
- numeTxb.Text = dr.ItemArray[1].ToString();
- prenumeTxb.Text = dr.ItemArray[2].ToString();
- varstaTxb.Text = dr.ItemArray[5].ToString();
- colesterolTotalTxb.Text = dr.ItemArray[11].ToString();
- colesterolHdlTxb.Text = dr.ItemArray[12].ToString();
- emailTxb.Text = dr.ItemArray[4].ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement