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

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.AllowUserToAddRows = false;
this.dataGridView.AllowUserToDeleteRows = false; this.dataGridView.AllowUserToDeleteRows = false;
this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 12); this.dataGridView.Location = new System.Drawing.Point(12, 12);
this.dataGridView.Name = "dataGridView"; this.dataGridView.Name = "dataGridView";

View File

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

View File

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

View File

@ -1,6 +1,7 @@
using ExamTimetable_Database; using ExamTimetable_Database;
using ExamTimetable_Forms; using ExamTimetable_Forms;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using System.Windows.Forms;
namespace ExamTimetable namespace ExamTimetable
{ {
@ -61,10 +62,41 @@ namespace ExamTimetable
var service = Program.ServiceProvider?.GetService(typeof(Abstractions)); var service = Program.ServiceProvider?.GetService(typeof(Abstractions));
if (service is Abstractions bd) if (service is Abstractions bd)
{ {
// Замените "GetCars" на метод вашего класса, который выполняет запрос к сущности /*var exams = bd.GetExams();
DateTime startTime = DateTime.Now; int id = exams.Last().exam_id;
var result = bd.GetExams(); // Выполняем запрос к сущности var exam = exams.Last();*/
DateTime endTime = DateTime.Now; 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} ìèëëèñåêóíä"; textBoxTest.Text = $"Âðåìÿ âûïîëíåíèÿ çàïðîñà: {(endTime - startTime).TotalMilliseconds} ìèëëèñåêóíä";

View File

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

View File

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

View File

@ -128,7 +128,10 @@ namespace ExamTimetable_Database
{ {
using var conn = GetConnection(); using var conn = GetConnection();
conn.Open(); 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(); cmd.ExecuteNonQuery();
} }
public override void DeleteFaculty(int id) public override void DeleteFaculty(int id)
@ -315,8 +318,15 @@ namespace ExamTimetable_Database
{ {
using var conn = GetConnection(); using var conn = GetConnection();
conn.Open(); 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); //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_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) public override void DeleteExam(int id)
{ {