Exemplo n.º 1
0
        public List<DepartmentModel> GetAllDepartmentName(List<DepartmentModel> departmentModelsParameter)
        {
            List<DepartmentModel> departmentModels = new List<DepartmentModel>();
            string query = String.Format(@"select id,name from tblDepartment where id=@deptId");

            foreach (DepartmentModel department in departmentModelsParameter)
            {
                using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings[1].ConnectionString))
                {
                    using (SqlCommand command = new SqlCommand(query, connection))
                    {
                        command.Parameters.Clear();
                        command.Parameters.AddWithValue("@deptId",department.DeptID);
                        connection.Open();
                        SqlDataReader rdr = command.ExecuteReader();
                        while (rdr.Read())
                        {
                            DepartmentModel departmentModel = new DepartmentModel();
                            departmentModel.DeptID = Convert.ToInt32(rdr[0]);
                            departmentModel.DepartmentName = rdr[1].ToString();
                            departmentModels.Add(departmentModel);
                        }
                        connection.Close();
                    }
                }
            }

            return departmentModels;
        }
Exemplo n.º 2
0
        public int SaveDepartmentName(DepartmentModel departmentModel)
        {
            string query = String.Format("Insert into tblDepartment values(@name,@facultyID)");
            sqlCommand.CommandText = query;
            SqlParameter nameParameter = new SqlParameter("@name",departmentModel.DepartmentName);
            sqlCommand.Parameters.Add(nameParameter);

            SqlParameter facultyIdParameter = new SqlParameter("@facultyID",departmentModel.FacultyID);
            sqlCommand.Parameters.Add(facultyIdParameter);

            sqlConnection.Open();
            int rowsAffected = sqlCommand.ExecuteNonQuery();
            sqlConnection.Close();
            return rowsAffected;
        }
Exemplo n.º 3
0
        public bool IsDepartNameExist(DepartmentModel departmentModel)
        {
            bool isDepartmentNameExist = false;
            string query = String.Format("Select * from tblDepartment where name=@deptName");
            SqlParameter nameParameter = new SqlParameter("@deptName",departmentModel.DepartmentName);
            sqlCommand.Parameters.Add(nameParameter);
            sqlCommand.CommandText = query;

            sqlConnection.Open();
             SqlDataReader rdr = sqlCommand.ExecuteReader();
             while (rdr.Read())
             {
                 isDepartmentNameExist = true;
             }

            sqlConnection.Close();
            return isDepartmentNameExist;
        }
Exemplo n.º 4
0
        public void saveDepartmentButton_Click(object sender, EventArgs e)
        {
            DepartmentModel departmentModel = new DepartmentModel();
            departmentModel.DepartmentName = departmentNameTextBox.Text;
            departmentModel.FacultyID = Convert.ToInt32(facultyDropDownList.SelectedItem.Value);
            if (departmentNameTextBox.Text=="")
            {
                successStatusLabel.InnerText = "Please enter the department name";
            }
            else
            {
                if (facultyDropDownList.SelectedValue=="-1")
                {
                    successStatusLabel.InnerText = "Please select the faculty.";
                }
                else
                {
                    if (addDepartmentBll.IsDepartNameExist(departmentModel))
                    {
                        failStatusLabel.InnerText = "Department name already exist";
                        successStatusLabel.InnerText = "";
                    }
                    else
                    {
                        if (addDepartmentBll.SaveDepartmentName(departmentModel) > 0)
                        {
                            failStatusLabel.InnerText = "";
                            successStatusLabel.InnerText = "Department name saved";
                            ShowDepartmentInformationInGridView();
                            GetAllFacultyInDropDownList();
                            ListItem listItem = new ListItem("Select faculty", "-1");
                            facultyDropDownList.Items.Insert(0, listItem);

                        }
                        else
                        {
                            failStatusLabel.InnerText = "";
                            failStatusLabel.InnerText = "Department name not saved";
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        public List<DepartmentModel> GetAllDepartmentId()
        {
            List<DepartmentModel> departmentModels = new List<DepartmentModel>();
            string query = String.Format(@"select deptId from tblStudentSemisterRegistration");

            using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings[1].ConnectionString))
            {
                using (SqlCommand command = new SqlCommand(query,connection))
                {
                    connection.Open();
                    SqlDataReader rdr = command.ExecuteReader();
                    while (rdr.Read())
                    {
                       DepartmentModel departmentModel = new DepartmentModel();
                        departmentModel.DeptID = Convert.ToInt32(rdr[0]);
                        departmentModels.Add(departmentModel);
                    }
                    connection.Close();
                }
            }
            return departmentModels;
        }
Exemplo n.º 6
0
 public int SaveDepartmentName(DepartmentModel departmentModel)
 {
     return addDepartmentDal.SaveDepartmentName(departmentModel);
 }
Exemplo n.º 7
0
 public bool IsDepartNameExist(DepartmentModel departmentModel)
 {
     return addDepartmentDal.IsDepartNameExist(departmentModel);
 }