Диплом: Автоматизация учета рабочего времени сотрудников в ТОО "Профессиональные охранные системы"

Внимание! Если размещение файла нарушает Ваши авторские права, то обязательно сообщите нам
117
Приложение 2. Листинг программы
namespace WorkersTimes
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Spatial;
public partial class Workers
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage",
"CA2214:DoNotCallOverridableMethodsInConstructors")]
public Workers()
{
Departments = new HashSet<Departments>();
Visits = new HashSet<Visits>();
Brigades = new HashSet<Brigades>();
Departments1 = new HashSet<Departments>();
}
[Key]
public int WorkerId { get; set; }
[StringLength(50)]
public string Name { get; set; }
[StringLength(50)]
public string Surname { get; set; }
[StringLength(50)]
public string Phone { get; set; }
[Column(TypeName = "money")]
public decimal? Salary { get; set; }
[StringLength(50)]
public string Address { get; set; }
[StringLength(50)]
public string Position { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage",
"CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Departments> Departments { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage",
"CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Visits> Visits { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage",
"CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Brigades> Brigades { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage",
"CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Departments> Departments1 { get; set; }
}
}
namespace WorkersTimes
{
118
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Spatial;
public partial class Visits
{
[Key]
[Column(Order = 0, TypeName = "date")]
public DateTime Date { get; set; }
[Key]
[Column(Order = 1)]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int WorkerId { get; set; }
public TimeSpan? Time_out { get; set; }
public TimeSpan? Time_in { get; set; }
public virtual Workers Workers { get; set; }
}
}
namespace WorkersTimes
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Spatial;
public partial class sysdiagrams
{
[Required]
[StringLength(128)]
public string name { get; set; }
public int principal_id { get; set; }
[Key]
public int diagram_id { get; set; }
public int? version { get; set; }
public byte[] definition { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WorkersTimes
{
static class Program
{
/// <summary>
/// Главная точка входа для приложения.
/// </summary>
[STAThread]
static void Main()
{
119
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Login());
}
}
}
namespace WorkersTimes
{
using System;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
public partial class Model1 : DbContext
{
public Model1()
: base("name=dbModel")
{
}
public virtual DbSet<Admins> Admins { get; set; }
public virtual DbSet<Brigades> Brigades { get; set; }
public virtual DbSet<Departments> Departments { get; set; }
public virtual DbSet<sysdiagrams> sysdiagrams { get; set; }
public virtual DbSet<Visits> Visits { get; set; }
public virtual DbSet<Workers> Workers { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Admins>()
.Property(e => e.Password)
.IsUnicode(false);
modelBuilder.Entity<Admins>()
.Property(e => e.email)
.IsUnicode(false);
modelBuilder.Entity<Brigades>()
.Property(e => e.Name)
.IsUnicode(false);
modelBuilder.Entity<Departments>()
.HasMany(e => e.Workers1)
.WithMany(e => e.Departments1)
.Map(m => m.ToTable("DepartmentsOfWorkers").MapLeftKey("Departmen-
tId").MapRightKey("WorkerId"));
modelBuilder.Entity<Visits>()
.Property(e => e.Time_out)
.HasPrecision(0);
modelBuilder.Entity<Visits>()
.Property(e => e.Time_in)
.HasPrecision(0);
modelBuilder.Entity<Workers>()
.Property(e => e.Name)
.IsUnicode(false);
modelBuilder.Entity<Workers>()
.Property(e => e.Surname)
.IsUnicode(false);
modelBuilder.Entity<Workers>()
120
.Property(e => e.Phone)
.IsUnicode(false);
modelBuilder.Entity<Workers>()
.Property(e => e.Salary)
.HasPrecision(19, 4);
modelBuilder.Entity<Workers>()
.Property(e => e.Address)
.IsUnicode(false);
modelBuilder.Entity<Workers>()
.Property(e => e.Position)
.IsUnicode(false);
modelBuilder.Entity<Workers>()
.HasMany(e => e.Departments)
.WithOptional(e => e.Workers)
.HasForeignKey(e => e.WorkerId);
modelBuilder.Entity<Workers>()
.HasMany(e => e.Visits)
.WithRequired(e => e.Workers)
.WillCascadeOnDelete(false);
modelBuilder.Entity<Workers>()
.HasMany(e => e.Brigades)
.WithMany(e => e.Workers)
.Map(m => m.ToTable("BrigadesOfWorkers").MapLeft-
Key("WorkerId").MapRightKey("BrigadeId"));
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WorkersTimes
{
static class Global
{
public static int KeyAvtor;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WorkersTimes
{
static class Global
{
public static int KeyAvtor;
}
}
namespace WorkersTimes
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
121
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Spatial;
public partial class Brigades
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage",
"CA2214:DoNotCallOverridableMethodsInConstructors")]
public Brigades()
{
Workers = new HashSet<Workers>();
}
[Key]
public int BrigadeId { get; set; }
[StringLength(50)]
public string Name { get; set; }
public int? DepartmentId { get; set; }
public virtual Departments Departments { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage",
"CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Workers> Workers { get; set; }
}
}
namespace WorkersTimes
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Spatial;
public partial class Admins
{
[Key]
public int AdminId { get; set; }
[StringLength(50)]
public string Password { get; set; }
[StringLength(50)]
public string email { get; set; }
}
}
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 WorkersTimes
{
public partial class WorkTime : Form
{
Model1 DB = new Model1();
public WorkTime()
{
122
InitializeComponent();
var states = DB.Workers.Select(p => new { p.WorkerId, Fullname = p.Name +
" ID = " + p.WorkerId });
var pr1Q1 = states.ToList();
comboBox1.DataSource = pr1Q1;
comboBox1.DisplayMember = "Fullname";
comboBox1.ValueMember = "WorkerId";
}
private void label1_Click(object sender, EventArgs e)
{
var selectTimeWorker = DB.Workers.Join(DB.Visits, w => w.WorkerId, v =>
v.WorkerId, (w, v) => new
{
Код_работника=w.WorkerId,
Имя = w.Name,
Фамилия = w.Surname,
Телефон = w.Phone,
Дата = v.Date,
Время_прихода = v.Time_in,
Время_ухода = v.Time_out
}).Where(wh=>wh.Код_работника==(int)comboBox1.SelectedValue &&
wh.Дата.Month == DateTime.Today.Month);
var writeGrid = selectTimeWorker.ToList();
dataGridView1.DataSource = writeGrid;
}
}
}
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 WorkersTimes
{
public partial class Vizit : Form
{
Model1 DB = new Model1();
public Vizit()
{
InitializeComponent();
var states = DB.Workers.Select(p => new { p.WorkerId,Fullname= p.Name + "
ID = " + p.WorkerId });
var pr1Q1 = states.Take(300).ToList();
comboBox1.DataSource = pr1Q1;
comboBox1.DisplayMember = "Fullname";
comboBox1.ValueMember = "WorkerId";
}
private void label4_Click(object sender, EventArgs e)
{
var addVizit = new Visits
{
Date = DateTime.Today,
WorkerId = int.Parse(comboBox1.SelectedValue.ToString()),
Time_in = TimeSpan.Parse( dateTimePicker1.Text),
Time_out = TimeSpan.Parse(dateTimePicker2.Text),
123
};
DB.Visits.Add(addVizit);
DB.SaveChanges();
MessageBox.Show("Визит добавлен!!!");
}
}
}
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 WorkersTimes
{
public partial class TimeLog : Form
{
Model1 DB = new Model1();
public TimeLog()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
if (comboBox1.Text == "По отделу")
{
var selectDepartament = from d in DB.Departments
join w in DB.Workers on d.WorkerId equals
w.WorkerId
join v in DB.Visits on w.WorkerId equals
v.WorkerId
select new
{
Название_отдела = d.Name,
// Количество_часов =
Math.Abs(v.Time_out.Value.Hours - v.Time_in.Value.Hours)
Работник = w.Name+"; "+w.Surname,
Дата = v.Date
};
var writeGrid = selectDepartament.ToList();
dataGridView1.DataSource = writeGrid;
}
else if(comboBox1.Text == "По бригаде")
{
var selectDepartament = from d in DB.Departments
join b in DB.Brigades on d.DepartmentId equals
b.DepartmentId
join w in DB.Departments on b.DepartmentId
equals w.DepartmentId
join wo in DB.Workers on w.WorkerId equals
wo.WorkerId
join v in DB.Visits on wo.WorkerId equals
v.WorkerId
124
select new
{
Название_бригады = b.Name,
Работник = wo.Name + "; " + wo.Surname,
Дата = v.Date
};
var writeGrid = selectDepartament.ToList();
dataGridView1.DataSource = writeGrid;
}
else
{
MessageBox.Show("Некорректный запрос!!!!!!!!");
}
}
private void label2_Click(object sender, EventArgs e)
{
try
{
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Of-
fice.Interop.Excel.Application();
excel.Visible = true;
Microsoft.Office.Interop.Excel.Workbook workbook = excel.Work-
books.Add(System.Reflection.Missing.Value);
Microsoft.Office.Interop.Excel.Worksheet sheet1 = (Microsoft.Of-
fice.Interop.Excel.Worksheet)workbook.Sheets[1];
int StartCol = 1;
int StartRow = 1;
int j = 0, i = 0;
//Write Headers
for (j = 0; j < dataGridView1.Columns.Count; j++)
{
Microsoft.Office.Interop.Excel.Range myRange = (Microsoft.Of-
fice.Interop.Excel.Range)sheet1.Cells[StartRow, StartCol + j];
myRange.Value2 = dataGridView1.Columns[j].HeaderText;
}
StartRow++;
//Write datagridview content
for (i = 0; i < dataGridView1.Rows.Count; i++)
{
for (j = 0; j < dataGridView1.Columns.Count; j++)
{
try
{
Microsoft.Office.Interop.Excel.Range myRange = (Mi-
crosoft.Office.Interop.Excel.Range)sheet1.Cells[StartRow + i, StartCol + j];
myRange.Value2 = dataGridView1[j, i].Value == null ? "" :
dataGridView1[j, i].Value;
}
catch
{
;
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
125
}
}
}
}
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 WorkersTimes
{
public partial class Salary : Form
{
Model1 DB = new Model1();
public Salary()
{
InitializeComponent();
var states = DB.Workers.Select(p => new { p.WorkerId, Fullname = p.Name +
" ID = " + p.WorkerId });
var pr1Q1 = states.ToList();
comboBox2.DataSource = pr1Q1;
comboBox2.DisplayMember = "Fullname";
comboBox2.ValueMember = "WorkerId";
}
private void label5_Click(object sender, EventArgs e)
{
var selectTimeWorker = DB.Workers.Join(DB.Visits, w => w.WorkerId, v =>
v.WorkerId, (w, v) => new
{
Код_работника = w.WorkerId,
Имя = w.Name,
Фамилия = w.Surname,
Телефон = w.Phone,
Зарплата = w.Salary
}).Where(wh => wh.Код_работника == (int)comboBox2.SelectedValue);
var writeGrid = selectTimeWorker.ToList();
dataGridView1.DataSource = writeGrid;
}
private void label2_Click(object sender, EventArgs e)
{
try
{
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Of-
fice.Interop.Excel.Application();
excel.Visible = true;
Microsoft.Office.Interop.Excel.Workbook workbook = excel.Work-
books.Add(System.Reflection.Missing.Value);
Microsoft.Office.Interop.Excel.Worksheet sheet1 = (Microsoft.Of-
fice.Interop.Excel.Worksheet)workbook.Sheets[1];
int StartCol = 1;
int StartRow = 1;
int j = 0, i = 0;
//Write Headers
for (j = 0; j < dataGridView1.Columns.Count; j++)
126
{
Microsoft.Office.Interop.Excel.Range myRange = (Microsoft.Of-
fice.Interop.Excel.Range)sheet1.Cells[StartRow, StartCol + j];
myRange.Value2 = dataGridView1.Columns[j].HeaderText;
}
StartRow++;
//Write datagridview content
for (i = 0; i < dataGridView1.Rows.Count; i++)
{
for (j = 0; j < dataGridView1.Columns.Count; j++)
{
try
{
Microsoft.Office.Interop.Excel.Range myRange = (Mi-
crosoft.Office.Interop.Excel.Range)sheet1.Cells[StartRow + i, StartCol + j];
myRange.Value2 = dataGridView1[j, i].Value == null ? "" :
dataGridView1[j, i].Value;
}
catch
{
;
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}
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 WorkersTimes
{
public partial class Main : Form
{
public Main()
{
InitializeComponent();
}
private void label5_Click(object sender, EventArgs e)
{
Vizit f = new Vizit();
f.Show();
}
private void label1_Click(object sender, EventArgs e)
{
WorkTime f = new WorkTime();
f.Show();
}

Смотрите также:

"Автоматизация обработки заявок ООО "Проектно-Строительная Компания"
"Автоматизация процесса аттестации персонала для ООО "Нэт Бай Нэт Холдинг"
"Анализ интернет-активности конкурентов ( на примере конкурентов "Газпром нефть")
"Бухгалтерский учёт и аудит расчётов с подотчётними лицами в организации на примере ООО "ЛОЦ 10""
«Психологическое сопровождение персонала в организации на примере ООО «Крокус»
Cовершенствование деловой оценки персонала в организации (на примере ООО "Даймонд кейтеринг развитие")
IPO - инструмент финансирования деятельности организации. На примере ПАО «Нефтяная компания «Лукойл»
PR как средство продвижения организации (на примере ПАО "Тамбовский завод "Комсомолец им. Н.С. Артемова")
PR-коммуникации в сфере общественного питания (на примере кафе-кондитерской «Cream Cheese»)
SMM как средство повышения эффективности работы учреждений социокультурной сферы (на примере Малого театра)