7.Код - Angelok325/kredit GitHub Wiki
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms;
namespace PaymentSchedule { static class Program { ///
using Microsoft.Win32; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.OleDb; using System.Data.SqlClient; using System.Drawing; using System.Linq; using System.Net.Sockets; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
namespace PaymentSchedule { public partial class enter : Form { private string connectionString = "Provider=Microsoft.ACE.OLEDB.9.0.5;Data Source=C:\Users\User\Desktop\квал\Database31.accdb"; private TextBox userInputTextBox; private Label UserLabel1; private Label PasswordLabel1; public enter() { InitializeComponent(); this.passfield.AutoSize = false; this.passfield.Size = new Size(this.passfield.Size.Width, 86); }
Point lastPoin;
private void login_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.Left += e.X - lastPoin.X;
this.Top += e.Y - lastPoin.Y;
}
}
private void login_MouseDown(object sender, MouseEventArgs e)
{
lastPoin = new Point(e.X, e.Y);
}
private void registrlabel_Click(object sender, EventArgs e)
{
this.Hide();
registr registrForm = new registr();
registrForm.Show();
}
private void enter_button_Click(object sender, EventArgs e)
{
try
{
string login = loginfeald.Text;
string Password = passfield.Text;
int UserID = AuthenticateUser(login, Password);
if (UserID != -1)
{
Form2 userCabinet = new Form2();
FormSwitcher.SwitchMainForm(this, userCabinet);
}
else
{
MessageBox.Show("Неверное имя пользователя или пароль.");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private int AuthenticateUser(string FIO, string Password)
{
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
connection.Open();
using (OleDbCommand command = new OleDbCommand("SELECT UserID FROM Users WHERE [FIO] = @FIO AND [Password] = @Password", connection))
{
command.Parameters.Add("@FIO", OleDbType.VarChar).Value = FIO;
command.Parameters.Add("@Password", OleDbType.VarChar).Value = Password;
object result = command.ExecuteScalar();
return result != null ? Convert.ToInt32(result) : -1;
}
}
}
}
}
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; using System.Data.OleDb; using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace PaymentSchedule { public partial class registr : Form { private string connectionString = "Provider=Microsoft.ACE.OLEDB.9.0.5;Data Source= C:\Users\User\Desktop\квал\Database31.accdb"; public registr() { InitializeComponent(); }
private void registr_Load(object sender, EventArgs e)
{
}
private void enterr_button_Click_1(object sender, EventArgs e)
{
try
{
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
connection.Open();
string query = "INSERT INTO Users ([FIO],[login],[Password]) VALUES (?,?,?)";
using (OleDbCommand command = new OleDbCommand(query, connection))
{
command.Parameters.AddWithValue("@FIO", fioliabel.Text);
command.Parameters.AddWithValue("@login", loginfield.Text);
command.Parameters.AddWithValue("@Password", passfield.Text);
command.ExecuteNonQuery();
}
MessageBox.Show("Вы зарегистрированы!");
}
}
catch (Exception ex)
{
MessageBox.Show("Ошибка: " + ex.Message);
}
Form1 newForm = new Form1();
FormSwitcher.SwitchMainForm(this, newForm);
}
}
}
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 PaymentSchedule { public partial class Form1 : Form { DataTable dtShedule = new DataTable();
public Form1()
{
InitializeComponent();
comboPaymentType.SelectedIndex = 0;
}
private void checkCalcAtSum_CheckedChanged(object sender, EventArgs e)
{
nudCostOfPurchase.Enabled = nudInitialPayment.Enabled = !checkCalcAtSum.Checked;
nudCreditAmount.Enabled = checkCalcAtSum.Checked;
}
// Рассчитать стоимость
private void btnCalculate_Click(object sender, EventArgs e)
{
Calculator calculator = new Calculator((double)nudCreditAmount.Value, (double)nudCreditRate.Value, (int)nudCreditPeriod.Value, (CalcType)comboPaymentType.SelectedIndex);
dtShedule = calculator.GetShedule();
dgvSchedule.DataSource = dtShedule;
tbMonthlyPayment.Text = calculator.GetMonthlyPayment();
tbSummaryCreditAmount.Text = calculator.GetSummaryCreditAmount();
tbSummaryOverPayment.Text = calculator.GetSummaryOverPayment();
dgvSchedule.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
for (int i = 1; i < dgvSchedule.Columns.Count; i++)
{
dgvSchedule.Columns[i].DefaultCellStyle.Format = String.Format("### ### ### ##0.#0");
dgvSchedule.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
dgvSchedule.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
btnExportToCSV.Enabled = true;
}
// Очистить расчеты
private void btnClear_Click(object sender, EventArgs e)
{
dtShedule.Clear();
checkCalcAtSum.Checked = false;
nudCostOfPurchase.Value = nudCostOfPurchase.Minimum;
nudInitialPayment.Value = nudInitialPayment.Minimum;
nudCreditAmount.Value = nudCreditAmount.Minimum;
nudCreditPeriod.Value = 60M;
nudCreditRate.Value = 6.5M;
comboPaymentType.SelectedIndex = 0;
tbMonthlyPayment.Clear();
tbSummaryCreditAmount.Clear();
tbSummaryOverPayment.Clear();
btnExportToCSV.Enabled = false;
}
private void CalcCreditAmount(object sender, EventArgs e)
{
decimal cAm = Calculator.GetCreditAmount(nudCostOfPurchase.Value, nudInitialPayment.Value);
nudCreditAmount.Value = cAm < 0? 0 : cAm;
}
private void comboPaymentType_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboPaymentType.SelectedIndex == 0)
toolTip.SetToolTip(comboPaymentType, "Вариант ежемесячного платежа по кредиту, когда размер ежемесячного платежа остаётся постоянным на всём периоде кредитования.");
if (comboPaymentType.SelectedIndex == 1)
toolTip.SetToolTip(comboPaymentType, "Вариант ежемесячного платежа по кредиту, когда размер ежемесячного платежа по погашению кредита постепенно уменьшается к концу периода кредитования.");
}
private void nuds_Enter(object sender, EventArgs e)
{
if (sender is NumericUpDown)
(sender as NumericUpDown).Select(0, (sender as NumericUpDown).Value.ToString().Length);
}
private void nudCreditPeriod_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.K)
nudCreditPeriod.Value *= 12;
}
private void btnExportToCSV_Click(object sender, EventArgs e)
{
SaveFileDialog save = new SaveFileDialog();
save.Title = "Экспорт графика платежей";
save.Filter = "*.CSV-файл с разделителями |*.csv";
if (save.ShowDialog() == DialogResult.OK)
Export.ToCSV(save.FileName, dtShedule, tbSummaryCreditAmount.Text, nudCreditAmount.Value.ToString(), tbSummaryOverPayment.Text);
}
private void gbSchedule_Enter(object sender, EventArgs e)
{
}
}
}
using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using System.IO; using System.Threading.Tasks; using System.Windows.Forms;
namespace PaymentSchedule { public static class Export { public static void ToCSV(string filename, DataTable dataTable, string summaryCreditAmount, string creditAmount, string summaryOverpayment) { FileStream fs = null; StreamWriter sw = null; try { fs = new FileStream(filename, FileMode.Create, FileAccess.Write); sw = new StreamWriter(fs, Encoding.Default); sw.WriteLine(String.Join(";", dataTable.Columns[0].Caption, dataTable.Columns[1].Caption, dataTable.Columns[2].Caption, dataTable.Columns[3].Caption, dataTable.Columns[4].Caption)); for (int i = 0; i < dataTable.Rows.Count; i++) sw.WriteLine(String.Join(";", dataTable.Rows[i][0], dataTable.Rows[i][1], dataTable.Rows[i][2], dataTable.Rows[i][3], dataTable.Rows[i][4])); sw.WriteLine(String.Join(";", "Итого", summaryCreditAmount, creditAmount, summaryOverpayment)); } catch(Exception e) { MessageBox.Show(e.Message); } finally { sw?.Close(); fs?.Close(); } } } }