все операции на все сущности кроме вывода смжной таблицы из-за идиотской монго. я ненавижу эту субд
This commit is contained in:
parent
e3a95677f6
commit
ee5464553a
@ -3,6 +3,7 @@ using MongoDB.Driver;
|
||||
using Npgsql;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
using System.Text;
|
||||
@ -19,12 +20,6 @@ namespace DepartmentStaffDatabase
|
||||
private IMongoCollection<Contract> _contractCollection;
|
||||
private IMongoCollection<Course> _courseCollection;
|
||||
private IMongoCollection<Employee_Course> _employee_CourseCollection;
|
||||
|
||||
private int currentDepartmentId = 0;
|
||||
private int currentPositionId = 0;
|
||||
private int currentEmployeeId = 0;
|
||||
private int currentContractId = 0;
|
||||
private int currentCourseId = 0;
|
||||
public MongoImplements()
|
||||
{
|
||||
var client = new MongoClient("mongodb://localhost:27017");
|
||||
@ -40,8 +35,12 @@ namespace DepartmentStaffDatabase
|
||||
|
||||
public override void CreateDepartment(Department department)
|
||||
{
|
||||
currentDepartmentId++;
|
||||
department.Id = currentDepartmentId;
|
||||
var maxId = 0;
|
||||
if (GetDepartments().Count > 0)
|
||||
{
|
||||
maxId = _departmentCollection.AsQueryable().Max(dep => dep.Id);
|
||||
}
|
||||
department.Id = maxId + 1;
|
||||
_departmentCollection.InsertOne(department);
|
||||
}
|
||||
public override void UpdateDepartment(Department department)
|
||||
@ -69,41 +68,190 @@ namespace DepartmentStaffDatabase
|
||||
_departmentCollection.DeleteMany(_ => true);
|
||||
}
|
||||
|
||||
public override void CreatePosition(Position position) { }
|
||||
public override void UpdatePosition(Position position) { }
|
||||
public override void DeletePosition(int id) { }
|
||||
public override Position GetPosition(int id) { return new Position(); }
|
||||
public override Position GetPosition(string positionName) { return new Position(); }
|
||||
public override List<Position> GetPositions() { return new List<Position>(); }
|
||||
public override void Deletepositions() { }
|
||||
//=======================================================================
|
||||
|
||||
public override void CreateEmployee(Employee employee) { }
|
||||
public override void UpdateEmployee(Employee employee) { }
|
||||
public override void DeleteEmployee(int id) { }
|
||||
public override Employee GetEmployee(int id) { return new Employee(); }
|
||||
public override Employee GetEmployee(string employeeName) { return new Employee(); }
|
||||
public override List<Employee> GetEmployees() { return new List<Employee>(); }
|
||||
public override void DeleteEmployees() { }
|
||||
public override void CreatePosition(Position position)
|
||||
{
|
||||
var maxId = 0;
|
||||
if (GetPositions().Count > 0)
|
||||
{
|
||||
maxId = _positionCollection.AsQueryable().Max(pos => pos.Id);
|
||||
}
|
||||
position.Id = maxId + 1;
|
||||
_positionCollection.InsertOne(position);
|
||||
}
|
||||
public override void UpdatePosition(Position position)
|
||||
{
|
||||
var filter = Builders<Position>.Filter.Eq(pos => pos.Id, position.Id);
|
||||
var update = Builders<Position>.Update
|
||||
.Set(pos => pos.PositionName, position.PositionName)
|
||||
.Set(pos => pos.Salary, position.Salary)
|
||||
.Set(pos => pos.DepartmentId, position.DepartmentId);
|
||||
_positionCollection.UpdateOne(filter, update);
|
||||
}
|
||||
public override void DeletePosition(int id)
|
||||
{
|
||||
_positionCollection.DeleteOne(pos => pos.Id == id);
|
||||
}
|
||||
public override Position GetPosition(int id)
|
||||
{
|
||||
return _positionCollection.Find(pos => pos.Id == id).FirstOrDefault();
|
||||
}
|
||||
public override Position GetPosition(string positionName)
|
||||
{
|
||||
return _positionCollection.Find(pos => pos.PositionName == positionName).FirstOrDefault();
|
||||
}
|
||||
public override List<Position> GetPositions()
|
||||
{
|
||||
return _positionCollection.Find(_ => true).ToList();
|
||||
}
|
||||
public override void Deletepositions()
|
||||
{
|
||||
_positionCollection.DeleteMany(_ => true);
|
||||
}
|
||||
|
||||
public override void CreateContract(Contract contract) { }
|
||||
public override void UpdateContract(Contract contract) { }
|
||||
public override void DeleteContract(int id) { }
|
||||
public override Contract GetContract(int id) { return new Contract(); }
|
||||
public override List<Contract> GetContracts() { return new List<Contract>(); }
|
||||
public override void DeleteContracts() { }
|
||||
|
||||
public override void CreateCourse(Course course) { }
|
||||
public override void UpdateCourse(Course course) { }
|
||||
public override void DeleteCourse(int id) { }
|
||||
public override Course GetCourse(int id) { return new Course(); }
|
||||
public override List<Course> GetCourses() { return new List<Course>(); }
|
||||
public override void DeleteCourses() { }
|
||||
//=======================================================================
|
||||
|
||||
public override void CreateEmployee(Employee employee)
|
||||
{
|
||||
var maxId = 0;
|
||||
if (GetEmployees().Count > 0)
|
||||
{
|
||||
maxId = _employeeCollection.AsQueryable().Max(emp => emp.Id);
|
||||
}
|
||||
employee.Id = maxId + 1;
|
||||
_employeeCollection.InsertOne(employee);
|
||||
}
|
||||
public override void UpdateEmployee(Employee employee)
|
||||
{
|
||||
var filter = Builders<Employee>.Filter.Eq(emp => emp.Id, employee.Id);
|
||||
var update = Builders<Employee>.Update
|
||||
.Set(emp => emp.EmployeeName, employee.EmployeeName)
|
||||
.Set(emp => emp.Birthdate, employee.Birthdate)
|
||||
.Set(emp => emp.Address, employee.Address)
|
||||
.Set(emp => emp.PhoneNumber, employee.PhoneNumber)
|
||||
.Set(emp => emp.Email, employee.Email)
|
||||
.Set(emp => emp.PositionId, employee.PositionId);
|
||||
_employeeCollection.UpdateOne(filter, update);
|
||||
}
|
||||
public override void DeleteEmployee(int id)
|
||||
{
|
||||
_employeeCollection.DeleteOne(emp => emp.Id == id);
|
||||
}
|
||||
public override Employee GetEmployee(int id)
|
||||
{
|
||||
return _employeeCollection.Find(emp => emp.Id == id).FirstOrDefault();
|
||||
}
|
||||
public override Employee GetEmployee(string employeeName)
|
||||
{
|
||||
return _employeeCollection.Find(emp => emp.EmployeeName == employeeName).FirstOrDefault();
|
||||
}
|
||||
public override List<Employee> GetEmployees()
|
||||
{
|
||||
return _employeeCollection.Find(_ => true).ToList();
|
||||
}
|
||||
public override void DeleteEmployees()
|
||||
{
|
||||
_positionCollection.DeleteMany(_ => true);
|
||||
}
|
||||
|
||||
public override void CreateEmployee_Course(Employee_Course employee_course) { }
|
||||
public override void DeleteEmployee_Course(int empId, int courseId) { }
|
||||
public override Employee_Course GetEmployee_Course(int empId, int courseId) { return new Employee_Course(); }
|
||||
public override List<Employee_Course> GetEmployee_Courses() { return new List<Employee_Course>(); }
|
||||
public override void DeleteEmployee_Courses() { }
|
||||
//=======================================================================
|
||||
|
||||
public override void CreateContract(Contract contract)
|
||||
{
|
||||
var maxId = 0;
|
||||
if (GetContracts().Count > 0)
|
||||
{
|
||||
maxId = _contractCollection.AsQueryable().Max(con => con.Id);
|
||||
}
|
||||
contract.Id = maxId + 1;
|
||||
_contractCollection.InsertOne(contract);
|
||||
}
|
||||
public override void UpdateContract(Contract contract)
|
||||
{
|
||||
var filter = Builders<Contract>.Filter.Eq(con => con.Id, contract.Id);
|
||||
var update = Builders<Contract>.Update
|
||||
.Set(con => con.DateOfConclusion, contract.DateOfConclusion)
|
||||
.Set(con => con.Duration, contract.Duration)
|
||||
.Set(con => con.EmployeeId, contract.EmployeeId);
|
||||
_contractCollection.UpdateOne(filter, update);
|
||||
}
|
||||
public override void DeleteContract(int id)
|
||||
{
|
||||
_contractCollection.DeleteOne(con => con.Id == id);
|
||||
}
|
||||
public override Contract GetContract(int id)
|
||||
{
|
||||
return _contractCollection.Find(con => con.Id == id).FirstOrDefault();
|
||||
}
|
||||
public override List<Contract> GetContracts()
|
||||
{
|
||||
return _contractCollection.Find(_ => true).ToList();
|
||||
}
|
||||
public override void DeleteContracts()
|
||||
{
|
||||
_positionCollection.DeleteMany(_ => true);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
|
||||
public override void CreateCourse(Course course)
|
||||
{
|
||||
var maxId = 0;
|
||||
if (GetCourses().Count > 0)
|
||||
{
|
||||
maxId = _courseCollection.AsQueryable().Max(crs => crs.Id);
|
||||
}
|
||||
course.Id = maxId + 1;
|
||||
_courseCollection.InsertOne(course);
|
||||
}
|
||||
public override void UpdateCourse(Course course)
|
||||
{
|
||||
var filter = Builders<Course>.Filter.Eq(crs => crs.Id, course.Id);
|
||||
var update = Builders<Course>.Update
|
||||
.Set(crs => crs.DateOfEvent, course.DateOfEvent)
|
||||
.Set(crs => crs.HoursNumber, course.HoursNumber)
|
||||
.Set(crs => crs.Result, course.Result);
|
||||
_courseCollection.UpdateOne(filter, update);
|
||||
}
|
||||
public override void DeleteCourse(int id)
|
||||
{
|
||||
_courseCollection.DeleteOne(crs => crs.Id == id);
|
||||
}
|
||||
public override Course GetCourse(int id)
|
||||
{
|
||||
return _courseCollection.Find(crs => crs.Id == id).FirstOrDefault();
|
||||
}
|
||||
public override List<Course> GetCourses()
|
||||
{
|
||||
return _courseCollection.Find(_ => true).ToList();
|
||||
}
|
||||
public override void DeleteCourses()
|
||||
{
|
||||
_courseCollection.DeleteMany(_ => true);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
|
||||
public override void CreateEmployee_Course(Employee_Course employee_course)
|
||||
{
|
||||
_employee_CourseCollection.InsertOne(employee_course);
|
||||
}
|
||||
public override void DeleteEmployee_Course(int empId, int courseId)
|
||||
{
|
||||
_employee_CourseCollection.DeleteOne(e => e.EmployeeId == empId && e.CourseId == courseId);
|
||||
}
|
||||
public override Employee_Course GetEmployee_Course(int empId, int courseId)
|
||||
{
|
||||
return _employee_CourseCollection.Find(e => e.EmployeeId == empId && e.CourseId == courseId).FirstOrDefault();
|
||||
}
|
||||
public override List<Employee_Course> GetEmployee_Courses()
|
||||
{
|
||||
return _employee_CourseCollection.Find(_ => true).ToList();
|
||||
}
|
||||
public override void DeleteEmployee_Courses()
|
||||
{
|
||||
_employee_CourseCollection.DeleteMany(_ => true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using DepartmentStaffDatabase;
|
||||
using MongoDB.Bson;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -24,7 +25,6 @@ namespace DepartmentStaffView
|
||||
try
|
||||
{
|
||||
var list = db.GetEmployee_Courses();
|
||||
dataGridView1.DataSource = list;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user