Example #1
0
        public bool Update(StaffBase mClass)
        {
            bool          mResult = false;
            SqlConnection con     = new SqlConnection(ConfigurationManager.ConnectionStrings["csSwim"].ConnectionString);
            string        sql     = "UPDATE Staff SET FirstName = @FirstName, LastName = @LastName, Phone = @Phone, Mobile = @Mobile, Email = @Email, Password = @Password, IsActive = @IsActive " +
                                    "WHERE StaffId = @StaffId;";
            SqlCommand cmd = new SqlCommand(sql, con);

            cmd.Parameters.Add("@StaffId", SqlDbType.Int).Value       = mClass.StaffId;
            cmd.Parameters.Add("@FirstName", SqlDbType.VarChar).Value = mClass.FirstName;
            cmd.Parameters.Add("@LastName", SqlDbType.VarChar).Value  = mClass.LastName;
            cmd.Parameters.Add("@Phone", SqlDbType.VarChar).Value     = mClass.Phone;
            cmd.Parameters.Add("@Mobile", SqlDbType.VarChar).Value    = mClass.Mobile;
            cmd.Parameters.Add("@Email", SqlDbType.VarChar).Value     = mClass.Email;
            cmd.Parameters.Add("@Password", SqlDbType.VarChar).Value  = mClass.Password;
            cmd.Parameters.Add("@IsActive", SqlDbType.Bit).Value      = mClass.IsActive;
            try
            {
                con.Open();
                cmd.ExecuteNonQuery();
                mResult = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                con.Close();
                con.Dispose();
                cmd.Dispose();
            }
            return(mResult);
        }
Example #2
0
        public int Add(StaffBase mClass)
        {
            int           StaffId = 0;
            SqlConnection con     = new SqlConnection(ConfigurationManager.ConnectionStrings["csSwim"].ConnectionString);
            string        sql     = "INSERT INTO Staff (FirstName, LastName, Phone, Mobile, Email, Password, IsActive)" +
                                    " VALUES (@FirstName, @LastName, @Phone, @Mobile, @Email, @Password, @IsActive)" +
                                    " SELECT SCOPE_IDENTITY()";
            SqlCommand cmd = new SqlCommand(sql, con);

            cmd.Parameters.Add("@FirstName", SqlDbType.VarChar).Value = mClass.FirstName;
            cmd.Parameters.Add("@LastName", SqlDbType.VarChar).Value  = mClass.LastName;
            cmd.Parameters.Add("@Phone", SqlDbType.VarChar).Value     = mClass.Phone;
            cmd.Parameters.Add("@Mobile", SqlDbType.VarChar).Value    = mClass.Mobile;
            cmd.Parameters.Add("@Email", SqlDbType.VarChar).Value     = mClass.Email;
            cmd.Parameters.Add("@Password", SqlDbType.VarChar).Value  = mClass.Password;
            cmd.Parameters.Add("@IsActive", SqlDbType.Bit).Value      = mClass.IsActive;
            try
            {
                con.Open();
                StaffId = Convert.ToInt32(cmd.ExecuteScalar());
            }
            catch (Exception ex)
            {
                StaffId = -1;
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                con.Close();
                con.Dispose();
                cmd.Dispose();
            }
            return(StaffId);
        }
Example #3
0
        private StaffBase Get(string WhereClause, params SqlParameter[] commandparameters)
        {
            StaffBase     mClass = null;
            SqlConnection con    = new SqlConnection(ConfigurationManager.ConnectionStrings["csSwim"].ConnectionString);
            string        sql    = "SELECT db.StaffId, db.FirstName, db.LastName, db.Phone, db.Mobile, db.Email, db.Password, db.IsActive, db.Created " +
                                   "FROM Staff db  " + WhereClause;
            SqlCommand    cmd = new SqlCommand(sql, con);
            SqlDataReader rdr = null;

            foreach (var parameter in commandparameters)
            {
                cmd.Parameters.Add(parameter);
            }
            try
            {
                con.Open();
                rdr = cmd.ExecuteReader();
                if (rdr.Read())
                {
                    mClass = LoadRow(rdr);
                }
            }
            catch (Exception ex)
            {
                mClass = null;
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                con.Close();
                con.Dispose();
                cmd.Dispose();
            }
            return(mClass);
        }
Example #4
0
 private void Populate(StaffBase mClass)
 {
     this.StaffId   = mClass.StaffId;
     this.FirstName = mClass.FirstName;
     this.LastName  = mClass.LastName;
     this.Phone     = mClass.Phone;
     this.Mobile    = mClass.Mobile;
     this.Email     = mClass.Email;
     this.Password  = mClass.Password;
     this.IsActive  = mClass.IsActive;
     this.Created   = mClass.Created;
 }