コード例 #1
0
        protected Model.Flat getAdminFlat(Model.Building apartment, Model.User user)
        {
            connection.Open();
            Model.Flat adminFlat       = null;
            string     selectAdminFlat = "SELECT * FROM " + Util.Tables.TABLE_FLATS.TBL_FLATS + " WHERE " + Util.Tables.TABLE_FLATS.KEY_USER_ID + " = '" + user.getID() + "'";

            using (SqlCommand getFlatCommand = new SqlCommand(selectAdminFlat, connection))
            {
                using (SqlDataReader reader = getFlatCommand.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        //  int  l = (Int32)apartmentReader["flatsPerFloor"];
                        try
                        {
                            adminFlat = new Model.Flat(Convert.ToInt32(reader[TABLE_FLATS.KEY_FLAT_NUMBER]), reader[TABLE_FLATS.KEY_RESIDENT_NAME].ToString(), reader[TABLE_FLATS.KEY_EMAIL].ToString(), reader[TABLE_FLATS.KEY_MOBILE_NUMBER].ToString(), Convert.ToInt32(reader[TABLE_FLATS.KEY_DUES]), Convert.ToInt32(reader[TABLE_FLATS.KEY_MONTHLYFEE]), Convert.ToInt32(reader[TABLE_FLATS.KEY_IS_MANAGER]), apartment);
                        }

                        catch (InvalidCastException cs)
                        {
                            adminFlat = new Model.Flat(Convert.ToInt32(reader[TABLE_FLATS.KEY_FLAT_NUMBER]), reader[TABLE_FLATS.KEY_RESIDENT_NAME].ToString(), reader[TABLE_FLATS.KEY_EMAIL].ToString(), reader[TABLE_FLATS.KEY_MOBILE_NUMBER].ToString(), 0, 0, Convert.ToInt32(reader[TABLE_FLATS.KEY_IS_MANAGER]), apartment);
                        }
                    }
                }
            }
            connection.Close();
            return(adminFlat);
        }
コード例 #2
0
ファイル: Controller.cs プロジェクト: abdullah-raja/DBProject
        protected void getAllFlats(Building apartment)
        {
            connection.Open();
            string selectQuery = "SELECT * FROM " + TABLE_FLATS.TBL_FLATS + " WHERE " + TABLE_BUILDING.KEY_APPARTMENT_ID + " = '" + Guid.Parse(apartment.getID()) + "'";

            using (SqlCommand command = new SqlCommand(selectQuery, connection))
            {
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    for (int i = 0; i < apartment.getNoOfFloors(); i++)
                    {
                        for (int j = 0; j < apartment.getFlatsPerFloor(); j++)
                        {
                            if (reader.Read())
                            {
                                try
                                {
                                    Flat newFlat = new Model.Flat(Convert.ToInt32(reader[TABLE_FLATS.KEY_FLAT_NUMBER]), reader[TABLE_FLATS.KEY_RESIDENT_NAME].ToString(), reader[TABLE_FLATS.KEY_EMAIL].ToString(), reader[TABLE_FLATS.KEY_MOBILE_NUMBER].ToString(), Convert.ToInt32(reader[TABLE_FLATS.KEY_DUES]), Convert.ToInt32(reader[TABLE_FLATS.KEY_MONTHLYFEE]), Convert.ToInt32(reader[TABLE_FLATS.KEY_IS_MANAGER]), apartment);

                                    apartment.setFlatAt(newFlat.getFlatNumber(), newFlat);
                                    if (newFlat.getIsManager() == 3)
                                    {
                                        apartment.makeAdmin(newFlat.getFlatNumber());
                                    }
                                }

                                catch
                                {
                                    string name;
                                    var    r = reader[TABLE_FLATS.KEY_RESIDENT_NAME].Equals(DBNull.Value) ? name = "" : name = reader[TABLE_FLATS.KEY_RESIDENT_NAME].ToString();

                                    string email;
                                    r = reader[TABLE_FLATS.KEY_EMAIL].Equals(DBNull.Value) ? email = "" : email = reader[TABLE_FLATS.KEY_EMAIL].ToString();

                                    string mobile;
                                    r = reader[TABLE_FLATS.KEY_MOBILE_NUMBER].Equals(DBNull.Value) ? mobile = "" : mobile = reader[TABLE_FLATS.KEY_MOBILE_NUMBER].ToString();

                                    int dues;
                                    var a = reader[TABLE_FLATS.KEY_DUES].Equals(DBNull.Value) ? dues = 0 : dues = (int)reader[TABLE_FLATS.KEY_DUES];

                                    int fee;
                                    a = reader[TABLE_FLATS.KEY_MONTHLYFEE].Equals(DBNull.Value) ? fee = 0 : fee = (int)reader[TABLE_FLATS.KEY_MONTHLYFEE];

                                    Flat newFlat = new Model.Flat(Convert.ToInt32(reader[TABLE_FLATS.KEY_FLAT_NUMBER]), name, email, mobile, dues, fee, Convert.ToInt32(reader[TABLE_FLATS.KEY_IS_MANAGER]), apartment);

                                    apartment.setFlatAt(newFlat.getFlatNumber(), newFlat);
                                    if (newFlat.getIsManager() == 3)
                                    {
                                        apartment.makeAdmin(newFlat.getFlatNumber());
                                    }
                                }
                            }
                        }
                    }
                }
            }

            connection.Close();
        }
コード例 #3
0
        public FlatDTO(Model.Flat flat)
        {
            FlatMembers = new List <UserDTO>();

            if (flat != null)
            {
                foreach (Model.User user in flat.Users)
                {
                    UserDTO userDTO = new UserDTO(user);
                    FlatMembers.Add(userDTO);
                }
            }
        }
コード例 #4
0
        override public void signIn(Model.User user, Views.SignUp view, string enteredEmail, string enteredPassword, Model.Building apartment)
        {
            bool   passwordMatched = false;
            string selectAllQuery  = "SELECT userID, userFirstName, userLastName, userStatus, userMobileNumber, apartmentID FROM " + TABLE_NAME + " WHERE userEmail = '" + enteredEmail + "'";


            connection.Open();
            string selectQuery = "SELECT password FROM " + TABLE_NAME + " WHERE userEmail = '" + enteredEmail + "'";

            using (SqlCommand command = new SqlCommand(selectQuery, connection)) // getting password against entered email
            {
                using (SqlDataReader dr = command.ExecuteReader())
                {
                    if (dr.Read())
                    {
                        passwordMatched = enteredPassword == Model.User.encodePassword(dr["password"].ToString()); // if password matches
                    }
                    else
                    {
                        view.logInInFailed(false);
                        return;
                    }
                }
            }

            if (passwordMatched)
            {
                using (SqlCommand getUserCommand = new SqlCommand(selectAllQuery, connection))
                {
                    using (SqlDataReader dr2 = getUserCommand.ExecuteReader())
                    {
                        while (dr2.Read())
                        {
                            bool isAdmin;
                            if (dr2["userStatus"].ToString() == "Admin")
                            {
                                isAdmin = true;
                            }

                            else
                            {
                                isAdmin = false;
                            }

                            user.setAllValues(dr2["userID"].ToString(), dr2["userFirstName"].ToString(), dr2["userLastName"].ToString(), enteredEmail, enteredPassword, isAdmin, dr2["userMobileNumber"].ToString());

                            if (dr2["apartmentID"].ToString() != "") // user have already joined/created a building
                            {
                                user.setApartmentID(dr2["apartmentID"].ToString());
                            }

                            else // user have to join or create a building first
                            {
                                view.signUpSuccessful(isAdmin);
                                return;
                            }
                        }
                    }
                }

                if (user.getApartmentID() != null) // getting apartment details
                {
                    string selectApartmentQuery = "SELECT * FROM tbl_Buildings WHERE apartmentID = " + "'" + Guid.Parse(user.getApartmentID()) + "'";
                    using (SqlCommand getApartmentCommand = new SqlCommand(selectApartmentQuery, connection))
                    {
                        using (SqlDataReader apartmentReader = getApartmentCommand.ExecuteReader())
                        {
                            while (apartmentReader.Read())
                            {
                                //  int  l = (Int32)apartmentReader["flatsPerFloor"];
                                apartment.setAllValues(user.getApartmentID(), apartmentReader["apartmentName"].ToString(), (Int32)apartmentReader["numberOfFloors"], (Int32)apartmentReader["flatsPerFloor"], apartmentReader["code"].ToString(), user, 0, (int)apartmentReader["balance"]);
                            }
                        }
                    }

                    connection.Close();
                    this.getAllFlats(apartment);
                    Model.Flat adminFlat = getAdminFlat(apartment, user);
                    //apartment.makeAdmin(adminFlat.getFlatNumber());
                    user.setFlat(adminFlat);
                }

                else
                {
                    apartment = null;
                }

                view.logInSuccessful();
            }

            else // password incorrect
            {
                view.logInInFailed(true);
            }
        }