123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Data.SqlClient;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Windows.Forms.Design;
- namespace ImpulseVision
- {
- public partial class FormAutorize : Form
- {
- public FormAutorize()
- {
- InitializeComponent();
- TbxLogin.Focus();
- TbxLogin.SelectionStart = 0;
- }
- #region <Переменные>
- SqlConnection SCon = new SqlConnection(Properties.Settings.Default.ImpulseVisionAppConnectionString);
- #endregion
- private void BtnLogin_Click(object sender, EventArgs e)
- {
- if(TbxLogin.Text.Trim() == string.Empty || TbxPassword.Text.Trim() == string.Empty)
- {
- MessageBox.Show("Введите учётные данные и повторите попытку!", "ImpulseVision", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- return;
- }
- BsUsers.Filter = $"Login = '{TbxLogin.Text.Trim()}' and Password = '{TbxPassword.Text.Trim()}'";
- if (BsUsers.Count == 0)
- {
- MessageBox.Show("Пользователя с таким логином или паролем не существует!", "ImpilseVision", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- return;
- }
- else
- {
- Notify.Visible = false;
- try
- {
- SCon.Open();
- string QueryLogining = $@"insert into HistoryLogin (StaffsID, TimeLogin)
- values ('{LblUserID.Text.Trim()}',GETDATE())";
- SqlCommand Cmd = new SqlCommand(QueryLogining, SCon);
- Cmd.ExecuteNonQuery();
- SCon.Close();
- }
- catch
- {
- MessageBox.Show("Сервер не отвечает..\r\nПовторите попытку позже", "ImpulseVision", MessageBoxButtons
- .OK, MessageBoxIcon.Exclamation);
- return;
- }
- if (LblRole.Text == "1")
- {
- this.Hide();
- FormMain FMain = new FormMain();
- FMain.BsAdministrator.Filter = BsUsers.Filter;
- FMain.ShowDialog();
- this.Show();
- }
- else
- {
- this.Hide();
- FormGuard FGuard = new FormGuard();
- FGuard.BsStaffs.Filter = BsUsers.Filter;
- FGuard.ShowDialog();
- this.Show();
- }
- Notify.Visible = true;
- TbxLogin.Text = string.Empty;
- TbxPassword.Text = string.Empty;
- this.staffsTableAdapter.Fill(this.impulseVisionAppDataSet1.Staffs);
- GetLastTimeLogin();
- }
- }
- private void FormAutorize_FormClosing(object sender, FormClosingEventArgs e)
- {
- if(File.Exists(Application.StartupPath+"\\autorun.txt"))
- {
- this.WindowState = FormWindowState.Minimized;
- this.Hide();
- Notify.Visible = true;
- }
- else
- {
- Application.ExitThread();
- }
- }
- private void FormAutorize_Load(object sender, EventArgs e)
- {
- // TODO: This line of code loads data into the 'impulseVisionAppDataSet1.Staffs' table. You can move, or remove it, as needed.
- try
- {
- this.staffsTableAdapter.Fill(this.impulseVisionAppDataSet1.Staffs);
- }
- catch
- {
- MessageBox.Show("Проверьте подключение к сети интернет и повторите попытку!", "ImpulseVision", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- Application.ExitThread();
- }
- FormStart FStart = new FormStart();
- FStart.ShowDialog();
- ApplicationParameters application = new ApplicationParameters();
- ClearOldRecordInJournal(application.CountDay);
- GetLastTimeLogin();
- LblRole.Hide();
- LblUserID.Hide();
- if (File.Exists(Application.StartupPath + "\\autorun.txt"))
- {
- Notify.Visible = true;
- }
- }
- /// <summary>
- /// получение последнего времени входа
- /// </summary>
- private void GetLastTimeLogin()
- {
- string LastLogin = string.Empty;
- SCon.Open();
- string QueryLastLogin = $@"select Max(TimeLogin) as LastTimeLogin
- from HistoryLogin";
- SqlCommand Cmd = new SqlCommand(QueryLastLogin, SCon);
- SqlDataReader Res = Cmd.ExecuteReader();
- if(Res.HasRows)
- {
- Res.Read();
- LastLogin = "Последнее время входа: " + Res["LastTimeLogin"].ToString();
- }
- else
- {
- LastLogin = "Здесь будет отображаться последнее время входа в систему.";
- }
- SCon.Close();
- Card.TextDescrition = LastLogin;
- }
- /// <summary>
- /// удаление фотографий в журнале,
- /// которые старше указанного количества дней
- /// </summary>
- private void ClearOldRecordInJournal(int CountDay)
- {
- if (!Directory.Exists(Application.StartupPath + "\\Source\\log"))
- {
- return;
- }
- DirectoryInfo Dir = new DirectoryInfo(Application.StartupPath + "\\Source\\log\\");
- FileInfo[] Files = Dir.GetFiles();
- string Path = string.Empty;
- foreach (var t in Files)
- {
- Path = Application.StartupPath + "\\Source\\log\\" + t;
- if (!File.Exists(Path))
- continue;
- string[] Parts = t.ToString().Split('_');
- try
- {
- DateTime Tm = DateTime.Parse(Parts[3]);
- TimeSpan Span = DateTime.Now - Tm;
- int Dif = Span.Days;
- if(Dif > CountDay)
- {
- File.Delete(Path);
- }
- }
- catch
- {
- continue;
- }
- }
- }
- /// <summary>
- /// рисование градиентной заливки на форме
- /// </summary>
- private void FormAutorize_Paint(object sender, PaintEventArgs e)
- {
- Point PtStart = new Point(0, 0);
- Point PtEnd = new Point(Width, Height);
- Color ColFirst = ColorTranslator.FromHtml("#0F2834");
- Color ColThird = ColorTranslator.FromHtml("#496870");
- //градиентный цвет
- LinearGradientBrush LGB = new LinearGradientBrush(PtStart, PtEnd, ColFirst, ColThird);
- Pen MyPen = new Pen(LGB);
- Rectangle Rect = new Rectangle(PtStart,new Size(PtEnd));
- e.Graphics.FillRectangle(LGB, Rect);
- }
- private void FormAutorize_Resize(object sender, EventArgs e)
- {
- Invalidate();
- }
- private void Notify_MouseClick(object sender, MouseEventArgs e)
- {
- if (this.WindowState == FormWindowState.Minimized)
- {
- this.ShowInTaskbar = true;
- this.Show();
- this.WindowState = FormWindowState.Normal;
- }
- else
- {
- this.WindowState = FormWindowState.Minimized;
- this.Hide();
- }
- Notify.Visible = true;
- }
- private void CbxShowPass_CheckedChanged(object sender, EventArgs e)
- {
- TbxPassword.UseSystemPasswordChar = !CbxShowPass.Checked;
- }
- }
- }
|