Exemplo n.º 1
0
 public BookType GetByID(Guid ID)
 {
     Database db = new Database("Books");
     try
     {
         db.Command.CommandType = CommandType.StoredProcedure;
         db.Command.CommandText = "tblBookTypeGETBYID";
         db.Command.Parameters.Add("@ID", SqlDbType.UniqueIdentifier).Value = ID;
         DataTable dt = db.ExecuteQuery();
         if (dt.Rows.Count == 1)
         {
             DataRow dr = dt.Rows[0];
             base.Initialize(dr);
             InitializeBusinessData(dr);
             return this;
         }
         else
         {
             throw new Exception("Book");
         }
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Exemplo n.º 2
0
        public ReviewList GetByBookID(Guid BookID)
        {
            Database db = new Database("Books");
            try
            {
                db.Command.Parameters.Clear();
                db.Command.CommandType = CommandType.StoredProcedure;
                db.Command.CommandText = "tblReviewGETBYBOOKID";
                db.Command.Parameters.Add("@BookID", SqlDbType.UniqueIdentifier).Value = BookID;
                DataTable dt = db.ExecuteQuery();
                foreach (DataRow dr in dt.Rows)
                {
                    Review s = new Review();
                    s.Initialize(dr);
                    s.InitializeBusinessData(dr);
                    s.IsDirty = false;
                    s.IsNew = false;
                    s.evtIsSavable += new IsSavableHandler(s_evtIsSavable);
                    _list.Add(s);
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return this;
        }
Exemplo n.º 3
0
        public ReviewList GetAll()
        {
            try
            {
                _list.Clear();
                Database db = new Database("Books");
                db.Command.CommandType = System.Data.CommandType.StoredProcedure;
                db.Command.CommandText = "tblReviewGETALL";
                DataTable dt = db.ExecuteQuery();
                //dgvStudent.DataSource = dt;
                foreach (DataRow dr in dt.Rows)
                {
                    Review s = new Review();
                    s.Initialize(dr);
                    s.InitializeBusinessData(dr);
                    s.IsDirty = false;
                    s.IsNew = false;
                    s.evtIsSavable += new IsSavableHandler(s_evtIsSavable);
                    _list.Add(s);
                }
            }

            catch(Exception ex)
            {
                throw;
            }

            return this;
        }
Exemplo n.º 4
0
 public Zipcode GetByZipId(Guid zipId)
 {
     try
     {
         Database db = new Database("Student");
         db.Command.CommandType = System.Data.CommandType.StoredProcedure;
         db.Command.CommandText = "tblZipcodeGetById";
         db.Command.Parameters.Add("@Id", System.Data.SqlDbType.UniqueIdentifier).Value = zipId;
         DataTable dt = db.ExecuteQuery();
         if (dt.Rows.Count == 1)
         {
             DataRow dr = dt.Rows[0];
             Id = (Guid)dr["Id"];
             Zip = dr["Zipcode"].ToString();
             City = dr["City"].ToString();
             State = dr["State"].ToString();
             return this;
         }
         else
         {
             throw new Exception("Zipcode not found");
         }
     }
     catch
     {
         throw;
     }
 }
Exemplo n.º 5
0
 private Boolean Delete(Database db)
 {
     try
     {
         db.Command.CommandType = CommandType.StoredProcedure;
         db.Command.CommandText = "tblStudentClassDelete";
         base.Initialize(db.Command, base.Id);
         db.ExecuteNonQueryWithTransaction();
         base.Initialize(db.Command);
         return true;
     }
     catch (Exception ex) { throw; }
 }
Exemplo n.º 6
0
 public StudentClass Save(Database db, Guid parentid)
 {
     _studentId = parentid;
     Boolean result = false;
     if (base.IsNew == true && IsSavable() == true)
         result = Insert(db);
     else if (base.Deleted == true)
         result = Delete(db);
     else if (base.IsNew == false && IsSavable() == true)
         result = Update(db);
     base.IsDirty = false;
     base.IsNew = false;
     return this;
 }
 public Boolean Save(Database db, Guid parentId)
 {
     Boolean result = true;
     foreach (StudentComment s in _list)
         if (s.IsSavable() == true)
         {
             s.Save(db, parentId);
             if (s.IsNew == true)
             {
                 result = false;
                 break;
             }
         }
     return result;
 }
Exemplo n.º 8
0
 public Client GetById(Guid id)
 {
     Database db = new Database("Customer");
     db.Command.CommandType = CommandType.StoredProcedure;
     db.Command.CommandText = "tblClient_GetById";
     base.Initialize(db.Command, id);
     DataTable dt=db.ExecuteQuery();
     if (dt.Rows.Count == 1)
     {
         DataRow dr = dt.Rows[0];
         InitializeBusinessData(dr);
         base.Initialize(dr);
     }
     return this;
 }
 public bool Save(Database db, Guid studentId)
 {
     bool result = true;
     foreach (StudentAddress s in _list)
         if (s.IsSavable() == true)
         {
             s.Save(db, studentId);
             if (s.IsNew == true)
             {
                 result = false;
                 break;
             }
         }
     return result;
 }
Exemplo n.º 10
0
        public ForumList GetAll()
        {
            _list.Clear();
            Database db = new Database("student");
            db.Command.CommandType = System.Data.CommandType.StoredProcedure;
            db.Command.CommandText = "tblForumGetAll";
            DataTable dt = db.ExecuteQuery();

            foreach (DataRow dr in dt.Rows)
            {
                Forum f = new Forum();
                f.InitializeBusinessData(dr);
                _list.Add(f);
            }
            return this;
        }
Exemplo n.º 11
0
 public StudentList GetAll()
 {
     _list.Clear();
     Database db = new Database("student");
     db.Command.CommandType = System.Data.CommandType.StoredProcedure;
     db.Command.CommandText = "tblStudentGetAll";
     DataTable dt = db.ExecuteQuery();
     foreach (DataRow dr in dt.Rows)
     {
         Student s = new Student();
         s.Initialize(dr);
         s.InitializeBusinessData(dr);
         s.IsDirty = false;
         s.IsNew = false;
         s.evtIsSavable += new IsSavableHandler(s_evtIsSavable);
         _list.Add(s);
     }
     return this;
 }
Exemplo n.º 12
0
 public StudentAddressList GetByStudentId(Guid studentId)
 {
     _list.Clear();
     Database db = new Database("Student");
     db.Command.CommandType = CommandType.StoredProcedure;
     db.Command.CommandText = "tblStudentAddressGetByStudentID";
     db.Command.Parameters.Add("@StudentId", SqlDbType.UniqueIdentifier).Value = studentId;
     DataTable dt = db.ExecuteQuery();
     foreach (DataRow dr in dt.Rows)
     {
         StudentAddress s = new StudentAddress();
         s.Initialize(dr);
         s.InitializeBusinessData(dr);
         s.IsDirty = false;
         s.IsNew = false;
         s.evtIsSavable += new IsSavableHandler(s_evtIsSavable);
         _list.Add(s);
     }
     return this;
 }
Exemplo n.º 13
0
 public PhoneTypeList GetAll()
 {
     _list.Clear();
     Database db = new Database("student");
     db.Command.CommandType = System.Data.CommandType.StoredProcedure;
     db.Command.CommandText = "tblPhoneTypeGetAll";
     DataTable dt = db.ExecuteQuery();
     PhoneType Blank = new PhoneType();
     Blank.Type = "Select Phone Type";
     _list.Add(Blank);
     foreach (DataRow dr in dt.Rows)
     {
         PhoneType e = new PhoneType();
         e.Initialize(dr);
         e.InitializeBusinessData(dr);
         e.IsDirty = false;
         e.IsNew = false;
         e.evtIsSavable += new IsSavableHandler(s_evtIsSavable);
         _list.Add(e);
     }
     return this;
 }
Exemplo n.º 14
0
        public BookList GetByBookTypeID(Guid bookTypeID)
        {
            _list.Clear();
            Database db = new Database("Books");
            db.Command.CommandType = System.Data.CommandType.StoredProcedure;
            db.Command.CommandText = "tblBookGETBYBOOKTYPEID";
            db.Command.Parameters.Add("@BookTypeID", SqlDbType.UniqueIdentifier).Value = bookTypeID;
            DataTable dt = db.ExecuteQuery();
            //dgvStudent.DataSource = dt;
            foreach (DataRow dr in dt.Rows)
            {
                Book s = new Book();
                s.Initialize(dr);
                s.InitializeBusinessData(dr);
                s.IsDirty = false;
                s.IsNew = false;
                s.evtIsSavable += new IsSavableHandler(s_evtIsSavable);
                _list.Add(s);
            }

            return this;
        }
Exemplo n.º 15
0
 public ClassList GetByProgramId(Guid programId)
 {
     _list.Clear();
     Database db = new Database("student");
     db.Command.CommandType = System.Data.CommandType.StoredProcedure;
     db.Command.CommandText = "tblClassGetByProgramId";
     db.Command.Parameters.Add("@ProgramId", SqlDbType.UniqueIdentifier).Value = programId;
     DataTable dt = db.ExecuteQuery();
     Class Blank = new Class();
     Blank.Name = "Select Classes";
     _list.Add(Blank);
     foreach (DataRow dr in dt.Rows)
     {
         Class c = new Class();
         c.Initialize(dr);
         c.InitializeBusinessData(dr);
         c.IsDirty = false;
         c.IsNew = false;
         c.evtIsSavable += new IsSavableHandler(s_evtIsSavable);
         _list.Add(c);
     }
     return this;
 }
Exemplo n.º 16
0
        public bool Save(Database db, Guid studentId)
        {
            bool result = true;
            try
            {

                foreach (StudentClass s in _list)
                    if (s.IsSavable() == true)
                    {
                        s.Save(db, studentId);
                        if (s.IsNew == true)
                        {
                            result = false;
                            break;
                        }
                    }
            }
            catch (Exception e)
            {
                throw;
            }
            return result;
        }
Exemplo n.º 17
0
 public Program GetById(Guid Id)
 {
     Database db = new Database("Student");
     try
     {
         db.Command.CommandType = CommandType.StoredProcedure;
         db.Command.CommandText = "tblProgramGetById";
         db.Command.Parameters.Add("@Id", SqlDbType.UniqueIdentifier).Value = Id;
         DataTable dt = db.ExecuteQuery();
         if (dt.Rows.Count == 1)
         {
             DataRow dr = dt.Rows[0];
             base.Initialize(dr);
             InitializeBusinessData(dr);
             return this;
         }
         else
             throw new Exception("Program not found");
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Exemplo n.º 18
0
 public Student Register(string firstname,
                         string lastname,
                         string username, 
                         string password,
                         Guid programId)
 {
     Database db = new Database("student");
     try
     {
         db.Command.CommandType = CommandType.StoredProcedure;
         db.Command.CommandText = "tblStudentRegister";
         db.Command.Parameters.Add("@FirstName", SqlDbType.VarChar).Value = firstname;
         db.Command.Parameters.Add("@LastName", SqlDbType.VarChar).Value = lastname;
         db.Command.Parameters.Add("@UserName", SqlDbType.VarChar).Value = username;
         db.Command.Parameters.Add("@Password", SqlDbType.VarChar).Value = password;
         db.Command.Parameters.Add("@ProgramId", SqlDbType.UniqueIdentifier).Value = programId;
         DataTable dt = db.ExecuteQuery();
         if (dt.Rows.Count == 1)
         {
             DataRow dr = dt.Rows[0];
             base.Initialize(dr);
             InitializeBusinessData(dr);
             return this;
         }
         else
             return null;
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Exemplo n.º 19
0
 private Boolean Insert(Database db)
 {
     try
     {
         db.Command.CommandType = CommandType.StoredProcedure;
         db.Command.CommandText = "tblPhoneTypeInsert";
         base.Initialize(db.Command, Guid.Empty);
         db.Command.Parameters.Add("@Type", SqlDbType.VarChar).Value = _Type;
         db.ExecuteNonQuery();
         base.Initialize(db.Command);
         return true;
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Exemplo n.º 20
0
 private Boolean Update(Database db)
 {
     try
     {
         db.Command.Parameters.Clear();
         db.Command.CommandType = CommandType.StoredProcedure;
         db.Command.CommandText = "tblBookUPDATE";
         base.Initialize(db.Command, base.ID);
         db.Command.Parameters.Add("@BookTypeID", SqlDbType.UniqueIdentifier).Value = _BookTypeID;
         db.Command.Parameters.Add("@Title", SqlDbType.VarChar).Value = _Title;
         db.Command.Parameters.Add("@Price", SqlDbType.VarChar).Value = _Price;
         db.Command.Parameters.Add("@BookCover", SqlDbType.Image).Value = PhotoHelper.Photo.FileToByteArray(_PhotoName);
         db.Command.Parameters.Add("@MimeType", SqlDbType.VarChar).Value = Path.GetExtension(_PhotoName);
         db.ExecuteNonQueryWithTransaction();
         base.Initialize(db.Command);
         return true;
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Exemplo n.º 21
0
 private Boolean Delete(Database db)
 {
     try
     {
         db.Command.Parameters.Clear();
         db.Command.CommandType = CommandType.StoredProcedure;
         db.Command.CommandText = "tblBookDELETE";
         base.Initialize(db.Command, base.ID);
         db.ExecuteNonQueryWithTransaction();
         base.Initialize(db.Command);
         return true;
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Exemplo n.º 22
0
        public Book Save()
        {
            Database db = new Database("Books");
            db.BeginTransaction();
            Boolean result = true;

            if (base.IsNew == true && IsSavable() == true)
            {
                result = Insert(db);
            }
            else if (base.Deleted == true)
            {
                result = Delete(db);
            }
            else if (base.IsNew == false && IsSavable() == true)
            {
                result = Update(db);

            }

            base.IsDirty = false;
            base.IsNew = false;

            if (result == true && _ReviewList != null && _ReviewList.IsSavable() == true)
            {
                result = _ReviewList.Save(db, base.ID);
            }

            if (result == true)
            {
                db.EndTransaction();
            }
            else
            {
                db.RollBackTransaction();
            }

            return this;
        }
Exemplo n.º 23
0
        public Book Save(Database db, Guid userID)
        {
            _UserID = userID;
            Boolean result = true;

            if (base.IsNew == true && IsSavable() == true)
            {
                result = Insert(db);

                UserBook ub = new UserBook();
                ub.UserID = userID;
                _UserBooks = new UserBookList();
                _UserBooks.List.Add(ub);
            }
            else if (base.Deleted == true)
            {
                result = Delete(db);
            }
            else if (base.IsNew == false && IsSavable() == true)
            {
                result = Update(db);

            }

            base.IsDirty = false;
            base.IsNew = false;

            if (result == true && _UserBooks != null && _UserBooks.IsSavable() == true)
            {
                result = _UserBooks.Save(db, userID, base.ID);
            }

            return this;
        }
Exemplo n.º 24
0
 public Student ChangePassword(string newpassword)
 {
     Database db = new Database("student");
     try
     {
         db.Command.CommandType = CommandType.StoredProcedure;
         db.Command.CommandText = "tblStudentChangePassword";
         base.Initialize(db.Command, base.Id);
         db.Command.Parameters.Add("@Password", SqlDbType.VarChar).Value = newpassword;
         db.ExecuteNonQuery();
         base.Initialize(db.Command);
         return this;
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Exemplo n.º 25
0
 public Student Login(string username, string password)
 {
     Database db = new Database("student");
     try
     {
         db.Command.CommandType = CommandType.StoredProcedure;
         db.Command.CommandText = "tblStudentLogin";
         db.Command.Parameters.Add("@UserName", SqlDbType.VarChar).Value = username;
         db.Command.Parameters.Add("@Password", SqlDbType.VarChar).Value = password;
         DataTable dt = db.ExecuteQuery();
         if (dt.Rows.Count == 1)
         {
             DataRow dr = dt.Rows[0];
             base.Initialize(dr);
             InitializeBusinessData(dr);
             return this;
         }
         else
             throw new ApplicationException("Invalid Login");
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Exemplo n.º 26
0
 public Boolean Recover(string firstname,
                        string lastname,
                        string username,
                        string emailaddress)
 {
     Database db = new Database("student");
     try
     {
         db.Command.CommandType = CommandType.StoredProcedure;
         db.Command.CommandText = "tblStudentRecover";
         db.Command.Parameters.Add("@FirstName", SqlDbType.VarChar).Value = firstname;
         db.Command.Parameters.Add("@LastName", SqlDbType.VarChar).Value = lastname;
         db.Command.Parameters.Add("@UserName", SqlDbType.VarChar).Value = username;
         DataTable dt = db.ExecuteQuery();
         if (dt.Rows.Count == 1)
         {
             DataRow dr = dt.Rows[0];
             Email email = new Email();
             email.Host = "smtp.gmail.com";
             email.Port = 587;
             email.Username = "******";
             email.Password = "******";
             email.To = emailaddress;
             email.From = "*****@*****.**";
             email.Subject = "Password Recovery";
             email.Body =
                 String.Format("Your password is {0}",
                 dr["password"].ToString());
             email.Send();
             return true;
         }
         else
             return false;
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Exemplo n.º 27
0
 private Boolean Update(Database db)
 {
     try
     {
         db.Command.CommandType = CommandType.StoredProcedure;
         db.Command.CommandText = "tblProgramUpdate";
         base.Initialize(db.Command, base.Id);
         db.Command.Parameters.Add("@Name", SqlDbType.VarChar).Value = _Name;
         db.ExecuteNonQuery();
         base.Initialize(db.Command);
         return true;
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Exemplo n.º 28
0
        public Student Save()
        {
            Database db = new Database("student");
            try
            {

                db.BeginTransaction();

                Boolean result = true;
                if (base.IsNew == true && IsSavable() == true)
                {
                    result = Insert(db);
                }
                else if (base.Deleted == true)
                {
                    result = Delete(db);
                }
                else if (base.IsNew == false && IsSavable() == true)
                {
                    result = Update(db);
                }
                base.IsDirty = false;
                base.IsNew = false;

                //SAVE THE CHILDREN
                if (result == true && _comments != null && _comments.IsSavable() == true)
                {
                    result = _comments.Save(db, base.Id);
                }

                if (result == true && _emails != null && _emails.IsSavable() == true)
                {
                    result = _emails.Save(db, base.Id);
                }
                if (result == true && _phones != null && _phones.IsSavable() == true)
                {
                    result = _phones.Save(db, base.Id);
                }
                if (result == true && _addresses != null && _addresses.IsSavable() == true)
                {
                    result = _addresses.Save(db, base.Id);
                }
                if (result == true && _classes != null && _classes.IsSavable() == true)
                {
                    result = _classes.Save(db, base.Id);
                }
                if (result == true)
                {
                    db.EndTransaction();
                }
                else
                {
                    db.RollBackTransaction();
                }
            }
            catch (Exception e)
            {
                db.RollBackTransaction();
                throw;
            }
            return this;
        }
Exemplo n.º 29
0
        public Program Save()
        {
            Database db = new Database("student");
            Boolean result = false;
            if (base.IsNew == true && IsSavable() == true)
            {
                result = Insert(db);
            }
            else if (base.Deleted == true)
            {
                result = Delete(db);
            }
            else if (base.IsNew == false && IsSavable() == true)
            {
                result = Update(db);
            }
            base.IsDirty = false;
            base.IsNew = false;

            return this;
        }
Exemplo n.º 30
0
 private Boolean Update(Database db)
 {
     try
     {
         db.Command.CommandType = CommandType.StoredProcedure;
         db.Command.CommandText = "tblStudentUpdate";
         base.Initialize(db.Command, base.Id);
         db.Command.Parameters.Add("@FirstName", SqlDbType.VarChar).Value = _FirstName;
         db.Command.Parameters.Add("@LastName", SqlDbType.VarChar).Value = _LastName;
         db.Command.Parameters.Add("@UserName", SqlDbType.VarChar).Value = _UserName;
         db.Command.Parameters.Add("@Password", SqlDbType.VarChar).Value = _Password;
         db.ExecuteNonQueryWithTransaction();
         base.Initialize(db.Command);
         return true;
     }
     catch (Exception ex)
     {
         throw;
     }
 }