Esempio n. 1
0
 public int RegistrationRules(User user, Campus campus)
 {
     try
     {
         if (user.Name.Equals(string.Empty))
             return 1;
         else if (user.LastName.Equals(string.Empty))
             return 2;
         else if (user.Username.Equals(string.Empty))
             return 3;
         else if (user.Password.Equals(string.Empty))
             return 4;
         else if (user.UniversityCard.Equals(string.Empty))
             return 6;
         else if (campus.Id.Equals(string.Empty))
             return 7;
         else if (campus.Name.Equals(string.Empty))
             return 8;
         else
         {
             userData.InsertUser(user, campus);
             return 0;
         }
     }
     catch (SqlException)
     {
         return 5;
     }
 }
Esempio n. 2
0
 public void InsertCampus(Campus campus)
 {
     SqlConnection connection = ManageDatabaseConnection("Open");
     using (SqlCommand insert = new SqlCommand(@"InsertCampus", connection))
     {
         insert.CommandType = CommandType.StoredProcedure;
         insert.Parameters.Add("@Name", SqlDbType.VarChar).Value = campus.Name;
         insert.ExecuteNonQuery();
     }
     connection = ManageDatabaseConnection("Close");
 }
Esempio n. 3
0
 protected Campus CreateCampus()
 {
     try
     {
         Campus campus = new Campus();
         campus.Name = textboxCampus.Value;
         return campus;
     }
     catch (FormatException)
     {
         buttonStyle.buttonStyleWhite(buttonErrors, "Invalid data, please check it or contact with us.");
         return null;
     }
 }
Esempio n. 4
0
 public int InsertCampus(Campus campus)
 {
     try
     {
         if (campus.Name.Equals(string.Empty))
             return 1;
         else
         {
             campusData.InsertCampus(campus);
             return 0;
         }
     }
     catch (SqlException)
     {
         return 2;
     }
 }
Esempio n. 5
0
 public int UpdateCampus(Campus campus)
 {
     try
     {
         if (campus.Name.Equals(string.Empty))
         {
             return 1;
         }
         else
         {
             campusData.UpdateCampus(campus);
             return 0;
         }
     }
     catch (SqlException)
     {
         return 2;
     }
 }
Esempio n. 6
0
 public void InsertUser(User user, Campus campus)
 {
     SqlConnection connection = ManageDatabaseConnection("Open");
     using (SqlCommand insert = new SqlCommand(@"InsertUser", connection))
     {
         insert.CommandType = CommandType.StoredProcedure;
         insert.Parameters.Add("@Name", SqlDbType.VarChar).Value = user.Name;
         insert.Parameters.Add("@LastName", SqlDbType.VarChar).Value = user.LastName;
         insert.Parameters.Add("@UserName", SqlDbType.VarChar).Value = user.Username;
         insert.Parameters.Add("@Password", SqlDbType.VarChar).Value = EncryptPassword(user.Password);
         insert.Parameters.Add("@RoleId", SqlDbType.Int).Value = user.Role.Id;
         insert.Parameters.Add("@RoleName", SqlDbType.VarChar).Value = user.Role.Name;
         insert.Parameters.Add("@UniversityCard", SqlDbType.Int).Value = user.UniversityCard;
         insert.Parameters.Add("@CampusId", SqlDbType.Int).Value = campus.Id;
         insert.Parameters.Add("@CampusName", SqlDbType.VarChar).Value = campus.Name;
         insert.ExecuteNonQuery();
     }
     connection = ManageDatabaseConnection("Close");
 }
Esempio n. 7
0
 protected Campus CreateCampus()
 {
     try
     {
         Campus campus = new Campus();
         if (hiddenCampusValue.Value.Equals(string.Empty))
         {
             campus.Id = Convert.ToInt32(selectCampus.Items[0].Value);
             campus.Name = selectCampus.Items[0].Text;
         }
         else
         {
             campus.Id = Convert.ToInt32(hiddenCampusValue.Value);
             campus.Name = selectCampus.Items.FindByValue(hiddenCampusValue.Value).Text;
         }
         return campus;
     }
     catch (FormatException)
     {
         buttonStyle.buttonStyleRed(buttonErrors, "An error ocurred adding the user to a campus.");
         return null;
     }
 }
Esempio n. 8
0
        protected void UpdateCampus(Campus campus)
        {
            if (campus != null)
            {
                switch (campusRules.UpdateCampus(campus))
                {
                    case 0:
                        textboxCampus.Value = "";
                        buttonStyle.buttonStyleBlue(buttonErrors, "Campus updated successful.");
                        break;
                    case 1:
                        buttonStyle.buttonStyleWhite(buttonErrors, "Campus name field is empty.");
                        break;
                    case 2:
                        buttonStyle.buttonStyleRed(buttonErrors, "An error ocurred updating the campus, please check data or contact we us.");
                        break;

                }
            }
        }
Esempio n. 9
0
 protected void InsertUser(User user, Campus campus)
 {
     if (user != null)
     {
         if (campus != null)
         {
             UserBussinessRules userBussinessRules = new UserBussinessRules();
             switch (userBussinessRules.RegistrationRules(user, campus))
             {
                 case 0:
                     textboxName.Value = string.Empty;
                     textboxLastName.Value = string.Empty;
                     textboxUsernameR.Value = string.Empty;
                     textboxPasswordR.Value = string.Empty;
                     textboxUniversityCard.Value = string.Empty;
                     buttonStyle.buttonStyleBlue(buttonErrors, "User registered sucessful.");
                     break;
                 case 1:
                     buttonStyle.buttonStyleWhite(buttonErrors, "The name field is empty.");
                     break;
                 case 2:
                     buttonStyle.buttonStyleRed(buttonErrors, "The lastname field is empty.");
                     break;
                 case 3:
                     buttonStyle.buttonStyleWhite(buttonErrors, "The username field is empty.");
                     break;
                 case 4:
                     buttonStyle.buttonStyleRed(buttonErrors, "The password field is empty.");
                     break;
                 case 5:
                     buttonStyle.buttonStyleWhite(buttonErrors, "An error ocurred during your registration.");
                     break;
                 case 6:
                     buttonStyle.buttonStyleRed(buttonErrors, "The university card field is empty.");
                     break;
                 case 7:
                     buttonStyle.buttonStyleWhite(buttonErrors, "The campus id field is empty.");
                     break;
                 case 8:
                     buttonStyle.buttonStyleRed(buttonErrors, "The campus name field is empty.");
                     break;
             }
         }
     }
 }
Esempio n. 10
0
 public void UpdateCampus(Campus campus)
 {
     connection = ManageDatabaseConnection("Open");
     using (SqlCommand update = new SqlCommand(@"UpdateCampus", connection))
     {
         update.CommandType = CommandType.StoredProcedure;
         update.Parameters.Add("@Id", SqlDbType.Int).Value = campus.Id;
         update.Parameters.Add("@Name", SqlDbType.VarChar).Value = campus.Name;
         update.ExecuteNonQuery();
     }
     connection = ManageDatabaseConnection("Close");
 }