示例#1
0
 public SchoolName()
 {
     Auth = app.Auth;
     InitializeComponent();
     GetList();
     statuText.Content = "就绪";
 }
示例#2
0
 /// <summary>
 /// 删除一个院系
 /// </summary>
 /// <param name="id">将被删除的院系编号</param>
 /// <param name="auth">授权人员</param>
 /// <exception cref="NoPermissionException">NoPermissionException</exception>
 /// <returns>是否删除成功</returns>        
 public static bool Delete(int id, Authentication auth)
 {
     if (auth.CheckAllows("departments", Permission.DELETE))
     {
         String SQL = @"DELETE FROM [dbo].[departments] WHERE ([departid] = {0});";
         SQL = String.Format(SQL, id);
         SqlCommand cmd = new SqlCommand(SQL, auth.Connection);
         switch (cmd.ExecuteNonQuery())
         {
             case 1:
                 cmd.Dispose();
                 return true;
             default:
                 cmd.Dispose();
                 return false;
         }
     }
     throw new NoPermissionException();
 }
示例#3
0
 /// <summary>
 /// 获取院校列表
 /// </summary>
 /// <param name="auth">授权人员</param>
 /// <returns>院校信息列表</returns>
 public static Department[] GetDepartments(School school, Authentication auth)
 {
     if (auth.CheckAllows("departments", Permission.SELECT))
     {
         List<Department> departments = new List<Department>();
         String SQL = @"SELECT TOP 1000  * FROM [dbo].[departments] WHERE [schoolid] = {0};";
         SQL = String.Format(SQL, school.ID);
         SqlCommand cmd = new SqlCommand(SQL, auth.Connection);
         using (SqlDataReader data = cmd.ExecuteReader())
         {
             while (data.Read())
             {
                 departments.Add(new Department(data));
             }
         }
         return departments.ToArray();
     }
     return new Department[0];
 }
示例#4
0
 /// <summary>
 /// 将当前实例作为新纪录添加到相关数据表
 /// </summary>
 /// <param name="auth">授权人员</param>
 /// <exception cref="NoPermissionException">NoPermissionException</exception>
 /// <returns>操作是否成功</returns>
 public bool Insert(Authentication auth)
 {
     if (auth.CheckAllows("major", Permission.INSERT))
     {
         String INSERTSQL = "INSERT INTO [dbo].[major] ([majorname][departid]) VALUES (N'{0}',{1});";
         String SELECTSQL = "SELECT TOP 1 * FROM [dbo].[MajorView] WHERE majorname = N'{0}' AND departid = {1};";
         INSERTSQL = String.Format(INSERTSQL, this.Name, this.ParentDepartment);
         SELECTSQL = String.Format(SELECTSQL, this.Name, this.ParentDepartment);
         SqlTransaction transaction = auth.Connection.BeginTransaction();
         SqlCommand cmd = new SqlCommand(SELECTSQL, auth.Connection);
         cmd.Transaction = transaction;
         SqlDataReader data = cmd.ExecuteReader();
         try
         {
             if (data.HasRows)
             {
                 data.Close();
                 transaction.Rollback();
                 return false;
             }
             data.Close();
             cmd.CommandText = INSERTSQL;
             switch (cmd.ExecuteNonQuery())
             {
                 case 1:
                     transaction.Commit();
                     data = cmd.ExecuteReader();
                     if (data.Read())
                     {
                         ctor(data);
                         data.Close();
                     }
                     cmd.Dispose();
                     return true;
                 case 0:
                     transaction.Commit();
                     cmd.Dispose();
                     return false;
                 default:
                     transaction.Rollback();
                     cmd.Dispose();
                     return false;
             }
         }
         catch (Exception ex)
         {
             if (!data.IsClosed)
             {
                 data.Close();
             }
             Debuger.PrintException(ex);
             try
             {
                 transaction.Rollback();
                 cmd.Dispose();
             }
             catch (Exception ex2)
             {
                 // This catch block will handle any errors that may have occurred
                 // on the server that would cause the rollback to fail, such as
                 // a closed connection.
                 Debuger.PrintException(ex2);
             }
             return false;
         }
         finally
         {
             if (!data.IsClosed)
             {
                 data.Close();
             }
         }
     }
     throw new NoPermissionException();
 }
示例#5
0
 /// <summary>
 /// 删除当前专业
 /// </summary>
 /// <param name="auth">授权人员</param>
 /// <exception cref="NoPermissionException">NoPermissionException</exception>
 /// <returns>是否删除成功</returns>
 public bool Delete(Authentication auth)
 {
     return Delete(this.ID, auth);
 }
示例#6
0
 /// <summary>
 /// 获取指定院系下的所有专业
 /// </summary>
 /// <param name="depart">所属院系</param>
 /// <param name="auth">授权人员</param>
 /// <returns>指定院系下的专业列表</returns>
 public static Major[] GetMajor(Department depart, Authentication auth)
 {
     if (auth.CheckAllows("MajorView", Permission.SELECT))
     {
         List<Major> majors = new List<Major>();
         String SQL = @"SELECT  * FROM [dbo].[MajorView] WHERE [departid] = {0};";
         SQL = String.Format(SQL, depart.ID);
         SqlCommand cmd = new SqlCommand(SQL, auth.Connection);
         using (SqlDataReader data = cmd.ExecuteReader())
         {
             while (data.Read())
             {
                 majors.Add(new Major(data));
             }
         }
         return majors.ToArray();
     }
     return new Major[0];
 }
示例#7
0
 /// <summary>
 /// 在数据库中更新当前实例
 /// </summary>
 /// <param name="auth">授权人员</param>
 /// <exception cref="NoPermissionException">NoPermissionException</exception>
 /// <returns>操作是否成功</returns>/// <returns></returns>
 public bool Update(Authentication auth)
 {
     if (auth.CheckAllows("departments", Permission.UPDATE))
     {
         String SQL = "UPDATE departments SET departname = N'{1}',schoolid = {2} WHERE departid = {0};";
         SQL = String.Format(SQL, this.ID, this.Name, this.ParentSchoolID);
         SqlTransaction transaction = auth.Connection.BeginTransaction();
         SqlCommand cmd = new SqlCommand(SQL, auth.Connection);
         cmd.Transaction = transaction;
         try
         {
             switch (cmd.ExecuteNonQuery())
             {
                 case 1:
                     transaction.Commit();
                     cmd.Dispose();
                     return true;
                 case 0:
                     transaction.Commit();
                     cmd.Dispose();
                     return false;
                 default:
                     transaction.Rollback();
                     cmd.Dispose();
                     return false;
             }
         }
         catch (Exception ex)
         {
             Debuger.PrintException(ex);
             try
             {
                 transaction.Rollback();
                 cmd.Dispose();
             }
             catch (Exception ex2)
             {
                 // This catch block will handle any errors that may have occurred
                 // on the server that would cause the rollback to fail, such as
                 // a closed connection.
                 Debuger.PrintException(ex2);
             }
             return false;
         }
     }
     throw new NoPermissionException();
 }
示例#8
0
        /// <summary>
        /// 通过ID查找院系
        /// </summary>
        /// <param name="id">院系ID</param>
        /// <param name="auth">授权人员</param>
        /// <returns>查找到的院系实例或者查找失败返回默认实例</returns>
        public static Department Search(Int32 id, Authentication auth)
        {
            if (auth.CheckAllows("departments", Permission.SELECT))
            {
                String SQL = @"SELECT TOP 1 * FROM [dbo].[schools]  WHERE [schoolid] = {0};";
                SQL = String.Format(SQL, id);
                SqlCommand cmd = new SqlCommand(SQL, auth.Connection);
                Department s = null;
                using (SqlDataReader data = cmd.ExecuteReader())
                {

                    if (data.Read())
                    {
                        s = new Department(data);
                    }
                    else
                    {
                        s = new Department();
                    }
                }
                return s;
            }
            throw new NoPermissionException();
        }
示例#9
0
文件: Schools.cs 项目: JackJCSN/APMS
 /// <summary>
 /// 获取院校列表
 /// </summary>
 /// <param name="auth">授权人员</param>
 /// <returns>院校信息列表</returns>
 public static School[] GetSchools(Authentication auth)
 {
     if (auth.CheckAllows("schools", Permission.SELECT))
     {
         List<School> schools = new List<School>();
         String SQL = @"SELECT * FROM [dbo].[schools];";
         SqlCommand cmd = new SqlCommand(SQL, auth.Connection);
         SqlDataReader data = cmd.ExecuteReader();
         while (data.Read())
         {
             schools.Add(new School(data));
         }
         data.Close();
         return schools.ToArray();
     }
     return new School[0];
 }
示例#10
0
文件: Schools.cs 项目: JackJCSN/APMS
 /// <summary>
 /// 将当前实例作为新纪录添加到相关数据表
 /// </summary>
 /// <param name="auth">授权人员</param>
 /// <exception cref="NoPermissionException">NoPermissionException</exception>
 /// <returns>操作是否成功</returns>
 public bool Insert(Authentication auth)
 {
     return Insert(this.Name, auth);
 }
示例#11
0
文件: Schools.cs 项目: JackJCSN/APMS
 /// <summary>
 /// 新增一个院校到相关数据表
 /// </summary>
 /// <param name="name">院校名字</param>
 /// <param name="auth">授权人员</param>
 /// <exception cref="NoPermissionException">NoPermissionException</exception>
 /// <returns>操作是否成功</returns>
 public static bool Insert(String name, Authentication auth)
 {
     if (auth.CheckAllows("schools", Permission.INSERT))
     {
         String INSERTSQL = "INSERT INTO [dbo].[schools] ([schoolname]) VALUES (N'{0}');";
         String SELECTSQL = "SELECT * FROM [dbo].[schools] WHERE schoolname = N'{0}';";
         INSERTSQL = String.Format(INSERTSQL, name);
         SELECTSQL = String.Format(SELECTSQL, name);
         SqlTransaction transaction = auth.Connection.BeginTransaction();
         SqlCommand cmd = new SqlCommand(SELECTSQL, auth.Connection);
         cmd.Transaction = transaction;
         SqlDataReader data = cmd.ExecuteReader();
         try
         {
             if (data.HasRows)
             {
                 data.Close();
                 transaction.Rollback();
                 return false;
             }
             data.Close();
             cmd.CommandText = INSERTSQL;
             switch (cmd.ExecuteNonQuery())
             {
                 case 1:
                     transaction.Commit();
                     cmd.Dispose();
                     return true;
                 case 0:
                     transaction.Commit();
                     cmd.Dispose();
                     return false;
                 default:
                     transaction.Rollback();
                     cmd.Dispose();
                     return false;
             }
         }
         catch (Exception ex)
         {
             if (!data.IsClosed)
             {
                 data.Close();
             }
             Debuger.PrintException(ex);
             try
             {
                 transaction.Rollback();
                 cmd.Dispose();
             }
             catch (Exception ex2)
             {
                 // This catch block will handle any errors that may have occurred
                 // on the server that would cause the rollback to fail, such as
                 // a closed connection.
                 Debuger.PrintException(ex2);
             }
             return false;
         }
         finally
         {
             if (!data.IsClosed)
             {
                 data.Close();
             }
         }
     }
     throw new NoPermissionException();
 }
示例#12
0
 /// <summary>
 /// 将当前文档插入数据库
 /// </summary>
 /// <param name="auth">授权人员</param>
 /// <returns>插入操作是否成功</returns>
 public bool Insert(Authentication auth)
 {
     if (auth.CheckAllows("announcedoc", Permission.INSERT))
     {
         String INSERTSQL = "INSERT INTO [dbo].[announcedoc](fhash,fname,fdata) VALUES (@fid,@filename,@filedata);";
         SqlTransaction transaction = auth.Connection.BeginTransaction();
         SqlCommand cmd = new SqlCommand(INSERTSQL, auth.Connection);
         cmd.Parameters.AddWithValue("@fid", Authentication.SHA1(this.buffer));
         cmd.Parameters.AddWithValue("@filename", this.Name);
         cmd.Parameters.AddWithValue("@filedata", this.Data);
         cmd.Transaction = transaction;
         try
         {
             cmd.CommandText = INSERTSQL;
             switch (cmd.ExecuteNonQuery())
             {
                 case 1:
                     transaction.Commit();
                     cmd.Dispose();
                     return true;
                 case 0:
                     transaction.Rollback();
                     cmd.Dispose();
                     return false;
                 default:
                     transaction.Rollback();
                     cmd.Dispose();
                     return false;
             }
         }
         catch (Exception ex)
         {
             Debuger.PrintException(ex);
             try
             {
                 transaction.Rollback();
                 cmd.Dispose();
             }
             catch (Exception ex2)
             {
                 // This catch block will handle any errors that may have occurred
                 // on the server that would cause the rollback to fail, such as
                 // a closed connection.
                 Debuger.PrintException(ex2);
             }
             return false;
         }
     }
     throw new NoPermissionException();
 }
示例#13
0
 public static Documents[] GetDocuments(Authentication auth)
 {
     if (auth.CheckAllows("schools", Permission.SELECT))
     {
         SqlDataReader data = null;
         try
         {
             String SQL = @"SELECT TOP 1000 * FROM [dbo].[announcedoc];";
             SQL = String.Format(SQL);
             SqlCommand cmd = new SqlCommand(SQL, auth.Connection);
             data = cmd.ExecuteReader();
             List<Documents> d = new List<Documents>();
             while (data.Read())
             {
                 d.Add(new Documents(data));
             }
             data.Close();
             return d.ToArray<Documents>();
         }
         finally
         {
             if (!data.IsClosed)
             {
                 data.Close();
             }
         }
     }
     return new Documents[0];
 }