Files
PaymentLogs/sql2/Forms/DataForm.cs
T
2024-05-24 00:22:56 +03:00

90 lines
3.0 KiB
C#

using MySqlX.XDevAPI.Relational;
using PaymentLogs.Domain;
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 System.Windows.Forms;
namespace PaymentLogs
{
public partial class DataForm : Form
{
public DataForm()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.Columns.Add("id", "Номер");
dataGridView1.Columns.Add("fcs", "ФИО");
dataGridView1.Columns.Add("course", "Курс");
dataGridView1.Columns.Add("course_price", "Цена");
dataGridView1.Columns.Add("paid", "Оплачено");
dataGridView1.Columns.Add("debt", "Долг");
/* BindingList<Payment> list1 = new BindingList<Payment>();
dataGridView1.DataSource = list1;*/
foreach (Payment payment in Program.PaymentRepository.All())
{
dataGridView1.Rows.Add(payment.Id.ToString(), payment.FCs.ToString(), Program.CourseRepository.Get(payment.CourseId).Name,
payment.CoursePrice.ToString(), payment.Paid.ToString(), payment.Debt.ToString());
}
}
private void toolStripSplitButton1_ButtonClick(object sender, EventArgs e)
{
}
private void toolStripButton3_Click(object sender, EventArgs e)
{
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void toolStripButton2_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
try
{
if(row.Cells.Count > 1)
{
Payment payment = new Payment
{
Id = Convert.ToInt32(row.Cells["id"].Value),
FCs = row.Cells["fcs"].ToString(),
CourseId = Program.CourseRepository.ByName(row.Cells["course"].Value.ToString()).Id,
CoursePrice = Convert.ToInt32(row.Cells["course_price"].Value),
Paid = Convert.ToInt32(row.Cells["paid"].Value),
Debt = Convert.ToInt32(row.Cells["debt"].Value)
};
Program.PaymentRepository.Update(payment.Id, payment);
}
} catch(NullReferenceException ignored)
{
Console.WriteLine(ignored.Message);
} catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
Program.PaymentRepository.Save();
}
}
}