Exemple #1
0
        private void AddBtn_Click(object sender, EventArgs e)
        {
            try
            {
                string depName = DepartmentNameBox.Text;
                double salary  = double.Parse(DepartBaseSalaryBox.Text);
                if (!depController.DepartmentNameDataValidation(depName))
                {
                    throw new Exception("Department with this name already exists!");
                }
                else if (!depController.DepartmentSalaryDataValidation(salary))
                {
                    throw new Exception("The salary is too low!");
                }
                else
                {
                    depController.AddDepartment(depName, salary);
                    MessageBox.Show("Operation is successful!", "Successful operation", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    ClearInput();
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Incorrect data",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        public void AddNewDepartmentTest()
        {
            DepartmentController dc         = new DepartmentController();
            MySqlConnection      connection = CreateConnection();

            string name = "";
            bool   add  = dc.AddDepartment("Test department");

            using (connection)
            {
                connection.Open();

                string sql = "SELECT name FROM departments WHERE name = @name;";
                using (MySqlCommand cmd = new MySqlCommand(sql, connection))
                {
                    cmd.Parameters.AddWithValue("@name", "Test department");
                    name = cmd.ExecuteScalar().ToString();
                }
                string sql1 = "DELETE FROM departments WHERE name = @name;";
                using (MySqlCommand cmd = new MySqlCommand(sql1, connection))
                {
                    cmd.Parameters.AddWithValue("@name", "Test department");
                    cmd.ExecuteNonQuery();
                }
            }

            Assert.IsTrue(add);
            Assert.AreEqual("Test department", name);
        }
Exemple #3
0
        public void TestMethod1()
        {
            //部门
            //新增
            testcontroller.GetDepartmentList();
            DepartmentOperateDTO adddto = new DepartmentOperateDTO();

            adddto.DepartName = "单元测试部门";
            var addresult   = JsonConvert.DeserializeObject <ResultDTO <object> >(testcontroller.AddDepartment(adddto).Content.ReadAsStringAsync().Result);
            var resultlist1 = JsonConvert.DeserializeObject <List <DepartmentResultDTO> >(testcontroller.GetDepartmentList().Content.ReadAsStringAsync().Result);
            var target      = resultlist1.Where(m => m.DepartName == "单元测试部门").FirstOrDefault();

            Assert.IsNotNull(target);

            //修改
            adddto.DepartID   = target.DepartID;
            adddto.DepartName = "修改单元测试部门";
            var updateresult = JsonConvert.DeserializeObject <ResultDTO <object> >(testcontroller.UpdateDepartment(adddto).Content.ReadAsStringAsync().Result);
            var resultlist2  = JsonConvert.DeserializeObject <List <DepartmentResultDTO> >(testcontroller.GetDepartmentList().Content.ReadAsStringAsync().Result);

            target = resultlist2.Where(m => m.DepartName == "修改单元测试部门").FirstOrDefault();
            Assert.IsNotNull(target);

            //删除
            DepartmentSearchDTO deletedto = new DepartmentSearchDTO();

            deletedto.DepartID = target.DepartID;
            var deletedtostr    = TransformHelper.ConvertDTOTOBase64JsonString(deletedto);
            var deleteresultstr = testcontroller.DeleteDepartment(deletedtostr).Content.ReadAsStringAsync().Result;
            var deleteresult    = JsonConvert.DeserializeObject <ResultDTO <object> >(deleteresultstr);
            var resultlist3     = JsonConvert.DeserializeObject <List <DepartmentResultDTO> >(testcontroller.GetDepartmentList().Content.ReadAsStringAsync().Result);

            target = resultlist3.Where(m => m.DepartID == target.DepartID).FirstOrDefault();
            Assert.IsNull(target);
        }
        public void AddExistingDepartmentTest()
        {
            DepartmentController dc         = new DepartmentController();
            MySqlConnection      connection = CreateConnection();

            bool add  = dc.AddDepartment("Test department");
            bool add1 = dc.AddDepartment("Test department");

            using (connection)
            {
                connection.Open();
                string sql = "DELETE FROM departments WHERE name = @name;";
                using (MySqlCommand cmd = new MySqlCommand(sql, connection))
                {
                    cmd.Parameters.AddWithValue("@name", "Test department");
                    cmd.ExecuteNonQuery();
                }
            }
            Assert.IsFalse(add1);
        }
 private void add_Click(object sender, RoutedEventArgs e)
 {
     if (flag == false)
     {
         validMessage.Visibility = Visibility.Visible;
     }
     else
     {
         DepartmentController.AddDepartment(departmentName.Text);
         Close();
     }
 }
Exemple #6
0
        private bool AddDepartments()
        {
            bool success;

            try
            {
                string   name    = tbDepartmentName.Text;
                Personal manager = (Personal)cmbManager.SelectedItem;
                int      min     = Convert.ToInt32(tbMin.Text);
                int      max     = Convert.ToInt32(tbMax.Text);

                Department newDepartment = new Department(name, manager.Id, min, max);
                departmentcontroller.AddDepartment(newDepartment);
                success = true;
            }
            catch
            {
                success = false;
            }
            return(success);
        }
        public void GetDepartmentTest()
        {
            DepartmentController dc         = new DepartmentController();
            MySqlConnection      connection = CreateConnection();

            bool add = dc.AddDepartment("Test department");
            ProductDepartment dept = dc.GetDepartment("Test department");

            using (connection)
            {
                connection.Open();
                string sql = "DELETE FROM departments WHERE name = @name;";
                using (MySqlCommand cmd = new MySqlCommand(sql, connection))
                {
                    cmd.Parameters.AddWithValue("@name", "Test department");
                    cmd.ExecuteNonQuery();
                }
            }

            Assert.AreEqual("Test department", dept.DptName);
        }
Exemple #8
0
        private void AddDepartment()
        {
            Department dept = (Department)deptBox.SelectedItem;

            if (ValidateEdits())
            {
                List <SqlParameter> sqlParameters = new List <SqlParameter>();

                SqlParameter idd = new SqlParameter("@id", SqlDbType.UniqueIdentifier);
                idd.IsNullable = false;
                idd.Value      = Guid.NewGuid();
                sqlParameters.Add(idd);

                SqlParameter name = new SqlParameter("@name", SqlDbType.NVarChar);
                name.Value      = nameBox.Text.Trim();
                name.IsNullable = false;
                sqlParameters.Add(name);

                SqlParameter code = new SqlParameter("@code", SqlDbType.NVarChar);
                code.IsNullable = false;
                code.Value      = codeBox.Text.Trim();
                sqlParameters.Add(code);

                SqlParameter parentid = new SqlParameter("@parentid", SqlDbType.UniqueIdentifier);
                parentid.IsNullable = true;
                parentid.Value      = dept.ID;
                sqlParameters.Add(parentid);

                if (deptController.AddDepartment(sqlParameters))
                {
                    statusLabel.Text = "Новывй отдел добавлен";
                    ClearEdits();
                    //FillGrid();
                }
                else
                {
                    statusLabel.Text = "Отдел добавлен не добавлен";
                }
            }
        }
        public void EditDepartmentTest()
        {
            DepartmentController dc         = new DepartmentController();
            MySqlConnection      connection = CreateConnection();

            bool add          = dc.AddDepartment("Test department");
            bool edit         = dc.EditDepartment("Test department", "New department name");
            int  numberOfRows = 0;

            using (connection)
            {
                connection.Open();
                string sql = "DELETE FROM departments WHERE name = @name;";
                using (MySqlCommand cmd = new MySqlCommand(sql, connection))
                {
                    cmd.Parameters.AddWithValue("@name", "New department name");
                    numberOfRows = cmd.ExecuteNonQuery();
                }
            }
            Assert.IsTrue(edit);
            Assert.AreEqual(1, numberOfRows);
        }
        public void DeleteDepartmentTest()
        {
            DepartmentController dc         = new DepartmentController();
            MySqlConnection      connection = CreateConnection();

            dc.AddDepartment("Test department");
            bool   deletion = dc.DeleteDepartment("Test department");
            object results  = null;

            using (connection)
            {
                connection.Open();
                string sql = "SELECT id FROM departments WHERE name = @name;";
                using (MySqlCommand cmd = new MySqlCommand(sql, connection))
                {
                    cmd.Parameters.AddWithValue("@name", "Test department");
                    results = cmd.ExecuteScalar();
                }
            }
            Assert.IsTrue(deletion);
            Assert.AreEqual(null, results);
        }