コード例 #1
0
        public void DeleteByIdTest()
        {
            // Добавим 2 сущности
            Guid id1 = Guid.NewGuid();
            Guid id2 = Guid.NewGuid();

            var department1 = new Department
                              {
                                  Id = id1,
                                  Name = "Для удаления 1",
                                  Budget = 15,
                                  StartDate = DateTime.Now
                              };

            var department2 = new Department
                              {
                                  Id = id2,
                                  Name = "Для удаления 2",
                                  Budget = 15,
                                  StartDate = DateTime.Now
                              };

            this._repositoryDepartment.Insert(department1, department2);

            // Проверим что добавились
            var departments = this._repositoryDepartment.GetAll(d => d.Id == id1 || d.Id == id2).ToList();
            Assert.IsTrue(departments.Count == 2);

            // Удаляем
            this._repositoryDepartment.Delete(id1, id2);

            // Проверим что удалились
            departments = this._repositoryDepartment.GetAll(d => d.Id == id1 || d.Id == id2).ToList();
            Assert.IsTrue(departments.Count == 0);
        }
コード例 #2
0
       public Department GetDepartmentData(string id)
       {
           Department dept = new Department();
           string query = "select departmentName from department where departmentId = '" + id + "'";
           SqlCommand cmd = da.GetCommand(query);
           cmd.Connection.Open();
           SqlDataReader reader = cmd.ExecuteReader();

           if (reader.Read())
           {
               dept.departmentName = reader.GetString(0);


           }
           return dept;
       }
コード例 #3
0
       public bool updateDepartment(Department obj)
       {
           string insertCommand = "update department set departmentName=@departmentName " +
                                  "where departmentId=@departmentId";
           SqlCommand command = new SqlCommand(insertCommand);
           SqlParameter idParameter = new SqlParameter("@departmentid", SqlDbType.NVarChar, 50);
           idParameter.Value = obj.departmentId;
           SqlParameter nameParameter = new SqlParameter("@departmentName", SqlDbType.NVarChar, 50);
           nameParameter.Value = obj.departmentName;


           command.Parameters.Add(idParameter);
           command.Parameters.Add(nameParameter);

           if (da.Execution(command))
           {
               return true;
           }
           else
           {
               return false;
           }
       }
コード例 #4
0
       public bool insertDepartment(Department obj)
       {
           string insertCommand = "INSERT INTO department (departmentid,departmentName) " +
                                  "VALUES (@departmentid,@departmentName)";
           SqlCommand command = new SqlCommand(insertCommand);
           SqlParameter idParameter = new SqlParameter("@departmentid", SqlDbType.NVarChar, 50);
           idParameter.Value = obj.departmentId;
           SqlParameter nameParameter = new SqlParameter("@departmentName", SqlDbType.NVarChar, 50);
           nameParameter.Value = obj.departmentName;
           

           command.Parameters.Add(idParameter);
           command.Parameters.Add(nameParameter);
         
           if (da.Execution(command))
           {
               return true;
           }
           else
           {
               return false;
           }
       }
コード例 #5
0
       public bool deleteDepartment(Department obj)
       {
           string insertCommand = "delete from department  " +
                                  "where departmentId= @departmentId ";
           SqlCommand command = new SqlCommand(insertCommand);
           SqlParameter employeeIdParameter = new SqlParameter("@departmentId", SqlDbType.NVarChar, 50);
           employeeIdParameter.Value = obj.departmentId;


           command.Parameters.Add(employeeIdParameter);

           if (da.Execution(command))
           {
               return true;
           }
           else
           {
               return false;
           }

       }
コード例 #6
0
       public List<Department> GetDepartmentList()
       {
           List<Department> DepartmentList = new List<Department>();

           string query = "select departmentId,departmentName,departmentTotalEmployees,departmentTotalSalary from department";
           SqlCommand cmd = da.GetCommand(query);
           cmd.Connection.Open();
           SqlDataReader reader = cmd.ExecuteReader();

           while (reader.Read())
           {
               Department ej = new Department();
               ej.departmentId = reader.GetString(0);
               ej.departmentName = reader.GetString(1);
               ej.totalEmployee = reader.GetInt32(2);
               ej.totalSalary = reader.GetInt32(3);

               DepartmentList.Add(ej);
           }
           return DepartmentList;
       }
コード例 #7
0
        public void InsertTest()
        {
            var department = new Department
                             {
                                 Id = new Guid("4D97F4C1-A4F9-421B-8DCC-8D9127B2D756"),
                                 Name = "Test " + DateTime.Now,
                                 Budget = 15,
                                 StartDate = DateTime.Now
                             };

            this._repositoryDepartment.Insert(department);
        }
コード例 #8
0
        public void InsertOrUpdateTest()
        {
            // Проверим что такого нет
            var department = this._repositoryDepartment.Get(new Guid("4D97F4C1-A4F9-421B-8DCC-8D9127B2D759"));
            Assert.IsNull(department);

            // Создадим
            department = new Department
            {
                Id = new Guid("4D97F4C1-A4F9-421B-8DCC-8D9127B2D759"),
                Name = "Test " + DateTime.Now,
                Budget = 15,
                StartDate = DateTime.Now
            };

            this._repositoryDepartment.InsertOrUpdate(department);

            // Проверим что добавился
            department = this._repositoryDepartment.Get(new Guid("4D97F4C1-A4F9-421B-8DCC-8D9127B2D759"));
            Assert.IsNotNull(department);

            // Обновим
            var name = "Test " + DateTime.Now;
            department.Name = name;
            this._repositoryDepartment.InsertOrUpdate(department);

            // Проверим что обновился
            department = this._repositoryDepartment.Get(new Guid("4D97F4C1-A4F9-421B-8DCC-8D9127B2D759"));
            Assert.AreEqual(department.Name, name);

            // Удалим
            this._repositoryDepartment.Delete(department.Id);
        }
コード例 #9
0
        public void InsertCascadeTest()
        {
            var department = new Department
                             {
                                 Id = new Guid("5DE641CB-6D5F-4400-8F51-AEF4E4550955"),
                                 Name = "Test " + DateTime.Now,
                                 Budget = 15,
                                 StartDate = DateTime.Now,
                                 Courses =
                                     new Collection<Course>
                                     {
                                         new Course
                                         {
                                             Id = Guid.NewGuid(),
                                             Title = "Courses " + DateTime.Now,
                                             Credits = 100
                                         },
                                         new Course
                                         {
                                             Id = Guid.NewGuid(),
                                             Title = "Courses2 " + DateTime.Now,
                                             Credits = 100
                                         },
                                         new Course
                                         {
                                             Id = Guid.NewGuid(),
                                             Title = "Courses3 " + DateTime.Now,
                                             Credits = 100
                                         }
                                     }
                             };

            this._repositoryDepartment.Insert(department);
        }
コード例 #10
0
 private void updatedepartmentidcomboBox_SelectedValueChanged(object sender, EventArgs e)
 {
     string id = updatedepartmentidcomboBox.Text;
     dept = deptdata.GetDepartmentData(id);
     updatedepartmentnametext.Text = dept.departmentName;
 }