Advertisement
andreisophie

GestiunePacienti

Feb 28th, 2021
1,248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Data.SqlClient;
  11.  
  12. namespace GestiunePacienti
  13. {
  14.     public partial class ModifyForm : Form
  15.     {
  16.         SqlConnection conn;
  17.         SqlDataAdapter da;
  18.         DataSet ds;
  19.         DataRow dr;
  20.         int rowNumber, currentRow;
  21.  
  22.         public ModifyForm()
  23.         {
  24.             InitializeComponent();
  25.         }
  26.  
  27.         private void panel1_Paint(object sender, PaintEventArgs e)
  28.         {
  29.  
  30.         }
  31.  
  32.         private void AddForm_Load(object sender, EventArgs e)
  33.         {
  34.             string query = "SELECT p.*, r.* FROM pacient p LEFT JOIN rezultate r ON (p.id = r.id_pacient)";
  35.  
  36.             conn = new SqlConnection(Properties.Settings.Default.dbConn);            
  37.             da = new SqlDataAdapter(query, conn);
  38.             ds = new DataSet("pacienti");
  39.             da.Fill(ds, "pacienti");
  40.             currentRow = 0;
  41.             rowNumber = ds.Tables[0].Rows.Count;
  42.  
  43.             navigate();
  44.             //MessageBox.Show(ds.Tables[0].Rows.Count.ToString());
  45.             //MessageBox.Show(ds.Tables[0].Rows[0].ItemArray[2].ToString());
  46.         }
  47.  
  48.         private void button3_Click(object sender, EventArgs e)
  49.         {
  50.             if (currentRow + 1 < rowNumber)
  51.                 currentRow++;
  52.             else
  53.                 currentRow = 0;
  54.      
  55.             navigate();
  56.         }
  57.  
  58.         private void prevBtn_Click(object sender, EventArgs e)
  59.         {
  60.             if (currentRow > 0)
  61.                 currentRow--;
  62.             else
  63.                 currentRow = rowNumber - 1;
  64.             navigate();
  65.         }
  66.  
  67.         private void firstBtn_Click(object sender, EventArgs e)
  68.         {
  69.             currentRow = 0;
  70.             navigate();
  71.         }
  72.  
  73.         private void lastBtn_Click(object sender, EventArgs e)
  74.         {
  75.             currentRow = rowNumber - 1;
  76.             navigate();
  77.         }
  78.  
  79.         private void updateBtn_Click(object sender, EventArgs e)
  80.         {
  81.             //1. Construirea interogarii
  82.             string query = "UPDATE pacient SET nume = '" + numeTxb.Text + "', prenume = '" + prenumeTxb.Text;
  83.             query += "', email = '" + emailTxb.Text + "', gen = '";
  84.  
  85.             if (genFRbtn.Checked == true)
  86.                 query += 'F';
  87.             else
  88.                 query += 'M';
  89.             //to do:  de adaugat varsta , email
  90.             query +=  "' WHERE id = '" + dr.ItemArray[0].ToString() + "'; ";
  91.  
  92.             //2. Deschiderea conexiunii cu baza de date
  93.             if (conn == null)
  94.                 conn = new SqlConnection(Properties.Settings.Default.dbConn);
  95.             else
  96.                 if (conn.State == ConnectionState.Closed)
  97.                     conn.Open();
  98.  
  99.             //3. Execut interogarea pe baza de date
  100.             SqlCommand cmd = new SqlCommand(query, conn);
  101.             int result = cmd.ExecuteNonQuery();
  102.  
  103.             if (result > 0)
  104.             {
  105.                 MessageBox.Show("Modificare cu success !", "ATENTIE!", MessageBoxButtons.OK, MessageBoxIcon.Information);
  106.                 //4. Reimprospatez setul de date (dateSet-ul)
  107.                 AddForm_Load(sender, e);
  108.             }
  109.             else
  110.             {
  111.                 MessageBox.Show("Eroare la modificare datelor !", "ATENTIE!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  112.             }
  113.         }
  114.  
  115.         private void navigate()
  116.         {
  117.             dr = ds.Tables[0].Rows[currentRow];
  118.  
  119.             codTxb.Text     = dr.ItemArray[0].ToString();
  120.             numeTxb.Text    = dr.ItemArray[1].ToString();
  121.             prenumeTxb.Text = dr.ItemArray[2].ToString();
  122.             varstaTxb.Text  = dr.ItemArray[5].ToString();
  123.             colesterolTotalTxb.Text = dr.ItemArray[11].ToString();
  124.             colesterolHdlTxb.Text = dr.ItemArray[12].ToString();
  125.             emailTxb.Text   = dr.ItemArray[4].ToString();
  126.         }
  127.     }
  128. }
  129.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement