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 MySql.Data.MySqlClient;
- using System.Windows.Forms;
- namespace Dienynas
- {
- public partial class StudentForm : Form
- {
- string FullName;
- ulong ID;
- private MySqlConnection connection;
- DateTime boldDate;
- DataTable table = new DataTable();
- MySqlDataAdapter adapter;
- public StudentForm(ulong ID, string FullName)
- {
- InitializeComponent();
- this.ID = ID;
- this.FullName = FullName;
- this.connection = Tools.OpenConnection();
- this.Text = "Welcome: " + FullName;
- if (DateTime.Now.Month >= 1 && DateTime.Now.Month < 9)
- {
- monCal.MinDate = new DateTime(DateTime.Now.Year - 1, 09, 01);
- monCal.MaxDate = new DateTime(DateTime.Now.Year, 06, 15);
- }
- else
- {
- monCal.MinDate = new DateTime(DateTime.Now.Year, 09, 1);
- monCal.MaxDate = new DateTime(DateTime.Now.Year + 1, 06, 15);
- }
- GetAllDates();
- }
- private void GetAllDates()
- {
- string query = "SELECT DISTINCT MarkDate FROM Marks WHERE StudentID = " + ID + ";";
- try
- {
- if (connection.State != ConnectionState.Open) connection.Open();
- var reader = Tools.SelectDataWithReader(connection, query);
- if (reader == null) return;
- if (!reader.HasRows) return;
- while(reader.Read())
- {
- monCal.AddBoldedDate((DateTime)reader[0]);
- }
- reader.Close();
- }
- catch(Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- private void monCal_DateChanged(object sender, DateRangeEventArgs e)
- {
- GetCurrentDateMarks();
- }
- private void GetCurrentDateMarks()
- {
- boldDate = monCal.SelectionStart;
- if(monCal.BoldedDates.Contains(boldDate))
- {
- 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+"; ";
- try
- {
- adapter = Tools.SelectDataWithAdapter(connection, query);
- table.Clear();
- adapter.Fill(table);
- dgv.DataSource = table;
- }
- catch(Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement