Advertisement
Guest User

NKKM5.21

a guest
May 21st, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 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 MySql.Data.MySqlClient;
  10. using System.Windows.Forms;
  11.  
  12. namespace Dienynas
  13. {
  14. public partial class StudentForm : Form
  15. {
  16. string FullName;
  17. ulong ID;
  18. private MySqlConnection connection;
  19. DateTime boldDate;
  20. DataTable table = new DataTable();
  21. MySqlDataAdapter adapter;
  22.  
  23. public StudentForm(ulong ID, string FullName)
  24. {
  25. InitializeComponent();
  26. this.ID = ID;
  27. this.FullName = FullName;
  28. this.connection = Tools.OpenConnection();
  29. this.Text = "Welcome: " + FullName;
  30. if (DateTime.Now.Month >= 1 && DateTime.Now.Month < 9)
  31. {
  32. monCal.MinDate = new DateTime(DateTime.Now.Year - 1, 09, 01);
  33. monCal.MaxDate = new DateTime(DateTime.Now.Year, 06, 15);
  34.  
  35. }
  36. else
  37. {
  38. monCal.MinDate = new DateTime(DateTime.Now.Year, 09, 1);
  39. monCal.MaxDate = new DateTime(DateTime.Now.Year + 1, 06, 15);
  40. }
  41. GetAllDates();
  42. }
  43.  
  44. private void GetAllDates()
  45. {
  46. string query = "SELECT DISTINCT MarkDate FROM Marks WHERE StudentID = " + ID + ";";
  47.  
  48. try
  49. {
  50. if (connection.State != ConnectionState.Open) connection.Open();
  51. var reader = Tools.SelectDataWithReader(connection, query);
  52. if (reader == null) return;
  53. if (!reader.HasRows) return;
  54. while(reader.Read())
  55. {
  56. monCal.AddBoldedDate((DateTime)reader[0]);
  57. }
  58. reader.Close();
  59. }
  60. catch(Exception ex)
  61. {
  62. MessageBox.Show(ex.Message);
  63. }
  64.  
  65.  
  66.  
  67. }
  68.  
  69. private void monCal_DateChanged(object sender, DateRangeEventArgs e)
  70. {
  71. GetCurrentDateMarks();
  72. }
  73.  
  74. private void GetCurrentDateMarks()
  75. {
  76. boldDate = monCal.SelectionStart;
  77. if(monCal.BoldedDates.Contains(boldDate))
  78. {
  79. string query = "SELECT s.Name as 'Study name', m.Mark as 'Mark', t.FullName 'Teacher' FROM Marks m LEFT JOIN Study s ON s.ID = m.StudyID LEFT JOIN Teacher t ON m.TeacherID = t.ID WHERE m.MarkDate = '"+boldDate+"' AND m.StudentID = "+ID+"; ";
  80. try
  81. {
  82. adapter = Tools.SelectDataWithAdapter(connection, query);
  83. table.Clear();
  84. adapter.Fill(table);
  85. dgv.DataSource = table;
  86. }
  87. catch(Exception ex)
  88. {
  89. MessageBox.Show(ex.Message);
  90. }
  91. }
  92. }
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement