Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.23 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 WindowsFormsApp6
  13. {
  14. public partial class Form3 : Form
  15. {
  16. public Form3()
  17. {
  18. InitializeComponent();
  19. }
  20.  
  21. private void label9_Click(object sender, EventArgs e)
  22. {
  23.  
  24. }
  25.  
  26. private void label10_Click(object sender, EventArgs e)
  27. {
  28.  
  29. }
  30.  
  31. private void textBox3_Leave(object sender, EventArgs e)
  32. {
  33. verificCNP(textBox3.Text);
  34. }
  35. public static bool verificCNP(string cnp)
  36. {
  37. int s, a1, a2, l1, l2, z1, z2, j1, j2, n1, n2, n3, cifc, u;
  38. if (cnp.Trim().Length != 13)
  39. return false;
  40. else
  41. {
  42. s = Convert.ToInt16(cnp.Substring(0, 1));
  43. a1 = Convert.ToInt16(cnp.Substring(1, 1));
  44. a2 = Convert.ToInt16(cnp.Substring(2, 1));
  45. l1 = Convert.ToInt16(cnp.Substring(3, 1));
  46. l2 = Convert.ToInt16(cnp.Substring(4, 1));
  47. z1 = Convert.ToInt16(cnp.Substring(5, 1));
  48. z2 = Convert.ToInt16(cnp.Substring(6, 1));
  49. j1 = Convert.ToInt16(cnp.Substring(7, 1));
  50. j2 = Convert.ToInt16(cnp.Substring(8, 1));
  51. n1 = Convert.ToInt16(cnp.Substring(9, 1));
  52. n2 = Convert.ToInt16(cnp.Substring(10, 1));
  53. n3 = Convert.ToInt16(cnp.Substring(11, 1));
  54. cifc = Convert.ToInt16(((s * 2 + a1 * 7 + a2 * 9 + l1 * 1 + l2 * 4 + z1 * 6 +
  55. z2 * 3 + j1 * 5 + j2 * 8 + n1 * 2 + n2 * 7 + n3 * 9) % 11));
  56. if (cifc == 10)
  57. {
  58. cifc = 1;
  59. }
  60. u = Convert.ToInt16(cnp.Substring(12, 1));
  61. if (cifc == u)
  62. return true;
  63. else
  64. return false;
  65. }
  66.  
  67. }
  68.  
  69. private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
  70. {
  71.  
  72. }
  73.  
  74. private void textBox3_TextChanged(object sender, EventArgs e)
  75. {
  76. if (verificCNP(textBox3.Text) == true)
  77. dataa();
  78. }
  79. public void dataa()
  80. {
  81. if (verificCNP(textBox3.Text) == true)
  82. {
  83. string cnp = textBox3.Text;
  84. int a1, a2, l1, l2, z1, z2;
  85. a1 = Convert.ToInt16(cnp.Substring(1, 1));
  86. a2 = Convert.ToInt16(cnp.Substring(2, 1));
  87. l1 = Convert.ToInt16(cnp.Substring(3, 1));
  88. l2 = Convert.ToInt16(cnp.Substring(4, 1));
  89. z1 = Convert.ToInt16(cnp.Substring(5, 1));
  90. z2 = Convert.ToInt16(cnp.Substring(6, 1));
  91. int year = 1900 + (a1 * 10) + a2;
  92. int month = (l1 * 10) + l2;
  93. int day = (z1 * 10) + z2;
  94. dateTimePicker1.Value = new DateTime(year, month, day);
  95. int varsta1 = DateTime.Today.Year - year;
  96. string vs = Convert.ToString(varsta1);
  97. textBox6.Text = vs;
  98. }
  99. }
  100.  
  101. private void textBox6_TextChanged(object sender, EventArgs e)
  102. {
  103.  
  104. }
  105.  
  106. private void button1_Click(object sender, EventArgs e)
  107. {
  108. string connetionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Student\source\repos\WindowsFormsApp6\WindowsFormsApp6\PacientiSpital.mdf;Integrated Security=True";
  109. SqlConnection cnn = new SqlConnection(connetionString);
  110. cnn.Open();
  111. string tabel_date = "insert into Pacienti ([Nume], [Prenume],[CNP],[Sex],[NumeMama],[NumeTata],[DataNasterii],[Varsta],[LoculNasterii],[APGAR],[MedicFam],[Antecendente])values(@nume, @prenume, @cnp,@sex,@numemama,@numetata,@datanasterii,@varsta,@loculnasterii,@apgar,@medicfam,@antecedente)";
  112. SqlCommand sc = new SqlCommand(tabel_date, cnn);
  113. sc.Parameters.AddWithValue("@nume", textBox1.Text);
  114. sc.Parameters.AddWithValue("@prenume", textBox2.Text);
  115. sc.Parameters.AddWithValue("@cnp", textBox3.Text);
  116. sc.Parameters.AddWithValue("@sex", comboBox1.Text);
  117. sc.Parameters.AddWithValue("@numemama", textBox4.Text);
  118. sc.Parameters.AddWithValue("@numetata", textBox5.Text);
  119. sc.Parameters.AddWithValue("@datanasterii", dateTimePicker1.Value);
  120. sc.Parameters.AddWithValue("@varsta", textBox6.Text);
  121. sc.Parameters.AddWithValue("@loculnasterii", textBox7.Text);
  122. sc.Parameters.AddWithValue("@apgar", textBox8.Text);
  123. sc.Parameters.AddWithValue("@medicfam", textBox9.Text);
  124. sc.Parameters.AddWithValue("@antecedente", textBox10.Text);
  125. sc.ExecuteNonQuery();
  126. cnn.Close();
  127. MessageBox.Show("Date salvate!");
  128. DialogResult = DialogResult.OK;
  129. }
  130.  
  131. private void textBox10_TextChanged(object sender, EventArgs e)
  132. {
  133.  
  134. }
  135. }
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement