доработки по формам

This commit is contained in:
AnnaLioness 2024-04-23 20:52:46 +04:00
parent 8bd5ec7e01
commit 47d1f3762b
7 changed files with 157 additions and 110 deletions

View File

@ -43,6 +43,7 @@
//
this.dataGridView.AllowUserToAddRows = false;
this.dataGridView.AllowUserToDeleteRows = false;
this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 12);
this.dataGridView.Name = "dataGridView";

View File

@ -49,6 +49,7 @@
//
this.dataGridView.AllowUserToAddRows = false;
this.dataGridView.AllowUserToDeleteRows = false;
this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 12);
this.dataGridView.Name = "dataGridView";

View File

@ -28,109 +28,110 @@
/// </summary>
private void InitializeComponent()
{
this.dataGridView = new System.Windows.Forms.DataGridView();
this.textBoxName = new System.Windows.Forms.TextBox();
this.comboBoxUni = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.buttonCreate = new System.Windows.Forms.Button();
this.buttonUpdate = new System.Windows.Forms.Button();
this.buttonDelete = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 12);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(514, 333);
this.dataGridView.TabIndex = 0;
this.dataGridView.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView_CellClick);
//
// textBoxName
//
this.textBoxName.Location = new System.Drawing.Point(638, 25);
this.textBoxName.Name = "textBoxName";
this.textBoxName.Size = new System.Drawing.Size(150, 23);
this.textBoxName.TabIndex = 1;
//
// comboBoxUni
//
this.comboBoxUni.FormattingEnabled = true;
this.comboBoxUni.Location = new System.Drawing.Point(638, 65);
this.comboBoxUni.Name = "comboBoxUni";
this.comboBoxUni.Size = new System.Drawing.Size(150, 23);
this.comboBoxUni.TabIndex = 2;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(570, 28);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(62, 15);
this.label1.TabIndex = 3;
this.label1.Text = "Название:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(553, 68);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(79, 15);
this.label2.TabIndex = 4;
this.label2.Text = "Университет:";
//
// buttonCreate
//
this.buttonCreate.Location = new System.Drawing.Point(713, 110);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(75, 23);
this.buttonCreate.TabIndex = 5;
this.buttonCreate.Text = "Создать";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
//
// buttonUpdate
//
this.buttonUpdate.Location = new System.Drawing.Point(713, 150);
this.buttonUpdate.Name = "buttonUpdate";
this.buttonUpdate.Size = new System.Drawing.Size(75, 23);
this.buttonUpdate.TabIndex = 6;
this.buttonUpdate.Text = "Изменить";
this.buttonUpdate.UseVisualStyleBackColor = true;
this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click);
//
// buttonDelete
//
this.buttonDelete.Location = new System.Drawing.Point(713, 193);
this.buttonDelete.Name = "buttonDelete";
this.buttonDelete.Size = new System.Drawing.Size(75, 23);
this.buttonDelete.TabIndex = 7;
this.buttonDelete.Text = "Удалить";
this.buttonDelete.UseVisualStyleBackColor = true;
this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click);
//
// FormFaculty
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 357);
this.Controls.Add(this.buttonDelete);
this.Controls.Add(this.buttonUpdate);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.comboBoxUni);
this.Controls.Add(this.textBoxName);
this.Controls.Add(this.dataGridView);
this.Name = "FormFaculty";
this.Text = "FormFaculty";
this.Load += new System.EventHandler(this.FormFaculty_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.textBoxName = new System.Windows.Forms.TextBox();
this.comboBoxUni = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.buttonCreate = new System.Windows.Forms.Button();
this.buttonUpdate = new System.Windows.Forms.Button();
this.buttonDelete = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// dataGridView
//
this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 12);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(514, 333);
this.dataGridView.TabIndex = 0;
this.dataGridView.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView_CellClick);
//
// textBoxName
//
this.textBoxName.Location = new System.Drawing.Point(638, 25);
this.textBoxName.Name = "textBoxName";
this.textBoxName.Size = new System.Drawing.Size(150, 23);
this.textBoxName.TabIndex = 1;
//
// comboBoxUni
//
this.comboBoxUni.FormattingEnabled = true;
this.comboBoxUni.Location = new System.Drawing.Point(638, 65);
this.comboBoxUni.Name = "comboBoxUni";
this.comboBoxUni.Size = new System.Drawing.Size(150, 23);
this.comboBoxUni.TabIndex = 2;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(570, 28);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(62, 15);
this.label1.TabIndex = 3;
this.label1.Text = "Название:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(553, 68);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(79, 15);
this.label2.TabIndex = 4;
this.label2.Text = "Университет:";
//
// buttonCreate
//
this.buttonCreate.Location = new System.Drawing.Point(713, 110);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(75, 23);
this.buttonCreate.TabIndex = 5;
this.buttonCreate.Text = "Создать";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
//
// buttonUpdate
//
this.buttonUpdate.Location = new System.Drawing.Point(713, 150);
this.buttonUpdate.Name = "buttonUpdate";
this.buttonUpdate.Size = new System.Drawing.Size(75, 23);
this.buttonUpdate.TabIndex = 6;
this.buttonUpdate.Text = "Изменить";
this.buttonUpdate.UseVisualStyleBackColor = true;
this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click);
//
// buttonDelete
//
this.buttonDelete.Location = new System.Drawing.Point(713, 193);
this.buttonDelete.Name = "buttonDelete";
this.buttonDelete.Size = new System.Drawing.Size(75, 23);
this.buttonDelete.TabIndex = 7;
this.buttonDelete.Text = "Удалить";
this.buttonDelete.UseVisualStyleBackColor = true;
this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click);
//
// FormFaculty
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 357);
this.Controls.Add(this.buttonDelete);
this.Controls.Add(this.buttonUpdate);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.comboBoxUni);
this.Controls.Add(this.textBoxName);
this.Controls.Add(this.dataGridView);
this.Name = "FormFaculty";
this.Text = "FormFaculty";
this.Load += new System.EventHandler(this.FormFaculty_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}

View File

@ -1,6 +1,7 @@
using ExamTimetable_Database;
using ExamTimetable_Forms;
using Microsoft.Extensions.DependencyInjection;
using System.Windows.Forms;
namespace ExamTimetable
{
@ -61,10 +62,41 @@ namespace ExamTimetable
var service = Program.ServiceProvider?.GetService(typeof(Abstractions));
if (service is Abstractions bd)
{
// Замените "GetCars" на метод вашего класса, который выполняет запрос к сущности
DateTime startTime = DateTime.Now;
var result = bd.GetExams(); // Выполняем запрос к сущности
DateTime endTime = DateTime.Now;
/*var exams = bd.GetExams();
int id = exams.Last().exam_id;
var exam = exams.Last();*/
string test = "test";
var faculties = bd.GetFaculties();
int id = faculties.Last().faculty_id;
var faculty = faculties.Last();
DateTime startTime = DateTime.Now;
/*Exam updatedExam = new Exam
{
exam_id = id,
exam_date = exam.exam_date,
exam_place = exam.exam_place,
exam_subject = test,
com_id = exam.com_id,
exam_time = exam.exam_time
};*/
Faculty updatedFaculty = new Faculty
{
faculty_id = id,
faculty_name = test,
uni_id = faculty.uni_id
};
//var result = bd.GetExams(); // Âûïîëíÿåì çàïðîñ ê ñóùíîñòè
//var result = bd.GetExamById(id);
//bd.AddExam(exam);
//bd.UpdateExam(updatedExam);
//bd.DeleteExam(id);
//var result = bd.GetFaculties();
//var result = bd.GetFacultyById(id);
//bd.AddFaculty(faculty);
bd.UpdateFaculty(updatedFaculty);
//bd.DeleteFaculty(id);
DateTime endTime = DateTime.Now;
// Âûâîäèì âðåìÿ âûïîëíåíèÿ çàïðîñà â êîíñîëü
textBoxTest.Text = $"Âðåìÿ âûïîëíåíèÿ çàïðîñà: {(endTime - startTime).TotalMilliseconds} ìèëëèñåêóíä";

View File

@ -43,6 +43,7 @@
//
this.dataGridView.AllowUserToAddRows = false;
this.dataGridView.AllowUserToDeleteRows = false;
this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 12);
this.dataGridView.Name = "dataGridView";

View File

@ -47,6 +47,7 @@
//
this.dataGridView.AllowUserToAddRows = false;
this.dataGridView.AllowUserToDeleteRows = false;
this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 12);
this.dataGridView.Name = "dataGridView";

View File

@ -128,7 +128,10 @@ namespace ExamTimetable_Database
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand($"UPDATE faculty SET faculty_name = {faculty.faculty_name}, uni_id = {faculty.uni_id} WHERE faculty_id = {faculty.faculty_id}", conn);
using var cmd = new NpgsqlCommand($"UPDATE faculty SET faculty_name = @faculty_name, uni_id = @uni_id WHERE faculty_id = @faculty_id", conn);
cmd.Parameters.AddWithValue("@faculty_id", faculty.faculty_id);
cmd.Parameters.AddWithValue("@faculty_name", faculty.faculty_name);
cmd.Parameters.AddWithValue("@uni_id", faculty.uni_id);
cmd.ExecuteNonQuery();
}
public override void DeleteFaculty(int id)
@ -315,8 +318,15 @@ namespace ExamTimetable_Database
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand($"UPDATE exam SET exam_date = {exam.exam_date}, exam_place = {exam.exam_place}, exam_subject = {exam.exam_subject}, com_id = {exam.com_id}, exam_time= {exam.exam_time} WHERE exam_id = {exam.exam_id}", conn);
cmd.ExecuteNonQuery();
//using var cmd = new NpgsqlCommand($"UPDATE exam SET exam_date = {exam.exam_date}, exam_place = {exam.exam_place}, exam_subject = {exam.exam_subject}, com_id = {exam.com_id}, exam_time= {exam.exam_time} WHERE exam_id = {exam.exam_id}", conn);
using var cmd = new NpgsqlCommand($"UPDATE exam SET exam_date = @exam_date, exam_place = @exam_place, exam_subject = @exam_subject, com_id = @com_id, exam_time= @exam_time WHERE exam_id = @exam_id", conn);
cmd.Parameters.AddWithValue("@exam_id", exam.exam_id);
cmd.Parameters.AddWithValue("@exam_date", exam.exam_date);
cmd.Parameters.AddWithValue("@exam_place", exam.exam_place);
cmd.Parameters.AddWithValue("@exam_subject", exam.exam_subject);
cmd.Parameters.AddWithValue("@com_id", exam.com_id);
cmd.Parameters.AddWithValue("@exam_time", exam.exam_time);
cmd.ExecuteNonQuery();
}
public override void DeleteExam(int id)
{